Skip to content

Commit

Permalink
Guard PackageInfo behind cabal-version ≥ 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
ffaf1 committed Dec 15, 2023
1 parent ca22e68 commit 68f2599
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 22 deletions.
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
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
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
@@ -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 68f2599

Please sign in to comment.