Commit ec7d3f2d authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

Track pkg-config deps in hash, fixes #3493.



Tested by building glib and eyeballing cabal-hashes.txt.

Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
parent 3a96032e
......@@ -29,7 +29,7 @@ module Distribution.Client.PackageHash (
) where
import Distribution.Package
( PackageId, PackageIdentifier(..), ComponentId(..) )
( PackageId, PackageName, PackageIdentifier(..), ComponentId(..) )
import Distribution.System
( Platform, OS(Windows), buildOS )
import Distribution.PackageDescription
......@@ -59,6 +59,7 @@ import Data.Maybe (catMaybes)
import Data.List (sortBy, intercalate)
import Data.Map (Map)
import Data.Function (on)
import Data.Version (Version)
import Distribution.Compat.Binary (Binary(..))
import Control.Exception (evaluate)
import System.IO (withBinaryFile, IOMode(..))
......@@ -138,6 +139,7 @@ data PackageHashInputs = PackageHashInputs {
pkgHashPkgId :: PackageId,
pkgHashComponent :: Maybe CD.Component,
pkgHashSourceHash :: PackageSourceHash,
pkgHashPkgConfigDeps :: Set (PackageName, Maybe Version),
pkgHashDirectDeps :: Set InstalledPackageId,
pkgHashOtherConfig :: PackageHashConfigInputs
}
......@@ -195,6 +197,7 @@ renderPackageHashInputs PackageHashInputs{
pkgHashComponent,
pkgHashSourceHash,
pkgHashDirectDeps,
pkgHashPkgConfigDeps,
pkgHashOtherConfig =
PackageHashConfigInputs{..}
} =
......@@ -216,6 +219,12 @@ renderPackageHashInputs PackageHashInputs{
[ entry "pkgid" display pkgHashPkgId
, mentry "component" show pkgHashComponent
, entry "src" showHashValue pkgHashSourceHash
, entry "pkg-config-deps"
(intercalate ", " . map (\(pn, mb_v) -> display pn ++
case mb_v of
Nothing -> ""
Just v -> " " ++ display v)
. Set.toList) pkgHashPkgConfigDeps
, entry "deps" (intercalate ", " . map display
. Set.toList) pkgHashDirectDeps
-- and then all the config
......
......@@ -305,12 +305,15 @@ rebuildInstallPlan verbosity
localPackages <- phaseReadLocalPackages projectConfig
compilerEtc <- phaseConfigureCompiler projectConfig
_ <- phaseConfigurePrograms projectConfig compilerEtc
solverPlan <- phaseRunSolver projectConfigTransient
compilerEtc localPackages
(solverPlan, pkgConfigDB)
<- phaseRunSolver projectConfigTransient
compilerEtc
localPackages
(elaboratedPlan,
elaboratedShared) <- phaseElaboratePlan projectConfigTransient
compilerEtc
solverPlan localPackages
compilerEtc pkgConfigDB
solverPlan
localPackages
return (elaboratedPlan, elaboratedShared, projectConfig)
......@@ -460,7 +463,7 @@ rebuildInstallPlan verbosity
phaseRunSolver :: ProjectConfig
-> (Compiler, Platform, ProgramDb)
-> [UnresolvedSourcePackage]
-> Rebuild SolverInstallPlan
-> Rebuild (SolverInstallPlan, PkgConfigDb)
phaseRunSolver projectConfig@ProjectConfig {
projectConfigShared,
projectConfigBuildOnly
......@@ -489,10 +492,11 @@ rebuildInstallPlan verbosity
(compilerInfo compiler)
notice verbosity "Resolving dependencies..."
foldProgress logMsg die return $
plan <- foldProgress logMsg die return $
planPackages compiler platform solver solverSettings
installedPkgIndex sourcePkgDb pkgConfigDB
localPackages localPackagesEnabledStanzas
return (plan, pkgConfigDB)
where
corePackageDbs = [GlobalPackageDB]
withRepoCtx = projectConfigWithSolverRepoContext verbosity
......@@ -526,6 +530,7 @@ rebuildInstallPlan verbosity
--
phaseElaboratePlan :: ProjectConfig
-> (Compiler, Platform, ProgramDb)
-> PkgConfigDb
-> SolverInstallPlan
-> [SourcePackage loc]
-> Rebuild ( ElaboratedInstallPlan
......@@ -536,7 +541,7 @@ rebuildInstallPlan verbosity
projectConfigSpecificPackage,
projectConfigBuildOnly
}
(compiler, platform, progdb)
(compiler, platform, progdb) pkgConfigDB
solverPlan localPackages = do
liftIO $ debug verbosity "Elaborating the install plan..."
......@@ -549,7 +554,7 @@ rebuildInstallPlan verbosity
defaultInstallDirs <- liftIO $ userInstallDirTemplates compiler
let (elaboratedPlan, elaboratedShared) =
elaborateInstallPlan
platform compiler progdb
platform compiler progdb pkgConfigDB
distDirLayout
cabalDirLayout
solverPlan
......@@ -1026,7 +1031,7 @@ planPackages comp platform solver SolverSettings{..}
-- matching that of the classic @cabal install --user@ or @--global@
--
elaborateInstallPlan
:: Platform -> Compiler -> ProgramDb
:: Platform -> Compiler -> ProgramDb -> PkgConfigDb
-> DistDirLayout
-> CabalDirLayout
-> SolverInstallPlan
......@@ -1037,7 +1042,7 @@ elaborateInstallPlan
-> PackageConfig
-> Map PackageName PackageConfig
-> (ElaboratedInstallPlan, ElaboratedSharedConfig)
elaborateInstallPlan platform compiler compilerprogdb
elaborateInstallPlan platform compiler compilerprogdb pkgConfigDB
DistDirLayout{..}
cabalDirLayout@CabalDirLayout{cabalStorePackageDB}
solverPlan localPackages
......@@ -1151,6 +1156,11 @@ elaborateInstallPlan platform compiler compilerprogdb
concatMap (elaborateExePath mapDep)
(CD.select (== compSolverName) exe_deps0) ++
internal_exe_paths
compPkgConfigDependencies =
[ (pn, fromMaybe (error $ "compPkgConfigDependencies: impossible! "
++ display pn ++ " from " ++ display elabPkgSourceId)
(pkgConfigDbPkgVersion pkgConfigDB pn))
| Dependency pn _ <- PD.pkgconfigDepends bi ]
bi = Cabal.componentBuildInfo comp
confid = ConfiguredId elabPkgSourceId cid
......@@ -1301,6 +1311,14 @@ elaborateInstallPlan platform compiler compilerprogdb
pkgLibDependencies = deps
pkgExeDependencies = fmap (concatMap (elaborateExeSolverId mapDep)) exe_deps0
pkgExeDependencyPaths = fmap (concatMap (elaborateExePath mapDep)) exe_deps0
pkgPkgConfigDependencies =
ordNub
$ [ (pn, fromMaybe (error $ "pkgPkgConfigDependencies: impossible! "
++ display pn ++ " from " ++ display pkgid)
(pkgConfigDbPkgVersion pkgConfigDB pn))
| Dependency pn _ <- concatMap PD.pkgconfigDepends
(PD.allBuildInfo elabPkgDescription)
]
-- Filled in later
pkgStanzasEnabled = Set.empty
......@@ -2515,6 +2533,7 @@ packageHashInputs
pkgHashPkgId = packageId elab,
pkgHashComponent = Nothing,
pkgHashSourceHash = srchash,
pkgHashPkgConfigDeps = Set.fromList (elabPkgConfigDependencies elab),
pkgHashDirectDeps =
case elabPkgOrComp elab of
ElabPackage (ElaboratedPackage{..}) ->
......
......@@ -18,6 +18,7 @@ module Distribution.Client.ProjectPlanning.Types (
elabLibDependencies,
elabExeDependencies,
elabSetupDependencies,
elabPkgConfigDependencies,
ElaboratedPackageOrComponent(..),
ElaboratedComponent(..),
......@@ -316,6 +317,12 @@ elabSetupDependencies ElaboratedConfiguredPackage { elabPkgOrComp = ElabPackage
elabSetupDependencies ElaboratedConfiguredPackage { elabPkgOrComp = ElabComponent comp }
= compSetupDependencies comp
elabPkgConfigDependencies :: ElaboratedConfiguredPackage -> [(PackageName, Maybe Version)]
elabPkgConfigDependencies ElaboratedConfiguredPackage { elabPkgOrComp = ElabPackage pkg }
= pkgPkgConfigDependencies pkg
elabPkgConfigDependencies ElaboratedConfiguredPackage { elabPkgOrComp = ElabComponent comp }
= compPkgConfigDependencies comp
-- | Some extra metadata associated with an
-- 'ElaboratedConfiguredPackage' which indicates that the "package"
......@@ -335,6 +342,8 @@ data ElaboratedComponent
compLibDependencies :: [ConfiguredId],
-- | The executable dependencies of this component.
compExeDependencies :: [ComponentId],
-- | The @pkg-config@ dependencies of the component
compPkgConfigDependencies :: [(PackageName, Maybe Version)],
-- | The paths all our executable dependencies will be installed
-- to once they are installed.
compExeDependencyPaths :: [FilePath],
......@@ -369,6 +378,13 @@ data ElaboratedPackage
--
pkgExeDependencyPaths :: ComponentDeps [FilePath],
-- | Dependencies on @pkg-config@ packages.
-- NB: this is NOT per-component (although it could be)
-- because Cabal library does not track per-component
-- pkg-config depends; it always does them all at once.
--
pkgPkgConfigDependencies :: [(PackageName, Maybe Version)],
-- | Which optional stanzas (ie testsuites, benchmarks) will actually
-- be enabled during the package configure step.
pkgStanzasEnabled :: Set OptionalStanza
......
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE CPP #-}
-----------------------------------------------------------------------------
-- |
......@@ -15,6 +16,7 @@ module Distribution.Solver.Types.PkgConfigDb
, readPkgConfigDb
, pkgConfigDbFromList
, pkgConfigPkgIsPresent
, pkgConfigDbPkgVersion
, getPkgConfigDbDirs
) where
......@@ -43,6 +45,8 @@ import Distribution.Simple.Program
requireProgram )
import Distribution.Simple.Utils
( info )
import Distribution.Compat.Binary (Binary(..))
import GHC.Generics (Generic)
-- | The list of packages installed in the system visible to
-- @pkg-config@. This is an opaque datatype, to be constructed with
......@@ -54,7 +58,9 @@ data PkgConfigDb = PkgConfigDb (M.Map PackageName (Maybe Version))
-- number failed).
| NoPkgConfigDb
-- ^ For when we could not run pkg-config successfully.
deriving (Show)
deriving (Show, Generic)
instance Binary PkgConfigDb
-- | Query pkg-config for the list of installed packages, together
-- with their versions. Return a `PkgConfigDb` encapsulating this
......@@ -106,6 +112,19 @@ pkgConfigPkgIsPresent (PkgConfigDb db) pn vr =
pkgConfigPkgIsPresent NoPkgConfigDb _ _ = True
-- | Query the version of a package in the @pkg-config@ database.
-- @Nothing@ indicates the package is not in the database, while
-- @Just Nothing@ indicates that the package is in the database,
-- but its version is not known.
pkgConfigDbPkgVersion :: PkgConfigDb -> PackageName -> Maybe (Maybe Version)
pkgConfigDbPkgVersion (PkgConfigDb db) pn = M.lookup pn db
-- NB: Since the solver allows solving to succeed if there is
-- NoPkgConfigDb, we should report that we *guess* that there
-- is a matching pkg-config configuration, but that we just
-- don't know about it.
pkgConfigDbPkgVersion NoPkgConfigDb _ = Just Nothing
-- | Query pkg-config for the locations of pkg-config's package files. Use this
-- to monitor for changes in the pkg-config DB.
--
......
Supports Markdown
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