Skip to content

Commit 1b1e908

Browse files
authored
Merge pull request #4909 from hvr/pr/2.2/solver-spec-ver
Have the solver reject packages with a too-new/unsupported spec-version
2 parents a72efb2 + b92cdcf commit 1b1e908

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

cabal-install/Distribution/Solver/Modular/IndexConversion.hs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Distribution.Compiler
1212
import Distribution.InstalledPackageInfo as IPI
1313
import Distribution.Package -- from Cabal
1414
import Distribution.Simple.BuildToolDepends -- from Cabal
15+
import Distribution.Simple.Utils (cabalVersion) -- from Cabal
1516
import Distribution.Types.ExeDependency -- from Cabal
1617
import Distribution.Types.PkgconfigDependency -- from Cabal
1718
import Distribution.Types.ComponentName -- from Cabal
@@ -191,8 +192,37 @@ convGPD os arch cinfo strfl solveExes pn
191192

192193
addStanza :: Stanza -> DependencyReason pn -> DependencyReason pn
193194
addStanza s (DependencyReason pn' fs ss) = DependencyReason pn' fs (s : ss)
195+
196+
-- | We infer the maximally supported spec-version from @lib:Cabal@'s version
197+
--
198+
-- As we cannot predict the future, we can only properly support
199+
-- spec-versions predating (and including) the @lib:Cabal@ version
200+
-- used by @cabal-install@.
201+
--
202+
-- This relies on 'cabalVersion' having always at least 3 components to avoid
203+
-- comparisons like @2.0.0 > 2.0@ which would result in confusing results.
204+
--
205+
-- NOTE: Before we can switch to a /normalised/ spec-version
206+
-- comparison (e.g. by truncating to 3 components, and removing
207+
-- trailing zeroes) we'd have to make sure all other places where
208+
-- the spec-version is compared against a bound do it
209+
-- consistently.
210+
maxSpecVer = cabalVersion
211+
212+
-- | Required/declared spec-version of the package
213+
--
214+
-- We don't truncate patch-levels, as specifying a patch-level
215+
-- spec-version is discouraged and not supported anymore starting
216+
-- with spec-version 2.2.
217+
reqSpecVer = specVersion pkg
218+
219+
-- | A too-new specVersion is turned into a global 'FailReason'
220+
-- which prevents the solver from selecting this release (and if
221+
-- forced to, emit a meaningful solver error message).
222+
fr | reqSpecVer > maxSpecVer = Just (UnsupportedSpecVer reqSpecVer)
223+
| otherwise = Nothing
194224
in
195-
PInfo flagged_deps (L.map fst exes) fds Nothing
225+
PInfo flagged_deps (L.map fst exes) fds fr
196226

197227
-- | Create a flagged dependency tree from a list @fds@ of flagged
198228
-- dependencies, using @f@ to form the tree node (@f@ will be

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ showFR c Backjump = " (backjumping, conflict set: " ++ s
146146
showFR _ MultipleInstances = " (multiple instances)"
147147
showFR c (DependenciesNotLinked msg) = " (dependencies not linked: " ++ msg ++ "; conflict set: " ++ showConflictSet c ++ ")"
148148
showFR c CyclicDependencies = " (cyclic dependencies; conflict set: " ++ showConflictSet c ++ ")"
149+
showFR _ (UnsupportedSpecVer ver) = " (unsupported spec-version " ++ display ver ++ ")"
149150
-- The following are internal failures. They should not occur. In the
150151
-- interest of not crashing unnecessarily, we still just print an error
151152
-- message though.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ data FailReason = UnsupportedExtension Extension
118118
| MultipleInstances
119119
| DependenciesNotLinked String
120120
| CyclicDependencies
121+
| UnsupportedSpecVer Ver
121122
deriving (Eq, Show)
122123

123124
-- | Information about a dependency involved in a conflict, for error messages.

cabal-testsuite/PackageTests/CustomWithoutCabal/custom-setup-without-cabal.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
cabal-version: 2.0
12
name: custom-setup-without-cabal
23
version: 1.0
34
build-type: Custom
4-
cabal-version: >= 99999
55

66
custom-setup
77
setup-depends: base

cabal-testsuite/PackageTests/Regression/T3436/custom-setup/custom-setup.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
cabal-version: 2.0
12
name: custom-setup
23
version: 1.0
34
build-type: Custom
4-
cabal-version: >= 99999
55

66
custom-setup
77
setup-depends: base, Cabal >= 99999

0 commit comments

Comments
 (0)