Skip to content

Commit a5b1bb4

Browse files
committed
Refine the fix for requiring Cabal > 1.20 for Setup.hs
Going along with the existing approach of using a constraint rather than altering the deps of custom Setup.hs scripts, but make the constraint only apply to Cabal instances that are dependencies of Setup.hs scripts not all instances of Cabal. Also rearrange things a little with a dedicated solver policy function for adding a min dep on Cabal versions for setup scripts.
1 parent 80de7ff commit a5b1bb4

File tree

5 files changed

+59
-38
lines changed

5 files changed

+59
-38
lines changed

cabal-install/Distribution/Client/Dependency.hs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module Distribution.Client.Dependency (
5656
removeLowerBounds,
5757
removeUpperBounds,
5858
addDefaultSetupDependencies,
59+
addSetupCabalMinVersionConstraint,
5960
) where
6061

6162
import Distribution.Solver.Modular
@@ -84,9 +85,9 @@ import Distribution.PackageDescription.Configuration
8485
import Distribution.Client.PackageUtils
8586
( externalBuildDepends )
8687
import Distribution.Version
87-
( mkVersion, VersionRange, anyVersion, thisVersion, orLaterVersion
88-
, withinRange, simplifyVersionRange
89-
, removeLowerBound, removeUpperBound )
88+
( Version, mkVersion
89+
, VersionRange, anyVersion, thisVersion, orLaterVersion, withinRange
90+
, simplifyVersionRange, removeLowerBound, removeUpperBound )
9091
import Distribution.Compiler
9192
( CompilerInfo(..) )
9293
import Distribution.System
@@ -460,6 +461,22 @@ addDefaultSetupDependencies defaultSetupDeps params =
460461
gpkgdesc = packageDescription srcpkg
461462
pkgdesc = PD.packageDescription gpkgdesc
462463

464+
-- | There If a package has a custom setup then we need to add a setup-depends
465+
-- on Cabal. For now it's easier to add this unconditionally. Once
466+
-- qualified constraints land we can turn this into a custom setup
467+
-- only constraint.
468+
--
469+
addSetupCabalMinVersionConstraint :: Version
470+
-> DepResolverParams -> DepResolverParams
471+
addSetupCabalMinVersionConstraint minVersion =
472+
addConstraints
473+
[ LabeledPackageConstraint
474+
(PackageConstraintVersion cabalPkgname (orLaterVersion minVersion))
475+
ConstraintSetupCabalMinVersion
476+
]
477+
where
478+
cabalPkgname = mkPackageName "Cabal"
479+
463480

464481
upgradeDependencies :: DepResolverParams -> DepResolverParams
465482
upgradeDependencies = setPreferenceDefault PreferAllLatest

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -946,23 +946,25 @@ planPackages comp platform solver SolverSettings{..}
946946
. PD.packageDescription
947947
. packageDescription)
948948

949+
. addSetupCabalMinVersionConstraint (mkVersion [1,20])
950+
-- While we can talk to older Cabal versions (we need to be able to
951+
-- do so for custom Setup scripts that require older Cabal lib
952+
-- versions), we have problems talking to some older versions that
953+
-- don't support certain features.
954+
--
955+
-- For example, Cabal-1.16 and older do not know about build targets.
956+
-- Even worse, 1.18 and older only supported the --constraint flag
957+
-- with source package ids, not --dependency with installed package
958+
-- ids. That is bad because we cannot reliably select the right
959+
-- dependencies in the presence of multiple instances (i.e. the
960+
-- store). See issue #3932. So we require Cabal 1.20 as a minimum.
961+
949962
. addPreferences
950963
-- preferences from the config file or command line
951964
[ PackageVersionPreference name ver
952965
| Dependency name ver <- solverSettingPreferences ]
953966

954967
. addConstraints
955-
956-
-- If a package has a custom setup then we need to add a setup-depends
957-
-- on Cabal. For now it's easier to add this unconditionally. Once
958-
-- qualified constraints land we can turn this into a custom setup
959-
-- only constraint.
960-
--
961-
-- TODO: use a qualified constraint
962-
[ LabeledPackageConstraint (PackageConstraintVersion cabalPkgname
963-
(orLaterVersion (mkVersion [1,20])))
964-
ConstraintNewBuildCustomSetupLowerBoundCabal
965-
] . addConstraints
966968
-- version constraints from the config file or command line
967969
[ LabeledPackageConstraint (userToPackageConstraint pc) src
968970
| (pc, src) <- solverSettingConstraints ]
@@ -2383,6 +2385,10 @@ packageSetupScriptStyle pkg
23832385
-- we still need to distinguish the case of explicit and implict setup deps.
23842386
-- See 'rememberImplicitSetupDeps'.
23852387
--
2388+
-- Note in addition to adding default setup deps, we also use
2389+
-- 'addSetupCabalMinVersionConstraint' (in 'planPackages') to require
2390+
-- @Cabal >= 1.20@ for Setup scripts.
2391+
--
23862392
defaultSetupDeps :: Compiler -> Platform
23872393
-> PD.PackageDescription
23882394
-> Maybe [Dependency]
@@ -2401,35 +2407,19 @@ defaultSetupDeps compiler platform pkg =
24012407
where
24022408
-- The Cabal dep is slightly special:
24032409
-- * We omit the dep for the Cabal lib itself, since it bootstraps.
2404-
-- * We constrain it to be >= 1.18 < 2
2410+
-- * We constrain it to be < 1.25
24052411
--
2406-
-- Note: cabalCompatMinVer only gets applied WHEN WE ARE ADDING a
2407-
-- default setup build info, i.e., when there is no custom-setup
2408-
-- stanza. If there is a custom-setup stanza, this codepath never gets
2409-
-- invoked (that's why there's an error case for
2410-
-- SetupCustomExplicitDeps).
2412+
-- Note: we also add a global constraint to require Cabal >= 1.20
2413+
-- for Setup scripts (see use addSetupCabalMinVersionConstraint).
24112414
--
2412-
-- One way we could solve this problem is by also modifying
2413-
-- custom-setup stanzas when they exist, but we're going to take a
2414-
-- different approach: add an extra constraint on Cabal globally to
2415-
-- make sure the solver respects it regardless of whether or not there
2416-
-- is an explicit setup build info or not. See planPackages.
2417-
cabalConstraint = orLaterVersion cabalCompatMinVer
2418-
`intersectVersionRanges`
2419-
orLaterVersion (PD.specVersion pkg)
2415+
cabalConstraint = orLaterVersion (PD.specVersion pkg)
24202416
`intersectVersionRanges`
24212417
earlierVersion cabalCompatMaxVer
24222418
-- The idea here is that at some point we will make significant
24232419
-- breaking changes to the Cabal API that Setup.hs scripts use.
24242420
-- So for old custom Setup scripts that do not specify explicit
24252421
-- constraints, we constrain them to use a compatible Cabal version.
24262422
cabalCompatMaxVer = mkVersion [1,25]
2427-
-- In principle we can talk to any old Cabal version, and we need to
2428-
-- be able to do that for custom Setup scripts that require older
2429-
-- Cabal lib versions. However in practice we have currently have
2430-
-- problems with Cabal-1.16. (1.16 does not know about build targets)
2431-
-- If this is fixed we can relax this constraint.
2432-
cabalCompatMinVer = mkVersion [1,18]
24332423

24342424
-- For other build types (like Simple) if we still need to compile an
24352425
-- external Setup.hs, it'll be one of the simple ones that only depends
@@ -2444,7 +2434,7 @@ defaultSetupDeps compiler platform pkg =
24442434
SetupNonCustomInternalLib -> Just []
24452435

24462436
-- This case gets ruled out by the caller, planPackages, see the note
2447-
-- above in the SetupCustomIplicitDeps case.
2437+
-- above in the SetupCustomImplicitDeps case.
24482438
SetupCustomExplicitDeps ->
24492439
error $ "defaultSetupDeps: called for a package with explicit "
24502440
++ "setup deps: " ++ display (packageId pkg)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Distribution.Solver.Modular.Package
1111
, instI
1212
, makeIndependent
1313
, primaryPP
14+
, setupPP
1415
, showI
1516
, showPI
1617
, unPN
@@ -91,6 +92,14 @@ primaryPP (PackagePath _ns q) = go q
9192
go (Setup _) = False
9293
go (Exe _ _) = False
9394

95+
-- | Is the package a dependency of a setup script. This is used establish
96+
-- whether or not certain constraints should apply to this dependency
97+
-- (grep 'setupPP' to see the use sites).
98+
--
99+
setupPP :: PackagePath -> Bool
100+
setupPP (PackagePath _ns (Setup _)) = True
101+
setupPP (PackagePath _ns _) = False
102+
94103
-- | Create artificial parents for each of the package names, making
95104
-- them all independent.
96105
makeIndependent :: [PN] -> [QPN]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ processPackageConstraintP pp _ _ (LabeledPackageConstraint _ src) r
156156
| src == ConstraintSourceUserTarget && not (primaryPP pp) = r
157157
-- the constraints arising from targets, like "foo-1.0" only apply to
158158
-- the main packages in the solution, they don't constrain setup deps
159+
| src == ConstraintSetupCabalMinVersion && not (setupPP pp) = r
160+
-- the internal constraints on the Setup.hs CLI version don't apply to
161+
-- the main packages in the solution, they only constrain setup deps
159162

160163
processPackageConstraintP _ c i (LabeledPackageConstraint pc src) r = go i pc
161164
where

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ data ConstraintSource =
4646
-- | The source of the constraint is not specified.
4747
| ConstraintSourceUnknown
4848

49-
-- | Custom setup requires a minimum lower bound on Cabal
50-
| ConstraintNewBuildCustomSetupLowerBoundCabal
49+
-- | An internal constraint due to compatability issues with the Setup.hs
50+
-- command line interface requires a minimum lower bound on Cabal
51+
| ConstraintSetupCabalMinVersion
5152
deriving (Eq, Show, Generic)
5253

5354
instance Binary ConstraintSource
@@ -71,4 +72,5 @@ showConstraintSource ConstraintSourceFreeze = "cabal freeze"
7172
showConstraintSource ConstraintSourceConfigFlagOrTarget =
7273
"config file, command line flag, or user target"
7374
showConstraintSource ConstraintSourceUnknown = "unknown source"
74-
showConstraintSource ConstraintNewBuildCustomSetupLowerBoundCabal = "new-build's support of Custom Setup (issue #3932)"
75+
showConstraintSource ConstraintSetupCabalMinVersion =
76+
"minimum version of Cabal used by Setup.hs"

0 commit comments

Comments
 (0)