{-# LANGUAGE ApplicativeDo #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} module HaskellWorks.CabalCache.Types ( CompilerId, PackageId, PackageName, CompilerContext(..), Components(..), PlanJson(..), Package(..), Lib(..), ) where import Data.Aeson (FromJSON(parseJSON), (.!=), (.:), (.:?)) import Data.Text (Text) import GHC.Generics (Generic) import Prelude hiding (id) import qualified Data.Aeson as J type CompilerId = Text type PackageId = Text type PackageName = Text data PlanJson = PlanJson { PlanJson -> CompilerId compilerId :: CompilerId , PlanJson -> [Package] installPlan :: [Package] } deriving (PlanJson -> PlanJson -> Bool (PlanJson -> PlanJson -> Bool) -> (PlanJson -> PlanJson -> Bool) -> Eq PlanJson forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a $c== :: PlanJson -> PlanJson -> Bool == :: PlanJson -> PlanJson -> Bool $c/= :: PlanJson -> PlanJson -> Bool /= :: PlanJson -> PlanJson -> Bool Eq, Int -> PlanJson -> ShowS [PlanJson] -> ShowS PlanJson -> String (Int -> PlanJson -> ShowS) -> (PlanJson -> String) -> ([PlanJson] -> ShowS) -> Show PlanJson forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a $cshowsPrec :: Int -> PlanJson -> ShowS showsPrec :: Int -> PlanJson -> ShowS $cshow :: PlanJson -> String show :: PlanJson -> String $cshowList :: [PlanJson] -> ShowS showList :: [PlanJson] -> ShowS Show, (forall x. PlanJson -> Rep PlanJson x) -> (forall x. Rep PlanJson x -> PlanJson) -> Generic PlanJson forall x. Rep PlanJson x -> PlanJson forall x. PlanJson -> Rep PlanJson x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cfrom :: forall x. PlanJson -> Rep PlanJson x from :: forall x. PlanJson -> Rep PlanJson x $cto :: forall x. Rep PlanJson x -> PlanJson to :: forall x. Rep PlanJson x -> PlanJson Generic) data Package = Package { Package -> CompilerId packageType :: Text , Package -> CompilerId id :: PackageId , Package -> CompilerId name :: Text , Package -> CompilerId version :: Text , Package -> Maybe CompilerId style :: Maybe Text , Package -> Maybe CompilerId componentName :: Maybe Text , Package -> Maybe Components components :: Maybe Components , Package -> [CompilerId] depends :: [Text] , Package -> [CompilerId] exeDepends :: [Text] } deriving (Package -> Package -> Bool (Package -> Package -> Bool) -> (Package -> Package -> Bool) -> Eq Package forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a $c== :: Package -> Package -> Bool == :: Package -> Package -> Bool $c/= :: Package -> Package -> Bool /= :: Package -> Package -> Bool Eq, Int -> Package -> ShowS [Package] -> ShowS Package -> String (Int -> Package -> ShowS) -> (Package -> String) -> ([Package] -> ShowS) -> Show Package forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a $cshowsPrec :: Int -> Package -> ShowS showsPrec :: Int -> Package -> ShowS $cshow :: Package -> String show :: Package -> String $cshowList :: [Package] -> ShowS showList :: [Package] -> ShowS Show, (forall x. Package -> Rep Package x) -> (forall x. Rep Package x -> Package) -> Generic Package forall x. Rep Package x -> Package forall x. Package -> Rep Package x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cfrom :: forall x. Package -> Rep Package x from :: forall x. Package -> Rep Package x $cto :: forall x. Rep Package x -> Package to :: forall x. Rep Package x -> Package Generic) newtype Components = Components { Components -> Maybe Lib lib :: Maybe Lib } deriving (Components -> Components -> Bool (Components -> Components -> Bool) -> (Components -> Components -> Bool) -> Eq Components forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a $c== :: Components -> Components -> Bool == :: Components -> Components -> Bool $c/= :: Components -> Components -> Bool /= :: Components -> Components -> Bool Eq, Int -> Components -> ShowS [Components] -> ShowS Components -> String (Int -> Components -> ShowS) -> (Components -> String) -> ([Components] -> ShowS) -> Show Components forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a $cshowsPrec :: Int -> Components -> ShowS showsPrec :: Int -> Components -> ShowS $cshow :: Components -> String show :: Components -> String $cshowList :: [Components] -> ShowS showList :: [Components] -> ShowS Show, (forall x. Components -> Rep Components x) -> (forall x. Rep Components x -> Components) -> Generic Components forall x. Rep Components x -> Components forall x. Components -> Rep Components x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cfrom :: forall x. Components -> Rep Components x from :: forall x. Components -> Rep Components x $cto :: forall x. Rep Components x -> Components to :: forall x. Rep Components x -> Components Generic) data Lib = Lib { Lib -> [CompilerId] depends :: [Text] , Lib -> [CompilerId] exeDepends :: [Text] } deriving (Lib -> Lib -> Bool (Lib -> Lib -> Bool) -> (Lib -> Lib -> Bool) -> Eq Lib forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a $c== :: Lib -> Lib -> Bool == :: Lib -> Lib -> Bool $c/= :: Lib -> Lib -> Bool /= :: Lib -> Lib -> Bool Eq, Int -> Lib -> ShowS [Lib] -> ShowS Lib -> String (Int -> Lib -> ShowS) -> (Lib -> String) -> ([Lib] -> ShowS) -> Show Lib forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a $cshowsPrec :: Int -> Lib -> ShowS showsPrec :: Int -> Lib -> ShowS $cshow :: Lib -> String show :: Lib -> String $cshowList :: [Lib] -> ShowS showList :: [Lib] -> ShowS Show, (forall x. Lib -> Rep Lib x) -> (forall x. Rep Lib x -> Lib) -> Generic Lib forall x. Rep Lib x -> Lib forall x. Lib -> Rep Lib x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cfrom :: forall x. Lib -> Rep Lib x from :: forall x. Lib -> Rep Lib x $cto :: forall x. Rep Lib x -> Lib to :: forall x. Rep Lib x -> Lib Generic) newtype CompilerContext = CompilerContext { CompilerContext -> [String] ghcPkgCmd :: [String] } deriving (Int -> CompilerContext -> ShowS [CompilerContext] -> ShowS CompilerContext -> String (Int -> CompilerContext -> ShowS) -> (CompilerContext -> String) -> ([CompilerContext] -> ShowS) -> Show CompilerContext forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a $cshowsPrec :: Int -> CompilerContext -> ShowS showsPrec :: Int -> CompilerContext -> ShowS $cshow :: CompilerContext -> String show :: CompilerContext -> String $cshowList :: [CompilerContext] -> ShowS showList :: [CompilerContext] -> ShowS Show, CompilerContext -> CompilerContext -> Bool (CompilerContext -> CompilerContext -> Bool) -> (CompilerContext -> CompilerContext -> Bool) -> Eq CompilerContext forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a $c== :: CompilerContext -> CompilerContext -> Bool == :: CompilerContext -> CompilerContext -> Bool $c/= :: CompilerContext -> CompilerContext -> Bool /= :: CompilerContext -> CompilerContext -> Bool Eq, (forall x. CompilerContext -> Rep CompilerContext x) -> (forall x. Rep CompilerContext x -> CompilerContext) -> Generic CompilerContext forall x. Rep CompilerContext x -> CompilerContext forall x. CompilerContext -> Rep CompilerContext x forall a. (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a $cfrom :: forall x. CompilerContext -> Rep CompilerContext x from :: forall x. CompilerContext -> Rep CompilerContext x $cto :: forall x. Rep CompilerContext x -> CompilerContext to :: forall x. Rep CompilerContext x -> CompilerContext Generic) instance FromJSON PlanJson where parseJSON :: Value -> Parser PlanJson parseJSON = String -> (Object -> Parser PlanJson) -> Value -> Parser PlanJson forall a. String -> (Object -> Parser a) -> Value -> Parser a J.withObject String "PlanJson" ((Object -> Parser PlanJson) -> Value -> Parser PlanJson) -> (Object -> Parser PlanJson) -> Value -> Parser PlanJson forall a b. (a -> b) -> a -> b $ \Object v -> CompilerId -> [Package] -> PlanJson PlanJson (CompilerId -> [Package] -> PlanJson) -> Parser CompilerId -> Parser ([Package] -> PlanJson) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Object v Object -> Key -> Parser CompilerId forall a. FromJSON a => Object -> Key -> Parser a .: Key "compiler-id" Parser ([Package] -> PlanJson) -> Parser [Package] -> Parser PlanJson forall a b. Parser (a -> b) -> Parser a -> Parser b forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Object v Object -> Key -> Parser [Package] forall a. FromJSON a => Object -> Key -> Parser a .: Key "install-plan" instance FromJSON Package where parseJSON :: Value -> Parser Package parseJSON = String -> (Object -> Parser Package) -> Value -> Parser Package forall a. String -> (Object -> Parser a) -> Value -> Parser a J.withObject String "Package" ((Object -> Parser Package) -> Value -> Parser Package) -> (Object -> Parser Package) -> Value -> Parser Package forall a b. (a -> b) -> a -> b $ \Object v -> do CompilerId packageType <- Object v Object -> Key -> Parser CompilerId forall a. FromJSON a => Object -> Key -> Parser a .: Key "type" CompilerId id <- Object v Object -> Key -> Parser CompilerId forall a. FromJSON a => Object -> Key -> Parser a .: Key "id" CompilerId name <- Object v Object -> Key -> Parser CompilerId forall a. FromJSON a => Object -> Key -> Parser a .: Key "pkg-name" CompilerId version <- Object v Object -> Key -> Parser CompilerId forall a. FromJSON a => Object -> Key -> Parser a .: Key "pkg-version" Maybe CompilerId style <- Object v Object -> Key -> Parser (Maybe CompilerId) forall a. FromJSON a => Object -> Key -> Parser (Maybe a) .:? Key "style" Maybe CompilerId componentName <- Object v Object -> Key -> Parser (Maybe CompilerId) forall a. FromJSON a => Object -> Key -> Parser (Maybe a) .:? Key "component-name" Maybe Components components <- Object v Object -> Key -> Parser (Maybe Components) forall a. FromJSON a => Object -> Key -> Parser (Maybe a) .:? Key "components" [CompilerId] depends <- Object v Object -> Key -> Parser (Maybe [CompilerId]) forall a. FromJSON a => Object -> Key -> Parser (Maybe a) .:? Key "depends" Parser (Maybe [CompilerId]) -> [CompilerId] -> Parser [CompilerId] forall a. Parser (Maybe a) -> a -> Parser a .!= [] [CompilerId] exeDepends <- Object v Object -> Key -> Parser (Maybe [CompilerId]) forall a. FromJSON a => Object -> Key -> Parser (Maybe a) .:? Key "exe-depends" Parser (Maybe [CompilerId]) -> [CompilerId] -> Parser [CompilerId] forall a. Parser (Maybe a) -> a -> Parser a .!= [] return Package {[CompilerId] Maybe CompilerId Maybe Components CompilerId $sel:packageType:Package :: CompilerId $sel:id:Package :: CompilerId $sel:name:Package :: CompilerId $sel:version:Package :: CompilerId $sel:style:Package :: Maybe CompilerId $sel:componentName:Package :: Maybe CompilerId $sel:components:Package :: Maybe Components $sel:depends:Package :: [CompilerId] $sel:exeDepends:Package :: [CompilerId] packageType :: CompilerId id :: CompilerId name :: CompilerId version :: CompilerId style :: Maybe CompilerId componentName :: Maybe CompilerId components :: Maybe Components depends :: [CompilerId] exeDepends :: [CompilerId] ..} instance FromJSON Components where parseJSON :: Value -> Parser Components parseJSON = String -> (Object -> Parser Components) -> Value -> Parser Components forall a. String -> (Object -> Parser a) -> Value -> Parser a J.withObject String "Components" ((Object -> Parser Components) -> Value -> Parser Components) -> (Object -> Parser Components) -> Value -> Parser Components forall a b. (a -> b) -> a -> b $ \Object v -> Maybe Lib -> Components Components (Maybe Lib -> Components) -> Parser (Maybe Lib) -> Parser Components forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Object v Object -> Key -> Parser (Maybe Lib) forall a. FromJSON a => Object -> Key -> Parser (Maybe a) .:? Key "lib" instance FromJSON Lib where parseJSON :: Value -> Parser Lib parseJSON = String -> (Object -> Parser Lib) -> Value -> Parser Lib forall a. String -> (Object -> Parser a) -> Value -> Parser a J.withObject String "Lib" ((Object -> Parser Lib) -> Value -> Parser Lib) -> (Object -> Parser Lib) -> Value -> Parser Lib forall a b. (a -> b) -> a -> b $ \Object v -> [CompilerId] -> [CompilerId] -> Lib Lib ([CompilerId] -> [CompilerId] -> Lib) -> Parser [CompilerId] -> Parser ([CompilerId] -> Lib) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Object v Object -> Key -> Parser (Maybe [CompilerId]) forall a. FromJSON a => Object -> Key -> Parser (Maybe a) .:? Key "depends" Parser (Maybe [CompilerId]) -> [CompilerId] -> Parser [CompilerId] forall a. Parser (Maybe a) -> a -> Parser a .!= [] Parser ([CompilerId] -> Lib) -> Parser [CompilerId] -> Parser Lib forall a b. Parser (a -> b) -> Parser a -> Parser b forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Object v Object -> Key -> Parser (Maybe [CompilerId]) forall a. FromJSON a => Object -> Key -> Parser (Maybe a) .:? Key "exe-depends" Parser (Maybe [CompilerId]) -> [CompilerId] -> Parser [CompilerId] forall a. Parser (Maybe a) -> a -> Parser a .!= []