diff --git a/Cabal/Cabal.cabal b/Cabal/Cabal.cabal
index 54d5d874f763d88a8b68cf6cc889835e0da516f2..548017796f0afe8b7d8cee6003f6605d061241ad 100644
--- a/Cabal/Cabal.cabal
+++ b/Cabal/Cabal.cabal
@@ -84,6 +84,8 @@ extra-source-files:
tests/ParserTests/regressions/encoding-0.8.cabal
tests/ParserTests/regressions/encoding-0.8.expr
tests/ParserTests/regressions/encoding-0.8.format
+ tests/ParserTests/regressions/extensions-paths-5054.cabal
+ tests/ParserTests/regressions/extensions-paths-5054.check
tests/ParserTests/regressions/generics-sop.cabal
tests/ParserTests/regressions/generics-sop.expr
tests/ParserTests/regressions/generics-sop.format
diff --git a/Cabal/Distribution/PackageDescription/Check.hs b/Cabal/Distribution/PackageDescription/Check.hs
index ee9fd817ca76bb044e00579d4bff9dcdeb91567b..1a5964d50e9ba29b8dbb823addfc3ab191c681ef 100644
--- a/Cabal/Distribution/PackageDescription/Check.hs
+++ b/Cabal/Distribution/PackageDescription/Check.hs
@@ -150,6 +150,7 @@ checkPackage gpkg mpkg =
++ checkFlagNames gpkg
++ checkUnusedFlags gpkg
++ checkUnicodeXFields gpkg
+ ++ checkPathsModuleExtensions pkg
where
pkg = fromMaybe (flattenPackageDescription gpkg) mpkg
@@ -1657,6 +1658,36 @@ checkUnicodeXFields gpd
, toDListOf (L.buildInfos . L.customFieldsBI . traverse) gpd
]
+-- | cabal-version <2.2 + Paths_module + default-extensions: doesn't build.
+checkPathsModuleExtensions :: PackageDescription -> [PackageCheck]
+checkPathsModuleExtensions pd
+ | specVersion pd >= mkVersion [2,1] = []
+ | any checkBI (allBuildInfo pd) || any checkLib (allLibraries pd)
+ = return $ PackageBuildImpossible $ unwords
+ [ "The package uses RebindableSyntax with OverloadedStrings or OverloadedLists"
+ , "in default-extensions, and also Paths_ autogen module."
+ , "That configuration is known to cause compile failures with Cabal < 2.2."
+ , "To use these default-extensions with Paths_ autogen module"
+ , "specify at least 'cabal-version: 2.2'."
+ ]
+ | otherwise = []
+ where
+ mn = autogenPathsModuleName pd
+
+ checkLib :: Library -> Bool
+ checkLib l = mn `elem` exposedModules l && checkExts (l ^. L.defaultExtensions)
+
+ checkBI :: BuildInfo -> Bool
+ checkBI bi =
+ (mn `elem` otherModules bi || mn `elem` autogenModules bi) &&
+ checkExts (bi ^. L.defaultExtensions)
+
+ checkExts exts = rebind `elem` exts && (strings `elem` exts || lists `elem` exts)
+ where
+ rebind = EnableExtension RebindableSyntax
+ strings = EnableExtension OverloadedStrings
+ lists = EnableExtension OverloadedLists
+
checkDevelopmentOnlyFlagsBuildInfo :: BuildInfo -> [PackageCheck]
checkDevelopmentOnlyFlagsBuildInfo bi =
catMaybes [
diff --git a/Cabal/Distribution/Simple/Build/PathsModule.hs b/Cabal/Distribution/Simple/Build/PathsModule.hs
index da2cbce9e930f29ce4a7134dbbfcdb8188acdd60..e239973e4a2fbe12ac44d9d78b927b311fa2017d 100644
--- a/Cabal/Distribution/Simple/Build/PathsModule.hs
+++ b/Cabal/Distribution/Simple/Build/PathsModule.hs
@@ -41,7 +41,6 @@ generate :: PackageDescription -> LocalBuildInfo -> ComponentLocalBuildInfo -> S
generate pkg_descr lbi clbi =
let pragmas =
cpp_pragma
- ++ no_overloaded_strings_pragma
++ no_rebindable_syntax_pragma
++ ffi_pragmas
++ warning_pragmas
@@ -50,14 +49,10 @@ generate pkg_descr lbi clbi =
| supports_cpp = "{-# LANGUAGE CPP #-}\n"
| otherwise = ""
- -- -XOverloadedStrings is problematic because 'fromString' is not
- -- in scope, so disable it.
- no_overloaded_strings_pragma
- | supports_overloaded_strings = "{-# LANGUAGE NoOverloadedStrings #-}\n"
- | otherwise = ""
-
-- -XRebindableSyntax is problematic because when paired with
- -- -XOverloadedLists, 'fromListN' is not in scope, so disable it.
+ -- -XOverloadedLists, 'fromListN' is not in scope,
+ -- or -XOverloadedStrings 'fromString' is not in scope,
+ -- so we disable 'RebindableSyntax'.
no_rebindable_syntax_pragma
| supports_rebindable_syntax = "{-# LANGUAGE NoRebindableSyntax #-}\n"
| otherwise = ""
@@ -253,7 +248,6 @@ generate pkg_descr lbi clbi =
path_sep = show [pathSeparator]
supports_cpp = supports_language_pragma
- supports_overloaded_strings = supports_language_pragma
supports_rebindable_syntax= ghc_newer_than (mkVersion [7,0,1])
supports_language_pragma = ghc_newer_than (mkVersion [6,6,1])
diff --git a/Cabal/Distribution/Types/PackageDescription.hs b/Cabal/Distribution/Types/PackageDescription.hs
index 5550c090cf0d74e5ba4d825f9ce2bd4b2a806fb1..b9dd51735c6f54a23e0c7bdbdae3ca42d46e5dcd 100644
--- a/Cabal/Distribution/Types/PackageDescription.hs
+++ b/Cabal/Distribution/Types/PackageDescription.hs
@@ -364,27 +364,21 @@ withForeignLib pkg_descr f =
-- ---------------------------------------------------------------------------
-- The BuildInfo type
--- | The 'BuildInfo' for the library (if there is one and it's buildable), and
--- all buildable executables, test suites and benchmarks. Useful for gathering
--- dependencies.
+-- | All 'BuildInfo' in the 'PackageDescription':
+-- libraries, executables, test-suites and benchmarks.
+--
+-- Useful for implementing package checks.
allBuildInfo :: PackageDescription -> [BuildInfo]
allBuildInfo pkg_descr = [ bi | lib <- allLibraries pkg_descr
- , let bi = libBuildInfo lib
- , buildable bi ]
- ++ [ bi | flib <- foreignLibs pkg_descr
- , let bi = foreignLibBuildInfo flib
- , buildable bi ]
- ++ [ bi | exe <- executables pkg_descr
- , let bi = buildInfo exe
- , buildable bi ]
- ++ [ bi | tst <- testSuites pkg_descr
- , let bi = testBuildInfo tst
- , buildable bi ]
- ++ [ bi | tst <- benchmarks pkg_descr
- , let bi = benchmarkBuildInfo tst
- , buildable bi ]
- --FIXME: many of the places where this is used, we actually want to look at
- -- unbuildable bits too, probably need separate functions
+ , let bi = libBuildInfo lib ]
+ ++ [ bi | flib <- foreignLibs pkg_descr
+ , let bi = foreignLibBuildInfo flib ]
+ ++ [ bi | exe <- executables pkg_descr
+ , let bi = buildInfo exe ]
+ ++ [ bi | tst <- testSuites pkg_descr
+ , let bi = testBuildInfo tst ]
+ ++ [ bi | tst <- benchmarks pkg_descr
+ , let bi = benchmarkBuildInfo tst ]
-- | Return all of the 'BuildInfo's of enabled components, i.e., all of
-- the ones that would be built if you run @./Setup build@.
diff --git a/Cabal/changelog b/Cabal/changelog
index ec477ea51ee1487b6aa69965b95c73994753be81..7dcd28fd6665fe136587de8f16ece6ada439e78f 100644
--- a/Cabal/changelog
+++ b/Cabal/changelog
@@ -16,6 +16,8 @@
* Use better defaulting for `build-type`; rename `PackageDescription`'s
`buildType` field to `buildTypeRaw` and introduce new `buildType`
function (#4958)
+ * `D.T.PackageDescription.allBuildInfo` returns all build infos, not
+ only for buildable components (#5087)
* Removed `UnknownBuildType` constructor from `BuildType` (#5003).
* Added `HexFloatLiterals` to `KnownExtension`.
* Cabal will no longer try to build an empty set of `inputModules`
diff --git a/Cabal/tests/CheckTests.hs b/Cabal/tests/CheckTests.hs
index dcdd67710c8f1119b1f786b2d2a6c02ba0fab64c..12105a679124a0ca9e969ecd70198258cfb3fee9 100644
--- a/Cabal/tests/CheckTests.hs
+++ b/Cabal/tests/CheckTests.hs
@@ -29,6 +29,7 @@ checkTests = testGroup "regressions"
, checkTest "haddock-api-2.18.1-check.cabal"
, checkTest "issue-774.cabal"
, checkTest "MiniAgda.cabal"
+ , checkTest "extensions-paths-5054.cabal"
]
checkTest :: FilePath -> TestTree
diff --git a/Cabal/tests/ParserTests/regressions/extensions-paths-5054.cabal b/Cabal/tests/ParserTests/regressions/extensions-paths-5054.cabal
new file mode 100644
index 0000000000000000000000000000000000000000..d6cc4fea72b88fe6a2655f1d3752bf4d259af5c4
--- /dev/null
+++ b/Cabal/tests/ParserTests/regressions/extensions-paths-5054.cabal
@@ -0,0 +1,39 @@
+name: extensions-paths
+version: 5054
+category: Test
+maintainer: Oleg Grenrus
+license: BSD3
+license-file: LICENSe
+synopsis: Paths_pkg module + "bad" extensions + old cabal
+description:
+ Only cabal-version: 2.2 or later will build Paths_pkg ok with
+
+ * RebindableSyntax and
+
+ * OverloadedLists or OverloadedStrings
+
+ `fromList` or `fromString` will be out-of-scope when compiling Paths_ module.
+
+ Other extensions (like NoImplicitPrelude) were handled before
+build-type: Simple
+cabal-version: 1.12
+
+library
+ default-language: Haskell2010
+ exposed-modules: Issue Paths_extensions_paths
+ default-extensions:
+ RebindableSyntax
+ OverloadedStrings
+
+test-suite tests
+ default-language: Haskell2010
+ main-is: Test.hs
+ type: exitcode-stdio-1.0
+ if os(linux)
+ other-modules: Paths_extensions_paths
+ else
+ buildable: False
+
+ default-extensions:
+ OverloadedLists
+ RebindableSyntax
diff --git a/Cabal/tests/ParserTests/regressions/extensions-paths-5054.check b/Cabal/tests/ParserTests/regressions/extensions-paths-5054.check
new file mode 100644
index 0000000000000000000000000000000000000000..6268308c77df8ece6f6f1e54ee3e19fd72ca5639
--- /dev/null
+++ b/Cabal/tests/ParserTests/regressions/extensions-paths-5054.check
@@ -0,0 +1 @@
+The package uses RebindableSyntax with OverloadedStrings or OverloadedLists in default-extensions, and also Paths_ autogen module. That configuration is known to cause compile failures with Cabal < 2.2. To use these default-extensions with Paths_ autogen module specify at least 'cabal-version: 2.2'.
diff --git a/Makefile b/Makefile
index 4c338c935dfe490d58cc7d20b4c6da71f0380277..4fd5f8ba83054fc25701aaff4452ed2df5bdf2c1 100644
--- a/Makefile
+++ b/Makefile
@@ -35,5 +35,6 @@ gen-extra-source-files:
cabal new-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-extra-source-files -- cabal-install/cabal-install.cabal
cabal-install-test:
- cabal new-build cabal cabal-tests
- cd cabal-testsuite && `cabal-plan list-bin cabal-tests` --with-cabal=`cabal-plan list-bin cabal` --hide-successes -j3
+ cabal new-build -j3 all --disable-tests --disable-benchmarks
+ rm -rf .ghc.environment.*
+ cd cabal-testsuite && `cabal-plan list-bin cabal-tests` --with-cabal=`cabal-plan list-bin cabal` --hide-successes -j3 ${TEST}
diff --git a/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal b/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal
index 44205af3f5933aad5caa2ff0be50f729281b0b19..4eb489be6d085a009b5e38268d532c823ec6a354 100644
--- a/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal
+++ b/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal
@@ -1,11 +1,11 @@
+Cabal-version: 2.1
name: PathsModule
version: 0.1
-license: BSD3
+license: BSD-3-Clause
author: Johan Tibell
stability: stable
category: PackageTests
build-type: Simple
-Cabal-version: >= 1.10
description:
Check that the generated paths module compiles.