Skip to content

Commit

Permalink
Add tests Paths_ autogen module + default.extensions
Browse files Browse the repository at this point in the history
Fixes #5086

The #5054 links to
commercialhaskell/stack#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.
  • Loading branch information
phadej committed Feb 2, 2018
1 parent b36cf3c commit 8fc1032
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions Cabal/Distribution/PackageDescription/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ checkPackage gpkg mpkg =
++ checkFlagNames gpkg
++ checkUnusedFlags gpkg
++ checkUnicodeXFields gpkg
++ checkPathsModuleExtensions pkg
where
pkg = fromMaybe (flattenPackageDescription gpkg) mpkg

Expand Down Expand Up @@ -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 [
Expand Down
32 changes: 13 additions & 19 deletions Cabal/Distribution/Types/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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@.
Expand Down
2 changes: 2 additions & 0 deletions Cabal/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 1 addition & 0 deletions Cabal/tests/CheckTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 39 additions & 0 deletions Cabal/tests/ParserTests/regressions/extensions-paths-5054.cabal
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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'.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
4 changes: 2 additions & 2 deletions cabal-testsuite/PackageTests/PathsModule/Library/my.cabal
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 8fc1032

Please sign in to comment.