{-# LANGUAGE NoImplicitPrelude          #-}
{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE OverloadedStrings          #-}

-- | Build-specific types.


module Stack.Types.Build
  ( InstallLocation (..)
  , Installed (..)
  , psVersion
  , Task (..)
  , taskIsTarget
  , taskLocation
  , taskTargetIsMutable
  , LocalPackage (..)
  , Plan (..)
  , TestOpts (..)
  , BenchmarkOpts (..)
  , FileWatchOpts (..)
  , BuildOpts (..)
  , BuildSubset (..)
  , defaultBuildOpts
  , TaskType (..)
  , installLocationIsMutable
  , TaskConfigOpts (..)
  , BuildCache (..)
  , ConfigCache (..)
  , configureOpts
  , CachePkgSrc (..)
  , toCachePkgSrc
  , FileCacheInfo (..)
  , PrecompiledCache (..)
  ) where

import           Data.Aeson ( ToJSON, FromJSON )
import qualified Data.ByteString as S
import           Data.List as L
import qualified Data.Map as Map
import qualified Data.Text as T
import           Database.Persist.Sql
                   ( PersistField (..), PersistFieldSql (..)
                   , PersistValue (PersistText), SqlType (SqlString)
                   )
import           Path ( parent )
import           Stack.Prelude
import           Stack.Types.BuildOpts
                   ( BenchmarkOpts (..), BuildOpts (..), BuildSubset (..)
                   , FileWatchOpts (..), TestOpts (..), defaultBuildOpts
                   )
import           Stack.Types.ConfigureOpts ( ConfigureOpts, configureOpts )
import           Stack.Types.GhcPkgId ( GhcPkgId )
import           Stack.Types.IsMutable ( IsMutable (..) )
import           Stack.Types.Package
                   ( FileCacheInfo (..), InstallLocation (..), Installed (..)
                   , LocalPackage (..), Package (..), PackageSource (..)
                   , psVersion
                   )

-- | Package dependency oracle.

newtype PkgDepsOracle
  = PkgDeps PackageName
  deriving (PkgDepsOracle -> PkgDepsOracle -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PkgDepsOracle -> PkgDepsOracle -> Bool
$c/= :: PkgDepsOracle -> PkgDepsOracle -> Bool
== :: PkgDepsOracle -> PkgDepsOracle -> Bool
$c== :: PkgDepsOracle -> PkgDepsOracle -> Bool
Eq, PkgDepsOracle -> ()
forall a. (a -> ()) -> NFData a
rnf :: PkgDepsOracle -> ()
$crnf :: PkgDepsOracle -> ()
NFData, Int -> PkgDepsOracle -> ShowS
[PkgDepsOracle] -> ShowS
PkgDepsOracle -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [PkgDepsOracle] -> ShowS
$cshowList :: [PkgDepsOracle] -> ShowS
show :: PkgDepsOracle -> FilePath
$cshow :: PkgDepsOracle -> FilePath
showsPrec :: Int -> PkgDepsOracle -> ShowS
$cshowsPrec :: Int -> PkgDepsOracle -> ShowS
Show, Typeable)

-- | Stored on disk to know whether the files have changed.

newtype BuildCache = BuildCache
  { BuildCache -> Map FilePath FileCacheInfo
buildCacheTimes :: Map FilePath FileCacheInfo
    -- ^ Modification times of files.

  }
  deriving (BuildCache -> BuildCache -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BuildCache -> BuildCache -> Bool
$c/= :: BuildCache -> BuildCache -> Bool
== :: BuildCache -> BuildCache -> Bool
$c== :: BuildCache -> BuildCache -> Bool
Eq, Value -> Parser [BuildCache]
Value -> Parser BuildCache
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [BuildCache]
$cparseJSONList :: Value -> Parser [BuildCache]
parseJSON :: Value -> Parser BuildCache
$cparseJSON :: Value -> Parser BuildCache
FromJSON, forall x. Rep BuildCache x -> BuildCache
forall x. BuildCache -> Rep BuildCache x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BuildCache x -> BuildCache
$cfrom :: forall x. BuildCache -> Rep BuildCache x
Generic, Int -> BuildCache -> ShowS
[BuildCache] -> ShowS
BuildCache -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [BuildCache] -> ShowS
$cshowList :: [BuildCache] -> ShowS
show :: BuildCache -> FilePath
$cshow :: BuildCache -> FilePath
showsPrec :: Int -> BuildCache -> ShowS
$cshowsPrec :: Int -> BuildCache -> ShowS
Show, [BuildCache] -> Encoding
[BuildCache] -> Value
BuildCache -> Encoding
BuildCache -> Value
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [BuildCache] -> Encoding
$ctoEncodingList :: [BuildCache] -> Encoding
toJSONList :: [BuildCache] -> Value
$ctoJSONList :: [BuildCache] -> Value
toEncoding :: BuildCache -> Encoding
$ctoEncoding :: BuildCache -> Encoding
toJSON :: BuildCache -> Value
$ctoJSON :: BuildCache -> Value
ToJSON, Typeable)

instance NFData BuildCache

-- | Stored on disk to know whether the flags have changed.

data ConfigCache = ConfigCache
  { ConfigCache -> ConfigureOpts
configCacheOpts :: !ConfigureOpts
    -- ^ All options used for this package.

  , ConfigCache -> Set GhcPkgId
configCacheDeps :: !(Set GhcPkgId)
    -- ^ The GhcPkgIds of all of the dependencies. Since Cabal doesn't take

    -- the complete GhcPkgId (only a PackageIdentifier) in the configure

    -- options, just using the previous value is insufficient to know if

    -- dependencies have changed.

  , ConfigCache -> Set ByteString
configCacheComponents :: !(Set S.ByteString)
    -- ^ The components to be built. It's a bit of a hack to include this in

    -- here, as it's not a configure option (just a build option), but this

    -- is a convenient way to force compilation when the components change.

  , ConfigCache -> Bool
configCacheHaddock :: !Bool
    -- ^ Are haddocks to be built?

  , ConfigCache -> CachePkgSrc
configCachePkgSrc :: !CachePkgSrc
  , ConfigCache -> Text
configCachePathEnvVar :: !Text
  -- ^ Value of the PATH env var, see

  -- <https://github.com/commercialhaskell/stack/issues/3138>

  }
  deriving (Typeable ConfigCache
ConfigCache -> DataType
ConfigCache -> Constr
(forall b. Data b => b -> b) -> ConfigCache -> ConfigCache
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ConfigCache -> u
forall u. (forall d. Data d => d -> u) -> ConfigCache -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConfigCache
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfigCache -> c ConfigCache
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConfigCache)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConfigCache)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConfigCache -> m ConfigCache
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ConfigCache -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ConfigCache -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> ConfigCache -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ConfigCache -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfigCache -> r
gmapT :: (forall b. Data b => b -> b) -> ConfigCache -> ConfigCache
$cgmapT :: (forall b. Data b => b -> b) -> ConfigCache -> ConfigCache
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConfigCache)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ConfigCache)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConfigCache)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ConfigCache)
dataTypeOf :: ConfigCache -> DataType
$cdataTypeOf :: ConfigCache -> DataType
toConstr :: ConfigCache -> Constr
$ctoConstr :: ConfigCache -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConfigCache
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ConfigCache
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfigCache -> c ConfigCache
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfigCache -> c ConfigCache
Data, ConfigCache -> ConfigCache -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfigCache -> ConfigCache -> Bool
$c/= :: ConfigCache -> ConfigCache -> Bool
== :: ConfigCache -> ConfigCache -> Bool
$c== :: ConfigCache -> ConfigCache -> Bool
Eq, forall x. Rep ConfigCache x -> ConfigCache
forall x. ConfigCache -> Rep ConfigCache x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ConfigCache x -> ConfigCache
$cfrom :: forall x. ConfigCache -> Rep ConfigCache x
Generic, Int -> ConfigCache -> ShowS
[ConfigCache] -> ShowS
ConfigCache -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ConfigCache] -> ShowS
$cshowList :: [ConfigCache] -> ShowS
show :: ConfigCache -> FilePath
$cshow :: ConfigCache -> FilePath
showsPrec :: Int -> ConfigCache -> ShowS
$cshowsPrec :: Int -> ConfigCache -> ShowS
Show, Typeable)

instance NFData ConfigCache

data CachePkgSrc
  = CacheSrcUpstream
  | CacheSrcLocal FilePath
  deriving (Typeable CachePkgSrc
CachePkgSrc -> DataType
CachePkgSrc -> Constr
(forall b. Data b => b -> b) -> CachePkgSrc -> CachePkgSrc
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> CachePkgSrc -> u
forall u. (forall d. Data d => d -> u) -> CachePkgSrc -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CachePkgSrc
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CachePkgSrc -> c CachePkgSrc
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CachePkgSrc)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CachePkgSrc)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CachePkgSrc -> m CachePkgSrc
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CachePkgSrc -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> CachePkgSrc -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> CachePkgSrc -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> CachePkgSrc -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> CachePkgSrc -> r
gmapT :: (forall b. Data b => b -> b) -> CachePkgSrc -> CachePkgSrc
$cgmapT :: (forall b. Data b => b -> b) -> CachePkgSrc -> CachePkgSrc
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CachePkgSrc)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c CachePkgSrc)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CachePkgSrc)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c CachePkgSrc)
dataTypeOf :: CachePkgSrc -> DataType
$cdataTypeOf :: CachePkgSrc -> DataType
toConstr :: CachePkgSrc -> Constr
$ctoConstr :: CachePkgSrc -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CachePkgSrc
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c CachePkgSrc
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CachePkgSrc -> c CachePkgSrc
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CachePkgSrc -> c CachePkgSrc
Data, CachePkgSrc -> CachePkgSrc -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CachePkgSrc -> CachePkgSrc -> Bool
$c/= :: CachePkgSrc -> CachePkgSrc -> Bool
== :: CachePkgSrc -> CachePkgSrc -> Bool
$c== :: CachePkgSrc -> CachePkgSrc -> Bool
Eq, forall x. Rep CachePkgSrc x -> CachePkgSrc
forall x. CachePkgSrc -> Rep CachePkgSrc x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CachePkgSrc x -> CachePkgSrc
$cfrom :: forall x. CachePkgSrc -> Rep CachePkgSrc x
Generic, ReadPrec [CachePkgSrc]
ReadPrec CachePkgSrc
Int -> ReadS CachePkgSrc
ReadS [CachePkgSrc]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CachePkgSrc]
$creadListPrec :: ReadPrec [CachePkgSrc]
readPrec :: ReadPrec CachePkgSrc
$creadPrec :: ReadPrec CachePkgSrc
readList :: ReadS [CachePkgSrc]
$creadList :: ReadS [CachePkgSrc]
readsPrec :: Int -> ReadS CachePkgSrc
$creadsPrec :: Int -> ReadS CachePkgSrc
Read, Int -> CachePkgSrc -> ShowS
[CachePkgSrc] -> ShowS
CachePkgSrc -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [CachePkgSrc] -> ShowS
$cshowList :: [CachePkgSrc] -> ShowS
show :: CachePkgSrc -> FilePath
$cshow :: CachePkgSrc -> FilePath
showsPrec :: Int -> CachePkgSrc -> ShowS
$cshowsPrec :: Int -> CachePkgSrc -> ShowS
Show, Typeable)

instance NFData CachePkgSrc

instance PersistField CachePkgSrc where
  toPersistValue :: CachePkgSrc -> PersistValue
toPersistValue CachePkgSrc
CacheSrcUpstream = Text -> PersistValue
PersistText Text
"upstream"
  toPersistValue (CacheSrcLocal FilePath
fp) = Text -> PersistValue
PersistText (Text
"local:" forall a. Semigroup a => a -> a -> a
<> FilePath -> Text
T.pack FilePath
fp)
  fromPersistValue :: PersistValue -> Either Text CachePkgSrc
fromPersistValue (PersistText Text
t) =
    if Text
t forall a. Eq a => a -> a -> Bool
== Text
"upstream"
      then forall a b. b -> Either a b
Right CachePkgSrc
CacheSrcUpstream
      else case Text -> Text -> Maybe Text
T.stripPrefix Text
"local:" Text
t of
        Just Text
fp -> forall a b. b -> Either a b
Right forall a b. (a -> b) -> a -> b
$ FilePath -> CachePkgSrc
CacheSrcLocal (Text -> FilePath
T.unpack Text
fp)
        Maybe Text
Nothing -> forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ Text
"Unexpected CachePkgSrc value: " forall a. Semigroup a => a -> a -> a
<> Text
t
  fromPersistValue PersistValue
_ = forall a b. a -> Either a b
Left Text
"Unexpected CachePkgSrc type"

instance PersistFieldSql CachePkgSrc where
  sqlType :: Proxy CachePkgSrc -> SqlType
sqlType Proxy CachePkgSrc
_ = SqlType
SqlString

toCachePkgSrc :: PackageSource -> CachePkgSrc
toCachePkgSrc :: PackageSource -> CachePkgSrc
toCachePkgSrc (PSFilePath LocalPackage
lp) =
  FilePath -> CachePkgSrc
CacheSrcLocal (forall b t. Path b t -> FilePath
toFilePath (forall b t. Path b t -> Path b Dir
parent (LocalPackage -> Path Abs File
lpCabalFile LocalPackage
lp)))
toCachePkgSrc PSRemote{} = CachePkgSrc
CacheSrcUpstream

-- | A task to perform when building

data Task = Task
  { Task -> PackageIdentifier
taskProvides        :: !PackageIdentifier -- FIXME turn this into a function on taskType?

    -- ^ the package/version to be built

  , Task -> TaskType
taskType            :: !TaskType
    -- ^ the task type, telling us how to build this

  , Task -> TaskConfigOpts
taskConfigOpts      :: !TaskConfigOpts
  , Task -> Bool
taskBuildHaddock    :: !Bool
  , Task -> Map PackageIdentifier GhcPkgId
taskPresent         :: !(Map PackageIdentifier GhcPkgId)
    -- ^ GhcPkgIds of already-installed dependencies

  , Task -> Bool
taskAllInOne        :: !Bool
    -- ^ indicates that the package can be built in one step

  , Task -> CachePkgSrc
taskCachePkgSrc     :: !CachePkgSrc
  , Task -> Bool
taskAnyMissing      :: !Bool
    -- ^ Were any of the dependencies missing? The reason this is necessary is...

    -- hairy. And as you may expect, a bug in Cabal. See:

    -- <https://github.com/haskell/cabal/issues/4728#issuecomment-337937673>.

    -- The problem is that Cabal may end up generating the same package ID for a

    -- dependency, even if the ABI has changed. As a result, without this field,

    -- Stack would think that a reconfigure is unnecessary, when in fact we _do_

    -- need to reconfigure. The details here suck. We really need proper hashes

    -- for package identifiers.

  , Task -> Bool
taskBuildTypeConfig :: !Bool
    -- ^ Is the build type of this package Configure. Check out

    -- ensureConfigureScript in Stack.Build.Execute for the motivation

  }
  deriving Int -> Task -> ShowS
[Task] -> ShowS
Task -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Task] -> ShowS
$cshowList :: [Task] -> ShowS
show :: Task -> FilePath
$cshow :: Task -> FilePath
showsPrec :: Int -> Task -> ShowS
$cshowsPrec :: Int -> Task -> ShowS
Show

-- | Given the IDs of any missing packages, produce the configure options

data TaskConfigOpts = TaskConfigOpts
  { TaskConfigOpts -> Set PackageIdentifier
tcoMissing :: !(Set PackageIdentifier)
    -- ^ Dependencies for which we don't yet have an GhcPkgId

  , TaskConfigOpts -> Map PackageIdentifier GhcPkgId -> ConfigureOpts
tcoOpts    :: !(Map PackageIdentifier GhcPkgId -> ConfigureOpts)
    -- ^ Produce the list of options given the missing @GhcPkgId@s

  }

instance Show TaskConfigOpts where
  show :: TaskConfigOpts -> FilePath
show (TaskConfigOpts Set PackageIdentifier
missing Map PackageIdentifier GhcPkgId -> ConfigureOpts
f) = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
    [ FilePath
"Missing: "
    , forall a. Show a => a -> FilePath
show Set PackageIdentifier
missing
    , FilePath
". Without those: "
    , forall a. Show a => a -> FilePath
show forall a b. (a -> b) -> a -> b
$ Map PackageIdentifier GhcPkgId -> ConfigureOpts
f forall k a. Map k a
Map.empty
    ]

-- | The type of a task, either building local code or something from the

-- package index (upstream)

data TaskType
  = TTLocalMutable LocalPackage
  | TTRemotePackage IsMutable Package PackageLocationImmutable
  deriving Int -> TaskType -> ShowS
[TaskType] -> ShowS
TaskType -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [TaskType] -> ShowS
$cshowList :: [TaskType] -> ShowS
show :: TaskType -> FilePath
$cshow :: TaskType -> FilePath
showsPrec :: Int -> TaskType -> ShowS
$cshowsPrec :: Int -> TaskType -> ShowS
Show

taskIsTarget :: Task -> Bool
taskIsTarget :: Task -> Bool
taskIsTarget Task
t =
  case Task -> TaskType
taskType Task
t of
    TTLocalMutable LocalPackage
lp -> LocalPackage -> Bool
lpWanted LocalPackage
lp
    TaskType
_ -> Bool
False

taskLocation :: Task -> InstallLocation
taskLocation :: Task -> InstallLocation
taskLocation Task
task =
  case Task -> TaskType
taskType Task
task of
    TTLocalMutable LocalPackage
_ -> InstallLocation
Local
    TTRemotePackage IsMutable
Mutable Package
_ PackageLocationImmutable
_ -> InstallLocation
Local
    TTRemotePackage IsMutable
Immutable Package
_ PackageLocationImmutable
_ -> InstallLocation
Snap

taskTargetIsMutable :: Task -> IsMutable
taskTargetIsMutable :: Task -> IsMutable
taskTargetIsMutable Task
task =
  case Task -> TaskType
taskType Task
task of
    TTLocalMutable LocalPackage
_ -> IsMutable
Mutable
    TTRemotePackage IsMutable
mutable Package
_ PackageLocationImmutable
_ -> IsMutable
mutable

installLocationIsMutable :: InstallLocation -> IsMutable
installLocationIsMutable :: InstallLocation -> IsMutable
installLocationIsMutable InstallLocation
Snap = IsMutable
Immutable
installLocationIsMutable InstallLocation
Local = IsMutable
Mutable

-- | A complete plan of what needs to be built and how to do it

data Plan = Plan
  { Plan -> Map PackageName Task
planTasks :: !(Map PackageName Task)
  , Plan -> Map PackageName Task
planFinals :: !(Map PackageName Task)
    -- ^ Final actions to be taken (test, benchmark, etc)

  , Plan -> Map GhcPkgId (PackageIdentifier, Text)
planUnregisterLocal :: !(Map GhcPkgId (PackageIdentifier, Text))
    -- ^ Text is reason we're unregistering, for display only

  , Plan -> Map Text InstallLocation
planInstallExes :: !(Map Text InstallLocation)
    -- ^ Executables that should be installed after successful building

  }
  deriving Int -> Plan -> ShowS
[Plan] -> ShowS
Plan -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Plan] -> ShowS
$cshowList :: [Plan] -> ShowS
show :: Plan -> FilePath
$cshow :: Plan -> FilePath
showsPrec :: Int -> Plan -> ShowS
$cshowsPrec :: Int -> Plan -> ShowS
Show

-- | Information on a compiled package: the library conf file (if relevant),

-- the sublibraries (if present) and all of the executable paths.

data PrecompiledCache base = PrecompiledCache
  { forall base. PrecompiledCache base -> Maybe (Path base File)
pcLibrary :: !(Maybe (Path base File))
    -- ^ .conf file inside the package database

  , forall base. PrecompiledCache base -> [Path base File]
pcSubLibs :: ![Path base File]
    -- ^ .conf file inside the package database, for each of the sublibraries

  , forall base. PrecompiledCache base -> [Path base File]
pcExes    :: ![Path base File]
    -- ^ Full paths to executables

  }
  deriving (PrecompiledCache base -> PrecompiledCache base -> Bool
forall base. PrecompiledCache base -> PrecompiledCache base -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrecompiledCache base -> PrecompiledCache base -> Bool
$c/= :: forall base. PrecompiledCache base -> PrecompiledCache base -> Bool
== :: PrecompiledCache base -> PrecompiledCache base -> Bool
$c== :: forall base. PrecompiledCache base -> PrecompiledCache base -> Bool
Eq, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall base x.
Rep (PrecompiledCache base) x -> PrecompiledCache base
forall base x.
PrecompiledCache base -> Rep (PrecompiledCache base) x
$cto :: forall base x.
Rep (PrecompiledCache base) x -> PrecompiledCache base
$cfrom :: forall base x.
PrecompiledCache base -> Rep (PrecompiledCache base) x
Generic, Int -> PrecompiledCache base -> ShowS
forall base. Int -> PrecompiledCache base -> ShowS
forall base. [PrecompiledCache base] -> ShowS
forall base. PrecompiledCache base -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [PrecompiledCache base] -> ShowS
$cshowList :: forall base. [PrecompiledCache base] -> ShowS
show :: PrecompiledCache base -> FilePath
$cshow :: forall base. PrecompiledCache base -> FilePath
showsPrec :: Int -> PrecompiledCache base -> ShowS
$cshowsPrec :: forall base. Int -> PrecompiledCache base -> ShowS
Show, Typeable)

instance NFData (PrecompiledCache Abs)

instance NFData (PrecompiledCache Rel)