{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Distribution.Client.ProjectPlanOutput
(
writePlanExternalRepresentation
, PostBuildProjectStatus (..)
, updatePostBuildProjectStatus
, createPackageEnvironmentAndArgs
, writePlanGhcEnvironment
, argsEquivalentOfGhcEnvironmentFile
) where
import Distribution.Client.DistDirLayout
import Distribution.Client.HashValue (hashValue, showHashValue)
import Distribution.Client.ProjectBuilding.Types
import Distribution.Client.ProjectPlanning.Types
import Distribution.Client.Types.ConfiguredId (confInstId)
import Distribution.Client.Types.PackageLocation (PackageLocation (..))
import Distribution.Client.Types.Repo (RemoteRepo (..), Repo (..))
import Distribution.Client.Types.SourceRepo (SourceRepoMaybe, SourceRepositoryPackage (..))
import Distribution.Client.Version (cabalInstallVersion)
import qualified Distribution.Client.InstallPlan as InstallPlan
import qualified Distribution.Client.Utils.Json as J
import qualified Distribution.Simple.InstallDirs as InstallDirs
import qualified Distribution.Solver.Types.ComponentDeps as ComponentDeps
import qualified Distribution.Compat.Binary as Binary
import Distribution.Compat.Graph (Graph, Node)
import qualified Distribution.Compat.Graph as Graph
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
import Distribution.Package
import qualified Distribution.PackageDescription as PD
import Distribution.Simple.BuildPaths
( buildInfoPref
, dllExtension
, exeExtension
)
import Distribution.Simple.Compiler
import Distribution.Simple.GHC
( GhcEnvironmentFileEntry (..)
, GhcImplInfo (supportsPkgEnvFiles)
, getImplInfo
, simpleGhcEnvironmentFile
, writeGhcEnvironmentFile
)
import Distribution.Simple.Utils
import Distribution.System
import Distribution.Types.Version
( mkVersion
)
import Distribution.Utils.Path hiding
( (<.>)
, (</>)
)
import Distribution.Verbosity
import Distribution.Client.Compat.Prelude
import Prelude ()
import qualified Data.ByteString.Builder as BB
import qualified Data.ByteString.Lazy as BS
import qualified Data.Map as Map
import qualified Data.Set as Set
import System.FilePath
import System.IO
import Distribution.Simple.Program.GHC (packageDbArgsDb)
writePlanExternalRepresentation
:: DistDirLayout
-> ElaboratedInstallPlan
-> ElaboratedSharedConfig
-> IO ()
writePlanExternalRepresentation :: DistDirLayout
-> ElaboratedInstallPlan -> ElaboratedSharedConfig -> IO ()
writePlanExternalRepresentation
DistDirLayout
distDirLayout
ElaboratedInstallPlan
elaboratedInstallPlan
ElaboratedSharedConfig
elaboratedSharedConfig =
FilePath -> ByteString -> IO ()
writeFileAtomic (DistDirLayout -> FilePath -> FilePath
distProjectCacheFile DistDirLayout
distDirLayout FilePath
"plan.json")
(ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ Builder -> ByteString
BB.toLazyByteString
(Builder -> ByteString)
-> (Value -> Builder) -> Value -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Value -> Builder
forall a. ToJSON a => a -> Builder
J.encodeToBuilder
(Value -> ByteString) -> Value -> ByteString
forall a b. (a -> b) -> a -> b
$ DistDirLayout
-> ElaboratedInstallPlan -> ElaboratedSharedConfig -> Value
encodePlanAsJson DistDirLayout
distDirLayout ElaboratedInstallPlan
elaboratedInstallPlan ElaboratedSharedConfig
elaboratedSharedConfig
encodePlanAsJson :: DistDirLayout -> ElaboratedInstallPlan -> ElaboratedSharedConfig -> J.Value
encodePlanAsJson :: DistDirLayout
-> ElaboratedInstallPlan -> ElaboratedSharedConfig -> Value
encodePlanAsJson DistDirLayout
distDirLayout ElaboratedInstallPlan
elaboratedInstallPlan ElaboratedSharedConfig
elaboratedSharedConfig =
[Pair] -> Value
J.object
[ FilePath
"cabal-version" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= Version -> Value
forall a. Pretty a => a -> Value
jdisplay Version
cabalInstallVersion
, FilePath
"cabal-lib-version" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= Version -> Value
forall a. Pretty a => a -> Value
jdisplay Version
cabalVersion
, FilePath
"compiler-id"
FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (FilePath -> Value
J.String (FilePath -> Value)
-> (ElaboratedSharedConfig -> FilePath)
-> ElaboratedSharedConfig
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compiler -> FilePath
showCompilerId (Compiler -> FilePath)
-> (ElaboratedSharedConfig -> Compiler)
-> ElaboratedSharedConfig
-> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElaboratedSharedConfig -> Compiler
pkgConfigCompiler)
ElaboratedSharedConfig
elaboratedSharedConfig
, FilePath
"compiler-abi" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= AbiTag -> Value
forall a. Pretty a => a -> Value
jdisplay (Compiler -> AbiTag
compilerAbiTag (ElaboratedSharedConfig -> Compiler
pkgConfigCompiler ElaboratedSharedConfig
elaboratedSharedConfig))
, FilePath
"os" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= OS -> Value
forall a. Pretty a => a -> Value
jdisplay OS
os
, FilePath
"arch" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= Arch -> Value
forall a. Pretty a => a -> Value
jdisplay Arch
arch
, FilePath
"install-plan" FilePath -> [Value] -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= ElaboratedInstallPlan -> [Value]
installPlanToJ ElaboratedInstallPlan
elaboratedInstallPlan
]
where
plat :: Platform
plat :: Platform
plat@(Platform Arch
arch OS
os) = ElaboratedSharedConfig -> Platform
pkgConfigPlatform ElaboratedSharedConfig
elaboratedSharedConfig
installPlanToJ :: ElaboratedInstallPlan -> [J.Value]
installPlanToJ :: ElaboratedInstallPlan -> [Value]
installPlanToJ = (ElaboratedPlanPackage -> Value)
-> [ElaboratedPlanPackage] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map ElaboratedPlanPackage -> Value
planPackageToJ ([ElaboratedPlanPackage] -> [Value])
-> (ElaboratedInstallPlan -> [ElaboratedPlanPackage])
-> ElaboratedInstallPlan
-> [Value]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElaboratedInstallPlan -> [ElaboratedPlanPackage]
forall ipkg srcpkg.
GenericInstallPlan ipkg srcpkg -> [GenericPlanPackage ipkg srcpkg]
InstallPlan.toList
planPackageToJ :: ElaboratedPlanPackage -> J.Value
planPackageToJ :: ElaboratedPlanPackage -> Value
planPackageToJ ElaboratedPlanPackage
pkg =
case ElaboratedPlanPackage
pkg of
InstallPlan.PreExisting InstalledPackageInfo
ipi -> InstalledPackageInfo -> Value
installedPackageInfoToJ InstalledPackageInfo
ipi
InstallPlan.Configured ElaboratedConfiguredPackage
elab -> Bool -> ElaboratedConfiguredPackage -> Value
elaboratedPackageToJ Bool
False ElaboratedConfiguredPackage
elab
InstallPlan.Installed ElaboratedConfiguredPackage
elab -> Bool -> ElaboratedConfiguredPackage -> Value
elaboratedPackageToJ Bool
True ElaboratedConfiguredPackage
elab
installedPackageInfoToJ :: InstalledPackageInfo -> J.Value
installedPackageInfoToJ :: InstalledPackageInfo -> Value
installedPackageInfoToJ InstalledPackageInfo
ipi =
[Pair] -> Value
J.object
[ FilePath
"type" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
"pre-existing"
, FilePath
"id" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (UnitId -> Value
forall a. Pretty a => a -> Value
jdisplay (UnitId -> Value)
-> (InstalledPackageInfo -> UnitId)
-> InstalledPackageInfo
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InstalledPackageInfo -> UnitId
forall pkg. HasUnitId pkg => pkg -> UnitId
installedUnitId) InstalledPackageInfo
ipi
, FilePath
"pkg-name" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (PackageName -> Value
forall a. Pretty a => a -> Value
jdisplay (PackageName -> Value)
-> (InstalledPackageInfo -> PackageName)
-> InstalledPackageInfo
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageIdentifier -> PackageName
pkgName (PackageIdentifier -> PackageName)
-> (InstalledPackageInfo -> PackageIdentifier)
-> InstalledPackageInfo
-> PackageName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InstalledPackageInfo -> PackageIdentifier
forall pkg. Package pkg => pkg -> PackageIdentifier
packageId) InstalledPackageInfo
ipi
, FilePath
"pkg-version" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (Version -> Value
forall a. Pretty a => a -> Value
jdisplay (Version -> Value)
-> (InstalledPackageInfo -> Version)
-> InstalledPackageInfo
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageIdentifier -> Version
pkgVersion (PackageIdentifier -> Version)
-> (InstalledPackageInfo -> PackageIdentifier)
-> InstalledPackageInfo
-> Version
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InstalledPackageInfo -> PackageIdentifier
forall pkg. Package pkg => pkg -> PackageIdentifier
packageId) InstalledPackageInfo
ipi
, FilePath
"depends" FilePath -> [Value] -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (UnitId -> Value) -> [UnitId] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map UnitId -> Value
forall a. Pretty a => a -> Value
jdisplay (InstalledPackageInfo -> [UnitId]
forall pkg. PackageInstalled pkg => pkg -> [UnitId]
installedDepends InstalledPackageInfo
ipi)
]
elaboratedPackageToJ :: Bool -> ElaboratedConfiguredPackage -> J.Value
elaboratedPackageToJ :: Bool -> ElaboratedConfiguredPackage -> Value
elaboratedPackageToJ Bool
isInstalled ElaboratedConfiguredPackage
elab =
[Pair] -> Value
J.object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
[ FilePath
"type"
FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String
( if Bool
isInstalled
then FilePath
"installed"
else FilePath
"configured"
)
, FilePath
"id" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (UnitId -> Value
forall a. Pretty a => a -> Value
jdisplay (UnitId -> Value)
-> (ElaboratedConfiguredPackage -> UnitId)
-> ElaboratedConfiguredPackage
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElaboratedConfiguredPackage -> UnitId
forall pkg. HasUnitId pkg => pkg -> UnitId
installedUnitId) ElaboratedConfiguredPackage
elab
, FilePath
"pkg-name" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (PackageName -> Value
forall a. Pretty a => a -> Value
jdisplay (PackageName -> Value)
-> (ElaboratedConfiguredPackage -> PackageName)
-> ElaboratedConfiguredPackage
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageIdentifier -> PackageName
pkgName (PackageIdentifier -> PackageName)
-> (ElaboratedConfiguredPackage -> PackageIdentifier)
-> ElaboratedConfiguredPackage
-> PackageName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElaboratedConfiguredPackage -> PackageIdentifier
forall pkg. Package pkg => pkg -> PackageIdentifier
packageId) ElaboratedConfiguredPackage
elab
, FilePath
"pkg-version" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (Version -> Value
forall a. Pretty a => a -> Value
jdisplay (Version -> Value)
-> (ElaboratedConfiguredPackage -> Version)
-> ElaboratedConfiguredPackage
-> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PackageIdentifier -> Version
pkgVersion (PackageIdentifier -> Version)
-> (ElaboratedConfiguredPackage -> PackageIdentifier)
-> ElaboratedConfiguredPackage
-> Version
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElaboratedConfiguredPackage -> PackageIdentifier
forall pkg. Package pkg => pkg -> PackageIdentifier
packageId) ElaboratedConfiguredPackage
elab
, FilePath
"flags"
FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= [Pair] -> Value
J.object
[ FlagName -> FilePath
PD.unFlagName FlagName
fn FilePath -> Bool -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= Bool
v
| (FlagName
fn, Bool
v) <- FlagAssignment -> [(FlagName, Bool)]
PD.unFlagAssignment (ElaboratedConfiguredPackage -> FlagAssignment
elabFlagAssignment ElaboratedConfiguredPackage
elab)
]
, FilePath
"style" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String (Bool -> BuildStyle -> FilePath
style2str (ElaboratedConfiguredPackage -> Bool
elabLocalToProject ElaboratedConfiguredPackage
elab) (ElaboratedConfiguredPackage -> BuildStyle
elabBuildStyle ElaboratedConfiguredPackage
elab))
, FilePath
"pkg-src" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= PackageLocation (Maybe FilePath) -> Value
packageLocationToJ (ElaboratedConfiguredPackage -> PackageLocation (Maybe FilePath)
elabPkgSourceLocation ElaboratedConfiguredPackage
elab)
]
[Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ [ FilePath
"pkg-cabal-sha256" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String (HashValue -> FilePath
showHashValue HashValue
hash)
| Just HashValue
hash <- [(ByteString -> HashValue) -> Maybe ByteString -> Maybe HashValue
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ByteString -> HashValue
hashValue (ElaboratedConfiguredPackage -> Maybe ByteString
elabPkgDescriptionOverride ElaboratedConfiguredPackage
elab)]
]
[Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ [ FilePath
"pkg-src-sha256" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String (HashValue -> FilePath
showHashValue HashValue
hash)
| Just HashValue
hash <- [ElaboratedConfiguredPackage -> Maybe HashValue
elabPkgSourceHash ElaboratedConfiguredPackage
elab]
]
[Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ ( case ElaboratedConfiguredPackage -> BuildStyle
elabBuildStyle ElaboratedConfiguredPackage
elab of
BuildInplaceOnly{} ->
[FilePath
"dist-dir" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
dist_dir] [Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ [Pair
buildInfoFileLocation]
BuildStyle
BuildAndInstall ->
[]
)
[Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ case ElaboratedConfiguredPackage -> ElaboratedPackageOrComponent
elabPkgOrComp ElaboratedConfiguredPackage
elab of
ElabPackage ElaboratedPackage
pkg ->
let components :: Value
components =
[Pair] -> Value
J.object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
[ Component -> FilePath
comp2str Component
c
FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= [Pair] -> Value
J.object
( [ FilePath
"depends" FilePath -> [Value] -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (ConfiguredId -> Value) -> [ConfiguredId] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map (ComponentId -> Value
forall a. Pretty a => a -> Value
jdisplay (ComponentId -> Value)
-> (ConfiguredId -> ComponentId) -> ConfiguredId -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConfiguredId -> ComponentId
confInstId) (((ConfiguredId, Bool) -> ConfiguredId)
-> [(ConfiguredId, Bool)] -> [ConfiguredId]
forall a b. (a -> b) -> [a] -> [b]
map (ConfiguredId, Bool) -> ConfiguredId
forall a b. (a, b) -> a
fst [(ConfiguredId, Bool)]
ldeps)
, FilePath
"exe-depends" FilePath -> [Value] -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (ConfiguredId -> Value) -> [ConfiguredId] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map (ComponentId -> Value
forall a. Pretty a => a -> Value
jdisplay (ComponentId -> Value)
-> (ConfiguredId -> ComponentId) -> ConfiguredId -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConfiguredId -> ComponentId
confInstId) [ConfiguredId]
edeps
]
[Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ Component -> [Pair]
bin_file Component
c
)
| (Component
c, ([(ConfiguredId, Bool)]
ldeps, [ConfiguredId]
edeps)) <-
ComponentDeps ([(ConfiguredId, Bool)], [ConfiguredId])
-> [(Component, ([(ConfiguredId, Bool)], [ConfiguredId]))]
forall a. ComponentDeps a -> [ComponentDep a]
ComponentDeps.toList (ComponentDeps ([(ConfiguredId, Bool)], [ConfiguredId])
-> [(Component, ([(ConfiguredId, Bool)], [ConfiguredId]))])
-> ComponentDeps ([(ConfiguredId, Bool)], [ConfiguredId])
-> [(Component, ([(ConfiguredId, Bool)], [ConfiguredId]))]
forall a b. (a -> b) -> a -> b
$
ComponentDeps [(ConfiguredId, Bool)]
-> ComponentDeps [ConfiguredId]
-> ComponentDeps ([(ConfiguredId, Bool)], [ConfiguredId])
forall a b.
(Monoid a, Monoid b) =>
ComponentDeps a -> ComponentDeps b -> ComponentDeps (a, b)
ComponentDeps.zip
(ElaboratedPackage -> ComponentDeps [(ConfiguredId, Bool)]
pkgLibDependencies ElaboratedPackage
pkg)
(ElaboratedPackage -> ComponentDeps [ConfiguredId]
pkgExeDependencies ElaboratedPackage
pkg)
]
in [FilePath
"components" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= Value
components]
ElabComponent ElaboratedComponent
comp ->
[ FilePath
"depends" FilePath -> [Value] -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (ConfiguredId -> Value) -> [ConfiguredId] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map (ComponentId -> Value
forall a. Pretty a => a -> Value
jdisplay (ComponentId -> Value)
-> (ConfiguredId -> ComponentId) -> ConfiguredId -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConfiguredId -> ComponentId
confInstId) (((ConfiguredId, Bool) -> ConfiguredId)
-> [(ConfiguredId, Bool)] -> [ConfiguredId]
forall a b. (a -> b) -> [a] -> [b]
map (ConfiguredId, Bool) -> ConfiguredId
forall a b. (a, b) -> a
fst ([(ConfiguredId, Bool)] -> [ConfiguredId])
-> [(ConfiguredId, Bool)] -> [ConfiguredId]
forall a b. (a -> b) -> a -> b
$ ElaboratedConfiguredPackage -> [(ConfiguredId, Bool)]
elabLibDependencies ElaboratedConfiguredPackage
elab)
, FilePath
"exe-depends" FilePath -> [Value] -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (ComponentId -> Value) -> [ComponentId] -> [Value]
forall a b. (a -> b) -> [a] -> [b]
map ComponentId -> Value
forall a. Pretty a => a -> Value
jdisplay (ElaboratedConfiguredPackage -> [ComponentId]
elabExeDependencies ElaboratedConfiguredPackage
elab)
, FilePath
"component-name" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String (Component -> FilePath
comp2str (ElaboratedComponent -> Component
compSolverName ElaboratedComponent
comp))
]
[Pair] -> [Pair] -> [Pair]
forall a. [a] -> [a] -> [a]
++ Component -> [Pair]
bin_file (ElaboratedComponent -> Component
compSolverName ElaboratedComponent
comp)
where
buildInfoFileLocation :: J.Pair
buildInfoFileLocation :: Pair
buildInfoFileLocation
| ElaboratedConfiguredPackage -> Version
elabSetupScriptCliVersion ElaboratedConfiguredPackage
elab Version -> Version -> Bool
forall a. Ord a => a -> a -> Bool
< [Int] -> Version
mkVersion [Int
3, Int
7, Int
0, Int
0] =
FilePath
"build-info" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= Value
J.Null
| Bool
otherwise =
FilePath
"build-info" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String (SymbolicPathX 'AllowAbsolute (ZonkAny 0) 'File -> FilePath
forall (allowAbsolute :: AllowAbsolute) from (to :: FileOrDir).
SymbolicPathX allowAbsolute from to -> FilePath
getSymbolicPath (SymbolicPathX 'AllowAbsolute (ZonkAny 0) 'File -> FilePath)
-> SymbolicPathX 'AllowAbsolute (ZonkAny 0) 'File -> FilePath
forall a b. (a -> b) -> a -> b
$ SymbolicPath (ZonkAny 0) ('Dir Dist)
-> SymbolicPathX 'AllowAbsolute (ZonkAny 0) 'File
forall root.
SymbolicPath root ('Dir Dist) -> SymbolicPath root 'File
buildInfoPref (SymbolicPath (ZonkAny 0) ('Dir Dist)
-> SymbolicPathX 'AllowAbsolute (ZonkAny 0) 'File)
-> SymbolicPath (ZonkAny 0) ('Dir Dist)
-> SymbolicPathX 'AllowAbsolute (ZonkAny 0) 'File
forall a b. (a -> b) -> a -> b
$ FilePath -> SymbolicPath (ZonkAny 0) ('Dir Dist)
forall from (to :: FileOrDir). FilePath -> SymbolicPath from to
makeSymbolicPath FilePath
dist_dir)
packageLocationToJ :: PackageLocation (Maybe FilePath) -> J.Value
packageLocationToJ :: PackageLocation (Maybe FilePath) -> Value
packageLocationToJ PackageLocation (Maybe FilePath)
pkgloc =
case PackageLocation (Maybe FilePath)
pkgloc of
LocalUnpackedPackage FilePath
local ->
[Pair] -> Value
J.object
[ FilePath
"type" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
"local"
, FilePath
"path" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
local
]
LocalTarballPackage FilePath
local ->
[Pair] -> Value
J.object
[ FilePath
"type" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
"local-tar"
, FilePath
"path" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
local
]
RemoteTarballPackage URI
uri Maybe FilePath
_ ->
[Pair] -> Value
J.object
[ FilePath
"type" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
"remote-tar"
, FilePath
"uri" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String (URI -> FilePath
forall a. Show a => a -> FilePath
show URI
uri)
]
RepoTarballPackage Repo
repo PackageIdentifier
_ Maybe FilePath
_ ->
[Pair] -> Value
J.object
[ FilePath
"type" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
"repo-tar"
, FilePath
"repo" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= Repo -> Value
repoToJ Repo
repo
]
RemoteSourceRepoPackage SourceRepoMaybe
srcRepo Maybe FilePath
_ ->
[Pair] -> Value
J.object
[ FilePath
"type" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
"source-repo"
, FilePath
"source-repo" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= SourceRepoMaybe -> Value
sourceRepoToJ SourceRepoMaybe
srcRepo
]
repoToJ :: Repo -> J.Value
repoToJ :: Repo -> Value
repoToJ Repo
repo =
case Repo
repo of
RepoLocalNoIndex{FilePath
LocalRepo
repoLocal :: LocalRepo
repoLocalDir :: FilePath
repoLocal :: Repo -> LocalRepo
repoLocalDir :: Repo -> FilePath
..} ->
[Pair] -> Value
J.object
[ FilePath
"type" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
"local-repo-no-index"
, FilePath
"path" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
repoLocalDir
]
RepoRemote{FilePath
RemoteRepo
repoLocalDir :: Repo -> FilePath
repoRemote :: RemoteRepo
repoLocalDir :: FilePath
repoRemote :: Repo -> RemoteRepo
..} ->
[Pair] -> Value
J.object
[ FilePath
"type" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
"remote-repo"
, FilePath
"uri" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String (URI -> FilePath
forall a. Show a => a -> FilePath
show (RemoteRepo -> URI
remoteRepoURI RemoteRepo
repoRemote))
]
RepoSecure{FilePath
RemoteRepo
repoLocalDir :: Repo -> FilePath
repoRemote :: Repo -> RemoteRepo
repoRemote :: RemoteRepo
repoLocalDir :: FilePath
..} ->
[Pair] -> Value
J.object
[ FilePath
"type" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
"secure-repo"
, FilePath
"uri" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String (URI -> FilePath
forall a. Show a => a -> FilePath
show (RemoteRepo -> URI
remoteRepoURI RemoteRepo
repoRemote))
]
sourceRepoToJ :: SourceRepoMaybe -> J.Value
sourceRepoToJ :: SourceRepoMaybe -> Value
sourceRepoToJ SourceRepositoryPackage{FilePath
[FilePath]
Maybe FilePath
RepoType
srpType :: RepoType
srpLocation :: FilePath
srpTag :: Maybe FilePath
srpBranch :: Maybe FilePath
srpSubdir :: Maybe FilePath
srpCommand :: [FilePath]
srpBranch :: forall (f :: * -> *). SourceRepositoryPackage f -> Maybe FilePath
srpCommand :: forall (f :: * -> *). SourceRepositoryPackage f -> [FilePath]
srpLocation :: forall (f :: * -> *). SourceRepositoryPackage f -> FilePath
srpSubdir :: forall (f :: * -> *). SourceRepositoryPackage f -> f FilePath
srpTag :: forall (f :: * -> *). SourceRepositoryPackage f -> Maybe FilePath
srpType :: forall (f :: * -> *). SourceRepositoryPackage f -> RepoType
..} =
[Pair] -> Value
J.object ([Pair] -> Value) -> [Pair] -> Value
forall a b. (a -> b) -> a -> b
$
(Pair -> Bool) -> [Pair] -> [Pair]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Value -> Value -> Bool
forall a. Eq a => a -> a -> Bool
/= Value
J.Null) (Value -> Bool) -> (Pair -> Value) -> Pair -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Pair -> Value
forall a b. (a, b) -> b
snd) ([Pair] -> [Pair]) -> [Pair] -> [Pair]
forall a b. (a -> b) -> a -> b
$
[ FilePath
"type" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= RepoType -> Value
forall a. Pretty a => a -> Value
jdisplay RepoType
srpType
, FilePath
"location" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
srpLocation
, FilePath
"branch" FilePath -> Maybe Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (FilePath -> Value) -> Maybe FilePath -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FilePath -> Value
J.String Maybe FilePath
srpBranch
, FilePath
"tag" FilePath -> Maybe Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (FilePath -> Value) -> Maybe FilePath -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FilePath -> Value
J.String Maybe FilePath
srpTag
, FilePath
"subdir" FilePath -> Maybe Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= (FilePath -> Value) -> Maybe FilePath -> Maybe Value
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FilePath -> Value
J.String Maybe FilePath
srpSubdir
]
dist_dir :: FilePath
dist_dir :: FilePath
dist_dir =
DistDirLayout -> DistDirParams -> FilePath
distBuildDirectory
DistDirLayout
distDirLayout
(ElaboratedSharedConfig
-> ElaboratedConfiguredPackage -> DistDirParams
elabDistDirParams ElaboratedSharedConfig
elaboratedSharedConfig ElaboratedConfiguredPackage
elab)
bin_file :: ComponentDeps.Component -> [J.Pair]
bin_file :: Component -> [Pair]
bin_file Component
c = case Component
c of
ComponentDeps.ComponentExe UnqualComponentName
s -> UnqualComponentName -> [Pair]
forall {p}. Pretty p => p -> [Pair]
bin_file' UnqualComponentName
s
ComponentDeps.ComponentTest UnqualComponentName
s -> UnqualComponentName -> [Pair]
forall {p}. Pretty p => p -> [Pair]
bin_file' UnqualComponentName
s
ComponentDeps.ComponentBench UnqualComponentName
s -> UnqualComponentName -> [Pair]
forall {p}. Pretty p => p -> [Pair]
bin_file' UnqualComponentName
s
ComponentDeps.ComponentFLib UnqualComponentName
s -> UnqualComponentName -> [Pair]
forall a. (Pretty a, Show a) => a -> [Pair]
flib_file' UnqualComponentName
s
Component
_ -> []
bin_file' :: p -> [Pair]
bin_file' p
s =
[FilePath
"bin-file" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
bin]
where
bin :: FilePath
bin =
if BuildStyle -> Bool
isInplaceBuildStyle (ElaboratedConfiguredPackage -> BuildStyle
elabBuildStyle ElaboratedConfiguredPackage
elab)
then FilePath
dist_dir FilePath -> FilePath -> FilePath
</> FilePath
"build" FilePath -> FilePath -> FilePath
</> p -> FilePath
forall a. Pretty a => a -> FilePath
prettyShow p
s FilePath -> FilePath -> FilePath
</> p -> FilePath
forall a. Pretty a => a -> FilePath
prettyShow p
s FilePath -> FilePath -> FilePath
<.> Platform -> FilePath
exeExtension Platform
plat
else InstallDirs FilePath -> FilePath
forall dir. InstallDirs dir -> dir
InstallDirs.bindir (ElaboratedConfiguredPackage -> InstallDirs FilePath
elabInstallDirs ElaboratedConfiguredPackage
elab) FilePath -> FilePath -> FilePath
</> p -> FilePath
forall a. Pretty a => a -> FilePath
prettyShow p
s FilePath -> FilePath -> FilePath
<.> Platform -> FilePath
exeExtension Platform
plat
flib_file' :: (Pretty a, Show a) => a -> [J.Pair]
flib_file' :: forall a. (Pretty a, Show a) => a -> [Pair]
flib_file' a
s =
[FilePath
"bin-file" FilePath -> Value -> Pair
forall v. ToJSON v => FilePath -> v -> Pair
J..= FilePath -> Value
J.String FilePath
bin]
where
bin :: FilePath
bin =
if BuildStyle -> Bool
isInplaceBuildStyle (ElaboratedConfiguredPackage -> BuildStyle
elabBuildStyle ElaboratedConfiguredPackage
elab)
then FilePath
dist_dir FilePath -> FilePath -> FilePath
</> FilePath
"build" FilePath -> FilePath -> FilePath
</> a -> FilePath
forall a. Pretty a => a -> FilePath
prettyShow a
s FilePath -> FilePath -> FilePath
</> (FilePath
"lib" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ a -> FilePath
forall a. Pretty a => a -> FilePath
prettyShow a
s) FilePath -> FilePath -> FilePath
<.> Platform -> FilePath
dllExtension Platform
plat
else InstallDirs FilePath -> FilePath
forall dir. InstallDirs dir -> dir
InstallDirs.bindir (ElaboratedConfiguredPackage -> InstallDirs FilePath
elabInstallDirs ElaboratedConfiguredPackage
elab) FilePath -> FilePath -> FilePath
</> (FilePath
"lib" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ a -> FilePath
forall a. Pretty a => a -> FilePath
prettyShow a
s) FilePath -> FilePath -> FilePath
<.> Platform -> FilePath
dllExtension Platform
plat
comp2str :: ComponentDeps.Component -> String
comp2str :: Component -> FilePath
comp2str = Component -> FilePath
forall a. Pretty a => a -> FilePath
prettyShow
style2str :: Bool -> BuildStyle -> String
style2str :: Bool -> BuildStyle -> FilePath
style2str Bool
True BuildStyle
_ = FilePath
"local"
style2str Bool
False (BuildInplaceOnly MemoryOrDisk
OnDisk) = FilePath
"inplace"
style2str Bool
False (BuildInplaceOnly MemoryOrDisk
InMemory) = FilePath
"interactive"
style2str Bool
False BuildStyle
BuildAndInstall = FilePath
"global"
jdisplay :: Pretty a => a -> J.Value
jdisplay :: forall a. Pretty a => a -> Value
jdisplay = FilePath -> Value
J.String (FilePath -> Value) -> (a -> FilePath) -> a -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> FilePath
forall a. Pretty a => a -> FilePath
prettyShow
type PackageIdSet = Set UnitId
type PackagesUpToDate = PackageIdSet
data PostBuildProjectStatus = PostBuildProjectStatus
{ PostBuildProjectStatus -> Set UnitId
packagesDefinitelyUpToDate :: PackageIdSet
, PostBuildProjectStatus -> Set UnitId
packagesProbablyUpToDate :: PackageIdSet
, PostBuildProjectStatus -> Set UnitId
packagesOutOfDate :: PackageIdSet
, PostBuildProjectStatus -> Set UnitId
packagesInvalidByChangedLibDeps :: PackageIdSet
, PostBuildProjectStatus -> Set UnitId
packagesInvalidByFailedBuild :: PackageIdSet
, PostBuildProjectStatus -> Graph (Node UnitId ElaboratedPlanPackage)
packagesLibDepGraph :: Graph (Node UnitId ElaboratedPlanPackage)
, PostBuildProjectStatus -> Set UnitId
packagesBuildLocal :: PackageIdSet
, PostBuildProjectStatus -> Set UnitId
packagesBuildInplace :: PackageIdSet
, PostBuildProjectStatus -> Set UnitId
packagesAlreadyInStore :: PackageIdSet
}
postBuildProjectStatus
:: ElaboratedInstallPlan
-> PackagesUpToDate
-> BuildStatusMap
-> BuildOutcomes
-> PostBuildProjectStatus
postBuildProjectStatus :: ElaboratedInstallPlan
-> Set UnitId
-> BuildStatusMap
-> BuildOutcomes
-> PostBuildProjectStatus
postBuildProjectStatus
ElaboratedInstallPlan
plan
Set UnitId
previousPackagesUpToDate
BuildStatusMap
pkgBuildStatus
BuildOutcomes
buildOutcomes =
PostBuildProjectStatus
{ Set UnitId
packagesDefinitelyUpToDate :: Set UnitId
packagesDefinitelyUpToDate :: Set UnitId
packagesDefinitelyUpToDate
, Set UnitId
packagesProbablyUpToDate :: Set UnitId
packagesProbablyUpToDate :: Set UnitId
packagesProbablyUpToDate
, Set UnitId
packagesOutOfDate :: Set UnitId
packagesOutOfDate :: Set UnitId
packagesOutOfDate
, Set UnitId
packagesInvalidByChangedLibDeps :: Set UnitId
packagesInvalidByChangedLibDeps :: Set UnitId
packagesInvalidByChangedLibDeps
, Set UnitId
packagesInvalidByFailedBuild :: Set UnitId
packagesInvalidByFailedBuild :: Set UnitId
packagesInvalidByFailedBuild
,
Graph (Node UnitId ElaboratedPlanPackage)
packagesLibDepGraph :: Graph (Node UnitId ElaboratedPlanPackage)
packagesLibDepGraph :: Graph (Node UnitId ElaboratedPlanPackage)
packagesLibDepGraph
, Set UnitId
packagesBuildLocal :: Set UnitId
packagesBuildLocal :: Set UnitId
packagesBuildLocal
, Set UnitId
packagesBuildInplace :: Set UnitId
packagesBuildInplace :: Set UnitId
packagesBuildInplace
, Set UnitId
packagesAlreadyInStore :: Set UnitId
packagesAlreadyInStore :: Set UnitId
packagesAlreadyInStore
}
where
packagesDefinitelyUpToDate :: Set UnitId
packagesDefinitelyUpToDate =
Set UnitId
packagesUpToDatePreBuild
Set UnitId -> Set UnitId -> Set UnitId
forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set UnitId
packagesSuccessfulPostBuild
packagesProbablyUpToDate :: Set UnitId
packagesProbablyUpToDate =
Set UnitId
packagesDefinitelyUpToDate
Set UnitId -> Set UnitId -> Set UnitId
forall a. Ord a => Set a -> Set a -> Set a
`Set.union` (Set UnitId
previousPackagesUpToDate' Set UnitId -> Set UnitId -> Set UnitId
forall a. Ord a => Set a -> Set a -> Set a
`Set.difference` Set UnitId
packagesOutOfDatePreBuild)
packagesOutOfDate :: Set UnitId
packagesOutOfDate =
Set UnitId
packagesOutOfDatePreBuild Set UnitId -> Set UnitId -> Set UnitId
forall a. Ord a => Set a -> Set a -> Set a
`Set.difference` Set UnitId
packagesSuccessfulPostBuild
packagesInvalidByChangedLibDeps :: Set UnitId
packagesInvalidByChangedLibDeps =
Set UnitId
packagesDepOnChangedLib Set UnitId -> Set UnitId -> Set UnitId
forall a. Ord a => Set a -> Set a -> Set a
`Set.difference` Set UnitId
packagesSuccessfulPostBuild
packagesInvalidByFailedBuild :: Set UnitId
packagesInvalidByFailedBuild =
Set UnitId
packagesFailurePostBuild
previousPackagesUpToDate' :: Set UnitId
previousPackagesUpToDate' =
Set UnitId -> Set UnitId -> Set UnitId
forall a. Ord a => Set a -> Set a -> Set a
Set.intersection
Set UnitId
previousPackagesUpToDate
(ElaboratedInstallPlan -> Set UnitId
forall ipkg srcpkg. GenericInstallPlan ipkg srcpkg -> Set UnitId
InstallPlan.keysSet ElaboratedInstallPlan
plan)
packagesUpToDatePreBuild :: Set UnitId
packagesUpToDatePreBuild =
(UnitId -> Bool) -> Set UnitId -> Set UnitId
forall a. (a -> Bool) -> Set a -> Set a
Set.filter
(\UnitId
ipkgid -> Bool -> Bool
not (Bool -> UnitId -> Bool
lookupBuildStatusRequiresBuild Bool
True UnitId
ipkgid))
(ElaboratedInstallPlan -> Set UnitId
forall ipkg srcpkg. GenericInstallPlan ipkg srcpkg -> Set UnitId
InstallPlan.keysSet ElaboratedInstallPlan
plan)
packagesOutOfDatePreBuild :: Set UnitId
packagesOutOfDatePreBuild =
[UnitId] -> Set UnitId
forall a. Ord a => [a] -> Set a
Set.fromList ([UnitId] -> Set UnitId)
-> ([ElaboratedPlanPackage] -> [UnitId])
-> [ElaboratedPlanPackage]
-> Set UnitId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ElaboratedPlanPackage -> UnitId)
-> [ElaboratedPlanPackage] -> [UnitId]
forall a b. (a -> b) -> [a] -> [b]
map ElaboratedPlanPackage -> UnitId
forall pkg. HasUnitId pkg => pkg -> UnitId
installedUnitId ([ElaboratedPlanPackage] -> Set UnitId)
-> [ElaboratedPlanPackage] -> Set UnitId
forall a b. (a -> b) -> a -> b
$
ElaboratedInstallPlan -> [UnitId] -> [ElaboratedPlanPackage]
forall ipkg srcpkg.
GenericInstallPlan ipkg srcpkg
-> [UnitId] -> [GenericPlanPackage ipkg srcpkg]
InstallPlan.reverseDependencyClosure
ElaboratedInstallPlan
plan
[ UnitId
ipkgid
| ElaboratedPlanPackage
pkg <- ElaboratedInstallPlan -> [ElaboratedPlanPackage]
forall ipkg srcpkg.
GenericInstallPlan ipkg srcpkg -> [GenericPlanPackage ipkg srcpkg]
InstallPlan.toList ElaboratedInstallPlan
plan
, let ipkgid :: UnitId
ipkgid = ElaboratedPlanPackage -> UnitId
forall pkg. HasUnitId pkg => pkg -> UnitId
installedUnitId ElaboratedPlanPackage
pkg
, Bool -> UnitId -> Bool
lookupBuildStatusRequiresBuild Bool
False UnitId
ipkgid
]
packagesSuccessfulPostBuild :: Set UnitId
packagesSuccessfulPostBuild =
[UnitId] -> Set UnitId
forall a. Ord a => [a] -> Set a
Set.fromList
[UnitId
ikgid | (UnitId
ikgid, Right BuildResult
_) <- BuildOutcomes -> [(UnitId, BuildOutcome)]
forall k a. Map k a -> [(k, a)]
Map.toList BuildOutcomes
buildOutcomes]
packagesFailurePostBuild :: Set UnitId
packagesFailurePostBuild =
[UnitId] -> Set UnitId
forall a. Ord a => [a] -> Set a
Set.fromList
[ UnitId
ikgid
| (UnitId
ikgid, Left BuildFailure
failure) <- BuildOutcomes -> [(UnitId, BuildOutcome)]
forall k a. Map k a -> [(k, a)]
Map.toList BuildOutcomes
buildOutcomes
, case BuildFailure -> BuildFailureReason
buildFailureReason BuildFailure
failure of
DependentFailed PackageIdentifier
_ -> Bool
False
BuildFailureReason
_ -> Bool
True
]
packagesDepOnChangedLib :: Set UnitId
packagesDepOnChangedLib =
[UnitId] -> Set UnitId
forall a. Ord a => [a] -> Set a
Set.fromList ([UnitId] -> Set UnitId)
-> ([Node UnitId ElaboratedPlanPackage] -> [UnitId])
-> [Node UnitId ElaboratedPlanPackage]
-> Set UnitId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Node UnitId ElaboratedPlanPackage -> UnitId)
-> [Node UnitId ElaboratedPlanPackage] -> [UnitId]
forall a b. (a -> b) -> [a] -> [b]
map Node UnitId ElaboratedPlanPackage -> UnitId
Node UnitId ElaboratedPlanPackage
-> Key (Node UnitId ElaboratedPlanPackage)
forall a. IsNode a => a -> Key a
Graph.nodeKey ([Node UnitId ElaboratedPlanPackage] -> Set UnitId)
-> [Node UnitId ElaboratedPlanPackage] -> Set UnitId
forall a b. (a -> b) -> a -> b
$
[Node UnitId ElaboratedPlanPackage]
-> Maybe [Node UnitId ElaboratedPlanPackage]
-> [Node UnitId ElaboratedPlanPackage]
forall a. a -> Maybe a -> a
fromMaybe (FilePath -> [Node UnitId ElaboratedPlanPackage]
forall a. HasCallStack => FilePath -> a
error FilePath
"packagesBuildStatusAfterBuild: broken dep closure") (Maybe [Node UnitId ElaboratedPlanPackage]
-> [Node UnitId ElaboratedPlanPackage])
-> Maybe [Node UnitId ElaboratedPlanPackage]
-> [Node UnitId ElaboratedPlanPackage]
forall a b. (a -> b) -> a -> b
$
Graph (Node UnitId ElaboratedPlanPackage)
-> [Key (Node UnitId ElaboratedPlanPackage)]
-> Maybe [Node UnitId ElaboratedPlanPackage]
forall a. Graph a -> [Key a] -> Maybe [a]
Graph.revClosure
Graph (Node UnitId ElaboratedPlanPackage)
packagesLibDepGraph
( Map UnitId (BuildStatus, BuildOutcome) -> [UnitId]
Map UnitId (BuildStatus, BuildOutcome)
-> [Key (Node UnitId ElaboratedPlanPackage)]
forall k a. Map k a -> [k]
Map.keys
(Map UnitId (BuildStatus, BuildOutcome)
-> [Key (Node UnitId ElaboratedPlanPackage)])
-> (Map UnitId (BuildStatus, BuildOutcome)
-> Map UnitId (BuildStatus, BuildOutcome))
-> Map UnitId (BuildStatus, BuildOutcome)
-> [Key (Node UnitId ElaboratedPlanPackage)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((BuildStatus, BuildOutcome) -> Bool)
-> Map UnitId (BuildStatus, BuildOutcome)
-> Map UnitId (BuildStatus, BuildOutcome)
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter ((BuildStatus -> BuildOutcome -> Bool)
-> (BuildStatus, BuildOutcome) -> Bool
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry BuildStatus -> BuildOutcome -> Bool
buildAttempted)
(Map UnitId (BuildStatus, BuildOutcome)
-> [Key (Node UnitId ElaboratedPlanPackage)])
-> Map UnitId (BuildStatus, BuildOutcome)
-> [Key (Node UnitId ElaboratedPlanPackage)]
forall a b. (a -> b) -> a -> b
$ (BuildStatus -> BuildOutcome -> (BuildStatus, BuildOutcome))
-> BuildStatusMap
-> BuildOutcomes
-> Map UnitId (BuildStatus, BuildOutcome)
forall k a b c.
Ord k =>
(a -> b -> c) -> Map k a -> Map k b -> Map k c
Map.intersectionWith (,) BuildStatusMap
pkgBuildStatus BuildOutcomes
buildOutcomes
)
packagesLibDepGraph :: Graph (Node UnitId ElaboratedPlanPackage)
packagesLibDepGraph :: Graph (Node UnitId ElaboratedPlanPackage)
packagesLibDepGraph =
[Node UnitId ElaboratedPlanPackage]
-> Graph (Node UnitId ElaboratedPlanPackage)
forall a. (IsNode a, Show (Key a)) => [a] -> Graph a
Graph.fromDistinctList
[ ElaboratedPlanPackage
-> UnitId -> [UnitId] -> Node UnitId ElaboratedPlanPackage
forall k a. a -> k -> [k] -> Node k a
Graph.N ElaboratedPlanPackage
pkg (ElaboratedPlanPackage -> UnitId
forall pkg. HasUnitId pkg => pkg -> UnitId
installedUnitId ElaboratedPlanPackage
pkg) [UnitId]
libdeps
| ElaboratedPlanPackage
pkg <- ElaboratedInstallPlan -> [ElaboratedPlanPackage]
forall ipkg srcpkg.
GenericInstallPlan ipkg srcpkg -> [GenericPlanPackage ipkg srcpkg]
InstallPlan.toList ElaboratedInstallPlan
plan
, let libdeps :: [UnitId]
libdeps = case ElaboratedPlanPackage
pkg of
InstallPlan.PreExisting InstalledPackageInfo
ipkg -> InstalledPackageInfo -> [UnitId]
forall pkg. PackageInstalled pkg => pkg -> [UnitId]
installedDepends InstalledPackageInfo
ipkg
InstallPlan.Configured ElaboratedConfiguredPackage
srcpkg -> ElaboratedConfiguredPackage -> [UnitId]
elabLibDeps ElaboratedConfiguredPackage
srcpkg
InstallPlan.Installed ElaboratedConfiguredPackage
srcpkg -> ElaboratedConfiguredPackage -> [UnitId]
elabLibDeps ElaboratedConfiguredPackage
srcpkg
]
elabLibDeps :: ElaboratedConfiguredPackage -> [UnitId]
elabLibDeps :: ElaboratedConfiguredPackage -> [UnitId]
elabLibDeps = (ConfiguredId -> UnitId) -> [ConfiguredId] -> [UnitId]
forall a b. (a -> b) -> [a] -> [b]
map (ComponentId -> UnitId
newSimpleUnitId (ComponentId -> UnitId)
-> (ConfiguredId -> ComponentId) -> ConfiguredId -> UnitId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConfiguredId -> ComponentId
confInstId) ([ConfiguredId] -> [UnitId])
-> (ElaboratedConfiguredPackage -> [ConfiguredId])
-> ElaboratedConfiguredPackage
-> [UnitId]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((ConfiguredId, Bool) -> ConfiguredId)
-> [(ConfiguredId, Bool)] -> [ConfiguredId]
forall a b. (a -> b) -> [a] -> [b]
map (ConfiguredId, Bool) -> ConfiguredId
forall a b. (a, b) -> a
fst ([(ConfiguredId, Bool)] -> [ConfiguredId])
-> (ElaboratedConfiguredPackage -> [(ConfiguredId, Bool)])
-> ElaboratedConfiguredPackage
-> [ConfiguredId]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ElaboratedConfiguredPackage -> [(ConfiguredId, Bool)]
elabLibDependencies
buildAttempted :: BuildStatus -> BuildOutcome -> Bool
buildAttempted :: BuildStatus -> BuildOutcome -> Bool
buildAttempted BuildStatus
buildStatus BuildOutcome
_buildOutcome
| Bool -> Bool
not (BuildStatus -> Bool
buildStatusRequiresBuild BuildStatus
buildStatus) =
Bool
False
buildAttempted BuildStatus
_ (Left BuildFailure{BuildFailureReason
buildFailureReason :: BuildFailure -> BuildFailureReason
buildFailureReason :: BuildFailureReason
buildFailureReason})
| DependentFailed PackageIdentifier
_ <- BuildFailureReason
buildFailureReason =
Bool
False
buildAttempted BuildStatus
_ (Left BuildFailure{}) = Bool
True
buildAttempted BuildStatus
_ (Right BuildResult
_) = Bool
True
lookupBuildStatusRequiresBuild :: Bool -> UnitId -> Bool
lookupBuildStatusRequiresBuild :: Bool -> UnitId -> Bool
lookupBuildStatusRequiresBuild Bool
def UnitId
ipkgid =
case UnitId -> BuildStatusMap -> Maybe BuildStatus
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup UnitId
ipkgid BuildStatusMap
pkgBuildStatus of
Maybe BuildStatus
Nothing -> Bool
def
Just BuildStatus
buildStatus -> BuildStatus -> Bool
buildStatusRequiresBuild BuildStatus
buildStatus
packagesBuildLocal :: Set UnitId
packagesBuildLocal :: Set UnitId
packagesBuildLocal =
(ElaboratedPlanPackage -> Bool) -> Set UnitId
selectPlanPackageIdSet ((ElaboratedPlanPackage -> Bool) -> Set UnitId)
-> (ElaboratedPlanPackage -> Bool) -> Set UnitId
forall a b. (a -> b) -> a -> b
$ \ElaboratedPlanPackage
pkg ->
case ElaboratedPlanPackage
pkg of
InstallPlan.PreExisting InstalledPackageInfo
_ -> Bool
False
InstallPlan.Installed ElaboratedConfiguredPackage
_ -> Bool
False
InstallPlan.Configured ElaboratedConfiguredPackage
srcpkg -> ElaboratedConfiguredPackage -> Bool
elabLocalToProject ElaboratedConfiguredPackage
srcpkg
packagesBuildInplace :: Set UnitId
packagesBuildInplace :: Set UnitId
packagesBuildInplace =
(ElaboratedPlanPackage -> Bool) -> Set UnitId
selectPlanPackageIdSet ((ElaboratedPlanPackage -> Bool) -> Set UnitId)
-> (ElaboratedPlanPackage -> Bool) -> Set UnitId
forall a b. (a -> b) -> a -> b
$ \ElaboratedPlanPackage
pkg ->
case ElaboratedPlanPackage
pkg of
InstallPlan.PreExisting InstalledPackageInfo
_ -> Bool
False
InstallPlan.Installed ElaboratedConfiguredPackage
_ -> Bool
False
InstallPlan.Configured ElaboratedConfiguredPackage
srcpkg -> BuildStyle -> Bool
isInplaceBuildStyle (ElaboratedConfiguredPackage -> BuildStyle
elabBuildStyle ElaboratedConfiguredPackage
srcpkg)
packagesAlreadyInStore :: Set UnitId
packagesAlreadyInStore :: Set UnitId
packagesAlreadyInStore =
(ElaboratedPlanPackage -> Bool) -> Set UnitId
selectPlanPackageIdSet ((ElaboratedPlanPackage -> Bool) -> Set UnitId)
-> (ElaboratedPlanPackage -> Bool) -> Set UnitId
forall a b. (a -> b) -> a -> b
$ \ElaboratedPlanPackage
pkg ->
case ElaboratedPlanPackage
pkg of
InstallPlan.PreExisting InstalledPackageInfo
_ -> Bool
True
InstallPlan.Installed ElaboratedConfiguredPackage
_ -> Bool
True
InstallPlan.Configured ElaboratedConfiguredPackage
_ -> Bool
False
selectPlanPackageIdSet
:: ( InstallPlan.GenericPlanPackage InstalledPackageInfo ElaboratedConfiguredPackage
-> Bool
)
-> Set UnitId
selectPlanPackageIdSet :: (ElaboratedPlanPackage -> Bool) -> Set UnitId
selectPlanPackageIdSet ElaboratedPlanPackage -> Bool
p =
Map UnitId ElaboratedPlanPackage -> Set UnitId
forall k a. Map k a -> Set k
Map.keysSet
(Map UnitId ElaboratedPlanPackage -> Set UnitId)
-> (Map UnitId ElaboratedPlanPackage
-> Map UnitId ElaboratedPlanPackage)
-> Map UnitId ElaboratedPlanPackage
-> Set UnitId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ElaboratedPlanPackage -> Bool)
-> Map UnitId ElaboratedPlanPackage
-> Map UnitId ElaboratedPlanPackage
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter ElaboratedPlanPackage -> Bool
p
(Map UnitId ElaboratedPlanPackage -> Set UnitId)
-> Map UnitId ElaboratedPlanPackage -> Set UnitId
forall a b. (a -> b) -> a -> b
$ ElaboratedInstallPlan -> Map UnitId ElaboratedPlanPackage
forall ipkg srcpkg.
GenericInstallPlan ipkg srcpkg
-> Map UnitId (GenericPlanPackage ipkg srcpkg)
InstallPlan.toMap ElaboratedInstallPlan
plan
updatePostBuildProjectStatus
:: Verbosity
-> DistDirLayout
-> ElaboratedInstallPlan
-> BuildStatusMap
-> BuildOutcomes
-> IO PostBuildProjectStatus
updatePostBuildProjectStatus :: Verbosity
-> DistDirLayout
-> ElaboratedInstallPlan
-> BuildStatusMap
-> BuildOutcomes
-> IO PostBuildProjectStatus
updatePostBuildProjectStatus
Verbosity
verbosity
DistDirLayout
distDirLayout
ElaboratedInstallPlan
elaboratedInstallPlan
BuildStatusMap
pkgsBuildStatus
BuildOutcomes
buildOutcomes = do
previousUpToDate <- DistDirLayout -> IO (Set UnitId)
readPackagesUpToDateCacheFile DistDirLayout
distDirLayout
let currentBuildStatus@PostBuildProjectStatus{..} =
postBuildProjectStatus
elaboratedInstallPlan
previousUpToDate
pkgsBuildStatus
buildOutcomes
let currentUpToDate = Set UnitId
packagesProbablyUpToDate
writePackagesUpToDateCacheFile distDirLayout currentUpToDate
debugNoWrap verbosity $
"packages definitely up to date: "
++ displayPackageIdSet
( packagesDefinitelyUpToDate
`Set.intersection` packagesBuildInplace
)
debugNoWrap verbosity $
"packages previously probably up to date: "
++ displayPackageIdSet
( previousUpToDate
`Set.intersection` packagesBuildInplace
)
debugNoWrap verbosity $
"packages now probably up to date: "
++ displayPackageIdSet
( packagesProbablyUpToDate
`Set.intersection` packagesBuildInplace
)
debugNoWrap verbosity $
"packages newly up to date: "
++ displayPackageIdSet
( packagesDefinitelyUpToDate
`Set.difference` previousUpToDate
`Set.intersection` packagesBuildInplace
)
debugNoWrap verbosity $
"packages out to date: "
++ displayPackageIdSet
( packagesOutOfDate
`Set.intersection` packagesBuildInplace
)
debugNoWrap verbosity $
"packages invalid due to dep change: "
++ displayPackageIdSet packagesInvalidByChangedLibDeps
debugNoWrap verbosity $
"packages invalid due to build failure: "
++ displayPackageIdSet packagesInvalidByFailedBuild
return currentBuildStatus
where
displayPackageIdSet :: Set UnitId -> FilePath
displayPackageIdSet = FilePath -> [FilePath] -> FilePath
forall a. [a] -> [[a]] -> [a]
intercalate FilePath
", " ([FilePath] -> FilePath)
-> (Set UnitId -> [FilePath]) -> Set UnitId -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UnitId -> FilePath) -> [UnitId] -> [FilePath]
forall a b. (a -> b) -> [a] -> [b]
map UnitId -> FilePath
forall a. Pretty a => a -> FilePath
prettyShow ([UnitId] -> [FilePath])
-> (Set UnitId -> [UnitId]) -> Set UnitId -> [FilePath]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set UnitId -> [UnitId]
forall a. Set a -> [a]
Set.toList
readPackagesUpToDateCacheFile :: DistDirLayout -> IO PackagesUpToDate
readPackagesUpToDateCacheFile :: DistDirLayout -> IO (Set UnitId)
readPackagesUpToDateCacheFile DistDirLayout{FilePath -> FilePath
distProjectCacheFile :: DistDirLayout -> FilePath -> FilePath
distProjectCacheFile :: FilePath -> FilePath
distProjectCacheFile} =
Set UnitId -> IO (Set UnitId) -> IO (Set UnitId)
forall a. a -> IO a -> IO a
handleDoesNotExist Set UnitId
forall a. Set a
Set.empty (IO (Set UnitId) -> IO (Set UnitId))
-> IO (Set UnitId) -> IO (Set UnitId)
forall a b. (a -> b) -> a -> b
$
IO (Either FilePath (Set UnitId)) -> IO (Set UnitId)
forall {b} {a}. IO (Either b (Set a)) -> IO (Set a)
handleDecodeFailure (IO (Either FilePath (Set UnitId)) -> IO (Set UnitId))
-> IO (Either FilePath (Set UnitId)) -> IO (Set UnitId)
forall a b. (a -> b) -> a -> b
$
FilePath
-> IOMode
-> (Handle -> IO (Either FilePath (Set UnitId)))
-> IO (Either FilePath (Set UnitId))
forall r. FilePath -> IOMode -> (Handle -> IO r) -> IO r
withBinaryFile (FilePath -> FilePath
distProjectCacheFile FilePath
"up-to-date") IOMode
ReadMode ((Handle -> IO (Either FilePath (Set UnitId)))
-> IO (Either FilePath (Set UnitId)))
-> (Handle -> IO (Either FilePath (Set UnitId)))
-> IO (Either FilePath (Set UnitId))
forall a b. (a -> b) -> a -> b
$ \Handle
hnd ->
ByteString -> IO (Either FilePath (Set UnitId))
forall a. Binary a => ByteString -> IO (Either FilePath a)
Binary.decodeOrFailIO (ByteString -> IO (Either FilePath (Set UnitId)))
-> IO ByteString -> IO (Either FilePath (Set UnitId))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Handle -> IO ByteString
BS.hGetContents Handle
hnd
where
handleDecodeFailure :: IO (Either b (Set a)) -> IO (Set a)
handleDecodeFailure = (Either b (Set a) -> Set a) -> IO (Either b (Set a)) -> IO (Set a)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((b -> Set a) -> (Set a -> Set a) -> Either b (Set a) -> Set a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (Set a -> b -> Set a
forall a b. a -> b -> a
const Set a
forall a. Set a
Set.empty) Set a -> Set a
forall a. a -> a
id)
writePackagesUpToDateCacheFile :: DistDirLayout -> PackagesUpToDate -> IO ()
writePackagesUpToDateCacheFile :: DistDirLayout -> Set UnitId -> IO ()
writePackagesUpToDateCacheFile DistDirLayout{FilePath -> FilePath
distProjectCacheFile :: DistDirLayout -> FilePath -> FilePath
distProjectCacheFile :: FilePath -> FilePath
distProjectCacheFile} Set UnitId
upToDate =
FilePath -> ByteString -> IO ()
writeFileAtomic (FilePath -> FilePath
distProjectCacheFile FilePath
"up-to-date") (ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$
Set UnitId -> ByteString
forall a. Binary a => a -> ByteString
Binary.encode Set UnitId
upToDate
createPackageEnvironmentAndArgs
:: Verbosity
-> FilePath
-> ElaboratedInstallPlan
-> ElaboratedSharedConfig
-> PostBuildProjectStatus
-> IO ([String], [(String, Maybe String)])
createPackageEnvironmentAndArgs :: Verbosity
-> FilePath
-> ElaboratedInstallPlan
-> ElaboratedSharedConfig
-> PostBuildProjectStatus
-> IO ([FilePath], [(FilePath, Maybe FilePath)])
createPackageEnvironmentAndArgs
Verbosity
verbosity
FilePath
path
ElaboratedInstallPlan
elaboratedPlan
ElaboratedSharedConfig
elaboratedShared
PostBuildProjectStatus
buildStatus
| Compiler -> CompilerFlavor
compilerFlavor (ElaboratedSharedConfig -> Compiler
pkgConfigCompiler ElaboratedSharedConfig
elaboratedShared) CompilerFlavor -> CompilerFlavor -> Bool
forall a. Eq a => a -> a -> Bool
== CompilerFlavor
GHC =
do
envFileM <-
FilePath
-> ElaboratedInstallPlan
-> ElaboratedSharedConfig
-> PostBuildProjectStatus
-> IO (Maybe FilePath)
writePlanGhcEnvironment
FilePath
path
ElaboratedInstallPlan
elaboratedPlan
ElaboratedSharedConfig
elaboratedShared
PostBuildProjectStatus
buildStatus
case envFileM of
Just FilePath
envFile -> ([FilePath], [(FilePath, Maybe FilePath)])
-> IO ([FilePath], [(FilePath, Maybe FilePath)])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([FilePath
"-package-env=" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
envFile], [(FilePath
"GHC_ENVIRONMENT", FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
envFile)])
Maybe FilePath
Nothing -> do
Verbosity -> FilePath -> IO ()
warn Verbosity
verbosity FilePath
"the configured version of GHC does not support reading package lists from the environment; commands that need the current project's package database are likely to fail"
([FilePath], [(FilePath, Maybe FilePath)])
-> IO ([FilePath], [(FilePath, Maybe FilePath)])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [])
| Bool
otherwise =
do
Verbosity -> FilePath -> IO ()
warn Verbosity
verbosity FilePath
"package environment configuration is not supported for the currently configured compiler; commands that need the current project's package database are likely to fail"
([FilePath], [(FilePath, Maybe FilePath)])
-> IO ([FilePath], [(FilePath, Maybe FilePath)])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [])
writePlanGhcEnvironment
:: FilePath
-> ElaboratedInstallPlan
-> ElaboratedSharedConfig
-> PostBuildProjectStatus
-> IO (Maybe FilePath)
writePlanGhcEnvironment :: FilePath
-> ElaboratedInstallPlan
-> ElaboratedSharedConfig
-> PostBuildProjectStatus
-> IO (Maybe FilePath)
writePlanGhcEnvironment
FilePath
path
ElaboratedInstallPlan
elaboratedInstallPlan
ElaboratedSharedConfig
{ pkgConfigCompiler :: ElaboratedSharedConfig -> Compiler
pkgConfigCompiler = Compiler
compiler
, pkgConfigPlatform :: ElaboratedSharedConfig -> Platform
pkgConfigPlatform = Platform
platform
}
PostBuildProjectStatus
postBuildStatus
| Compiler -> CompilerFlavor
compilerFlavor Compiler
compiler CompilerFlavor -> CompilerFlavor -> Bool
forall a. Eq a => a -> a -> Bool
== CompilerFlavor
GHC
, GhcImplInfo -> Bool
supportsPkgEnvFiles (Compiler -> GhcImplInfo
getImplInfo Compiler
compiler) =
(FilePath -> Maybe FilePath) -> IO FilePath -> IO (Maybe FilePath)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just (IO FilePath -> IO (Maybe FilePath))
-> IO FilePath -> IO (Maybe FilePath)
forall a b. (a -> b) -> a -> b
$
FilePath
-> Platform
-> Version
-> [GhcEnvironmentFileEntry FilePath]
-> IO FilePath
writeGhcEnvironmentFile
FilePath
path
Platform
platform
(Compiler -> Version
compilerVersion Compiler
compiler)
( FilePath
-> ElaboratedInstallPlan
-> PostBuildProjectStatus
-> [GhcEnvironmentFileEntry FilePath]
renderGhcEnvironmentFile
FilePath
path
ElaboratedInstallPlan
elaboratedInstallPlan
PostBuildProjectStatus
postBuildStatus
)
writePlanGhcEnvironment FilePath
_ ElaboratedInstallPlan
_ ElaboratedSharedConfig
_ PostBuildProjectStatus
_ = Maybe FilePath -> IO (Maybe FilePath)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe FilePath
forall a. Maybe a
Nothing
renderGhcEnvironmentFile
:: FilePath
-> ElaboratedInstallPlan
-> PostBuildProjectStatus
-> [GhcEnvironmentFileEntry FilePath]
renderGhcEnvironmentFile :: FilePath
-> ElaboratedInstallPlan
-> PostBuildProjectStatus
-> [GhcEnvironmentFileEntry FilePath]
renderGhcEnvironmentFile
FilePath
projectRootDir
ElaboratedInstallPlan
elaboratedInstallPlan
PostBuildProjectStatus
postBuildStatus =
GhcEnvironmentFileEntry FilePath
forall {fp}. GhcEnvironmentFileEntry fp
headerComment
GhcEnvironmentFileEntry FilePath
-> [GhcEnvironmentFileEntry FilePath]
-> [GhcEnvironmentFileEntry FilePath]
forall a. a -> [a] -> [a]
: [PackageDBX FilePath]
-> [UnitId] -> [GhcEnvironmentFileEntry FilePath]
forall fp.
PackageDBStackX fp -> [UnitId] -> [GhcEnvironmentFileEntry fp]
simpleGhcEnvironmentFile [PackageDBX FilePath]
packageDBs [UnitId]
unitIds
where
headerComment :: GhcEnvironmentFileEntry fp
headerComment =
FilePath -> GhcEnvironmentFileEntry fp
forall fp. FilePath -> GhcEnvironmentFileEntry fp
GhcEnvFileComment (FilePath -> GhcEnvironmentFileEntry fp)
-> FilePath -> GhcEnvironmentFileEntry fp
forall a b. (a -> b) -> a -> b
$
FilePath
"This is a GHC environment file written by cabal. This means you can\n"
FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"run ghc or ghci and get the environment of the project as a whole.\n"
FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"But you still need to use cabal repl $target to get the environment\n"
FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"of specific components (libs, exes, tests etc) because each one can\n"
FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"have its own source dirs, cpp flags etc.\n\n"
unitIds :: [UnitId]
unitIds = PostBuildProjectStatus -> [UnitId]
selectGhcEnvironmentFileLibraries PostBuildProjectStatus
postBuildStatus
packageDBs :: [PackageDBX FilePath]
packageDBs =
FilePath -> [PackageDBX FilePath] -> [PackageDBX FilePath]
relativePackageDBPaths FilePath
projectRootDir ([PackageDBX FilePath] -> [PackageDBX FilePath])
-> [PackageDBX FilePath] -> [PackageDBX FilePath]
forall a b. (a -> b) -> a -> b
$
ElaboratedInstallPlan -> [PackageDBX FilePath]
selectGhcEnvironmentFilePackageDbs ElaboratedInstallPlan
elaboratedInstallPlan
argsEquivalentOfGhcEnvironmentFile
:: Compiler
-> DistDirLayout
-> ElaboratedInstallPlan
-> PostBuildProjectStatus
-> [String]
argsEquivalentOfGhcEnvironmentFile :: Compiler
-> DistDirLayout
-> ElaboratedInstallPlan
-> PostBuildProjectStatus
-> [FilePath]
argsEquivalentOfGhcEnvironmentFile Compiler
compiler =
case Compiler -> CompilerId
compilerId Compiler
compiler of
CompilerId CompilerFlavor
GHC Version
_ -> DistDirLayout
-> ElaboratedInstallPlan -> PostBuildProjectStatus -> [FilePath]
argsEquivalentOfGhcEnvironmentFileGhc
CompilerId CompilerFlavor
GHCJS Version
_ -> DistDirLayout
-> ElaboratedInstallPlan -> PostBuildProjectStatus -> [FilePath]
argsEquivalentOfGhcEnvironmentFileGhc
CompilerId CompilerFlavor
_ Version
_ -> FilePath
-> DistDirLayout
-> ElaboratedInstallPlan
-> PostBuildProjectStatus
-> [FilePath]
forall a. HasCallStack => FilePath -> a
error FilePath
"Only GHC and GHCJS are supported"
argsEquivalentOfGhcEnvironmentFileGhc
:: DistDirLayout
-> ElaboratedInstallPlan
-> PostBuildProjectStatus
-> [String]
argsEquivalentOfGhcEnvironmentFileGhc :: DistDirLayout
-> ElaboratedInstallPlan -> PostBuildProjectStatus -> [FilePath]
argsEquivalentOfGhcEnvironmentFileGhc
DistDirLayout
distDirLayout
ElaboratedInstallPlan
elaboratedInstallPlan
PostBuildProjectStatus
postBuildStatus =
[FilePath]
clearPackageDbStackFlag
[FilePath] -> [FilePath] -> [FilePath]
forall a. [a] -> [a] -> [a]
++ [PackageDBX FilePath] -> [FilePath]
packageDbArgsDb [PackageDBX FilePath]
packageDBs
[FilePath] -> [FilePath] -> [FilePath]
forall a. [a] -> [a] -> [a]
++ (UnitId -> [FilePath]) -> [UnitId] -> [FilePath]
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap UnitId -> [FilePath]
forall {a}. Pretty a => a -> [FilePath]
packageIdFlag [UnitId]
packageIds
where
projectRootDir :: FilePath
projectRootDir = DistDirLayout -> FilePath
distProjectRootDirectory DistDirLayout
distDirLayout
packageIds :: [UnitId]
packageIds = PostBuildProjectStatus -> [UnitId]
selectGhcEnvironmentFileLibraries PostBuildProjectStatus
postBuildStatus
packageDBs :: [PackageDBX FilePath]
packageDBs =
FilePath -> [PackageDBX FilePath] -> [PackageDBX FilePath]
relativePackageDBPaths FilePath
projectRootDir ([PackageDBX FilePath] -> [PackageDBX FilePath])
-> [PackageDBX FilePath] -> [PackageDBX FilePath]
forall a b. (a -> b) -> a -> b
$
ElaboratedInstallPlan -> [PackageDBX FilePath]
selectGhcEnvironmentFilePackageDbs ElaboratedInstallPlan
elaboratedInstallPlan
clearPackageDbStackFlag :: [FilePath]
clearPackageDbStackFlag = [FilePath
"-clear-package-db", FilePath
"-global-package-db"]
packageIdFlag :: a -> [FilePath]
packageIdFlag a
uid = [FilePath
"-package-id", a -> FilePath
forall a. Pretty a => a -> FilePath
prettyShow a
uid]
selectGhcEnvironmentFileLibraries :: PostBuildProjectStatus -> [UnitId]
selectGhcEnvironmentFileLibraries :: PostBuildProjectStatus -> [UnitId]
selectGhcEnvironmentFileLibraries PostBuildProjectStatus{Set UnitId
Graph (Node UnitId ElaboratedPlanPackage)
packagesDefinitelyUpToDate :: PostBuildProjectStatus -> Set UnitId
packagesProbablyUpToDate :: PostBuildProjectStatus -> Set UnitId
packagesOutOfDate :: PostBuildProjectStatus -> Set UnitId
packagesInvalidByChangedLibDeps :: PostBuildProjectStatus -> Set UnitId
packagesInvalidByFailedBuild :: PostBuildProjectStatus -> Set UnitId
packagesLibDepGraph :: PostBuildProjectStatus -> Graph (Node UnitId ElaboratedPlanPackage)
packagesBuildLocal :: PostBuildProjectStatus -> Set UnitId
packagesBuildInplace :: PostBuildProjectStatus -> Set UnitId
packagesAlreadyInStore :: PostBuildProjectStatus -> Set UnitId
packagesDefinitelyUpToDate :: Set UnitId
packagesProbablyUpToDate :: Set UnitId
packagesOutOfDate :: Set UnitId
packagesInvalidByChangedLibDeps :: Set UnitId
packagesInvalidByFailedBuild :: Set UnitId
packagesLibDepGraph :: Graph (Node UnitId ElaboratedPlanPackage)
packagesBuildLocal :: Set UnitId
packagesBuildInplace :: Set UnitId
packagesAlreadyInStore :: Set UnitId
..} =
case Graph (Node UnitId ElaboratedPlanPackage)
-> [Key (Node UnitId ElaboratedPlanPackage)]
-> Maybe [Node UnitId ElaboratedPlanPackage]
forall a. Graph a -> [Key a] -> Maybe [a]
Graph.closure Graph (Node UnitId ElaboratedPlanPackage)
packagesLibDepGraph (Set UnitId -> [UnitId]
forall a. Set a -> [a]
Set.toList Set UnitId
packagesBuildLocal) of
Maybe [Node UnitId ElaboratedPlanPackage]
Nothing -> FilePath -> [UnitId]
forall a. HasCallStack => FilePath -> a
error FilePath
"renderGhcEnvironmentFile: broken dep closure"
Just [Node UnitId ElaboratedPlanPackage]
nodes ->
[ UnitId
pkgid | Graph.N ElaboratedPlanPackage
pkg UnitId
pkgid [UnitId]
_ <- [Node UnitId ElaboratedPlanPackage]
nodes, ElaboratedPlanPackage -> Bool
forall {ipkg}.
GenericPlanPackage ipkg ElaboratedConfiguredPackage -> Bool
hasUpToDateLib ElaboratedPlanPackage
pkg
]
where
hasUpToDateLib :: GenericPlanPackage ipkg ElaboratedConfiguredPackage -> Bool
hasUpToDateLib GenericPlanPackage ipkg ElaboratedConfiguredPackage
planpkg = case GenericPlanPackage ipkg ElaboratedConfiguredPackage
planpkg of
InstallPlan.PreExisting ipkg
_ -> Bool
True
InstallPlan.Installed ElaboratedConfiguredPackage
pkg -> ElaboratedConfiguredPackage -> Bool
elabRequiresRegistration ElaboratedConfiguredPackage
pkg
InstallPlan.Configured ElaboratedConfiguredPackage
pkg ->
ElaboratedConfiguredPackage -> Bool
elabRequiresRegistration ElaboratedConfiguredPackage
pkg
Bool -> Bool -> Bool
&& ElaboratedConfiguredPackage -> UnitId
forall pkg. HasUnitId pkg => pkg -> UnitId
installedUnitId ElaboratedConfiguredPackage
pkg UnitId -> Set UnitId -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.member` Set UnitId
packagesProbablyUpToDate
selectGhcEnvironmentFilePackageDbs :: ElaboratedInstallPlan -> PackageDBStackCWD
selectGhcEnvironmentFilePackageDbs :: ElaboratedInstallPlan -> [PackageDBX FilePath]
selectGhcEnvironmentFilePackageDbs ElaboratedInstallPlan
elaboratedInstallPlan =
case ([ElaboratedConfiguredPackage]
inplacePackages, [ElaboratedConfiguredPackage]
sourcePackages) of
([], [ElaboratedConfiguredPackage]
pkgs) -> [ElaboratedConfiguredPackage] -> [PackageDBX FilePath]
checkSamePackageDBs [ElaboratedConfiguredPackage]
pkgs
([ElaboratedConfiguredPackage]
pkgs, [ElaboratedConfiguredPackage]
_) -> [ElaboratedConfiguredPackage] -> [PackageDBX FilePath]
checkSamePackageDBs [ElaboratedConfiguredPackage]
pkgs
where
checkSamePackageDBs :: [ElaboratedConfiguredPackage] -> PackageDBStackCWD
checkSamePackageDBs :: [ElaboratedConfiguredPackage] -> [PackageDBX FilePath]
checkSamePackageDBs [ElaboratedConfiguredPackage]
pkgs =
case [[PackageDBX FilePath]] -> [[PackageDBX FilePath]]
forall a. Ord a => [a] -> [a]
ordNub ((ElaboratedConfiguredPackage -> [PackageDBX FilePath])
-> [ElaboratedConfiguredPackage] -> [[PackageDBX FilePath]]
forall a b. (a -> b) -> [a] -> [b]
map ElaboratedConfiguredPackage -> [PackageDBX FilePath]
elabBuildPackageDBStack [ElaboratedConfiguredPackage]
pkgs) of
[[PackageDBX FilePath]
packageDbs] -> [PackageDBX FilePath]
packageDbs
[] -> []
[[PackageDBX FilePath]]
_ ->
FilePath -> [PackageDBX FilePath]
forall a. HasCallStack => FilePath -> a
error (FilePath -> [PackageDBX FilePath])
-> FilePath -> [PackageDBX FilePath]
forall a b. (a -> b) -> a -> b
$
FilePath
"renderGhcEnvironmentFile: packages with "
FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"different package db stacks"
inplacePackages :: [ElaboratedConfiguredPackage]
inplacePackages :: [ElaboratedConfiguredPackage]
inplacePackages =
[ ElaboratedConfiguredPackage
srcpkg
| ElaboratedConfiguredPackage
srcpkg <- [ElaboratedConfiguredPackage]
sourcePackages
, BuildStyle -> Bool
isInplaceBuildStyle (ElaboratedConfiguredPackage -> BuildStyle
elabBuildStyle ElaboratedConfiguredPackage
srcpkg)
]
sourcePackages :: [ElaboratedConfiguredPackage]
sourcePackages :: [ElaboratedConfiguredPackage]
sourcePackages =
[ ElaboratedConfiguredPackage
srcpkg
| ElaboratedPlanPackage
pkg <- ElaboratedInstallPlan -> [ElaboratedPlanPackage]
forall ipkg srcpkg.
GenericInstallPlan ipkg srcpkg -> [GenericPlanPackage ipkg srcpkg]
InstallPlan.toList ElaboratedInstallPlan
elaboratedInstallPlan
, ElaboratedConfiguredPackage
srcpkg <- Maybe ElaboratedConfiguredPackage -> [ElaboratedConfiguredPackage]
forall a. Maybe a -> [a]
maybeToList (Maybe ElaboratedConfiguredPackage
-> [ElaboratedConfiguredPackage])
-> Maybe ElaboratedConfiguredPackage
-> [ElaboratedConfiguredPackage]
forall a b. (a -> b) -> a -> b
$ case ElaboratedPlanPackage
pkg of
InstallPlan.Configured ElaboratedConfiguredPackage
srcpkg -> ElaboratedConfiguredPackage -> Maybe ElaboratedConfiguredPackage
forall a. a -> Maybe a
Just ElaboratedConfiguredPackage
srcpkg
InstallPlan.Installed ElaboratedConfiguredPackage
srcpkg -> ElaboratedConfiguredPackage -> Maybe ElaboratedConfiguredPackage
forall a. a -> Maybe a
Just ElaboratedConfiguredPackage
srcpkg
InstallPlan.PreExisting InstalledPackageInfo
_ -> Maybe ElaboratedConfiguredPackage
forall a. Maybe a
Nothing
]
relativePackageDBPaths :: FilePath -> PackageDBStackCWD -> PackageDBStackCWD
relativePackageDBPaths :: FilePath -> [PackageDBX FilePath] -> [PackageDBX FilePath]
relativePackageDBPaths FilePath
relroot = (PackageDBX FilePath -> PackageDBX FilePath)
-> [PackageDBX FilePath] -> [PackageDBX FilePath]
forall a b. (a -> b) -> [a] -> [b]
map (FilePath -> PackageDBX FilePath -> PackageDBX FilePath
relativePackageDBPath FilePath
relroot)
relativePackageDBPath :: FilePath -> PackageDBCWD -> PackageDBCWD
relativePackageDBPath :: FilePath -> PackageDBX FilePath -> PackageDBX FilePath
relativePackageDBPath FilePath
relroot PackageDBX FilePath
pkgdb =
case PackageDBX FilePath
pkgdb of
PackageDBX FilePath
GlobalPackageDB -> PackageDBX FilePath
forall fp. PackageDBX fp
GlobalPackageDB
PackageDBX FilePath
UserPackageDB -> PackageDBX FilePath
forall fp. PackageDBX fp
UserPackageDB
SpecificPackageDB FilePath
path -> FilePath -> PackageDBX FilePath
forall fp. fp -> PackageDBX fp
SpecificPackageDB FilePath
relpath
where
relpath :: FilePath
relpath = FilePath -> FilePath -> FilePath
makeRelative (FilePath -> FilePath
normalise FilePath
relroot) FilePath
path