Commit 6dbaa920 authored by John Ericson's avatar John Ericson
Browse files

Filter build-tool-resolving components to what's needed

I'd like to instead change the solver to route the used
components through (baby steps towards per-component
solving), rather than reconstruct it post-hoc from the
Package Description, but this gets the job done for now.
parent 824d0bae
......@@ -54,7 +54,7 @@ module Distribution.Client.ProjectPlanning (
import Prelude ()
import Distribution.Client.Compat.Prelude
import Distribution.Client.ProjectPlanning.Types
import Distribution.Client.ProjectPlanning.Types as Ty
import Distribution.Client.PackageHash
import Distribution.Client.RebuildMonad
import Distribution.Client.ProjectConfig
......@@ -95,12 +95,14 @@ import Distribution.ModuleName
import Distribution.Package hiding
(InstalledPackageId, installedPackageId)
import Distribution.Types.Dependency
import Distribution.Types.ExeDependency
import Distribution.Types.PkgconfigDependency
import Distribution.Types.UnqualComponentName
import Distribution.System
import qualified Distribution.PackageDescription as Cabal
import qualified Distribution.PackageDescription as PD
import qualified Distribution.PackageDescription.Configuration as PD
import Distribution.Simple.BuildToolDepends
import Distribution.Simple.PackageIndex (InstalledPackageIndex)
import Distribution.Simple.Compiler hiding (Flag)
import qualified Distribution.Simple.GHC as GHC --TODO: [code cleanup] eliminate
......@@ -1011,7 +1013,7 @@ planPackages comp platform solver SolverSettings{..}
-- former we just apply all these flags to all local targets which
-- is silly. We should check if the flags are appropriate.
[ LabeledPackageConstraint
(PackageConstraint (scopeToplevel pkgname)
(PackageConstraint (scopeToplevel pkgname)
(PackagePropertyFlags flags))
ConstraintSourceConfigFlagOrTarget
| let flags = solverSettingFlagAssignment
......@@ -1270,12 +1272,14 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
compLibDependencies =
-- concatMap (elaborateLibSolverId mapDep) external_lib_dep_sids
ordNub (map (\ci -> ConfiguredId (ci_pkgid ci) (ci_id ci)) (cc_includes cc))
filterExeMapDepApp = filterExeMapDep mapDep pd [Cabal.componentBuildInfo comp]
compExeDependencies =
map confInstId
(concatMap (elaborateExeSolverId mapDep) external_exe_dep_sids) ++
(concatMap (elaborateExeSolverId filterExeMapDepApp) external_exe_dep_sids) ++
cc_internal_build_tools cc
compExeDependencyPaths =
concatMap (elaborateExePath mapDep) external_exe_dep_sids ++
concatMap (elaborateExePath filterExeMapDepApp) external_exe_dep_sids ++
[ path
| cid' <- cc_internal_build_tools cc
, Just path <- [Map.lookup cid' exe_map]]
......@@ -1347,6 +1351,36 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
(Map.fromList [ (req, OpenModuleVar req)
| req <- Set.toList (modShapeRequires shape)])
filterExeMapDep :: (SolverId -> [ElaboratedPlanPackage])
-> PD.PackageDescription -> [PD.BuildInfo]
-> SolverId -> [ElaboratedPlanPackage]
filterExeMapDep mapDep pd bis = filter go . mapDep
where
toolDeps = getAllToolDependencies pd =<< bis
exeKV :: [(PackageName, Set UnqualComponentName)]
exeKV = map go' toolDeps where
go' (ExeDependency p n _) = (p, Set.singleton n)
-- Nothing means wildcard, the complete subset
exeMap :: Map PackageName (Set UnqualComponentName)
exeMap = Map.fromListWith mappend exeKV
go (InstallPlan.Installed _) = error "unexpected state"
go (InstallPlan.PreExisting _) = True
go (InstallPlan.Configured (ElaboratedConfiguredPackage {
elabPkgSourceId = PackageIdentifier { pkgName, .. },
elabPkgOrComp,
..
})) = case elabPkgOrComp of
ElabPackage _ -> True
ElabComponent comp' ->
case Ty.compSolverName comp' of
CD.ComponentExe n
| Just set <- Map.lookup pkgName exeMap
-> Set.member n set
_ -> error "unexpected state"
elaborateLibSolverId' :: (SolverId -> [ElaboratedPlanPackage])
-> SolverId -> [ElaboratedPlanPackage]
elaborateLibSolverId' mapDep = filter is_lib . mapDep
......@@ -1458,16 +1492,18 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
= error $ "elaborateInstallPlan: non-inplace package "
++ " is missing a source hash: " ++ display pkgid
buildInfos = PD.allBuildInfo elabPkgDescription
filterExeMapDepApp = filterExeMapDep mapDep elabPkgDescription buildInfos
pkgLibDependencies = deps
pkgExeDependencies = fmap (concatMap (elaborateExeSolverId mapDep)) exe_deps0
pkgExeDependencyPaths = fmap (concatMap (elaborateExePath mapDep)) exe_deps0
pkgExeDependencies = fmap (concatMap (elaborateExeSolverId filterExeMapDepApp)) exe_deps0
pkgExeDependencyPaths = fmap (concatMap (elaborateExePath filterExeMapDepApp)) exe_deps0
pkgPkgConfigDependencies =
ordNub
$ [ (pn, fromMaybe (error $ "pkgPkgConfigDependencies: impossible! "
++ display pn ++ " from " ++ display pkgid)
(pkgConfigDbPkgVersion pkgConfigDB pn))
| PkgconfigDependency pn _ <- concatMap PD.pkgconfigDepends
(PD.allBuildInfo elabPkgDescription)
| PkgconfigDependency pn _ <- concatMap PD.pkgconfigDepends buildInfos
]
-- Filled in later
......@@ -2985,4 +3021,3 @@ improveInstallPlanWithInstalledPackages installedPkgIdSet =
--TODO: decide what to do if we encounter broken installed packages,
-- since overwriting is never safe.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment