Skip to content

Commit 066b2a1

Browse files
authored
Merge pull request #5170 from grayjay/issue-4288
Look for transitive setup dependency on Cabal when choosing Cabal spec version.
2 parents 0d43277 + f4f382a commit 066b2a1

File tree

8 files changed

+73
-20
lines changed

8 files changed

+73
-20
lines changed

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
12651265
if null not_per_component_reasons
12661266
then return comps
12671267
else do checkPerPackageOk comps not_per_component_reasons
1268-
return [elaborateSolverToPackage mapDep spkg g $
1268+
return [elaborateSolverToPackage spkg g $
12691269
comps ++ maybeToList setupComponent]
12701270
Left cns ->
12711271
dieProgress $
@@ -1331,7 +1331,7 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
13311331
fsep (punctuate comma reasons)
13321332
-- TODO: Maybe exclude Backpack too
13331333

1334-
elab0 = elaborateSolverToCommon mapDep spkg
1334+
elab0 = elaborateSolverToCommon spkg
13351335
pkgid = elabPkgSourceId elab0
13361336
pd = elabPkgDescription elab0
13371337

@@ -1556,13 +1556,11 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
15561556
Just (Just n) -> display n
15571557
_ -> ""
15581558

1559-
elaborateSolverToPackage :: (SolverId -> [ElaboratedPlanPackage])
1560-
-> SolverPackage UnresolvedPkgLoc
1559+
elaborateSolverToPackage :: SolverPackage UnresolvedPkgLoc
15611560
-> ComponentsGraph
15621561
-> [ElaboratedConfiguredPackage]
15631562
-> ElaboratedConfiguredPackage
15641563
elaborateSolverToPackage
1565-
mapDep
15661564
pkg@(SolverPackage (SourcePackage pkgid _gdesc _srcloc _descOverride)
15671565
_flags _stanzas _deps0 _exe_deps0)
15681566
compGraph comps =
@@ -1571,7 +1569,7 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
15711569
-- of the other fields of the elaboratedPackage.
15721570
elab
15731571
where
1574-
elab0@ElaboratedConfiguredPackage{..} = elaborateSolverToCommon mapDep pkg
1572+
elab0@ElaboratedConfiguredPackage{..} = elaborateSolverToCommon pkg
15751573
elab = elab0 {
15761574
elabUnitId = newSimpleUnitId pkgInstalledId,
15771575
elabComponentId = pkgInstalledId,
@@ -1668,10 +1666,9 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
16681666
(compilerId compiler)
16691667
pkgInstalledId
16701668

1671-
elaborateSolverToCommon :: (SolverId -> [ElaboratedPlanPackage])
1672-
-> SolverPackage UnresolvedPkgLoc
1669+
elaborateSolverToCommon :: SolverPackage UnresolvedPkgLoc
16731670
-> ElaboratedConfiguredPackage
1674-
elaborateSolverToCommon mapDep
1671+
elaborateSolverToCommon
16751672
pkg@(SolverPackage (SourcePackage pkgid gdesc srcloc descOverride)
16761673
flags stanzas deps0 _exe_deps0) =
16771674
elaboratedPackage
@@ -1742,10 +1739,9 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
17421739
elabRegisterPackageDBStack = buildAndRegisterDbs
17431740

17441741
elabSetupScriptStyle = packageSetupScriptStyle elabPkgDescription
1745-
-- Computing the deps here is a little awful
1746-
deps = fmap (concatMap (elaborateLibSolverId mapDep)) deps0
1747-
elabSetupScriptCliVersion = packageSetupScriptSpecVersion
1748-
elabSetupScriptStyle elabPkgDescription deps
1742+
elabSetupScriptCliVersion =
1743+
packageSetupScriptSpecVersion
1744+
elabSetupScriptStyle elabPkgDescription libDepGraph deps0
17491745
elabSetupPackageDBStack = buildAndRegisterDbs
17501746

17511747
buildAndRegisterDbs
@@ -2965,31 +2961,34 @@ defaultSetupDeps compiler platform pkg =
29652961
-- of what the solver picked for us, based on the explicit setup deps or the
29662962
-- ones added implicitly by 'defaultSetupDeps'.
29672963
--
2968-
packageSetupScriptSpecVersion :: Package pkg
2969-
=> SetupScriptStyle
2964+
packageSetupScriptSpecVersion :: SetupScriptStyle
29702965
-> PD.PackageDescription
2971-
-> ComponentDeps [pkg]
2966+
-> Graph.Graph NonSetupLibDepSolverPlanPackage
2967+
-> ComponentDeps [SolverId]
29722968
-> Version
29732969

29742970
-- We're going to be using the internal Cabal library, so the spec version of
29752971
-- that is simply the version of the Cabal library that cabal-install has been
29762972
-- built with.
2977-
packageSetupScriptSpecVersion SetupNonCustomInternalLib _ _ =
2973+
packageSetupScriptSpecVersion SetupNonCustomInternalLib _ _ _ =
29782974
cabalVersion
29792975

29802976
-- If we happen to be building the Cabal lib itself then because that
29812977
-- bootstraps itself then we use the version of the lib we're building.
2982-
packageSetupScriptSpecVersion SetupCustomImplicitDeps pkg _
2978+
packageSetupScriptSpecVersion SetupCustomImplicitDeps pkg _ _
29832979
| packageName pkg == cabalPkgname
29842980
= packageVersion pkg
29852981

29862982
-- In all other cases we have a look at what version of the Cabal lib the
29872983
-- solver picked. Or if it didn't depend on Cabal at all (which is very rare)
29882984
-- then we look at the .cabal file to see what spec version it declares.
2989-
packageSetupScriptSpecVersion _ pkg deps =
2990-
case find ((cabalPkgname ==) . packageName) (CD.setupDeps deps) of
2985+
packageSetupScriptSpecVersion _ pkg libDepGraph deps =
2986+
case find ((cabalPkgname ==) . packageName) setupLibDeps of
29912987
Just dep -> packageVersion dep
29922988
Nothing -> PD.specVersion pkg
2989+
where
2990+
setupLibDeps = map packageId $ fromMaybe [] $
2991+
Graph.closure libDepGraph (CD.setupDeps deps)
29932992

29942993

29952994
cabalPkgname, basePkgname :: PackageName
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module CustomIssue where
2+
3+
f x = x + 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import SetupHelper (setupHelperDefaultMain)
2+
3+
main = setupHelperDefaultMain
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: T4288
2+
version: 1.0
3+
build-type: Custom
4+
5+
-- cabal-version is lower than the version of Cabal that will be chosen for the
6+
-- setup script.
7+
cabal-version: >=1.10
8+
9+
-- Setup script only has a transitive dependency on Cabal.
10+
custom-setup
11+
setup-depends: base, setup-helper
12+
13+
library
14+
exposed-modules: CustomIssue
15+
build-depends: base
16+
default-language: Haskell2010
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: . setup-helper/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Test.Cabal.Prelude
2+
3+
-- This test is similar to the simplified example in issue #4288. The package's
4+
-- setup script only depends on base and setup-helper. setup-helper exposes a
5+
-- function that is a wrapper for Cabal's defaultMain (similar to
6+
-- cabal-doctest). This test builds the package to check that the flags passed
7+
-- to the setup script are compatible with the version of Cabal that it depends
8+
-- on, even though Cabal is only a transitive dependency.
9+
main = cabalTest $ do
10+
skipUnless =<< hasNewBuildCompatBootCabal
11+
r <- recordMode DoNotRecord $ cabal' "new-build" ["T4288"]
12+
assertOutputContains "This is setup-helper-1.0." r
13+
assertOutputContains
14+
("In order, the following will be built: "
15+
++ " - setup-helper-1.0 (lib:setup-helper) (first run) "
16+
++ " - T4288-1.0 (lib:T4288) (first run)")
17+
r
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module SetupHelper (setupHelperDefaultMain) where
2+
3+
import Distribution.Simple
4+
5+
setupHelperDefaultMain = putStrLn "This is setup-helper-1.0." >> defaultMain
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: setup-helper
2+
version: 1.0
3+
build-type: Simple
4+
cabal-version: >= 1.2
5+
6+
library
7+
exposed-modules: SetupHelper
8+
build-depends: base, Cabal
9+
default-language: Haskell2010

0 commit comments

Comments
 (0)