From 97155ecd4f5ffdd84a734a19e5a1cba0dc0c1dd1 Mon Sep 17 00:00:00 2001 From: Herbert Valerio Riedel Date: Fri, 24 Nov 2017 13:12:20 +0100 Subject: [PATCH 1/2] Have the solver reject packages with a too-new/unsupported spec-version This compares the request spec-version to the lib:Cabal's version in order to determine whether cabal is able to properly understand the package. If it's newer than the currently linked lib:Cabal version it's turned into a global `FailResult` which the solver treats as desired in terms of backtracking and error reporting. This is related to the new spec-version forward-compat scheme (see #4899). This is a forward-port of #4907 to the `master` branch --- .../Solver/Modular/IndexConversion.hs | 32 ++++++++++++++++++- .../Distribution/Solver/Modular/Message.hs | 1 + .../Distribution/Solver/Modular/Tree.hs | 1 + 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/cabal-install/Distribution/Solver/Modular/IndexConversion.hs b/cabal-install/Distribution/Solver/Modular/IndexConversion.hs index 413c62ee51d..13b1eca5d99 100644 --- a/cabal-install/Distribution/Solver/Modular/IndexConversion.hs +++ b/cabal-install/Distribution/Solver/Modular/IndexConversion.hs @@ -12,6 +12,7 @@ import Distribution.Compiler import Distribution.InstalledPackageInfo as IPI import Distribution.Package -- from Cabal import Distribution.Simple.BuildToolDepends -- from Cabal +import Distribution.Simple.Utils (cabalVersion) -- from Cabal import Distribution.Types.ExeDependency -- from Cabal import Distribution.Types.PkgconfigDependency -- from Cabal import Distribution.Types.ComponentName -- from Cabal @@ -191,8 +192,37 @@ convGPD os arch cinfo strfl solveExes pn addStanza :: Stanza -> DependencyReason pn -> DependencyReason pn addStanza s (DependencyReason pn' fs ss) = DependencyReason pn' fs (s : ss) + + -- | We infer the maximally supported spec-version from @lib:Cabal@'s version + -- + -- As we cannot predict the future, we can only properly support + -- spec-versions predating (and including) the @lib:Cabal@ version + -- used by @cabal-install@. + -- + -- This relies on 'cabalVersion' having always at least 3 components to avoid + -- comparisons like @2.0.0 > 2.0@ which would result in confusing results. + -- + -- NOTE: Before we can switch to a /normalised/ spec-version + -- comparison (e.g. by truncating to 3 components, and removing + -- trailing zeroes) we'd have to make sure all other places where + -- the spec-version is compared against a bound do it + -- consistently. + maxSpecVer = cabalVersion + + -- | Required/declared spec-version of the package + -- + -- We don't truncate patch-levels, as specifying a patch-level + -- spec-version is discouraged and not supported anymore starting + -- with spec-version 2.2. + reqSpecVer = specVersion pkg + + -- | A too-new specVersion is turned into a global 'FailReason' + -- which prevents the solver from selecting this release (and if + -- forced to, emit a meaningful solver error message). + fr | reqSpecVer > maxSpecVer = Just (UnsupportedSpecVer reqSpecVer) + | otherwise = Nothing in - PInfo flagged_deps (L.map fst exes) fds Nothing + PInfo flagged_deps (L.map fst exes) fds fr -- | Create a flagged dependency tree from a list @fds@ of flagged -- dependencies, using @f@ to form the tree node (@f@ will be diff --git a/cabal-install/Distribution/Solver/Modular/Message.hs b/cabal-install/Distribution/Solver/Modular/Message.hs index 19bc0789371..99eecc843ee 100644 --- a/cabal-install/Distribution/Solver/Modular/Message.hs +++ b/cabal-install/Distribution/Solver/Modular/Message.hs @@ -146,6 +146,7 @@ showFR c Backjump = " (backjumping, conflict set: " ++ s showFR _ MultipleInstances = " (multiple instances)" showFR c (DependenciesNotLinked msg) = " (dependencies not linked: " ++ msg ++ "; conflict set: " ++ showConflictSet c ++ ")" showFR c CyclicDependencies = " (cyclic dependencies; conflict set: " ++ showConflictSet c ++ ")" +showFR _ (UnsupportedSpecVer ver) = " (unsupported spec-version " ++ display ver ++ ")" -- The following are internal failures. They should not occur. In the -- interest of not crashing unnecessarily, we still just print an error -- message though. diff --git a/cabal-install/Distribution/Solver/Modular/Tree.hs b/cabal-install/Distribution/Solver/Modular/Tree.hs index 6ae1b22a967..91c2f9becc4 100644 --- a/cabal-install/Distribution/Solver/Modular/Tree.hs +++ b/cabal-install/Distribution/Solver/Modular/Tree.hs @@ -118,6 +118,7 @@ data FailReason = UnsupportedExtension Extension | MultipleInstances | DependenciesNotLinked String | CyclicDependencies + | UnsupportedSpecVer Ver deriving (Eq, Show) -- | Information about a dependency involved in a conflict, for error messages. From b92cdcfb381fd408fa8efd395259dd559b62450e Mon Sep 17 00:00:00 2001 From: Herbert Valerio Riedel Date: Fri, 24 Nov 2017 17:57:02 +0100 Subject: [PATCH 2/2] Don't use `cabal-version: >= 99999` in test-cases Since we now reject unknown spec-versions in the solver, these test-cases were broken; this replaces the 2 occurences by `cabal-version: 2.0` instead. (cherry picked from commit 45c102d76b82d086bdf515d1cee10f82a72018c8) --- .../CustomWithoutCabal/custom-setup-without-cabal.cabal | 2 +- .../Regression/T3436/custom-setup/custom-setup.cabal | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cabal-testsuite/PackageTests/CustomWithoutCabal/custom-setup-without-cabal.cabal b/cabal-testsuite/PackageTests/CustomWithoutCabal/custom-setup-without-cabal.cabal index 7abdee77c71..64d2e55de4f 100644 --- a/cabal-testsuite/PackageTests/CustomWithoutCabal/custom-setup-without-cabal.cabal +++ b/cabal-testsuite/PackageTests/CustomWithoutCabal/custom-setup-without-cabal.cabal @@ -1,7 +1,7 @@ +cabal-version: 2.0 name: custom-setup-without-cabal version: 1.0 build-type: Custom -cabal-version: >= 99999 custom-setup setup-depends: base diff --git a/cabal-testsuite/PackageTests/Regression/T3436/custom-setup/custom-setup.cabal b/cabal-testsuite/PackageTests/Regression/T3436/custom-setup/custom-setup.cabal index 923de11e862..f06d6644610 100644 --- a/cabal-testsuite/PackageTests/Regression/T3436/custom-setup/custom-setup.cabal +++ b/cabal-testsuite/PackageTests/Regression/T3436/custom-setup/custom-setup.cabal @@ -1,7 +1,7 @@ +cabal-version: 2.0 name: custom-setup version: 1.0 build-type: Custom -cabal-version: >= 99999 custom-setup setup-depends: base, Cabal >= 99999