From 90249c6f83bddbab64d0f698741fd55c91fb06a0 Mon Sep 17 00:00:00 2001 From: Mikolaj <281893+Mikolaj@users.noreply.github.com> Date: Thu, 21 Dec 2023 18:06:58 +0000 Subject: [PATCH] `check`: add PackageInfo warning (#9525) Add test for #9331 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guard Paths_* behind `cabal-version: 3.12` or higher, “fail” and “succeed” tests. * check: guard PackageInfo behind cabal-version ≥ 3.12 Note we do not actually check for ≥ 3.12, since it is not possible to introduce constructors in point release. Instead the check always fires with PackageInfo_* is present, and suggests an upgrade path. * Fix testsuite * Add changelog --- .../src/Distribution/PackageDescription/Check.hs | 9 +++++++++ .../AutogenModules/Package/setup.cabal.out | 1 + .../AutogenModules/Package/setup.out | 1 + .../AutogenModules/SrcDist/setup.cabal.out | 3 +++ .../AutogenModules/SrcDist/setup.out | 3 +++ .../AutogenModules/SrcDist/setup.test.hs | 1 - .../CabalVersion/AutoGenMods/cabal.out | 1 + .../Sanity/AutogenVersion/cabal.out | 4 ++++ .../Sanity/AutogenVersion/cabal.test.hs | 6 ++++++ .../Sanity/AutogenVersion/pkg.cabal | 16 ++++++++++++++++ .../Check/NonConfCheck/PathsExtensions/cabal.out | 2 ++ changelog.d/pr-9525 | 10 ++++++++++ 12 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/cabal.out create mode 100644 cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/pkg.cabal create mode 100644 changelog.d/pr-9525 diff --git a/Cabal/src/Distribution/PackageDescription/Check.hs b/Cabal/src/Distribution/PackageDescription/Check.hs index 63ea09736f4..f07748f0db8 100644 --- a/Cabal/src/Distribution/PackageDescription/Check.hs +++ b/Cabal/src/Distribution/PackageDescription/Check.hs @@ -224,6 +224,7 @@ data CheckExplanation = | CVExpliticDepsCustomSetup | CVAutogenPaths | CVAutogenPackageInfo + | CVAutogenPackageInfoGuard | GlobNoMatch String String | GlobExactMatch String String FilePath | GlobNoDir String String FilePath @@ -664,6 +665,11 @@ 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. This is not possible in `cabal " + ++ "3.10`. To use this feature and be able to upload your package to " + ++ "Hackage, download `cabal 3.12`!" ppExplanation (GlobNoMatch field glob) = "In '" ++ field ++ "': the pattern '" ++ glob ++ "' does not" ++ " match any files." @@ -1814,6 +1820,9 @@ checkCabalVersion pkg = && not (elem (autogenPackageInfoModuleName pkg) allModuleNamesAutogen) ) $ PackageDistInexcusable CVAutogenPackageInfo + , check + (elem (autogenPackageInfoModuleName pkg) allModuleNames) + (PackageDistInexcusable CVAutogenPackageInfoGuard) ] where -- Perform a check on packages that use a version of the spec less than diff --git a/cabal-testsuite/PackageTests/AutogenModules/Package/setup.cabal.out b/cabal-testsuite/PackageTests/AutogenModules/Package/setup.cabal.out index a650205c593..07433c25abb 100644 --- a/cabal-testsuite/PackageTests/AutogenModules/Package/setup.cabal.out +++ b/cabal-testsuite/PackageTests/AutogenModules/Package/setup.cabal.out @@ -15,6 +15,7 @@ On test suite 'Test' an 'autogen-module' is not on 'other-modules' On benchmark 'Bench' an 'autogen-module' is not on 'other-modules' Packages using 'cabal-version: 2.0' and the autogenerated module Paths_* must include it also on the 'autogen-modules' field besides 'exposed-modules' and 'other-modules'. This specifies that 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. Packages using 'cabal-version: 2.0' and the autogenerated module PackageInfo_* must include it in 'autogen-modules' as well as 'exposed-modules' and 'other-modules'. This specifies that 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. +To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher. This is not possible in `cabal 3.10`. To use this feature and be able to upload your package to Hackage, download `cabal 3.12`! The filename './my.cabal' does not match package name (expected: 'AutogenModules.cabal') Note: the public hackage server would reject this package. Building source dist for AutogenModules-0.1... diff --git a/cabal-testsuite/PackageTests/AutogenModules/Package/setup.out b/cabal-testsuite/PackageTests/AutogenModules/Package/setup.out index c6203a64130..1c31921678a 100644 --- a/cabal-testsuite/PackageTests/AutogenModules/Package/setup.out +++ b/cabal-testsuite/PackageTests/AutogenModules/Package/setup.out @@ -15,6 +15,7 @@ On test suite 'Test' an 'autogen-module' is not on 'other-modules' On benchmark 'Bench' an 'autogen-module' is not on 'other-modules' Packages using 'cabal-version: 2.0' and the autogenerated module Paths_* must include it also on the 'autogen-modules' field besides 'exposed-modules' and 'other-modules'. This specifies that 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. Packages using 'cabal-version: 2.0' and the autogenerated module PackageInfo_* must include it in 'autogen-modules' as well as 'exposed-modules' and 'other-modules'. This specifies that 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. +To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher. This is not possible in `cabal 3.10`. To use this feature and be able to upload your package to Hackage, download `cabal 3.12`! The filename './my.cabal' does not match package name (expected: 'AutogenModules.cabal') Note: the public hackage server would reject this package. Building source dist for AutogenModules-0.1... diff --git a/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.cabal.out b/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.cabal.out index 774f230f1b9..96f54d60e07 100644 --- a/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.cabal.out +++ b/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.cabal.out @@ -1,6 +1,9 @@ # Setup configure Configuring AutogenModules-0.1... # Setup sdist +Distribution quality errors: +To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher. This is not possible in `cabal 3.10`. To use this feature and be able to upload your package to Hackage, download `cabal 3.12`! +Note: the public hackage server would reject this package. Building source dist for AutogenModules-0.1... Source tarball created: setup.cabal.dist/work/dist/AutogenModules-0.1.tar.gz # Setup sdist diff --git a/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.out b/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.out index 30f213c7cb1..661c24594f9 100644 --- a/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.out +++ b/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.out @@ -1,6 +1,9 @@ # Setup configure Configuring AutogenModules-0.1... # Setup sdist +Distribution quality errors: +To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher. This is not possible in `cabal 3.10`. To use this feature and be able to upload your package to Hackage, download `cabal 3.12`! +Note: the public hackage server would reject this package. Building source dist for AutogenModules-0.1... Source tarball created: setup.dist/work/dist/AutogenModules-0.1.tar.gz # Setup sdist diff --git a/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.test.hs b/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.test.hs index 84d702c57d2..64bf2f84446 100644 --- a/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.test.hs +++ b/cabal-testsuite/PackageTests/AutogenModules/SrcDist/setup.test.hs @@ -61,7 +61,6 @@ main = setupAndCabalTest $ do assertOutputDoesNotContain pathsAutogenMsg configureResult -- Asserts for the undesired check messages after sdist. - assertOutputDoesNotContain "Distribution quality errors:" sdistResult assertOutputDoesNotContain libAutogenMsg sdistResult assertOutputDoesNotContain exeAutogenMsg sdistResult assertOutputDoesNotContain testAutogenMsg sdistResult diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/cabal.out b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/cabal.out index 6ed067c93ac..a98c76501b3 100644 --- a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/cabal.out +++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/CabalVersion/AutoGenMods/cabal.out @@ -2,4 +2,5 @@ Warning: The following errors will cause portability problems on other environments: Warning: Packages using 'cabal-version: 2.0' and the autogenerated module Paths_* must include it also on the 'autogen-modules' field besides 'exposed-modules' and 'other-modules'. This specifies that 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. Warning: Packages using 'cabal-version: 2.0' and the autogenerated module PackageInfo_* must include it in 'autogen-modules' as well as 'exposed-modules' and 'other-modules'. This specifies that 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. +Warning: To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher. This is not possible in `cabal 3.10`. To use this feature and be able to upload your package to Hackage, download `cabal 3.12`! Warning: Hackage would reject this package. diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/cabal.out b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/cabal.out new file mode 100644 index 00000000000..3717e18e0f7 --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/cabal.out @@ -0,0 +1,4 @@ +# cabal check +Warning: The following errors will cause portability problems on other environments: +Warning: To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher. This is not possible in `cabal 3.10`. To use this feature and be able to upload your package to Hackage, download `cabal 3.12`! +Warning: Hackage would reject this package. diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/cabal.test.hs b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/cabal.test.hs new file mode 100644 index 00000000000..c9c2e56de21 --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/cabal.test.hs @@ -0,0 +1,6 @@ +import Test.Cabal.Prelude + +-- #9331: PackageInfo functionality should be guarded by cabal-version. +main = cabalTest $ + fails $ cabal "check" [] + diff --git a/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/pkg.cabal b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/pkg.cabal new file mode 100644 index 00000000000..aeef460f7f0 --- /dev/null +++ b/cabal-testsuite/PackageTests/Check/ConfiguredPackage/Sanity/AutogenVersion/pkg.cabal @@ -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 + diff --git a/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/cabal.out b/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/cabal.out index d21149b6c45..4dab53146a7 100644 --- a/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/cabal.out +++ b/cabal-testsuite/PackageTests/Check/NonConfCheck/PathsExtensions/cabal.out @@ -2,4 +2,6 @@ Warning: The package will not build sanely due to these errors: Warning: 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'. Warning: 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'. +Warning: The following errors will cause portability problems on other environments: +Warning: To use the autogenerated module PackageInfo_* you need to specify `cabal-version: 3.12` or higher. This is not possible in `cabal 3.10`. To use this feature and be able to upload your package to Hackage, download `cabal 3.12`! Warning: Hackage would reject this package. diff --git a/changelog.d/pr-9525 b/changelog.d/pr-9525 new file mode 100644 index 00000000000..2500db3e023 --- /dev/null +++ b/changelog.d/pr-9525 @@ -0,0 +1,10 @@ +synopsis: `check`: add PackageInfo warning +packages: cabal-install +prs: #9525 +issues: #9331 + +description: { + +`cabal check` will warn about PackageInfo_* modules and provide an upgrade path to 3.12. + +}