Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backtrack when no pkgconfigdb is present #7621

Merged
merged 4 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
-- Read the list of packages available to pkg-config.
-----------------------------------------------------------------------------
module Distribution.Solver.Types.PkgConfigDb
( PkgConfigDb
( PkgConfigDb (..)
, readPkgConfigDb
, pkgConfigDbFromList
, pkgConfigPkgIsPresent
Expand Down Expand Up @@ -95,11 +95,12 @@ pkgConfigPkgIsPresent (PkgConfigDb db) pn vr =
Nothing -> False -- Package not present in the DB.
Just Nothing -> True -- Package present, but version unknown.
Just (Just v) -> withinPkgconfigVersionRange v vr
-- If we could not read the pkg-config database successfully we allow
-- the check to succeed. The plan found by the solver may fail to be
-- executed later on, but we have no grounds for rejecting the plan at
-- this stage.
pkgConfigPkgIsPresent NoPkgConfigDb _ _ = True
-- 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



-- | Query the version of a package in the @pkg-config@ database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Distribution.Verbosity

-- cabal-install
import qualified Distribution.Solver.Types.PackagePath as P
import Distribution.Solver.Types.PkgConfigDb (PkgConfigDb, pkgConfigDbFromList)
import Distribution.Solver.Types.PkgConfigDb (PkgConfigDb (..), pkgConfigDbFromList)
import Distribution.Solver.Types.Settings
import Distribution.Solver.Types.Variable
import Distribution.Client.Dependency (foldProgress)
Expand Down Expand Up @@ -166,41 +166,41 @@ mkTest :: ExampleDb
-> [String]
-> SolverResult
-> SolverTest
mkTest = mkTestExtLangPC Nothing Nothing []
mkTest = mkTestExtLangPC Nothing Nothing (Just [])

mkTestExts :: [Extension]
-> ExampleDb
-> String
-> [String]
-> SolverResult
-> SolverTest
mkTestExts exts = mkTestExtLangPC (Just exts) Nothing []
mkTestExts exts = mkTestExtLangPC (Just exts) Nothing (Just [])

mkTestLangs :: [Language]
-> ExampleDb
-> String
-> [String]
-> SolverResult
-> SolverTest
mkTestLangs langs = mkTestExtLangPC Nothing (Just langs) []
mkTestLangs langs = mkTestExtLangPC Nothing (Just langs) (Just [])

mkTestPCDepends :: [(String, String)]
mkTestPCDepends :: Maybe [(String, String)]
-> ExampleDb
-> String
-> [String]
-> SolverResult
-> SolverTest
mkTestPCDepends pkgConfigDb = mkTestExtLangPC Nothing Nothing pkgConfigDb
mkTestPCDepends mPkgConfigDb = mkTestExtLangPC Nothing Nothing mPkgConfigDb

mkTestExtLangPC :: Maybe [Extension]
-> Maybe [Language]
-> [(String, String)]
-> Maybe [(String, String)]
-> ExampleDb
-> String
-> [String]
-> SolverResult
-> SolverTest
mkTestExtLangPC exts langs pkgConfigDb db label targets result = SolverTest {
mkTestExtLangPC exts langs mPkgConfigDb db label targets result = SolverTest {
testLabel = label
, testTargets = targets
, testResult = result
Expand All @@ -219,7 +219,7 @@ mkTestExtLangPC exts langs pkgConfigDb db label targets result = SolverTest {
, testDb = db
, testSupportedExts = exts
, testSupportedLangs = langs
, testPkgConfigDb = pkgConfigDbFromList pkgConfigDb
, testPkgConfigDb = maybe NoPkgConfigDb pkgConfigDbFromList mPkgConfigDb
, testEnableAllTests = EnableAllTests False
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,12 @@ tests = [
, runTest $ mkTest dbBuildable2 "choose version that sets buildable to false" ["A"] (solverSuccess [("A", 1), ("B", 2)])
]
, testGroup "Pkg-config dependencies" [
runTest $ mkTestPCDepends [] dbPC1 "noPkgs" ["A"] anySolverFailure
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be useful to also keep the empty pkg-config test case, using Just [].

, runTest $ mkTestPCDepends [("pkgA", "0")] dbPC1 "tooOld" ["A"] anySolverFailure
, runTest $ mkTestPCDepends [("pkgA", "1.0.0"), ("pkgB", "1.0.0")] dbPC1 "pruneNotFound" ["C"] (solverSuccess [("A", 1), ("B", 1), ("C", 1)])
, runTest $ mkTestPCDepends [("pkgA", "1.0.0"), ("pkgB", "2.0.0")] dbPC1 "chooseNewest" ["C"] (solverSuccess [("A", 1), ("B", 2), ("C", 1)])
runTest $ mkTestPCDepends (Just []) dbPC1 "noPkgs" ["A"] anySolverFailure
, runTest $ mkTestPCDepends (Just [("pkgA", "0")]) dbPC1 "tooOld" ["A"] anySolverFailure
, runTest $ mkTestPCDepends (Just [("pkgA", "1.0.0"), ("pkgB", "1.0.0")]) dbPC1 "pruneNotFound" ["C"] (solverSuccess [("A", 1), ("B", 1), ("C", 1)])
, runTest $ mkTestPCDepends (Just [("pkgA", "1.0.0"), ("pkgB", "2.0.0")]) dbPC1 "chooseNewest" ["C"] (solverSuccess [("A", 1), ("B", 2), ("C", 1)])
, runTest $ mkTestPCDepends Nothing dbPC1 "noPkgConfigFailure" ["A"] anySolverFailure
, runTest $ mkTestPCDepends Nothing dbPC1 "noPkgConfigSuccess" ["D"] (solverSuccess [("D",1)])
]
, testGroup "Independent goals" [
runTest $ indep $ mkTest db16 "indepGoals1" ["A", "B"] (solverSuccess [("A", 1), ("B", 1), ("C", 1), ("D", 1), ("D", 2), ("E", 1)])
Expand Down Expand Up @@ -1665,7 +1667,7 @@ dbLangs1 = [
testBuildable :: String -> ExampleDependency -> TestTree
testBuildable testName unavailableDep =
runTest $
mkTestExtLangPC (Just []) (Just [Haskell98]) [] db testName ["pkg"] expected
mkTestExtLangPC (Just []) (Just [Haskell98]) (Just []) db testName ["pkg"] expected
where
expected = solverSuccess [("false-dep", 1), ("pkg", 1)]
db = [
Expand Down Expand Up @@ -1718,12 +1720,14 @@ dbBuildable2 = [
]

-- | Package databases for testing @pkg-config@ dependencies.
-- when no pkgconfig db is present, cabal must pick flag1 false and flag2 true to avoid the pkg dependency.
dbPC1 :: ExampleDb
dbPC1 = [
Right $ exAv "A" 1 [ExPkg ("pkgA", 1)]
, Right $ exAv "B" 1 [ExPkg ("pkgB", 1), ExAny "A"]
, Right $ exAv "B" 2 [ExPkg ("pkgB", 2), ExAny "A"]
, Right $ exAv "C" 1 [ExAny "B"]
, Right $ exAv "D" 1 [exFlagged "flag1" [ExAny "A"] [], exFlagged "flag2" [] [ExAny "A"]]
]

-- | Test for the solver's summarized log. The final conflict set is {A, F},
Expand Down
10 changes: 10 additions & 0 deletions changelog.d/pr-7621
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
synopsis: Backtrack when no pkg-config is present
packages: Cabal
prs: #7621
issues: #7448

description: {

When solving for pkgconfig-depends, when pkg-config is not present, the cabal solver will now backtrack and try a different automatic flag and dependency configuration, just as it does if pkg-config is present, but does not contain the specified package.

}