Skip to content

Commit c92b715

Browse files
committed
Set upper bound on setup.Cabal relative to current version
As we can't predict the future, we also place a global upper bound on the lib:Cabal version we know how to interact with: The upper bound is computed by incrementing the current major version twice in order to allow for the current version, as well as the next adjacent major version (one of which will not be released, as only "even major" versions of Cabal are released to Hackage or bundled with proper GHC releases). For instance, if the current version of cabal-install is an odd development version, e.g. Cabal-2.1.0.0, then we impose an upper bound `setup.Cabal < 2.3`; if `cabal-install` is on a stable/release even version, e.g. Cabal-2.2.1.0, the upper bound is `setup.Cabal < 2.4`. This gives us enough flexibility when dealing with development snapshots of Cabal and cabal-install. This addresses #415 (cherry picked from commit e66106c)
1 parent de880a5 commit c92b715

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

cabal-install/Distribution/Client/Dependency.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ module Distribution.Client.Dependency (
6161
removeUpperBounds,
6262
addDefaultSetupDependencies,
6363
addSetupCabalMinVersionConstraint,
64+
addSetupCabalMaxVersionConstraint,
6465
) where
6566

6667
import Distribution.Solver.Modular
@@ -555,6 +556,21 @@ addSetupCabalMinVersionConstraint minVersion =
555556
where
556557
cabalPkgname = mkPackageName "Cabal"
557558

559+
-- | Variant of 'addSetupCabalMinVersionConstraint' which sets an
560+
-- upper bound on @setup.Cabal@ labeled with 'ConstraintSetupCabalMaxVersion'.
561+
--
562+
addSetupCabalMaxVersionConstraint :: Version
563+
-> DepResolverParams -> DepResolverParams
564+
addSetupCabalMaxVersionConstraint maxVersion =
565+
addConstraints
566+
[ LabeledPackageConstraint
567+
(PackageConstraint (ScopeAnySetupQualifier cabalPkgname)
568+
(PackagePropertyVersion $ earlierVersion maxVersion))
569+
ConstraintSetupCabalMaxVersion
570+
]
571+
where
572+
cabalPkgname = mkPackageName "Cabal"
573+
558574

559575
upgradeDependencies :: DepResolverParams -> DepResolverParams
560576
upgradeDependencies = setPreferenceDefault PreferAllLatest

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import qualified Distribution.Client.SolverInstallPlan as SolverInstallPlan
8080
import Distribution.Client.Dependency
8181
import Distribution.Client.Dependency.Types
8282
import qualified Distribution.Client.IndexUtils as IndexUtils
83+
import Distribution.Client.Init (incVersion)
8384
import Distribution.Client.Targets (userToPackageConstraint)
8485
import Distribution.Client.DistDirLayout
8586
import Distribution.Client.SetupWrapper
@@ -950,6 +951,7 @@ planPackages verbosity comp platform solver SolverSettings{..}
950951
. packageDescription)
951952

952953
. addSetupCabalMinVersionConstraint setupMinCabalVersionConstraint
954+
. addSetupCabalMaxVersionConstraint setupMaxCabalVersionConstraint
953955

954956
. addPreferences
955957
-- preferences from the config file or command line
@@ -1064,6 +1066,25 @@ planPackages verbosity comp platform solver SolverSettings{..}
10641066
compFlav = compilerFlavor comp
10651067
compVer = compilerVersion comp
10661068

1069+
-- As we can't predict the future, we also place a global upper
1070+
-- bound on the lib:Cabal version we know how to interact with:
1071+
--
1072+
-- The upper bound is computed by incrementing the current major
1073+
-- version twice in order to allow for the current version, as
1074+
-- well as the next adjacent major version (one of which will not
1075+
-- be released, as only "even major" versions of Cabal are
1076+
-- released to Hackage or bundled with proper GHC releases).
1077+
--
1078+
-- For instance, if the current version of cabal-install is an odd
1079+
-- development version, e.g. Cabal-2.1.0.0, then we impose an
1080+
-- upper bound `setup.Cabal < 2.3`; if `cabal-install` is on a
1081+
-- stable/release even version, e.g. Cabal-2.2.1.0, the upper
1082+
-- bound is `setup.Cabal < 2.4`. This gives us enough flexibility
1083+
-- when dealing with development snapshots of Cabal and cabal-install.
1084+
--
1085+
setupMaxCabalVersionConstraint =
1086+
alterVersion (take 2) $ incVersion 1 $ incVersion 1 cabalVersion
1087+
10671088
------------------------------------------------------------------------------
10681089
-- * Install plan post-processing
10691090
------------------------------------------------------------------------------

cabal-install/Distribution/Solver/Types/ConstraintSource.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ data ConstraintSource =
4949
-- | An internal constraint due to compatibility issues with the Setup.hs
5050
-- command line interface requires a minimum lower bound on Cabal
5151
| ConstraintSetupCabalMinVersion
52+
53+
-- | An internal constraint due to compatibility issues with the Setup.hs
54+
-- command line interface requires a maximum upper bound on Cabal
55+
| ConstraintSetupCabalMaxVersion
5256
deriving (Eq, Show, Generic)
5357

5458
instance Binary ConstraintSource
@@ -74,3 +78,5 @@ showConstraintSource ConstraintSourceConfigFlagOrTarget =
7478
showConstraintSource ConstraintSourceUnknown = "unknown source"
7579
showConstraintSource ConstraintSetupCabalMinVersion =
7680
"minimum version of Cabal used by Setup.hs"
81+
showConstraintSource ConstraintSetupCabalMaxVersion =
82+
"maximum version of Cabal used by Setup.hs"

0 commit comments

Comments
 (0)