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 18, 2024
1 parent e1f73a4 commit 5fd4617
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 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 = " (pkg-config packages are needed but no pkg-config program was found)"
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
| NewPackageDoesNotMatchExistingConstraint ConflictingDep
| ConflictingConstraints ConflictingDep ConflictingDep
| NewPackageIsMissingRequiredComponent ExposedComponent (DependencyReason QPN)
Expand Down
10 changes: 6 additions & 4 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 :: PkgconfigName -> PkgconfigVersionRange -> Maybe 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
-> (PkgconfigName -> PkgconfigVersionRange -> Maybe 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 pkgPresent pn vr of
Just True -> Right a
Just False -> Left (dependencyReasonToConflictSet dr, MissingPkgconfigPackage pn vr)
Nothing -> Left (dependencyReasonToConflictSet dr, MissingPkgconfigProgram)
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ pkgConfigDbFromList pairs = (PkgConfigDb . M.fromList . map convert) pairs

-- | Check whether a given package range is satisfiable in the given
-- @pkg-config@ database.
pkgConfigPkgIsPresent :: PkgConfigDb -> PkgconfigName -> PkgconfigVersionRange -> Bool
pkgConfigPkgIsPresent :: PkgConfigDb -> PkgconfigName -> PkgconfigVersionRange -> Maybe Bool
pkgConfigPkgIsPresent (PkgConfigDb db) pn vr =
case M.lookup pn db of
Nothing -> False -- Package not present in the DB.
Just Nothing -> True -- Package present, but version unknown.
Just (Just v) -> withinPkgconfigVersionRange v vr
Nothing -> Just False -- Package not present in the DB.
Just Nothing -> Just True -- Package present, but version unknown.
Just (Just v) -> Just $ withinPkgconfigVersionRange v vr
-- If we could not read the pkg-config database successfully we fail.
-- The plan found by the solver can't be executed later, because pkg-config itself
-- is going to be called in the build phase to get the library location for linking
-- so even if there is a library, it would need to be passed manual flags anyway.
pkgConfigPkgIsPresent NoPkgConfigDb _ _ = False
pkgConfigPkgIsPresent NoPkgConfigDb _ _ = 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 packages are needed but no pkg-config program was found)
[__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)

0 comments on commit 5fd4617

Please sign in to comment.