Commit 94a08f98 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Use accurate per-component package deps

Based on an original patch by Stephen Blackheath
Previously each component got built using the union of all package
deps of all components in the entire package. Now we use exactly the
deps specified for that component. To prevent breaking old packages
that rely on the sloppy behaviour, package will only get the new
behaviour if they specify they need at least cabal-version: >= 1.7.1
parent 02c35c6d
...@@ -70,8 +70,8 @@ import Distribution.Simple.Compiler ...@@ -70,8 +70,8 @@ import Distribution.Simple.Compiler
( CompilerFlavor(..), Compiler(compilerId), compilerFlavor, compilerVersion ( CompilerFlavor(..), Compiler(compilerId), compilerFlavor, compilerVersion
, showCompilerId, unsupportedExtensions, PackageDB(..), PackageDBStack ) , showCompilerId, unsupportedExtensions, PackageDB(..), PackageDBStack )
import Distribution.Package import Distribution.Package
( PackageName(PackageName), PackageIdentifier(PackageIdentifier) ( PackageName(PackageName), PackageId, PackageIdentifier(PackageIdentifier)
, packageVersion, Package(..), Dependency(Dependency) ) , packageName, packageVersion, Package(..), Dependency(Dependency) )
import Distribution.InstalledPackageInfo import Distribution.InstalledPackageInfo
( InstalledPackageInfo, emptyInstalledPackageInfo ) ( InstalledPackageInfo, emptyInstalledPackageInfo )
import qualified Distribution.InstalledPackageInfo as Installed import qualified Distribution.InstalledPackageInfo as Installed
...@@ -112,8 +112,8 @@ import Distribution.Simple.Register ...@@ -112,8 +112,8 @@ import Distribution.Simple.Register
import Distribution.System import Distribution.System
( OS(..), buildOS, buildArch ) ( OS(..), buildOS, buildArch )
import Distribution.Version import Distribution.Version
( Version(..) ( Version(..), orLaterVersion, withinRange, isSpecificVersion, isAnyVersion
, orLaterVersion, withinRange, isSpecificVersion, isAnyVersion ) , LowerBound(..), asVersionIntervals )
import Distribution.Verbosity import Distribution.Verbosity
( Verbosity, lessVerbose ) ( Verbosity, lessVerbose )
...@@ -408,6 +408,25 @@ configure (pkg_descr0, pbi) cfg ...@@ -408,6 +408,25 @@ configure (pkg_descr0, pbi) cfg
"--enable-split-objs; ignoring") "--enable-split-objs; ignoring")
return False return False
-- The dep_pkgs contains all the package deps for the whole package
-- but we need to select the subset for this specific component.
-- we just take the subset for the package names this component
-- needs. Note, this only works because we cannot yet depend on two
-- versions of the same package.
let configLib lib = configComponent (libBuildInfo lib)
configExe exe = (exeName exe, configComponent(buildInfo exe))
configComponent bi = ComponentLocalBuildInfo {
componentPackageDeps =
if newPackageDepsBehaviour pkg_descr'
then selectDependencies bi dep_pkgs
else dep_pkgs
}
selectDependencies :: BuildInfo -> [PackageId] -> [PackageId]
selectDependencies bi pkgs =
[ pkg | pkg <- pkgs, packageName pkg `elem` names ]
where
names = [ name | Dependency name _ <- targetBuildDepends bi ]
let lbi = LocalBuildInfo{ let lbi = LocalBuildInfo{
installDirTemplates = installDirs, installDirTemplates = installDirs,
compiler = comp, compiler = comp,
...@@ -415,10 +434,8 @@ configure (pkg_descr0, pbi) cfg ...@@ -415,10 +434,8 @@ configure (pkg_descr0, pbi) cfg
scratchDir = fromFlagOrDefault scratchDir = fromFlagOrDefault
(distPref </> "scratch") (distPref </> "scratch")
(configScratchDir cfg), (configScratchDir cfg),
libraryConfig = (\_ -> ComponentLocalBuildInfo dep_pkgs) libraryConfig = configLib `fmap` library pkg_descr',
`fmap` library pkg_descr', executableConfigs = configExe `fmap` executables pkg_descr',
executableConfigs = (\exe -> (exeName exe, ComponentLocalBuildInfo dep_pkgs))
`fmap` executables pkg_descr',
installedPkgs = packageDependsIndex, installedPkgs = packageDependsIndex,
pkgDescrFile = Nothing, pkgDescrFile = Nothing,
localPkgDescr = pkg_descr', localPkgDescr = pkg_descr',
...@@ -536,6 +553,23 @@ implicitPackageDbStack packageDB = case packageDB of ...@@ -536,6 +553,23 @@ implicitPackageDbStack packageDB = case packageDB of
UserPackageDB -> [GlobalPackageDB, UserPackageDB] UserPackageDB -> [GlobalPackageDB, UserPackageDB]
SpecificPackageDB p -> [GlobalPackageDB, SpecificPackageDB p] SpecificPackageDB p -> [GlobalPackageDB, SpecificPackageDB p]
newPackageDepsBehaviourMinVersion :: Version
newPackageDepsBehaviourMinVersion = Version { versionBranch = [1,7,1], versionTags = [] }
-- In older cabal versions, there was only one set of package dependencies for
-- the whole package. In this version, we can have separate dependencies per
-- target, but we only enable this behaviour if the minimum cabal version
-- specified is >= a certain minimum. Otherwise, for compatibility we use the
-- old behaviour.
newPackageDepsBehaviour :: PackageDescription -> Bool
newPackageDepsBehaviour pkg_descr =
minVersionRequired >= newPackageDepsBehaviourMinVersion
where
minVersionRequired =
case asVersionIntervals (descCabalVersion pkg_descr) of
[] -> Version [0] []
((LowerBound v _, _):_) -> v
-- ----------------------------------------------------------------------------- -- -----------------------------------------------------------------------------
-- Configuring program dependencies -- Configuring program dependencies
......
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