{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ViewPatterns #-}
module Stack.Types.SetupInfo
( SetupInfo (..)
) where
import Data.Aeson.Types ( FromJSON (..) )
import Data.Aeson.WarningParser
( WithJSONWarnings, (..:?), (..!=), jsonSubWarningsT
, jsonSubWarningsTT, withObjectWarnings
)
import qualified Data.Map as Map
import Stack.Prelude
import Stack.Types.DownloadInfo ( DownloadInfo )
import Stack.Types.VersionedDownloadInfo ( VersionedDownloadInfo )
import Stack.Types.GHCDownloadInfo ( GHCDownloadInfo )
data SetupInfo = SetupInfo
{ SetupInfo -> Maybe DownloadInfo
siSevenzExe :: Maybe DownloadInfo
, SetupInfo -> Maybe DownloadInfo
siSevenzDll :: Maybe DownloadInfo
, SetupInfo -> Map Text VersionedDownloadInfo
siMsys2 :: Map Text VersionedDownloadInfo
, SetupInfo -> Map Text (Map Version GHCDownloadInfo)
siGHCs :: Map Text (Map Version GHCDownloadInfo)
, SetupInfo -> Map Text (Map Version DownloadInfo)
siStack :: Map Text (Map Version DownloadInfo)
}
deriving Int -> SetupInfo -> ShowS
[SetupInfo] -> ShowS
SetupInfo -> String
(Int -> SetupInfo -> ShowS)
-> (SetupInfo -> String)
-> ([SetupInfo] -> ShowS)
-> Show SetupInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SetupInfo -> ShowS
showsPrec :: Int -> SetupInfo -> ShowS
$cshow :: SetupInfo -> String
show :: SetupInfo -> String
$cshowList :: [SetupInfo] -> ShowS
showList :: [SetupInfo] -> ShowS
Show
instance FromJSON (WithJSONWarnings SetupInfo) where
parseJSON :: Value -> Parser (WithJSONWarnings SetupInfo)
parseJSON = String
-> (Object -> WarningParser SetupInfo)
-> Value
-> Parser (WithJSONWarnings SetupInfo)
forall a.
String
-> (Object -> WarningParser a)
-> Value
-> Parser (WithJSONWarnings a)
withObjectWarnings String
"SetupInfo" ((Object -> WarningParser SetupInfo)
-> Value -> Parser (WithJSONWarnings SetupInfo))
-> (Object -> WarningParser SetupInfo)
-> Value
-> Parser (WithJSONWarnings SetupInfo)
forall a b. (a -> b) -> a -> b
$ \Object
o -> do
Maybe DownloadInfo
siSevenzExe <- WarningParser (Maybe (WithJSONWarnings DownloadInfo))
-> WarningParser (Maybe DownloadInfo)
forall (t :: * -> *) a.
Traversable t =>
WarningParser (t (WithJSONWarnings a)) -> WarningParser (t a)
jsonSubWarningsT (Object
o Object
-> Text -> WarningParser (Maybe (WithJSONWarnings DownloadInfo))
forall a. FromJSON a => Object -> Text -> WarningParser (Maybe a)
..:? Text
"sevenzexe-info")
Maybe DownloadInfo
siSevenzDll <- WarningParser (Maybe (WithJSONWarnings DownloadInfo))
-> WarningParser (Maybe DownloadInfo)
forall (t :: * -> *) a.
Traversable t =>
WarningParser (t (WithJSONWarnings a)) -> WarningParser (t a)
jsonSubWarningsT (Object
o Object
-> Text -> WarningParser (Maybe (WithJSONWarnings DownloadInfo))
forall a. FromJSON a => Object -> Text -> WarningParser (Maybe a)
..:? Text
"sevenzdll-info")
Map Text VersionedDownloadInfo
siMsys2 <- WarningParser (Map Text (WithJSONWarnings VersionedDownloadInfo))
-> WarningParser (Map Text VersionedDownloadInfo)
forall (t :: * -> *) a.
Traversable t =>
WarningParser (t (WithJSONWarnings a)) -> WarningParser (t a)
jsonSubWarningsT (Object
o Object
-> Text
-> WarningParser
(Maybe (Map Text (WithJSONWarnings VersionedDownloadInfo)))
forall a. FromJSON a => Object -> Text -> WarningParser (Maybe a)
..:? Text
"msys2" WarningParser
(Maybe (Map Text (WithJSONWarnings VersionedDownloadInfo)))
-> Map Text (WithJSONWarnings VersionedDownloadInfo)
-> WarningParser
(Map Text (WithJSONWarnings VersionedDownloadInfo))
forall a. WarningParser (Maybe a) -> a -> WarningParser a
..!= Map Text (WithJSONWarnings VersionedDownloadInfo)
forall a. Monoid a => a
mempty)
((Map (CabalString Version) GHCDownloadInfo
-> Map Version GHCDownloadInfo)
-> Map Text (Map (CabalString Version) GHCDownloadInfo)
-> Map Text (Map Version GHCDownloadInfo)
forall a b. (a -> b) -> Map Text a -> Map Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map (CabalString Version) GHCDownloadInfo
-> Map Version GHCDownloadInfo
forall a v. Map (CabalString a) v -> Map a v
unCabalStringMap -> Map Text (Map Version GHCDownloadInfo)
siGHCs) <-
WarningParser
(Map
Text
(Map (CabalString Version) (WithJSONWarnings GHCDownloadInfo)))
-> WarningParser
(Map Text (Map (CabalString Version) GHCDownloadInfo))
forall (t :: * -> *) (u :: * -> *) a.
(Traversable t, Traversable u) =>
WarningParser (u (t (WithJSONWarnings a)))
-> WarningParser (u (t a))
jsonSubWarningsTT (Object
o Object
-> Text
-> WarningParser
(Maybe
(Map
Text
(Map (CabalString Version) (WithJSONWarnings GHCDownloadInfo))))
forall a. FromJSON a => Object -> Text -> WarningParser (Maybe a)
..:? Text
"ghc" WarningParser
(Maybe
(Map
Text
(Map (CabalString Version) (WithJSONWarnings GHCDownloadInfo))))
-> Map
Text (Map (CabalString Version) (WithJSONWarnings GHCDownloadInfo))
-> WarningParser
(Map
Text
(Map (CabalString Version) (WithJSONWarnings GHCDownloadInfo)))
forall a. WarningParser (Maybe a) -> a -> WarningParser a
..!= Map
Text (Map (CabalString Version) (WithJSONWarnings GHCDownloadInfo))
forall a. Monoid a => a
mempty)
((Map (CabalString Version) DownloadInfo
-> Map Version DownloadInfo)
-> Map Text (Map (CabalString Version) DownloadInfo)
-> Map Text (Map Version DownloadInfo)
forall a b. (a -> b) -> Map Text a -> Map Text b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map (CabalString Version) DownloadInfo -> Map Version DownloadInfo
forall a v. Map (CabalString a) v -> Map a v
unCabalStringMap -> Map Text (Map Version DownloadInfo)
siStack) <-
WarningParser
(Map
Text (Map (CabalString Version) (WithJSONWarnings DownloadInfo)))
-> WarningParser
(Map Text (Map (CabalString Version) DownloadInfo))
forall (t :: * -> *) (u :: * -> *) a.
(Traversable t, Traversable u) =>
WarningParser (u (t (WithJSONWarnings a)))
-> WarningParser (u (t a))
jsonSubWarningsTT (Object
o Object
-> Text
-> WarningParser
(Maybe
(Map
Text (Map (CabalString Version) (WithJSONWarnings DownloadInfo))))
forall a. FromJSON a => Object -> Text -> WarningParser (Maybe a)
..:? Text
"stack" WarningParser
(Maybe
(Map
Text (Map (CabalString Version) (WithJSONWarnings DownloadInfo))))
-> Map
Text (Map (CabalString Version) (WithJSONWarnings DownloadInfo))
-> WarningParser
(Map
Text (Map (CabalString Version) (WithJSONWarnings DownloadInfo)))
forall a. WarningParser (Maybe a) -> a -> WarningParser a
..!= Map
Text (Map (CabalString Version) (WithJSONWarnings DownloadInfo))
forall a. Monoid a => a
mempty)
SetupInfo -> WarningParser SetupInfo
forall a. a -> WriterT WarningParserMonoid Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SetupInfo {Maybe DownloadInfo
Map Text (Map Version DownloadInfo)
Map Text (Map Version GHCDownloadInfo)
Map Text VersionedDownloadInfo
siSevenzExe :: Maybe DownloadInfo
siSevenzDll :: Maybe DownloadInfo
siMsys2 :: Map Text VersionedDownloadInfo
siGHCs :: Map Text (Map Version GHCDownloadInfo)
siStack :: Map Text (Map Version DownloadInfo)
siSevenzExe :: Maybe DownloadInfo
siSevenzDll :: Maybe DownloadInfo
siMsys2 :: Map Text VersionedDownloadInfo
siGHCs :: Map Text (Map Version GHCDownloadInfo)
siStack :: Map Text (Map Version DownloadInfo)
..}
instance Semigroup SetupInfo where
SetupInfo
l <> :: SetupInfo -> SetupInfo -> SetupInfo
<> SetupInfo
r =
SetupInfo
{ siSevenzExe :: Maybe DownloadInfo
siSevenzExe = SetupInfo -> Maybe DownloadInfo
siSevenzExe SetupInfo
l Maybe DownloadInfo -> Maybe DownloadInfo -> Maybe DownloadInfo
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> SetupInfo -> Maybe DownloadInfo
siSevenzExe SetupInfo
r
, siSevenzDll :: Maybe DownloadInfo
siSevenzDll = SetupInfo -> Maybe DownloadInfo
siSevenzDll SetupInfo
l Maybe DownloadInfo -> Maybe DownloadInfo -> Maybe DownloadInfo
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> SetupInfo -> Maybe DownloadInfo
siSevenzDll SetupInfo
r
, siMsys2 :: Map Text VersionedDownloadInfo
siMsys2 = SetupInfo -> Map Text VersionedDownloadInfo
siMsys2 SetupInfo
l Map Text VersionedDownloadInfo
-> Map Text VersionedDownloadInfo -> Map Text VersionedDownloadInfo
forall a. Semigroup a => a -> a -> a
<> SetupInfo -> Map Text VersionedDownloadInfo
siMsys2 SetupInfo
r
, siGHCs :: Map Text (Map Version GHCDownloadInfo)
siGHCs = (Map Version GHCDownloadInfo
-> Map Version GHCDownloadInfo -> Map Version GHCDownloadInfo)
-> Map Text (Map Version GHCDownloadInfo)
-> Map Text (Map Version GHCDownloadInfo)
-> Map Text (Map Version GHCDownloadInfo)
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith Map Version GHCDownloadInfo
-> Map Version GHCDownloadInfo -> Map Version GHCDownloadInfo
forall a. Semigroup a => a -> a -> a
(<>) (SetupInfo -> Map Text (Map Version GHCDownloadInfo)
siGHCs SetupInfo
l) (SetupInfo -> Map Text (Map Version GHCDownloadInfo)
siGHCs SetupInfo
r)
, siStack :: Map Text (Map Version DownloadInfo)
siStack = (Map Version DownloadInfo
-> Map Version DownloadInfo -> Map Version DownloadInfo)
-> Map Text (Map Version DownloadInfo)
-> Map Text (Map Version DownloadInfo)
-> Map Text (Map Version DownloadInfo)
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith Map Version DownloadInfo
-> Map Version DownloadInfo -> Map Version DownloadInfo
forall a. Semigroup a => a -> a -> a
(<>) (SetupInfo -> Map Text (Map Version DownloadInfo)
siStack SetupInfo
l) (SetupInfo -> Map Text (Map Version DownloadInfo)
siStack SetupInfo
r) }
instance Monoid SetupInfo where
mempty :: SetupInfo
mempty =
SetupInfo
{ siSevenzExe :: Maybe DownloadInfo
siSevenzExe = Maybe DownloadInfo
forall a. Maybe a
Nothing
, siSevenzDll :: Maybe DownloadInfo
siSevenzDll = Maybe DownloadInfo
forall a. Maybe a
Nothing
, siMsys2 :: Map Text VersionedDownloadInfo
siMsys2 = Map Text VersionedDownloadInfo
forall k a. Map k a
Map.empty
, siGHCs :: Map Text (Map Version GHCDownloadInfo)
siGHCs = Map Text (Map Version GHCDownloadInfo)
forall k a. Map k a
Map.empty
, siStack :: Map Text (Map Version DownloadInfo)
siStack = Map Text (Map Version DownloadInfo)
forall k a. Map k a
Map.empty
}
mappend :: SetupInfo -> SetupInfo -> SetupInfo
mappend = SetupInfo -> SetupInfo -> SetupInfo
forall a. Semigroup a => a -> a -> a
(<>)