Skip to content

Commit eda30d3

Browse files
authored
Merge pull request #4262 from Ericson2314/needed-exes-only
Fix #4217
2 parents 824d0ba + 0ed1909 commit eda30d3

File tree

10 files changed

+55
-19
lines changed

10 files changed

+55
-19
lines changed

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module Distribution.Client.ProjectPlanning (
5454
import Prelude ()
5555
import Distribution.Client.Compat.Prelude
5656

57-
import Distribution.Client.ProjectPlanning.Types
57+
import Distribution.Client.ProjectPlanning.Types as Ty
5858
import Distribution.Client.PackageHash
5959
import Distribution.Client.RebuildMonad
6060
import Distribution.Client.ProjectConfig
@@ -95,12 +95,14 @@ import Distribution.ModuleName
9595
import Distribution.Package hiding
9696
(InstalledPackageId, installedPackageId)
9797
import Distribution.Types.Dependency
98+
import Distribution.Types.ExeDependency
9899
import Distribution.Types.PkgconfigDependency
99100
import Distribution.Types.UnqualComponentName
100101
import Distribution.System
101102
import qualified Distribution.PackageDescription as Cabal
102103
import qualified Distribution.PackageDescription as PD
103104
import qualified Distribution.PackageDescription.Configuration as PD
105+
import Distribution.Simple.BuildToolDepends
104106
import Distribution.Simple.PackageIndex (InstalledPackageIndex)
105107
import Distribution.Simple.Compiler hiding (Flag)
106108
import qualified Distribution.Simple.GHC as GHC --TODO: [code cleanup] eliminate
@@ -1011,7 +1013,7 @@ planPackages comp platform solver SolverSettings{..}
10111013
-- former we just apply all these flags to all local targets which
10121014
-- is silly. We should check if the flags are appropriate.
10131015
[ LabeledPackageConstraint
1014-
(PackageConstraint (scopeToplevel pkgname)
1016+
(PackageConstraint (scopeToplevel pkgname)
10151017
(PackagePropertyFlags flags))
10161018
ConstraintSourceConfigFlagOrTarget
10171019
| let flags = solverSettingFlagAssignment
@@ -1270,12 +1272,14 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
12701272
compLibDependencies =
12711273
-- concatMap (elaborateLibSolverId mapDep) external_lib_dep_sids
12721274
ordNub (map (\ci -> ConfiguredId (ci_pkgid ci) (ci_id ci)) (cc_includes cc))
1275+
filterExeMapDepApp = filterExeMapDep mapDep pd [Cabal.componentBuildInfo comp]
1276+
12731277
compExeDependencies =
12741278
map confInstId
1275-
(concatMap (elaborateExeSolverId mapDep) external_exe_dep_sids) ++
1279+
(concatMap (elaborateExeSolverId filterExeMapDepApp) external_exe_dep_sids) ++
12761280
cc_internal_build_tools cc
12771281
compExeDependencyPaths =
1278-
concatMap (elaborateExePath mapDep) external_exe_dep_sids ++
1282+
concatMap (elaborateExePath filterExeMapDepApp) external_exe_dep_sids ++
12791283
[ path
12801284
| cid' <- cc_internal_build_tools cc
12811285
, Just path <- [Map.lookup cid' exe_map]]
@@ -1347,6 +1351,36 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
13471351
(Map.fromList [ (req, OpenModuleVar req)
13481352
| req <- Set.toList (modShapeRequires shape)])
13491353

1354+
filterExeMapDep :: (SolverId -> [ElaboratedPlanPackage])
1355+
-> PD.PackageDescription -> [PD.BuildInfo]
1356+
-> SolverId -> [ElaboratedPlanPackage]
1357+
filterExeMapDep mapDep pd bis = filter go . mapDep
1358+
where
1359+
toolDeps = getAllToolDependencies pd =<< bis
1360+
exeKV :: [(PackageName, Set UnqualComponentName)]
1361+
exeKV = map go' toolDeps where
1362+
go' (ExeDependency p n _) = (p, Set.singleton n)
1363+
1364+
-- Nothing means wildcard, the complete subset
1365+
exeMap :: Map PackageName (Set UnqualComponentName)
1366+
exeMap = Map.fromListWith mappend exeKV
1367+
1368+
go (InstallPlan.Installed _) = error "unexpected state"
1369+
go (InstallPlan.PreExisting _) = True
1370+
go (InstallPlan.Configured (ElaboratedConfiguredPackage {
1371+
elabPkgSourceId = PackageIdentifier { pkgName, .. },
1372+
elabPkgOrComp,
1373+
..
1374+
})) = case elabPkgOrComp of
1375+
ElabPackage _ -> True
1376+
ElabComponent comp' ->
1377+
case Ty.compSolverName comp' of
1378+
CD.ComponentExe n
1379+
| Just set <- Map.lookup pkgName exeMap
1380+
-> Set.member n set
1381+
_ -> error "unexpected state"
1382+
1383+
13501384
elaborateLibSolverId' :: (SolverId -> [ElaboratedPlanPackage])
13511385
-> SolverId -> [ElaboratedPlanPackage]
13521386
elaborateLibSolverId' mapDep = filter is_lib . mapDep
@@ -1458,16 +1492,18 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
14581492
= error $ "elaborateInstallPlan: non-inplace package "
14591493
++ " is missing a source hash: " ++ display pkgid
14601494

1495+
buildInfos = PD.allBuildInfo elabPkgDescription
1496+
filterExeMapDepApp = filterExeMapDep mapDep elabPkgDescription buildInfos
1497+
14611498
pkgLibDependencies = deps
1462-
pkgExeDependencies = fmap (concatMap (elaborateExeSolverId mapDep)) exe_deps0
1463-
pkgExeDependencyPaths = fmap (concatMap (elaborateExePath mapDep)) exe_deps0
1499+
pkgExeDependencies = fmap (concatMap (elaborateExeSolverId filterExeMapDepApp)) exe_deps0
1500+
pkgExeDependencyPaths = fmap (concatMap (elaborateExePath filterExeMapDepApp)) exe_deps0
14641501
pkgPkgConfigDependencies =
14651502
ordNub
14661503
$ [ (pn, fromMaybe (error $ "pkgPkgConfigDependencies: impossible! "
14671504
++ display pn ++ " from " ++ display pkgid)
14681505
(pkgConfigDbPkgVersion pkgConfigDB pn))
1469-
| PkgconfigDependency pn _ <- concatMap PD.pkgconfigDepends
1470-
(PD.allBuildInfo elabPkgDescription)
1506+
| PkgconfigDependency pn _ <- concatMap PD.pkgconfigDepends buildInfos
14711507
]
14721508

14731509
-- Filled in later
@@ -2985,4 +3021,3 @@ improveInstallPlanWithInstalledPackages installedPkgIdSet =
29853021

29863022
--TODO: decide what to do if we encounter broken installed packages,
29873023
-- since overwriting is never safe.
2988-

cabal-install/cabal-install.cabal

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ Extra-Source-Files:
8585
tests/IntegrationTests/new-build/T4017/cabal.project
8686
tests/IntegrationTests/new-build/T4017/p/p.cabal
8787
tests/IntegrationTests/new-build/T4017/q/q.cabal
88-
tests/IntegrationTests/new-build/build_tool_depends.sh
89-
tests/IntegrationTests/new-build/build_tool_depends/cabal.project
90-
tests/IntegrationTests/new-build/build_tool_depends/client/Hello.hs
91-
tests/IntegrationTests/new-build/build_tool_depends/client/client.cabal
92-
tests/IntegrationTests/new-build/build_tool_depends/pre-proc/MyCustomPreprocessor.hs
93-
tests/IntegrationTests/new-build/build_tool_depends/pre-proc/pre-proc.cabal
9488
tests/IntegrationTests/new-build/executable/Main.hs
9589
tests/IntegrationTests/new-build/executable/Setup.hs
9690
tests/IntegrationTests/new-build/executable/Test.hs

cabal-install/tests/IntegrationTests/new-build/build_tool_depends.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

cabal-install/tests/IntegrationTests/new-build/build_tool_depends/cabal.project

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages: client
2+
optional-packages: pre-proc
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ executable zero-to-one
1010
main-is: MyCustomPreprocessor.hs
1111
build-depends: base, directory
1212
default-language: Haskell2010
13+
14+
executable bad-do-not-build-me
15+
main-is: MyMissingPreprocessor.hs
16+
build-depends: base, directory
17+
default-language: Haskell2010
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Test.Cabal.Prelude
2+
-- Test unneed version bound on internal build-tools deps
3+
main = cabalTest $ do
4+
cabal "new-build" ["client"]

0 commit comments

Comments
 (0)