Skip to content

Commit

Permalink
Guard PackageInfo behind cabal-version ≥ 3.12 (#9481)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ffaf1 and mergify[bot] authored Dec 18, 2023
1 parent e3fd74c commit f3eafa7
Show file tree
Hide file tree
Showing 30 changed files with 149 additions and 28 deletions.
8 changes: 6 additions & 2 deletions Cabal-syntax/src/Distribution/CabalSpecVersion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ data CabalSpecVersion
CabalSpecV3_4
| CabalSpecV3_6
| CabalSpecV3_8
-- 3.10: no changes
| -- 3.10: no changes
CabalSpecV3_12
deriving (Eq, Ord, Show, Read, Enum, Bounded, Typeable, Data, Generic)

instance Binary CabalSpecVersion
Expand All @@ -43,6 +44,7 @@ instance NFData CabalSpecVersion where rnf = genericRnf
--
-- @since 3.0.0.0
showCabalSpecVersion :: CabalSpecVersion -> String
showCabalSpecVersion CabalSpecV3_12 = "3.12"
showCabalSpecVersion CabalSpecV3_8 = "3.8"
showCabalSpecVersion CabalSpecV3_6 = "3.6"
showCabalSpecVersion CabalSpecV3_4 = "3.4"
Expand All @@ -63,13 +65,14 @@ showCabalSpecVersion CabalSpecV1_2 = "1.2"
showCabalSpecVersion CabalSpecV1_0 = "1.0"

cabalSpecLatest :: CabalSpecVersion
cabalSpecLatest = CabalSpecV3_8
cabalSpecLatest = CabalSpecV3_12

-- | Parse 'CabalSpecVersion' from version digits.
--
-- It may fail if for recent versions the version is not exact.
cabalSpecFromVersionDigits :: [Int] -> Maybe CabalSpecVersion
cabalSpecFromVersionDigits v
| v == [3, 12] = Just CabalSpecV3_12
| v == [3, 8] = Just CabalSpecV3_8
| v == [3, 6] = Just CabalSpecV3_6
| v == [3, 4] = Just CabalSpecV3_4
Expand All @@ -92,6 +95,7 @@ cabalSpecFromVersionDigits v

-- | @since 3.4.0.0
cabalSpecToVersionDigits :: CabalSpecVersion -> [Int]
cabalSpecToVersionDigits CabalSpecV3_12 = [3, 12]
cabalSpecToVersionDigits CabalSpecV3_8 = [3, 8]
cabalSpecToVersionDigits CabalSpecV3_6 = [3, 6]
cabalSpecToVersionDigits CabalSpecV3_4 = [3, 4]
Expand Down
8 changes: 4 additions & 4 deletions Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ md5Check proxy md5Int = structureHash proxy @?= md5FromInteger md5Int
md5CheckGenericPackageDescription :: Proxy GenericPackageDescription -> Assertion
md5CheckGenericPackageDescription proxy = md5Check proxy
#if MIN_VERSION_base(4,19,0)
0x87037bc65fba873f53c03ce572a42229
0xc638caeb7531f107f64d12773f9430d0
#else
0x5817c798e23df281d794ad27754ad43f
0x7a231bff7bb37049ec7f2ebfd98d3243
#endif

md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion
md5CheckLocalBuildInfo proxy = md5Check proxy
#if MIN_VERSION_base(4,19,0)
0x83cb87bceb4c1634e7dda192c3ad6579
0x23942cff98237dc167ef90d64d7ef893
#else
0x4beeb42e94807be904bc5d15355c98cd
0xa4e9f8a7e1583906880d6ec2d1bbb14b
#endif
12 changes: 11 additions & 1 deletion Cabal/src/Distribution/PackageDescription/Check/Target.hs
Original file line number Diff line number Diff line change
Expand Up @@ -652,15 +652,25 @@ checkAutogenModules ams bi = do
-- Paths_* module + some default extension build failure.
autogenCheck autoInfoModuleName CVAutogenPackageInfo
rebindableClashCheck autoInfoModuleName RebindableClashPackageInfo

-- PackageInfo_* module + cabal-version < 3.12
-- See Mikolaj’s comments on #9481 on why this has to be
-- PackageBuildImpossible and not merely PackageDistInexcusable.
checkSpecVer
CabalSpecV3_12
(elem autoInfoModuleName allModsForAuto)
(PackageBuildImpossible CVAutogenPackageInfoGuard)
where
allModsForAuto :: [ModuleName]
allModsForAuto = ams ++ otherModules bi

autogenCheck
:: Monad m
=> ModuleName
-> CheckExplanation
-> CheckM m ()
autogenCheck name warning = do
sv <- asksCM ccSpecVersion
let allModsForAuto = ams ++ otherModules bi
checkP
( sv >= CabalSpecV2_0
&& elem name allModsForAuto
Expand Down
4 changes: 4 additions & 0 deletions Cabal/src/Distribution/PackageDescription/Check/Warning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ data CheckExplanation
| CVExpliticDepsCustomSetup
| CVAutogenPaths
| CVAutogenPackageInfo
| CVAutogenPackageInfoGuard
| GlobNoMatch String String
| GlobExactMatch String String FilePath
| GlobNoDir String String FilePath
Expand Down Expand Up @@ -778,6 +779,9 @@ ppExplanation CVAutogenPackageInfo =
++ "the module does not come with the package and is generated on "
++ "setup. Modules built with a custom Setup.hs script also go here "
++ "to ensure that commands like sdist don't fail."
ppExplanation CVAutogenPackageInfoGuard =
"To use the autogenerated module PackageInfo_* you need to specify "
++ "`cabal-version: 3.12` or higher."
ppExplanation (GlobNoMatch field glob) =
"In '"
++ field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ cabalVersionPrompt flags = getCabalVersion flags $ do
parseCabalVersion "2.4" = CabalSpecV2_4
parseCabalVersion "3.0" = CabalSpecV3_0
parseCabalVersion "3.4" = CabalSpecV3_4
parseCabalVersion "3.12" = CabalSpecV3_12
parseCabalVersion _ = defaultCabalVersion -- 2.4
displayCabalVersion :: CabalSpecVersion -> String
displayCabalVersion v = case v of
Expand Down
4 changes: 2 additions & 2 deletions cabal-testsuite/PackageTests/AutogenModules/Package/my.cabal
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cabal-version: 3.12
name: AutogenModules
version: 0.1
license: BSD3
license: BSD-3-Clause
license-file: LICENSE
author: Federico Mastellone
maintainer: Federico Mastellone
synopsis: AutogenModules
category: PackageTests
build-type: Simple
cabal-version: 2.0

description:
Check that Cabal recognizes the autogen-modules fields below.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cabal-version: 3.12
name: AutogenModules
version: 0.1
license: BSD3
license: BSD-3-Clause
license-file: LICENSE
author: Federico Mastellone
maintainer: Federico Mastellone
synopsis: AutogenModules
category: PackageTests
build-type: Simple
cabal-version: 2.0

description:
Check that Cabal recognizes the autogen-modules fields below.
Expand Down
10 changes: 10 additions & 0 deletions cabal-testsuite/PackageTests/BuildAutogenPackageGuard/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- pkg-0 (lib) (first run)
Configuring library for pkg-0...
Error: [Cabal-5559]
To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher.
Error: [Cabal-7125]
Failed to build pkg-0-inplace. The failure occurred during the configure step.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: .

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Test.Cabal.Prelude

-- #9331, guard PackageInfo functionality behind 3.12: make it a
-- build failure.
main = cabalTest $ do
withProjectFile "cabal.project" $ do
fails $ cabal "v2-build" ["pkg"]

17 changes: 17 additions & 0 deletions cabal-testsuite/PackageTests/BuildAutogenPackageGuard/pkg.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cabal-version: 2.4
name: pkg
version: 0
license: GPL-3.0-or-later
maintainer: Someone
category: Example
synopsis: Foo
description: FooBar
build-type: Simple

library
default-language: Haskell2010
build-depends: base == 4.*
-- ☞ N.B.: PackageInfo packages must contain the same name of
-- of the package! (In this example: `pkg`).
autogen-modules: PackageInfo_pkg
exposed-modules: PackageInfo_pkg
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
cabal-version: 2.0
cabal-version: 3.12
build-type: Simple
name: pkg
synopsis: synopsis
description: description
version: 0
category: example
maintainer: [email protected]
license: GPL-3
license: GPL-3.0-or-later
license-file: LICENSE

library
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# cabal check
The package will not build sanely due to these errors:
Error: To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher.
Error: Hackage would reject this package.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Test.Cabal.Prelude

-- #9331: PackageInfo functionality should be guarded by cabal-version.
main = cabalTest $
fails $ cabal "check" []

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cabal-version: 2.4
name: pkg
version: 0
license: GPL-3.0-or-later
maintainer: Someone
category: Example
synopsis: Foo
description: FooBar
build-type: Simple

library
default-language: Haskell2010
build-depends: base <5
autogen-modules: PackageInfo_pkg
exposed-modules: PackageInfo_pkg

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cabal check
No errors or warnings could be found in the package.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Test.Cabal.Prelude

-- #9331: PackageInfo functionality should be guarded by cabal-version,
-- does not error when cabal-version is 3.12 or higher.
main = cabalTest $
cabal "check" []

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cabal-version: 3.12
name: pkg
version: 0
license: GPL-3.0-or-later
maintainer: Someone
category: Example
synopsis: Foo
description: FooBar
build-type: Simple

library
default-language: Haskell2010
build-depends: base <5
autogen-modules: PackageInfo_pkg
exposed-modules: PackageInfo_pkg

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# cabal check
The package will not build sanely due to these errors:
Error: To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher.
Error: Packages using RebindableSyntax with OverloadedStrings or OverloadedLists in default-extensions, in conjunction with the autogenerated module Paths_*, are known to cause compile failures with Cabal < 2.2. To use these default-extensions with a Paths_* autogen module, specify at least 'cabal-version: 2.2'.
Error: Packages using RebindableSyntax with OverloadedStrings or OverloadedLists in default-extensions, in conjunction with the autogenerated module PackageInfo_*, are known to cause compile failures with Cabal < 2.2. To use these default-extensions with a PackageInfo_* autogen module, specify at least 'cabal-version: 2.2'.
Error: Hackage would reject this package.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cabal-version: 3.12
name: foo
version: 1.0
build-type: Simple
cabal-version: >= 1.10
data-dir: data
data-files: hello.txt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cabal-version: 3.12
name: setup-lib
version: 1.0
build-type: Simple
cabal-version: >= 1.10
data-files: example.txt

library
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Cabal-version: 3.12
name: PackageInfoModule
version: 0.1
license: BSD3
license: BSD-3-Clause
author: Gautier DI FOLCO
stability: stable
category: PackageTests
build-type: Simple
Cabal-version: >= 1.2

description:
Check that the generated package info module compiles.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Cabal-version: 3.12
name: PackageInfoModule
version: 0.1
license: BSD3
license: BSD-3-Clause
author: Gautier DI FOLCO
category: PackageTests
build-type: Simple
Cabal-version: >= 1.2

description:
Check that the generated package info module compiles.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cabal-version: 2.2
Cabal-version: 3.12
name: PackageInfoModule
version: 0.1
license: BSD-3-Clause
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Cabal-version: 3.12
name: PathsModule
version: 0.1
license: BSD3
license: BSD-3-Clause
author: Johan Tibell
stability: stable
category: PackageTests
build-type: Simple
Cabal-version: >= 1.2

description:
Check that the generated paths module compiles.
Expand Down
4 changes: 2 additions & 2 deletions cabal-testsuite/PackageTests/PathsModule/Executable/my.cabal
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Cabal-version: 3.12
name: PathsModule
version: 0.1
license: BSD3
license: BSD-3-Clause
author: Johan Tibell
stability: stable
category: PackageTests
build-type: Simple
Cabal-version: >= 1.2

description:
Check that the generated paths module compiles.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Cabal-version: 3.12
name: PathsModule
version: 0.1
license: BSD3
license: BSD-3-Clause
author: Martijn Bastiaan
category: PackageTests
build-type: Simple
Cabal-version: >= 1.2

description:
Check that the generated paths module compiles.
Expand Down
2 changes: 1 addition & 1 deletion cabal-testsuite/PackageTests/PathsModule/Library/my.cabal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cabal-version: 2.2
Cabal-version: 3.12
name: PathsModule
version: 0.1
license: BSD-3-Clause
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cabal-version: 2.2
cabal-version: 3.12
name: PathsModule
version: 0.1
license: BSD-3-Clause
Expand Down
13 changes: 13 additions & 0 deletions changelog.d/pr-9481
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
synopsis: Guard PackageInfo_* modules behind `cabal-version` ≥ 3.12
packages: Cabal cabal-install
prs: #9481
issues: #9331

description: {

`cabal check` now warns whenever PackageInfo_* autogen modules are
used with `cabal-version` ≥ 3.12.
Additionally, `cabal configure` will fail if you try to use PackageInfo_*
with `cabal-version` < 3.12.

}

0 comments on commit f3eafa7

Please sign in to comment.