Skip to content

Commit

Permalink
Make clear when pkg-config is not present
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasagredo committed Jun 25, 2024
1 parent 88d9449 commit a03daba
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ showFR :: ConflictSet -> FailReason -> String
showFR _ (UnsupportedExtension ext) = " (conflict: requires " ++ showUnsupportedExtension ext ++ ")"
showFR _ (UnsupportedLanguage lang) = " (conflict: requires " ++ showUnsupportedLanguage lang ++ ")"
showFR _ (MissingPkgconfigPackage pn vr) = " (conflict: pkg-config package " ++ prettyShow pn ++ prettyShow vr ++ ", not found in the pkg-config database)"
showFR _ (MissingPkgconfigProgram pn vr) = " (pkg-config package " ++ prettyShow pn ++ prettyShow vr ++ " is needed but no pkg-config executable was found or querying it failed)"
showFR _ (NewPackageDoesNotMatchExistingConstraint d) = " (conflict: " ++ showConflictingDep d ++ ")"
showFR _ (ConflictingConstraints d1 d2) = " (conflict: " ++ L.intercalate ", " (L.map showConflictingDep [d1, d2]) ++ ")"
showFR _ (NewPackageIsMissingRequiredComponent comp dr) = " (does not contain " ++ showExposedComponent comp ++ ", which is required by " ++ showDependencyReason dr ++ ")"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ data POption = POption I (Maybe PackagePath)
data FailReason = UnsupportedExtension Extension
| UnsupportedLanguage Language
| MissingPkgconfigPackage PkgconfigName PkgconfigVersionRange
| MissingPkgconfigProgram PkgconfigName PkgconfigVersionRange
| NewPackageDoesNotMatchExistingConstraint ConflictingDep
| ConflictingConstraints ConflictingDep ConflictingDep
| NewPackageIsMissingRequiredComponent ExposedComponent (DependencyReason QPN)
Expand Down
12 changes: 7 additions & 5 deletions cabal-install-solver/src/Distribution/Solver/Modular/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ import Distribution.Types.PkgconfigVersionRange
data ValidateState = VS {
supportedExt :: Extension -> Bool,
supportedLang :: Language -> Bool,
presentPkgs :: PkgconfigName -> PkgconfigVersionRange -> Bool,
presentPkgs :: Maybe (PkgconfigName -> PkgconfigVersionRange -> Bool),
index :: Index,

-- Saved, scoped, dependencies. Every time 'validate' makes a package choice,
Expand Down Expand Up @@ -383,7 +383,7 @@ extractNewDeps v b fa sa = go
-- or the successfully extended assignment.
extend :: (Extension -> Bool) -- ^ is a given extension supported
-> (Language -> Bool) -- ^ is a given language supported
-> (PkgconfigName -> PkgconfigVersionRange -> Bool) -- ^ is a given pkg-config requirement satisfiable
-> Maybe (PkgconfigName -> PkgconfigVersionRange -> Bool) -- ^ is a given pkg-config requirement satisfiable
-> [LDep QPN]
-> PPreAssignment
-> Either Conflict PPreAssignment
Expand All @@ -398,8 +398,10 @@ extend extSupported langSupported pkgPresent newactives ppa = foldM extendSingle
if langSupported lang then Right a
else Left (dependencyReasonToConflictSet dr, UnsupportedLanguage lang)
extendSingle a (LDep dr (Pkg pn vr)) =
if pkgPresent pn vr then Right a
else Left (dependencyReasonToConflictSet dr, MissingPkgconfigPackage pn vr)
case (\f -> f pn vr) <$> pkgPresent of
Just True -> Right a
Just False -> Left (dependencyReasonToConflictSet dr, MissingPkgconfigPackage pn vr)
Nothing -> Left (dependencyReasonToConflictSet dr, MissingPkgconfigProgram pn vr)
extendSingle a (LDep dr (Dep dep@(PkgComponent qpn _) ci)) =
let mergedDep = M.findWithDefault (MergedDepConstrained []) qpn a
in case (\ x -> M.insert qpn x a) <$> merge mergedDep (PkgDep dr dep ci) of
Expand Down Expand Up @@ -569,7 +571,7 @@ validateTree cinfo idx pkgConfigDb t = runValidate (validate t) VS {
, supportedLang = maybe (const True)
(flip L.elem) -- use list lookup because language list is small and no Ord instance
(compilerInfoLanguages cinfo)
, presentPkgs = maybe (\_pn _pvr -> False) pkgConfigPkgIsPresent pkgConfigDb
, presentPkgs = pkgConfigPkgIsPresent <$> pkgConfigDb
, index = idx
, saved = M.empty
, pa = PA M.empty M.empty M.empty
Expand Down
24 changes: 9 additions & 15 deletions cabal-install-solver/src/Distribution/Solver/Types/PkgConfigDb.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,15 @@ import Distribution.Types.PkgconfigVersion
import Distribution.Types.PkgconfigVersionRange
import Distribution.Verbosity (Verbosity)

-- | The list of packages installed in the system visible to
-- @pkg-config@.
--
-- If an entry is `Nothing`, this means that the package seems to be present,
-- but we don't know the exact version (because parsing of the version number
-- failed).
newtype PkgConfigDb = PkgConfigDb (M.Map PkgconfigName (Maybe PkgconfigVersion))
deriving (Show, Generic, Typeable)

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

instance Binary PkgConfigDb
instance Structured PkgConfigDb

Expand All @@ -71,7 +65,7 @@ readPkgConfigDb :: Verbosity -> ProgramDb -> IO (Maybe PkgConfigDb)
readPkgConfigDb verbosity progdb = handle ioErrorHandler $ do
mpkgConfig <- needProgram verbosity pkgConfigProgram progdb
case mpkgConfig of
Nothing -> noPkgConfig "Cannot find pkg-config program"
Nothing -> noPkgConfig "cannot find pkg-config program"
Just (pkgConfig, _) -> do
-- To prevent malformed Unicode in the descriptions from crashing cabal,
-- read without interpreting any encoding first. (#9608)
Expand Down Expand Up @@ -124,8 +118,8 @@ readPkgConfigDb verbosity progdb = handle ioErrorHandler $ do
-- For when pkg-config invocation fails (possibly because of a
-- too long command line).
noPkgConfig extra = do
info verbosity ("Failed to query pkg-config, Cabal will continue"
++ " without solving for pkg-config constraints: "
info verbosity ("Warning: Failed to query pkg-config, Cabal will backtrack "
++ "if a package from pkg-config is requested. Error message: "
++ extra)
return Nothing

Expand Down
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/ExtraProgPath/setup.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Resolving dependencies...
Error: [Cabal-7107]
Could not resolve dependencies:
[__0] next goal: CheckExtraProgPath (user goal)
[__0] rejecting: CheckExtraProgPath-0.1 (conflict: pkg-config package zlib-any, not found in the pkg-config database)
[__0] rejecting: CheckExtraProgPath-0.1 (pkg-config package zlib-any is needed but no pkg-config executable was found or querying it failed)
[__0] fail (backjumping, conflict set: CheckExtraProgPath)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: CheckExtraProgPath (2)
10 changes: 10 additions & 0 deletions changelog.d/pr-10122
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
synopsis: Clarify error message when pkg-config is not found
packages: cabal-install-solver
prs: #10122

description: {

- The error message when pkg-config is not found or querying it fails will no
longer incorrectly claim that the package is missing in the database.

}

0 comments on commit a03daba

Please sign in to comment.