{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
module Stack.Types.Plan
( Plan (..)
, Task (..)
, TaskType (..)
, TaskConfigOpts (..)
, taskAnyMissing
, taskIsTarget
, taskLocation
, taskProvides
, taskTargetIsMutable
, taskTypeLocation
, taskTypePackageIdentifier
, installLocationIsMutable
) where
import Data.List as L
import qualified RIO.Set as Set
import Stack.Prelude
import Stack.Types.Cache ( CachePkgSrc )
import Stack.Types.ComponentUtils ( StackUnqualCompName )
import Stack.Types.ConfigureOpts
( BaseConfigOpts, PackageConfigureOpts )
import Stack.Types.EnvConfig ( EnvConfig )
import Stack.Types.GhcPkgId ( GhcPkgId )
import Stack.Types.IsMutable ( IsMutable (..) )
import Stack.Types.Package
( InstallLocation (..), LocalPackage (..), Package (..)
, packageIdentifier
)
data Plan = Plan
{ Plan -> Map PackageName Task
tasks :: !(Map PackageName Task)
, Plan -> Map PackageName Task
finals :: !(Map PackageName Task)
, Plan -> Map GhcPkgId (PackageIdentifier, Text)
unregisterLocal :: !(Map GhcPkgId (PackageIdentifier, Text))
, Plan -> Map StackUnqualCompName InstallLocation
installExes :: !(Map StackUnqualCompName InstallLocation)
}
deriving Int -> Plan -> ShowS
[Plan] -> ShowS
Plan -> String
(Int -> Plan -> ShowS)
-> (Plan -> String) -> ([Plan] -> ShowS) -> Show Plan
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Plan -> ShowS
showsPrec :: Int -> Plan -> ShowS
$cshow :: Plan -> String
show :: Plan -> String
$cshowList :: [Plan] -> ShowS
showList :: [Plan] -> ShowS
Show
data Task = Task
{ Task -> TaskType
taskType :: !TaskType
, Task -> TaskConfigOpts
configOpts :: !TaskConfigOpts
, Task -> Bool
buildHaddocks :: !Bool
, Task -> Map PackageIdentifier GhcPkgId
present :: !(Map PackageIdentifier GhcPkgId)
, Task -> Bool
allInOne :: !Bool
, Task -> CachePkgSrc
cachePkgSrc :: !CachePkgSrc
, Task -> Bool
buildTypeConfig :: !Bool
}
deriving Int -> Task -> ShowS
[Task] -> ShowS
Task -> String
(Int -> Task -> ShowS)
-> (Task -> String) -> ([Task] -> ShowS) -> Show Task
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Task -> ShowS
showsPrec :: Int -> Task -> ShowS
$cshow :: Task -> String
show :: Task -> String
$cshowList :: [Task] -> ShowS
showList :: [Task] -> ShowS
Show
data TaskType
= TTLocalMutable LocalPackage
| TTRemotePackage IsMutable Package PackageLocationImmutable
deriving Int -> TaskType -> ShowS
[TaskType] -> ShowS
TaskType -> String
(Int -> TaskType -> ShowS)
-> (TaskType -> String) -> ([TaskType] -> ShowS) -> Show TaskType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TaskType -> ShowS
showsPrec :: Int -> TaskType -> ShowS
$cshow :: TaskType -> String
show :: TaskType -> String
$cshowList :: [TaskType] -> ShowS
showList :: [TaskType] -> ShowS
Show
data TaskConfigOpts = TaskConfigOpts
{ TaskConfigOpts -> Set PackageIdentifier
missing :: !(Set PackageIdentifier)
, TaskConfigOpts -> EnvConfig
envConfig :: !EnvConfig
, TaskConfigOpts -> BaseConfigOpts
baseConfigOpts :: !BaseConfigOpts
, :: !Bool
, TaskConfigOpts -> IsMutable
isMutable :: !IsMutable
, TaskConfigOpts -> PackageConfigureOpts
pkgConfigOpts :: PackageConfigureOpts
}
instance Show TaskConfigOpts where
show :: TaskConfigOpts -> String
show TaskConfigOpts
tco = String
"Missing: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Set PackageIdentifier -> String
forall a. Show a => a -> String
show TaskConfigOpts
tco.missing
taskAnyMissing :: Task -> Bool
taskAnyMissing :: Task -> Bool
taskAnyMissing Task
task = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Set PackageIdentifier -> Bool
forall a. Set a -> Bool
Set.null Task
task.configOpts.missing
taskTypePackageIdentifier :: TaskType -> PackageIdentifier
taskTypePackageIdentifier :: TaskType -> PackageIdentifier
taskTypePackageIdentifier (TTLocalMutable LocalPackage
lp) = Package -> PackageIdentifier
packageIdentifier LocalPackage
lp.package
taskTypePackageIdentifier (TTRemotePackage IsMutable
_ Package
p PackageLocationImmutable
_) = Package -> PackageIdentifier
packageIdentifier Package
p
taskIsTarget :: Task -> Bool
taskIsTarget :: Task -> Bool
taskIsTarget Task
t =
case Task
t.taskType of
TTLocalMutable LocalPackage
lp -> LocalPackage
lp.wanted
TaskType
_ -> Bool
False
taskTypeLocation :: TaskType -> InstallLocation
taskTypeLocation :: TaskType -> InstallLocation
taskTypeLocation (TTLocalMutable LocalPackage
_) = InstallLocation
Local
taskTypeLocation (TTRemotePackage IsMutable
Mutable Package
_ PackageLocationImmutable
_) = InstallLocation
Local
taskTypeLocation (TTRemotePackage IsMutable
Immutable Package
_ PackageLocationImmutable
_) = InstallLocation
Snap
taskLocation :: Task -> InstallLocation
taskLocation :: Task -> InstallLocation
taskLocation = TaskType -> InstallLocation
taskTypeLocation (TaskType -> InstallLocation)
-> (Task -> TaskType) -> Task -> InstallLocation
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (.taskType)
taskProvides :: Task -> PackageIdentifier
taskProvides :: Task -> PackageIdentifier
taskProvides = TaskType -> PackageIdentifier
taskTypePackageIdentifier (TaskType -> PackageIdentifier)
-> (Task -> TaskType) -> Task -> PackageIdentifier
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (.taskType)
taskTargetIsMutable :: Task -> IsMutable
taskTargetIsMutable :: Task -> IsMutable
taskTargetIsMutable Task
task =
case Task
task.taskType 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