Skip to content

Commit 80de7ff

Browse files
dagitezyang
authored andcommitted
Require Cabal >= 1.20 in new-build. (#4051)
Constrain Cabal >= 1.20 in all new-build install plans. This solves problems where Cabal 1.18 don't have a good enough API to let us handle the new-style store (we need --dependency flags.) In the future we plan to relax this to only Setup.hs dependencies. Fixes issue #3932.
1 parent 20bed06 commit 80de7ff

File tree

11 files changed

+53
-31
lines changed

11 files changed

+53
-31
lines changed

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,17 @@ planPackages comp platform solver SolverSettings{..}
952952
| Dependency name ver <- solverSettingPreferences ]
953953

954954
. 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
955966
-- version constraints from the config file or command line
956967
[ LabeledPackageConstraint (userToPackageConstraint pc) src
957968
| (pc, src) <- solverSettingConstraints ]
@@ -2392,6 +2403,17 @@ defaultSetupDeps compiler platform pkg =
23922403
-- * We omit the dep for the Cabal lib itself, since it bootstraps.
23932404
-- * We constrain it to be >= 1.18 < 2
23942405
--
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).
2411+
--
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.
23952417
cabalConstraint = orLaterVersion cabalCompatMinVer
23962418
`intersectVersionRanges`
23972419
orLaterVersion (PD.specVersion pkg)
@@ -2421,6 +2443,8 @@ defaultSetupDeps compiler platform pkg =
24212443
-- The internal setup wrapper method has no deps at all.
24222444
SetupNonCustomInternalLib -> Just []
24232445

2446+
-- This case gets ruled out by the caller, planPackages, see the note
2447+
-- above in the SetupCustomIplicitDeps case.
24242448
SetupCustomExplicitDeps ->
24252449
error $ "defaultSetupDeps: called for a package with explicit "
24262450
++ "setup deps: " ++ display (packageId pkg)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ data ConstraintSource =
4545

4646
-- | The source of the constraint is not specified.
4747
| ConstraintSourceUnknown
48+
49+
-- | Custom setup requires a minimum lower bound on Cabal
50+
| ConstraintNewBuildCustomSetupLowerBoundCabal
4851
deriving (Eq, Show, Generic)
4952

5053
instance Binary ConstraintSource
@@ -68,3 +71,4 @@ showConstraintSource ConstraintSourceFreeze = "cabal freeze"
6871
showConstraintSource ConstraintSourceConfigFlagOrTarget =
6972
"config file, command line flag, or user target"
7073
showConstraintSource ConstraintSourceUnknown = "unknown source"
74+
showConstraintSource ConstraintNewBuildCustomSetupLowerBoundCabal = "new-build's support of Custom Setup (issue #3932)"

cabal-install/cabal-install.cabal

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Extra-Source-Files:
5151
tests/IntegrationTests/custom-setup/Cabal-99998/CabalMessage.hs
5252
tests/IntegrationTests/custom-setup/Cabal-99999/Cabal.cabal
5353
tests/IntegrationTests/custom-setup/Cabal-99999/CabalMessage.hs
54+
tests/IntegrationTests/custom-setup/custom-setup-old-cabal/Setup.hs
55+
tests/IntegrationTests/custom-setup/custom-setup-old-cabal/custom-setup-old-cabal.cabal
5456
tests/IntegrationTests/custom-setup/custom-setup-without-cabal-defaultMain/Setup.hs
5557
tests/IntegrationTests/custom-setup/custom-setup-without-cabal-defaultMain/custom-setup-without-cabal-defaultMain.cabal
5658
tests/IntegrationTests/custom-setup/custom-setup-without-cabal/Setup.hs
@@ -60,6 +62,7 @@ Extra-Source-Files:
6062
tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_allow_Cabal_import.sh
6163
tests/IntegrationTests/custom-setup/custom_setup_without_Cabal_doesnt_require_Cabal.sh
6264
tests/IntegrationTests/custom-setup/installs_Cabal_as_setup_dep.sh
65+
tests/IntegrationTests/custom-setup/new_build_requires_Cabal_1_20.sh
6366
tests/IntegrationTests/custom/custom_dep.sh
6467
tests/IntegrationTests/custom/custom_dep/client/B.hs
6568
tests/IntegrationTests/custom/custom_dep/client/Setup.hs
@@ -171,11 +174,6 @@ Extra-Source-Files:
171174
tests/IntegrationTests/regression/t3199/Main.hs
172175
tests/IntegrationTests/regression/t3199/Setup.hs
173176
tests/IntegrationTests/regression/t3199/test-3199.cabal
174-
tests/IntegrationTests/regression/t3335.sh
175-
tests/IntegrationTests/regression/t3335/A.hs
176-
tests/IntegrationTests/regression/t3335/Setup.hs
177-
tests/IntegrationTests/regression/t3335/cabal.project
178-
tests/IntegrationTests/regression/t3335/t3335.cabal
179177
tests/IntegrationTests/regression/t3827.sh
180178
tests/IntegrationTests/regression/t3827/cabal.project
181179
tests/IntegrationTests/regression/t3827/p/P.hs
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import CabalMessage (message)
2+
import System.Exit
3+
import System.IO
4+
5+
main = hPutStrLn stderr message >> exitFailure
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: custom-setup
2+
version: 1.0
3+
build-type: Custom
4+
5+
custom-setup
6+
setup-depends: base, Cabal < 1.20
7+
8+
library
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Regression test for issue #3932
2+
3+
. ./common.sh
4+
5+
cd custom-setup-old-cabal
6+
! cabal new-build > output 2>&1
7+
8+
cat output
9+
grep -q "(issue #3932) requires >=1.20" output || die "Expect constraint failure"

cabal-install/tests/IntegrationTests/regression/t3335.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

cabal-install/tests/IntegrationTests/regression/t3335/A.hs

Lines changed: 0 additions & 1 deletion
This file was deleted.

cabal-install/tests/IntegrationTests/regression/t3335/Setup.hs

Lines changed: 0 additions & 2 deletions
This file was deleted.

cabal-install/tests/IntegrationTests/regression/t3335/cabal.project

Lines changed: 0 additions & 1 deletion
This file was deleted.

cabal-install/tests/IntegrationTests/regression/t3335/t3335.cabal

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)