Skip to content

Commit 68e2737

Browse files
gbazmergify[bot]
andauthored
Backtrack when no pkgconfigdb is present (#7621)
* Backtrack when no pkgconfigdb is present * changelog and test * one more test Co-authored-by: Gershom Bazerman <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 5b46af1 commit 68e2737

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
-- Read the list of packages available to pkg-config.
1313
-----------------------------------------------------------------------------
1414
module Distribution.Solver.Types.PkgConfigDb
15-
( PkgConfigDb
15+
( PkgConfigDb (..)
1616
, readPkgConfigDb
1717
, pkgConfigDbFromList
1818
, pkgConfigPkgIsPresent
@@ -95,11 +95,12 @@ pkgConfigPkgIsPresent (PkgConfigDb db) pn vr =
9595
Nothing -> False -- Package not present in the DB.
9696
Just Nothing -> True -- Package present, but version unknown.
9797
Just (Just v) -> withinPkgconfigVersionRange v vr
98-
-- If we could not read the pkg-config database successfully we allow
99-
-- the check to succeed. The plan found by the solver may fail to be
100-
-- executed later on, but we have no grounds for rejecting the plan at
101-
-- this stage.
102-
pkgConfigPkgIsPresent NoPkgConfigDb _ _ = True
98+
-- If we could not read the pkg-config database successfully we fail.
99+
-- The plan found by the solver can't be executed later, because pkg-config itself
100+
-- is going to be called in the build phase to get the library location for linking
101+
-- so even if there is a library, it would need to be passed manual flags anyway.
102+
pkgConfigPkgIsPresent NoPkgConfigDb _ _ = False
103+
103104

104105

105106
-- | Query the version of a package in the @pkg-config@ database.

cabal-install/tests/UnitTests/Distribution/Solver/Modular/DSL/TestCaseUtils.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import Distribution.Verbosity
4343

4444
-- cabal-install
4545
import qualified Distribution.Solver.Types.PackagePath as P
46-
import Distribution.Solver.Types.PkgConfigDb (PkgConfigDb, pkgConfigDbFromList)
46+
import Distribution.Solver.Types.PkgConfigDb (PkgConfigDb (..), pkgConfigDbFromList)
4747
import Distribution.Solver.Types.Settings
4848
import Distribution.Solver.Types.Variable
4949
import Distribution.Client.Dependency (foldProgress)
@@ -166,41 +166,41 @@ mkTest :: ExampleDb
166166
-> [String]
167167
-> SolverResult
168168
-> SolverTest
169-
mkTest = mkTestExtLangPC Nothing Nothing []
169+
mkTest = mkTestExtLangPC Nothing Nothing (Just [])
170170

171171
mkTestExts :: [Extension]
172172
-> ExampleDb
173173
-> String
174174
-> [String]
175175
-> SolverResult
176176
-> SolverTest
177-
mkTestExts exts = mkTestExtLangPC (Just exts) Nothing []
177+
mkTestExts exts = mkTestExtLangPC (Just exts) Nothing (Just [])
178178

179179
mkTestLangs :: [Language]
180180
-> ExampleDb
181181
-> String
182182
-> [String]
183183
-> SolverResult
184184
-> SolverTest
185-
mkTestLangs langs = mkTestExtLangPC Nothing (Just langs) []
185+
mkTestLangs langs = mkTestExtLangPC Nothing (Just langs) (Just [])
186186

187-
mkTestPCDepends :: [(String, String)]
187+
mkTestPCDepends :: Maybe [(String, String)]
188188
-> ExampleDb
189189
-> String
190190
-> [String]
191191
-> SolverResult
192192
-> SolverTest
193-
mkTestPCDepends pkgConfigDb = mkTestExtLangPC Nothing Nothing pkgConfigDb
193+
mkTestPCDepends mPkgConfigDb = mkTestExtLangPC Nothing Nothing mPkgConfigDb
194194

195195
mkTestExtLangPC :: Maybe [Extension]
196196
-> Maybe [Language]
197-
-> [(String, String)]
197+
-> Maybe [(String, String)]
198198
-> ExampleDb
199199
-> String
200200
-> [String]
201201
-> SolverResult
202202
-> SolverTest
203-
mkTestExtLangPC exts langs pkgConfigDb db label targets result = SolverTest {
203+
mkTestExtLangPC exts langs mPkgConfigDb db label targets result = SolverTest {
204204
testLabel = label
205205
, testTargets = targets
206206
, testResult = result
@@ -219,7 +219,7 @@ mkTestExtLangPC exts langs pkgConfigDb db label targets result = SolverTest {
219219
, testDb = db
220220
, testSupportedExts = exts
221221
, testSupportedLangs = langs
222-
, testPkgConfigDb = pkgConfigDbFromList pkgConfigDb
222+
, testPkgConfigDb = maybe NoPkgConfigDb pkgConfigDbFromList mPkgConfigDb
223223
, testEnableAllTests = EnableAllTests False
224224
}
225225

cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,12 @@ tests = [
253253
, runTest $ mkTest dbBuildable2 "choose version that sets buildable to false" ["A"] (solverSuccess [("A", 1), ("B", 2)])
254254
]
255255
, testGroup "Pkg-config dependencies" [
256-
runTest $ mkTestPCDepends [] dbPC1 "noPkgs" ["A"] anySolverFailure
257-
, runTest $ mkTestPCDepends [("pkgA", "0")] dbPC1 "tooOld" ["A"] anySolverFailure
258-
, runTest $ mkTestPCDepends [("pkgA", "1.0.0"), ("pkgB", "1.0.0")] dbPC1 "pruneNotFound" ["C"] (solverSuccess [("A", 1), ("B", 1), ("C", 1)])
259-
, runTest $ mkTestPCDepends [("pkgA", "1.0.0"), ("pkgB", "2.0.0")] dbPC1 "chooseNewest" ["C"] (solverSuccess [("A", 1), ("B", 2), ("C", 1)])
256+
runTest $ mkTestPCDepends (Just []) dbPC1 "noPkgs" ["A"] anySolverFailure
257+
, runTest $ mkTestPCDepends (Just [("pkgA", "0")]) dbPC1 "tooOld" ["A"] anySolverFailure
258+
, runTest $ mkTestPCDepends (Just [("pkgA", "1.0.0"), ("pkgB", "1.0.0")]) dbPC1 "pruneNotFound" ["C"] (solverSuccess [("A", 1), ("B", 1), ("C", 1)])
259+
, runTest $ mkTestPCDepends (Just [("pkgA", "1.0.0"), ("pkgB", "2.0.0")]) dbPC1 "chooseNewest" ["C"] (solverSuccess [("A", 1), ("B", 2), ("C", 1)])
260+
, runTest $ mkTestPCDepends Nothing dbPC1 "noPkgConfigFailure" ["A"] anySolverFailure
261+
, runTest $ mkTestPCDepends Nothing dbPC1 "noPkgConfigSuccess" ["D"] (solverSuccess [("D",1)])
260262
]
261263
, testGroup "Independent goals" [
262264
runTest $ indep $ mkTest db16 "indepGoals1" ["A", "B"] (solverSuccess [("A", 1), ("B", 1), ("C", 1), ("D", 1), ("D", 2), ("E", 1)])
@@ -1665,7 +1667,7 @@ dbLangs1 = [
16651667
testBuildable :: String -> ExampleDependency -> TestTree
16661668
testBuildable testName unavailableDep =
16671669
runTest $
1668-
mkTestExtLangPC (Just []) (Just [Haskell98]) [] db testName ["pkg"] expected
1670+
mkTestExtLangPC (Just []) (Just [Haskell98]) (Just []) db testName ["pkg"] expected
16691671
where
16701672
expected = solverSuccess [("false-dep", 1), ("pkg", 1)]
16711673
db = [
@@ -1718,12 +1720,14 @@ dbBuildable2 = [
17181720
]
17191721

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

17291733
-- | Test for the solver's summarized log. The final conflict set is {A, F},

changelog.d/pr-7621

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
synopsis: Backtrack when no pkg-config is present
2+
packages: Cabal
3+
prs: #7621
4+
issues: #7448
5+
6+
description: {
7+
8+
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.
9+
10+
}

0 commit comments

Comments
 (0)