Skip to content

Commit 6750de6

Browse files
authored
Merge pull request #5076 from phadej/issue-5055
Make Cabal-2.2 behave like Cabal-2.0 related to #5055
2 parents c7a7436 + b0e697e commit 6750de6

File tree

10 files changed

+378
-0
lines changed

10 files changed

+378
-0
lines changed

Cabal/Cabal.cabal

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ extra-source-files:
4444
tests/ParserTests/errors/forward-compat2.errors
4545
tests/ParserTests/errors/forward-compat3.cabal
4646
tests/ParserTests/errors/forward-compat3.errors
47+
tests/ParserTests/errors/issue-5055-2.cabal
48+
tests/ParserTests/errors/issue-5055-2.errors
49+
tests/ParserTests/errors/issue-5055.cabal
50+
tests/ParserTests/errors/issue-5055.errors
4751
tests/ParserTests/errors/leading-comma.cabal
4852
tests/ParserTests/errors/leading-comma.errors
4953
tests/ParserTests/errors/range-ge-wild.cabal
@@ -82,6 +86,9 @@ extra-source-files:
8286
tests/ParserTests/regressions/generics-sop.expr
8387
tests/ParserTests/regressions/generics-sop.format
8488
tests/ParserTests/regressions/haddock-api-2.18.1-check.cabal
89+
tests/ParserTests/regressions/issue-5055.cabal
90+
tests/ParserTests/regressions/issue-5055.expr
91+
tests/ParserTests/regressions/issue-5055.format
8592
tests/ParserTests/regressions/issue-774.cabal
8693
tests/ParserTests/regressions/issue-774.expr
8794
tests/ParserTests/regressions/issue-774.format

Cabal/Distribution/PackageDescription/Parsec.hs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import Distribution.Text (display)
6161
import Distribution.Types.CondTree
6262
import Distribution.Types.Dependency (Dependency)
6363
import Distribution.Types.ForeignLib
64+
import Distribution.Types.ForeignLibType (knownForeignLibTypes)
6465
import Distribution.Types.GenericPackageDescription (emptyGenericPackageDescription)
6566
import Distribution.Types.PackageDescription (specVersion')
6667
import Distribution.Types.UnqualComponentName (UnqualComponentName, mkUnqualComponentName)
@@ -306,6 +307,16 @@ goSections specVer = traverse_ process
306307
commonStanzas <- use stateCommonStanzas
307308
name' <- parseUnqualComponentName pos args
308309
flib <- lift $ parseCondTree' (foreignLibFieldGrammar name') commonStanzas fields
310+
311+
let hasType ts = foreignLibType ts /= foreignLibType mempty
312+
unless (onAllBranches hasType flib) $ lift $ parseFailure pos $ concat
313+
[ "Foreign library " ++ show (display name')
314+
, " is missing required field \"type\" or the field "
315+
, "is not present in all conditional branches. The "
316+
, "available test types are: "
317+
, intercalate ", " (map display knownForeignLibTypes)
318+
]
319+
309320
-- TODO check duplicate name here?
310321
stateGpd . L.condForeignLibs %= snoc (name', flib)
311322

@@ -321,6 +332,16 @@ goSections specVer = traverse_ process
321332
name' <- parseUnqualComponentName pos args
322333
testStanza <- lift $ parseCondTree' testSuiteFieldGrammar commonStanzas fields
323334
testSuite <- lift $ traverse (validateTestSuite pos) testStanza
335+
336+
let hasType ts = testInterface ts /= testInterface mempty
337+
unless (onAllBranches hasType testSuite) $ lift $ parseFailure pos $ concat
338+
[ "Test suite " ++ show (display name')
339+
, " is missing required field \"type\" or the field "
340+
, "is not present in all conditional branches. The "
341+
, "available test types are: "
342+
, intercalate ", " (map display knownTestTypes)
343+
]
344+
324345
-- TODO check duplicate name here?
325346
stateGpd . L.condTestSuites %= snoc (name', testSuite)
326347

@@ -329,6 +350,16 @@ goSections specVer = traverse_ process
329350
name' <- parseUnqualComponentName pos args
330351
benchStanza <- lift $ parseCondTree' benchmarkFieldGrammar commonStanzas fields
331352
bench <- lift $ traverse (validateBenchmark pos) benchStanza
353+
354+
let hasType ts = benchmarkInterface ts /= benchmarkInterface mempty
355+
unless (onAllBranches hasType bench) $ lift $ parseFailure pos $ concat
356+
[ "Benchmark " ++ show (display name')
357+
, " is missing required field \"type\" or the field "
358+
, "is not present in all conditional branches. The "
359+
, "available benchmark types are: "
360+
, intercalate ", " (map display knownBenchmarkTypes)
361+
]
362+
332363
-- TODO check duplicate name here?
333364
stateGpd . L.condBenchmarks %= snoc (name', bench)
334365

@@ -599,6 +630,28 @@ mergeCommonStanza (CondNode bi _ bis) (CondNode x _ cs) =
599630
-- tree components are appended together.
600631
cs' = map (fmap fromBuildInfo) bis ++ cs
601632

633+
-------------------------------------------------------------------------------
634+
-- Branches
635+
-------------------------------------------------------------------------------
636+
637+
-- Check that a property holds on all branches of a condition tree
638+
onAllBranches :: forall v c a. Monoid a => (a -> Bool) -> CondTree v c a -> Bool
639+
onAllBranches p = go mempty
640+
where
641+
-- If the current level of the tree satisfies the property, then we are
642+
-- done. If not, then one of the conditional branches below the current node
643+
-- must satisfy it. Each node may have multiple immediate children; we only
644+
-- one need one to satisfy the property because the configure step uses
645+
-- 'mappend' to join together the results of flag resolution.
646+
go :: a -> CondTree v c a -> Bool
647+
go acc ct = let acc' = acc `mappend` condTreeData ct
648+
in p acc' || any (goBranch acc') (condTreeComponents ct)
649+
650+
-- Both the 'true' and the 'false' block must satisfy the property.
651+
goBranch :: a -> CondBranch v c a -> Bool
652+
goBranch _ (CondBranch _ _ Nothing) = False
653+
goBranch acc (CondBranch _ t (Just e)) = go acc t && go acc e
654+
602655
-------------------------------------------------------------------------------
603656
-- Old syntax
604657
-------------------------------------------------------------------------------

Cabal/tests/ParserTests.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ errorTests = testGroup "errors"
9999
, errorTest "forward-compat.cabal"
100100
, errorTest "forward-compat2.cabal"
101101
, errorTest "forward-compat3.cabal"
102+
, errorTest "issue-5055.cabal"
103+
, errorTest "issue-5055-2.cabal"
102104
]
103105

104106
errorTest :: FilePath -> TestTree
@@ -136,6 +138,7 @@ regressionTests = testGroup "regressions"
136138
, regressionTest "leading-comma.cabal"
137139
, regressionTest "wl-pprint-indef.cabal"
138140
, regressionTest "th-lift-instances.cabal"
141+
, regressionTest "issue-5055.cabal"
139142
]
140143

141144
regressionTest :: FilePath -> TestTree
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: issue
2+
version: 5055
3+
synopsis: no type in all branches
4+
description: no type in all branches.
5+
license: BSD3
6+
category: Test
7+
build-type: Simple
8+
cabal-version: >=2.0
9+
10+
executable flag-test-exe
11+
main-is: FirstMain.hs
12+
build-depends: base >= 4.8 && < 5
13+
default-language: Haskell2010
14+
15+
test-suite flag-cabal-test
16+
-- TODO: fix so `type` can be on the top level
17+
build-depends: base >= 4.8 && < 5
18+
default-language: Haskell2010
19+
20+
if os(windows)
21+
main-is: FirstMain.hs
22+
type: exitcode-stdio-1.0
23+
else:
24+
main-is: SecondMain.hs
25+
type: exitcode-stdio-1.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VERSION: Just (mkVersion [2,0])
2+
issue-5055-2.cabal:15:1: Test suite "flag-cabal-test" is missing required field "type" or the field is not present in all conditional branches. The available test types are: exitcode-stdio-1.0, detailed-0.9
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: issue
2+
version: 5055
3+
synopsis: no type in all branches
4+
description: no type in all branches.
5+
license: BSD3
6+
category: Test
7+
build-type: Simple
8+
cabal-version: >=2.0
9+
10+
executable flag-test-exe
11+
main-is: FirstMain.hs
12+
build-depends: base >= 4.8 && < 5
13+
default-language: Haskell2010
14+
15+
test-suite flag-cabal-test
16+
build-depends: base >= 4.8 && < 5
17+
default-language: Haskell2010
18+
19+
if os(windows)
20+
main-is: FirstMain.hs
21+
type: exitcode-stdio-1.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VERSION: Just (mkVersion [2,0])
2+
issue-5055.cabal:15:1: Test suite "flag-cabal-test" is missing required field "type" or the field is not present in all conditional branches. The available test types are: exitcode-stdio-1.0, detailed-0.9
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: issue
2+
version: 5055
3+
synopsis: no type in all branches
4+
description: no type in all branches.
5+
license: BSD3
6+
category: Test
7+
build-type: Simple
8+
cabal-version: >=2.0
9+
10+
executable flag-test-exe
11+
main-is: FirstMain.hs
12+
build-depends: base >= 4.8 && < 5
13+
default-language: Haskell2010
14+
15+
test-suite flag-cabal-test
16+
-- TODO: fix so `type` can be on the top level
17+
build-depends: base >= 4.8 && < 5
18+
default-language: Haskell2010
19+
20+
main-is: SecondMain.hs
21+
type: exitcode-stdio-1.0
22+
23+
if os(windows)
24+
main-is: FirstMain.hs
25+
-- type: exitcode-stdio-1.0

0 commit comments

Comments
 (0)