Skip to content

Commit e23d8d1

Browse files
authored
Merge pull request #5929 from hvr/pr/bkpcabal01-regression
Add bkpcabal01 regression test-case and fix the bug
2 parents 73b09cd + 011de3d commit e23d8d1

File tree

13 files changed

+132
-0
lines changed

13 files changed

+132
-0
lines changed

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,6 +2231,41 @@ instantiateInstallPlan plan =
22312231

22322232
indefiniteComponent :: UnitId -> ComponentId -> InstM ElaboratedPlanPackage
22332233
indefiniteComponent _uid cid
2234+
-- Only need Configured; this phase happens before improvement, so
2235+
-- there shouldn't be any Installed packages here.
2236+
| Just (InstallPlan.Configured epkg) <- Map.lookup cid cmap
2237+
, ElabComponent elab_comp <- elabPkgOrComp epkg
2238+
= do -- We need to do a little more processing of the includes: some
2239+
-- of them are fully definite even without substitution. We
2240+
-- want to build those too; see #5634.
2241+
--
2242+
-- This code mimics similar code in Distribution.Backpack.ReadyComponent;
2243+
-- however, unlike the conversion from LinkedComponent to
2244+
-- ReadyComponent, this transformation is done *without*
2245+
-- changing the type in question; and what we are simply
2246+
-- doing is enforcing tighter invariants on the data
2247+
-- structure in question. The new invariant is that there
2248+
-- is no IndefFullUnitId in compLinkedLibDependencies that actually
2249+
-- has no holes. We couldn't specify this invariant when
2250+
-- we initially created the ElaboratedPlanPackage because
2251+
-- we have no way of actually refiying the UnitId into a
2252+
-- DefiniteUnitId (that's what substUnitId does!)
2253+
new_deps <- forM (compLinkedLibDependencies elab_comp) $ \uid ->
2254+
if Set.null (openUnitIdFreeHoles uid)
2255+
then fmap DefiniteUnitId (substUnitId Map.empty uid)
2256+
else return uid
2257+
return $ InstallPlan.Configured epkg {
2258+
elabPkgOrComp = ElabComponent elab_comp {
2259+
compLinkedLibDependencies = new_deps,
2260+
-- I think this is right: any new definite unit ids we
2261+
-- minted in the phase above need to be built before us.
2262+
-- Add 'em in. This doesn't remove any old dependencies
2263+
-- on the indefinite package; they're harmless.
2264+
compOrderLibDependencies =
2265+
ordNub $ compOrderLibDependencies elab_comp ++
2266+
[unDefUnitId d | DefiniteUnitId d <- new_deps]
2267+
}
2268+
}
22342269
| Just planpkg <- Map.lookup cid cmap
22352270
= return planpkg
22362271
| otherwise = error ("indefiniteComponent: " ++ display cid)

cabal-install/Distribution/Client/ProjectPlanning/Types.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,12 @@ data ElaboratedComponent
648648
-- | The paths all our executable dependencies will be installed
649649
-- to once they are installed.
650650
compExeDependencyPaths :: [(ConfiguredId, FilePath)],
651+
-- | The UnitIds of the librarys (identifying elaborated packages/
652+
-- components) which must be built before this project. This
653+
-- is used purely for ordering purposes. It can contain both
654+
-- references to definite and indefinite packages; an indefinite
655+
-- UnitId indicates that we must typecheck that indefinite package
656+
-- before we can build this one.
651657
compOrderLibDependencies :: [UnitId]
652658
}
653659
deriving (Eq, Show, Generic)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Q
2+
main = print out
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cabal-version: 2.0
2+
name: bkpcabal01
3+
version: 0.1.0.0
4+
description: This test also exists in GHC's test-suite under the same name
5+
and was ported over to cabal's testsuite as it exposed a
6+
regression (see #5929)
7+
license: BSD3
8+
author: Edward Z. Yang
9+
maintainer: [email protected]
10+
build-type: Simple
11+
12+
library impl
13+
exposed-modules: H, I
14+
build-depends: base
15+
hs-source-dirs: impl
16+
default-language: Haskell2010
17+
18+
library p
19+
exposed-modules: P
20+
signatures: H
21+
hs-source-dirs: p
22+
build-depends: base
23+
default-language: Haskell2010
24+
25+
library q
26+
exposed-modules: Q
27+
signatures: I
28+
hs-source-dirs: q
29+
build-depends: p, impl, base
30+
mixins: impl (H)
31+
default-language: Haskell2010
32+
33+
executable exe
34+
main-is: Main.hs
35+
build-depends: base, q, impl
36+
default-language: Haskell2010
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# cabal v2-build
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- bkpcabal01-0.1.0.0 (lib:impl) (first run)
6+
- bkpcabal01-0.1.0.0 (lib:p) (first run)
7+
- bkpcabal01-0.1.0.0 (lib:p with H=bkpcabal01-0.1.0.0-inplace-impl:H) (first run)
8+
- bkpcabal01-0.1.0.0 (lib:q) (first run)
9+
- bkpcabal01-0.1.0.0 (lib:q with I=bkpcabal01-0.1.0.0-inplace-impl:I) (first run)
10+
- bkpcabal01-0.1.0.0 (exe:exe) (first run)
11+
Configuring library 'impl' for bkpcabal01-0.1.0.0..
12+
Preprocessing library 'impl' for bkpcabal01-0.1.0.0..
13+
Building library 'impl' for bkpcabal01-0.1.0.0..
14+
Configuring library 'p' for bkpcabal01-0.1.0.0..
15+
Preprocessing library 'p' for bkpcabal01-0.1.0.0..
16+
Building library 'p' instantiated with H = <H>
17+
for bkpcabal01-0.1.0.0..
18+
Configuring library 'p' instantiated with H = bkpcabal01-0.1.0.0-inplace-impl:H
19+
for bkpcabal01-0.1.0.0..
20+
Preprocessing library 'p' for bkpcabal01-0.1.0.0..
21+
Building library 'p' instantiated with H = bkpcabal01-0.1.0.0-inplace-impl:H
22+
for bkpcabal01-0.1.0.0..
23+
Configuring library 'q' for bkpcabal01-0.1.0.0..
24+
Preprocessing library 'q' for bkpcabal01-0.1.0.0..
25+
Building library 'q' instantiated with I = <I>
26+
for bkpcabal01-0.1.0.0..
27+
Configuring library 'q' instantiated with I = bkpcabal01-0.1.0.0-inplace-impl:I
28+
for bkpcabal01-0.1.0.0..
29+
Preprocessing library 'q' for bkpcabal01-0.1.0.0..
30+
Building library 'q' instantiated with I = bkpcabal01-0.1.0.0-inplace-impl:I
31+
for bkpcabal01-0.1.0.0..
32+
Configuring executable 'exe' for bkpcabal01-0.1.0.0..
33+
Preprocessing executable 'exe' for bkpcabal01-0.1.0.0..
34+
Building executable 'exe' for bkpcabal01-0.1.0.0..
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Test.Cabal.Prelude
2+
main = cabalTest $ do
3+
-- GHC 8.2.2 had a regression ("unknown package: hole"), see also #4908
4+
skipUnless =<< ghcVersionIs (\v -> v >= mkVersion [8,2] && v /= mkVersion [8,2,2])
5+
cabal "v2-build" ["all"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module H where
2+
x = True
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module I where
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
signature H where
2+
x :: Bool
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{-# LANGUAGE CPP #-}
2+
module P where
3+
import H
4+
y = x
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
signature I where
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Q where
2+
import P
3+
out = y

0 commit comments

Comments
 (0)