Skip to content

Commit 1bca648

Browse files
committed
Make clear when pkg-config is not present
When no pkg-config program was found, cabal would claim that the package is not in the db, instead of telling clearly that no pkg-config was found at all.
1 parent 88d9449 commit 1bca648

File tree

6 files changed

+23
-19
lines changed

6 files changed

+23
-19
lines changed

cabal-install-solver/src/Distribution/Solver/Modular/Message.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ showFR :: ConflictSet -> FailReason -> String
279279
showFR _ (UnsupportedExtension ext) = " (conflict: requires " ++ showUnsupportedExtension ext ++ ")"
280280
showFR _ (UnsupportedLanguage lang) = " (conflict: requires " ++ showUnsupportedLanguage lang ++ ")"
281281
showFR _ (MissingPkgconfigPackage pn vr) = " (conflict: pkg-config package " ++ prettyShow pn ++ prettyShow vr ++ ", not found in the pkg-config database)"
282+
showFR _ (MissingPkgconfigProgram pn vr) = " (pkg-config package " ++ prettyShow pn ++ prettyShow vr ++ " is needed but no pkg-config executable was found or querying it failed)"
282283
showFR _ (NewPackageDoesNotMatchExistingConstraint d) = " (conflict: " ++ showConflictingDep d ++ ")"
283284
showFR _ (ConflictingConstraints d1 d2) = " (conflict: " ++ L.intercalate ", " (L.map showConflictingDep [d1, d2]) ++ ")"
284285
showFR _ (NewPackageIsMissingRequiredComponent comp dr) = " (does not contain " ++ showExposedComponent comp ++ ", which is required by " ++ showDependencyReason dr ++ ")"

cabal-install-solver/src/Distribution/Solver/Modular/Tree.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ data POption = POption I (Maybe PackagePath)
102102
data FailReason = UnsupportedExtension Extension
103103
| UnsupportedLanguage Language
104104
| MissingPkgconfigPackage PkgconfigName PkgconfigVersionRange
105+
| MissingPkgconfigProgram PkgconfigName PkgconfigVersionRange
105106
| NewPackageDoesNotMatchExistingConstraint ConflictingDep
106107
| ConflictingConstraints ConflictingDep ConflictingDep
107108
| NewPackageIsMissingRequiredComponent ExposedComponent (DependencyReason QPN)

cabal-install-solver/src/Distribution/Solver/Modular/Validate.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ import Distribution.Types.PkgconfigVersionRange
9090
data ValidateState = VS {
9191
supportedExt :: Extension -> Bool,
9292
supportedLang :: Language -> Bool,
93-
presentPkgs :: PkgconfigName -> PkgconfigVersionRange -> Bool,
93+
presentPkgs :: Maybe (PkgconfigName -> PkgconfigVersionRange -> Bool),
9494
index :: Index,
9595

9696
-- Saved, scoped, dependencies. Every time 'validate' makes a package choice,
@@ -383,7 +383,7 @@ extractNewDeps v b fa sa = go
383383
-- or the successfully extended assignment.
384384
extend :: (Extension -> Bool) -- ^ is a given extension supported
385385
-> (Language -> Bool) -- ^ is a given language supported
386-
-> (PkgconfigName -> PkgconfigVersionRange -> Bool) -- ^ is a given pkg-config requirement satisfiable
386+
-> Maybe (PkgconfigName -> PkgconfigVersionRange -> Bool) -- ^ is a given pkg-config requirement satisfiable
387387
-> [LDep QPN]
388388
-> PPreAssignment
389389
-> Either Conflict PPreAssignment
@@ -398,8 +398,10 @@ extend extSupported langSupported pkgPresent newactives ppa = foldM extendSingle
398398
if langSupported lang then Right a
399399
else Left (dependencyReasonToConflictSet dr, UnsupportedLanguage lang)
400400
extendSingle a (LDep dr (Pkg pn vr)) =
401-
if pkgPresent pn vr then Right a
402-
else Left (dependencyReasonToConflictSet dr, MissingPkgconfigPackage pn vr)
401+
case (\f -> f pn vr) <$> pkgPresent of
402+
Just True -> Right a
403+
Just False -> Left (dependencyReasonToConflictSet dr, MissingPkgconfigPackage pn vr)
404+
Nothing -> Left (dependencyReasonToConflictSet dr, MissingPkgconfigProgram pn vr)
403405
extendSingle a (LDep dr (Dep dep@(PkgComponent qpn _) ci)) =
404406
let mergedDep = M.findWithDefault (MergedDepConstrained []) qpn a
405407
in case (\ x -> M.insert qpn x a) <$> merge mergedDep (PkgDep dr dep ci) of
@@ -569,7 +571,7 @@ validateTree cinfo idx pkgConfigDb t = runValidate (validate t) VS {
569571
, supportedLang = maybe (const True)
570572
(flip L.elem) -- use list lookup because language list is small and no Ord instance
571573
(compilerInfoLanguages cinfo)
572-
, presentPkgs = maybe (\_pn _pvr -> False) pkgConfigPkgIsPresent pkgConfigDb
574+
, presentPkgs = pkgConfigPkgIsPresent <$> pkgConfigDb
573575
, index = idx
574576
, saved = M.empty
575577
, pa = PA M.empty M.empty M.empty

cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,11 @@ import Distribution.Types.PkgconfigVersion
4646
import Distribution.Types.PkgconfigVersionRange
4747
import Distribution.Verbosity (Verbosity)
4848

49-
newtype PkgConfigDb = PkgConfigDb (M.Map PkgconfigName (Maybe PkgconfigVersion))
49+
-- | The list of packages installed in the system visible to
50+
-- @pkg-config@.
51+
data PkgConfigDb = PkgConfigDb (M.Map PkgconfigName (Maybe PkgconfigVersion))
5052
deriving (Show, Generic, Typeable)
5153

52-
-- -- | The list of packages installed in the system visible to
53-
-- -- @pkg-config@. This is an opaque datatype, to be constructed with
54-
-- -- `readPkgConfigDb` and queried with `pkgConfigPkgPresent`.
55-
-- data PkgConfigDb = PkgConfigDb (M.Map PkgconfigName (Maybe PkgconfigVersion))
56-
-- -- ^ If an entry is `Nothing`, this means that the
57-
-- -- package seems to be present, but we don't know the
58-
-- -- exact version (because parsing of the version
59-
-- -- number failed).
60-
-- | NoPkgConfigDb
61-
-- -- ^ For when we could not run pkg-config successfully.
62-
-- deriving (Show, Generic, Typeable)
63-
6454
instance Binary PkgConfigDb
6555
instance Structured PkgConfigDb
6656

cabal-testsuite/PackageTests/ExtraProgPath/setup.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ Resolving dependencies...
55
Error: [Cabal-7107]
66
Could not resolve dependencies:
77
[__0] next goal: CheckExtraProgPath (user goal)
8-
[__0] rejecting: CheckExtraProgPath-0.1 (conflict: pkg-config package zlib-any, not found in the pkg-config database)
8+
[__0] rejecting: CheckExtraProgPath-0.1 (pkg-config package zlib-any is needed but no pkg-config executable was found or querying it failed)
99
[__0] fail (backjumping, conflict set: CheckExtraProgPath)
1010
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: CheckExtraProgPath (2)

changelog.d/pr-10122

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
synopsis: Clarify error message when pkg-config is not found
2+
packages: cabal-install-solver
3+
prs: #10122
4+
5+
description: {
6+
7+
- The error message when pkg-config is not found or querying it fails will no
8+
longer incorrectly claim that the package is missing in the database.
9+
10+
}

0 commit comments

Comments
 (0)