Skip to content

Commit f3eafa7

Browse files
ffaf1mergify[bot]
andauthored
Guard PackageInfo behind cabal-version ≥ 3.12 (#9481)
* Add `cabal-version` 3.12 * Add test for #9331 - `cabal check`: Guard Paths_* behind `cabal-version: 3.12` or higher, “fail” and “succeed” tests. - `cabal build`: Guard Paths_* behind `cabal-version: 3.12` or higher, “fail” test. * Guard PackageInfo behind cabal-version ≥ 3.12 --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent e3fd74c commit f3eafa7

File tree

30 files changed

+149
-28
lines changed

30 files changed

+149
-28
lines changed

Cabal-syntax/src/Distribution/CabalSpecVersion.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ data CabalSpecVersion
3232
CabalSpecV3_4
3333
| CabalSpecV3_6
3434
| CabalSpecV3_8
35-
-- 3.10: no changes
35+
| -- 3.10: no changes
36+
CabalSpecV3_12
3637
deriving (Eq, Ord, Show, Read, Enum, Bounded, Typeable, Data, Generic)
3738

3839
instance Binary CabalSpecVersion
@@ -43,6 +44,7 @@ instance NFData CabalSpecVersion where rnf = genericRnf
4344
--
4445
-- @since 3.0.0.0
4546
showCabalSpecVersion :: CabalSpecVersion -> String
47+
showCabalSpecVersion CabalSpecV3_12 = "3.12"
4648
showCabalSpecVersion CabalSpecV3_8 = "3.8"
4749
showCabalSpecVersion CabalSpecV3_6 = "3.6"
4850
showCabalSpecVersion CabalSpecV3_4 = "3.4"
@@ -63,13 +65,14 @@ showCabalSpecVersion CabalSpecV1_2 = "1.2"
6365
showCabalSpecVersion CabalSpecV1_0 = "1.0"
6466

6567
cabalSpecLatest :: CabalSpecVersion
66-
cabalSpecLatest = CabalSpecV3_8
68+
cabalSpecLatest = CabalSpecV3_12
6769

6870
-- | Parse 'CabalSpecVersion' from version digits.
6971
--
7072
-- It may fail if for recent versions the version is not exact.
7173
cabalSpecFromVersionDigits :: [Int] -> Maybe CabalSpecVersion
7274
cabalSpecFromVersionDigits v
75+
| v == [3, 12] = Just CabalSpecV3_12
7376
| v == [3, 8] = Just CabalSpecV3_8
7477
| v == [3, 6] = Just CabalSpecV3_6
7578
| v == [3, 4] = Just CabalSpecV3_4
@@ -92,6 +95,7 @@ cabalSpecFromVersionDigits v
9295

9396
-- | @since 3.4.0.0
9497
cabalSpecToVersionDigits :: CabalSpecVersion -> [Int]
98+
cabalSpecToVersionDigits CabalSpecV3_12 = [3, 12]
9599
cabalSpecToVersionDigits CabalSpecV3_8 = [3, 8]
96100
cabalSpecToVersionDigits CabalSpecV3_6 = [3, 6]
97101
cabalSpecToVersionDigits CabalSpecV3_4 = [3, 4]

Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ md5Check proxy md5Int = structureHash proxy @?= md5FromInteger md5Int
3333
md5CheckGenericPackageDescription :: Proxy GenericPackageDescription -> Assertion
3434
md5CheckGenericPackageDescription proxy = md5Check proxy
3535
#if MIN_VERSION_base(4,19,0)
36-
0x87037bc65fba873f53c03ce572a42229
36+
0xc638caeb7531f107f64d12773f9430d0
3737
#else
38-
0x5817c798e23df281d794ad27754ad43f
38+
0x7a231bff7bb37049ec7f2ebfd98d3243
3939
#endif
4040

4141
md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion
4242
md5CheckLocalBuildInfo proxy = md5Check proxy
4343
#if MIN_VERSION_base(4,19,0)
44-
0x83cb87bceb4c1634e7dda192c3ad6579
44+
0x23942cff98237dc167ef90d64d7ef893
4545
#else
46-
0x4beeb42e94807be904bc5d15355c98cd
46+
0xa4e9f8a7e1583906880d6ec2d1bbb14b
4747
#endif

Cabal/src/Distribution/PackageDescription/Check/Target.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,15 +652,25 @@ checkAutogenModules ams bi = do
652652
-- Paths_* module + some default extension build failure.
653653
autogenCheck autoInfoModuleName CVAutogenPackageInfo
654654
rebindableClashCheck autoInfoModuleName RebindableClashPackageInfo
655+
656+
-- PackageInfo_* module + cabal-version < 3.12
657+
-- See Mikolaj’s comments on #9481 on why this has to be
658+
-- PackageBuildImpossible and not merely PackageDistInexcusable.
659+
checkSpecVer
660+
CabalSpecV3_12
661+
(elem autoInfoModuleName allModsForAuto)
662+
(PackageBuildImpossible CVAutogenPackageInfoGuard)
655663
where
664+
allModsForAuto :: [ModuleName]
665+
allModsForAuto = ams ++ otherModules bi
666+
656667
autogenCheck
657668
:: Monad m
658669
=> ModuleName
659670
-> CheckExplanation
660671
-> CheckM m ()
661672
autogenCheck name warning = do
662673
sv <- asksCM ccSpecVersion
663-
let allModsForAuto = ams ++ otherModules bi
664674
checkP
665675
( sv >= CabalSpecV2_0
666676
&& elem name allModsForAuto

Cabal/src/Distribution/PackageDescription/Check/Warning.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ data CheckExplanation
211211
| CVExpliticDepsCustomSetup
212212
| CVAutogenPaths
213213
| CVAutogenPackageInfo
214+
| CVAutogenPackageInfoGuard
214215
| GlobNoMatch String String
215216
| GlobExactMatch String String FilePath
216217
| GlobNoDir String String FilePath
@@ -778,6 +779,9 @@ ppExplanation CVAutogenPackageInfo =
778779
++ "the module does not come with the package and is generated on "
779780
++ "setup. Modules built with a custom Setup.hs script also go here "
780781
++ "to ensure that commands like sdist don't fail."
782+
ppExplanation CVAutogenPackageInfoGuard =
783+
"To use the autogenerated module PackageInfo_* you need to specify "
784+
++ "`cabal-version: 3.12` or higher."
781785
ppExplanation (GlobNoMatch field glob) =
782786
"In '"
783787
++ field

cabal-install/src/Distribution/Client/Init/Interactive/Command.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ cabalVersionPrompt flags = getCabalVersion flags $ do
312312
parseCabalVersion "2.4" = CabalSpecV2_4
313313
parseCabalVersion "3.0" = CabalSpecV3_0
314314
parseCabalVersion "3.4" = CabalSpecV3_4
315+
parseCabalVersion "3.12" = CabalSpecV3_12
315316
parseCabalVersion _ = defaultCabalVersion -- 2.4
316317
displayCabalVersion :: CabalSpecVersion -> String
317318
displayCabalVersion v = case v of

cabal-testsuite/PackageTests/AutogenModules/Package/my.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
cabal-version: 3.12
12
name: AutogenModules
23
version: 0.1
3-
license: BSD3
4+
license: BSD-3-Clause
45
license-file: LICENSE
56
author: Federico Mastellone
67
maintainer: Federico Mastellone
78
synopsis: AutogenModules
89
category: PackageTests
910
build-type: Simple
10-
cabal-version: 2.0
1111

1212
description:
1313
Check that Cabal recognizes the autogen-modules fields below.

cabal-testsuite/PackageTests/AutogenModules/SrcDist/AutogenModules.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
cabal-version: 3.12
12
name: AutogenModules
23
version: 0.1
3-
license: BSD3
4+
license: BSD-3-Clause
45
license-file: LICENSE
56
author: Federico Mastellone
67
maintainer: Federico Mastellone
78
synopsis: AutogenModules
89
category: PackageTests
910
build-type: Simple
10-
cabal-version: 2.0
1111

1212
description:
1313
Check that Cabal recognizes the autogen-modules fields below.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# cabal v2-build
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- pkg-0 (lib) (first run)
6+
Configuring library for pkg-0...
7+
Error: [Cabal-5559]
8+
To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher.
9+
Error: [Cabal-7125]
10+
Failed to build pkg-0-inplace. The failure occurred during the configure step.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages: .
2+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Test.Cabal.Prelude
2+
3+
-- #9331, guard PackageInfo functionality behind 3.12: make it a
4+
-- build failure.
5+
main = cabalTest $ do
6+
withProjectFile "cabal.project" $ do
7+
fails $ cabal "v2-build" ["pkg"]
8+

0 commit comments

Comments
 (0)