From fe667777ab223306c78da4ca14371abf0e9a4cb0 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Wed, 31 Jan 2018 22:22:44 +0200 Subject: [PATCH 1/3] Add tests Paths_ autogen module + default.extensions Fixes #5086 The https://github.com/haskell/cabal/pull/5054 links to https://github.com/commercialhaskell/stack/issues/3789 which says - `Ensure you have OverloadedStrings and RebindableSyntax extensions enabled.` So we warn only in that case. Only `OverloadeStrings` (or `OverloadedLists`) or `RebindableSyntax` seems to be ok. Also make `allBuildInfos` return all (not only buildable) build infos, removing FIXME. `allBuildInfos` is used only in D.PD.Check. --- Cabal/Cabal.cabal | 2 + .../Distribution/PackageDescription/Check.hs | 31 +++++++++++++++ .../Distribution/Types/PackageDescription.hs | 32 +++++++-------- Cabal/changelog | 2 + Cabal/tests/CheckTests.hs | 1 + .../regressions/extensions-paths-5054.cabal | 39 +++++++++++++++++++ .../regressions/extensions-paths-5054.check | 1 + Makefile | 5 ++- .../internal-preprocessor-test.cabal | 4 ++ .../PackageTests/PathsModule/Library/my.cabal | 4 +- 10 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 Cabal/tests/ParserTests/regressions/extensions-paths-5054.cabal create mode 100644 Cabal/tests/ParserTests/regressions/extensions-paths-5054.check diff --git a/Cabal/Cabal.cabal b/Cabal/Cabal.cabal index 54d5d874f76..548017796f0 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 ee9fd817ca7..877204bd978 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,2] = [] + | 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/Types/PackageDescription.hs b/Cabal/Distribution/Types/PackageDescription.hs index 5550c090cf0..b9dd51735c6 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 ec477ea51ee..7dcd28fd666 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 dcdd67710c8..12105a67912 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 00000000000..d6cc4fea72b --- /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 00000000000..6268308c77d --- /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 4c338c935df..4fd5f8ba830 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/CustomPreProcess/internal-preprocessor-test.cabal b/cabal-testsuite/PackageTests/CustomPreProcess/internal-preprocessor-test.cabal index 26735e39fa5..50cb5c51ba2 100644 --- a/cabal-testsuite/PackageTests/CustomPreProcess/internal-preprocessor-test.cabal +++ b/cabal-testsuite/PackageTests/CustomPreProcess/internal-preprocessor-test.cabal @@ -9,6 +9,10 @@ category: Testing build-type: Custom cabal-version: >=1.10 +custom-setup + setup-depends: + Cabal, base, process, filepath + -- Note that exe comes before the library. -- The reason is backwards compat: old versions of Cabal (< 1.18) -- don't have a proper component build graph, so components are diff --git a/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal b/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal index 44205af3f59..5260d9cbd5c 100644 --- a/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal +++ b/cabal-testsuite/PackageTests/PathsModule/Library/my.cabal @@ -1,11 +1,11 @@ +Cabal-version: 2.2 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. From 33e65404b006abe252a3cc4edea0ca3e256b071b Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Thu, 1 Feb 2018 10:27:22 +0200 Subject: [PATCH 2/3] OverloadedStrings or OverloadedLists are ok without RebindableSyntax --- Cabal/Distribution/Simple/Build/PathsModule.hs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/Cabal/Distribution/Simple/Build/PathsModule.hs b/Cabal/Distribution/Simple/Build/PathsModule.hs index da2cbce9e93..e239973e4a2 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]) From 1f8e8b26ce7e43767cf4f7080861f382bf84443b Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Thu, 1 Feb 2018 20:15:56 +0200 Subject: [PATCH 3/3] Hard-code cabalVersion. Currently 2.2 --- Cabal/Cabal.cabal | 1 - Cabal/Distribution/Simple/Utils.hs | 22 +--------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/Cabal/Cabal.cabal b/Cabal/Cabal.cabal index 548017796f0..d1eeac23e6a 100644 --- a/Cabal/Cabal.cabal +++ b/Cabal/Cabal.cabal @@ -423,7 +423,6 @@ library Distribution.Simple.GHC.IPI642 Distribution.Simple.GHC.IPIConvert Distribution.Simple.GHC.ImplInfo - Paths_Cabal if flag(bundled-binary-generic) other-modules: diff --git a/Cabal/Distribution/Simple/Utils.hs b/Cabal/Distribution/Simple/Utils.hs index 64498b01514..efa82e07365 100644 --- a/Cabal/Distribution/Simple/Utils.hs +++ b/Cabal/Distribution/Simple/Utils.hs @@ -189,20 +189,6 @@ import Distribution.Compat.Stack import Distribution.Verbosity import Distribution.Types.PackageId -#if __GLASGOW_HASKELL__ < 711 -#ifdef VERSION_base -#define BOOTSTRAPPED_CABAL 1 -#endif -#else -#ifdef CURRENT_PACKAGE_KEY -#define BOOTSTRAPPED_CABAL 1 -#endif -#endif - -#ifdef BOOTSTRAPPED_CABAL -import qualified Paths_Cabal (version) -#endif - import Control.Concurrent.MVar ( newEmptyMVar, putMVar, takeMVar ) import Data.Typeable @@ -244,13 +230,7 @@ import qualified Text.PrettyPrint as Disp -- We only get our own version number when we're building with ourselves cabalVersion :: Version -#if defined(BOOTSTRAPPED_CABAL) -cabalVersion = mkVersion' Paths_Cabal.version -#elif defined(CABAL_VERSION) -cabalVersion = mkVersion [CABAL_VERSION] -#else -cabalVersion = mkVersion [1,9999] --used when bootstrapping -#endif +cabalVersion = mkVersion [2,2] -- ---------------------------------------------------------------------------- -- Exception and logging utils