Skip to content

Commit

Permalink
Merge pull request #4262 from Ericson2314/needed-exes-only
Browse files Browse the repository at this point in the history
Fix #4217
  • Loading branch information
Ericson2314 authored Jan 26, 2017
2 parents 824d0ba + 0ed1909 commit eda30d3
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 19 deletions.
53 changes: 44 additions & 9 deletions cabal-install/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2985,4 +3021,3 @@ improveInstallPlanWithInstalledPackages installedPkgIdSet =

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

6 changes: 0 additions & 6 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ Extra-Source-Files:
tests/IntegrationTests/new-build/T4017/cabal.project
tests/IntegrationTests/new-build/T4017/p/p.cabal
tests/IntegrationTests/new-build/T4017/q/q.cabal
tests/IntegrationTests/new-build/build_tool_depends.sh
tests/IntegrationTests/new-build/build_tool_depends/cabal.project
tests/IntegrationTests/new-build/build_tool_depends/client/Hello.hs
tests/IntegrationTests/new-build/build_tool_depends/client/client.cabal
tests/IntegrationTests/new-build/build_tool_depends/pre-proc/MyCustomPreprocessor.hs
tests/IntegrationTests/new-build/build_tool_depends/pre-proc/pre-proc.cabal
tests/IntegrationTests/new-build/executable/Main.hs
tests/IntegrationTests/new-build/executable/Setup.hs
tests/IntegrationTests/new-build/executable/Test.hs
Expand Down

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/BuildToolDepends/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: client
optional-packages: pre-proc
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ executable zero-to-one
main-is: MyCustomPreprocessor.hs
build-depends: base, directory
default-language: Haskell2010

executable bad-do-not-build-me
main-is: MyMissingPreprocessor.hs
build-depends: base, directory
default-language: Haskell2010
4 changes: 4 additions & 0 deletions cabal-testsuite/PackageTests/BuildToolDepends/setup.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Test.Cabal.Prelude
-- Test unneed version bound on internal build-tools deps
main = cabalTest $ do
cabal "new-build" ["client"]

0 comments on commit eda30d3

Please sign in to comment.