Skip to content

Commit cc7c255

Browse files
committed
Add tests Paths_ autogen module + default.extensions
Fixes haskell#5086 The haskell#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.
1 parent ea862d6 commit cc7c255

File tree

6 files changed

+81
-16
lines changed

6 files changed

+81
-16
lines changed

Cabal/Cabal.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ extra-source-files:
8282
tests/ParserTests/regressions/encoding-0.8.cabal
8383
tests/ParserTests/regressions/encoding-0.8.expr
8484
tests/ParserTests/regressions/encoding-0.8.format
85+
tests/ParserTests/regressions/extensions-paths-5054.cabal
86+
tests/ParserTests/regressions/extensions-paths-5054.check
8587
tests/ParserTests/regressions/generics-sop.cabal
8688
tests/ParserTests/regressions/generics-sop.expr
8789
tests/ParserTests/regressions/generics-sop.format

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ checkPackage gpkg mpkg =
151151
++ checkFlagNames gpkg
152152
++ checkUnusedFlags gpkg
153153
++ checkUnicodeXFields gpkg
154+
++ checkPathsModuleExtensions pkg
154155
where
155156
pkg = fromMaybe (flattenPackageDescription gpkg) mpkg
156157

@@ -1664,6 +1665,34 @@ checkUnicodeXFields gpd
16641665
, toDListOf (L.buildInfos . L.customFieldsBI . traverse) gpd
16651666
]
16661667

1668+
-- | cabal-version <2.2 + Paths_module + default-extensions: doesn't build.
1669+
checkPathsModuleExtensions :: PackageDescription -> [PackageCheck]
1670+
checkPathsModuleExtensions pd
1671+
| specVersion pd >= mkVersion [2,2] = []
1672+
| any checkBI (allBuildInfo pd) || any checkLib (allLibraries pd)
1673+
= return $ PackageBuildImpossible $ unwords
1674+
[ "The package uses RebindableSyntax with OverloadedStrings or OverloadedLists"
1675+
, "in default-extensions, and also Paths_ autogen module."
1676+
, "That configuration is known to cause compile failures with Cabal < 2.2."
1677+
, "To use these default-extensions with Paths_ autogen module"
1678+
, "specify at least 'cabal-version: 2.2'."
1679+
]
1680+
| otherwise = []
1681+
where
1682+
mn = autogenPathsModuleName pd
1683+
1684+
checkLib :: Library -> Bool
1685+
checkLib l = mn `elem` exposedModules l && checkExts (l ^. L.defaultExtensions)
1686+
1687+
checkBI :: BuildInfo -> Bool
1688+
checkBI bi = mn `elem` otherModules bi && checkExts (bi ^. L.defaultExtensions)
1689+
1690+
checkExts exts = rebind `elem` exts && (strings `elem` exts || lists `elem` exts)
1691+
where
1692+
rebind = EnableExtension RebindableSyntax
1693+
strings = EnableExtension OverloadedStrings
1694+
lists = EnableExtension OverloadedLists
1695+
16671696
checkDevelopmentOnlyFlagsBuildInfo :: BuildInfo -> [PackageCheck]
16681697
checkDevelopmentOnlyFlagsBuildInfo bi =
16691698
catMaybes [

Cabal/Distribution/Types/PackageDescription.hs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -369,22 +369,15 @@ withForeignLib pkg_descr f =
369369
-- dependencies.
370370
allBuildInfo :: PackageDescription -> [BuildInfo]
371371
allBuildInfo pkg_descr = [ bi | lib <- allLibraries pkg_descr
372-
, let bi = libBuildInfo lib
373-
, buildable bi ]
374-
++ [ bi | flib <- foreignLibs pkg_descr
375-
, let bi = foreignLibBuildInfo flib
376-
, buildable bi ]
377-
++ [ bi | exe <- executables pkg_descr
378-
, let bi = buildInfo exe
379-
, buildable bi ]
380-
++ [ bi | tst <- testSuites pkg_descr
381-
, let bi = testBuildInfo tst
382-
, buildable bi ]
383-
++ [ bi | tst <- benchmarks pkg_descr
384-
, let bi = benchmarkBuildInfo tst
385-
, buildable bi ]
386-
--FIXME: many of the places where this is used, we actually want to look at
387-
-- unbuildable bits too, probably need separate functions
372+
, let bi = libBuildInfo lib ]
373+
++ [ bi | flib <- foreignLibs pkg_descr
374+
, let bi = foreignLibBuildInfo flib ]
375+
++ [ bi | exe <- executables pkg_descr
376+
, let bi = buildInfo exe ]
377+
++ [ bi | tst <- testSuites pkg_descr
378+
, let bi = testBuildInfo tst ]
379+
++ [ bi | tst <- benchmarks pkg_descr
380+
, let bi = benchmarkBuildInfo tst ]
388381

389382
-- | Return all of the 'BuildInfo's of enabled components, i.e., all of
390383
-- the ones that would be built if you run @./Setup build@.

Cabal/tests/CheckTests.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ checkTests = testGroup "regressions"
2727
[ checkTest "nothing-unicode.cabal"
2828
, checkTest "haddock-api-2.18.1-check.cabal"
2929
, checkTest "issue-774.cabal"
30+
, checkTest "extensions-paths-5054.cabal"
3031
]
3132

3233
checkTest :: FilePath -> TestTree
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: extensions-paths
2+
version: 5054
3+
category: Test
4+
maintainer: Oleg Grenrus
5+
license: BSD3
6+
license-file: LICENSe
7+
synopsis: Paths_pkg module + "bad" extensions + old cabal
8+
description:
9+
Only cabal-version: 2.2 or later will build Paths_pkg ok with
10+
11+
* RebindableSyntax and
12+
13+
* OverloadedLists or OverloadedStrings
14+
15+
`fromList` or `fromString` will be out-of-scope when compiling Paths_ module.
16+
17+
Other extensions (like NoImplicitPrelude) were handled before
18+
build-type: Simple
19+
cabal-version: 1.12
20+
21+
library
22+
default-language: Haskell2010
23+
exposed-modules: Issue Paths_extensions_paths
24+
default-extensions:
25+
RebindableSyntax
26+
OverloadedStrings
27+
28+
test-suite tests
29+
default-language: Haskell2010
30+
main-is: Test.hs
31+
type: exitcode-stdio-1.0
32+
if os(linux)
33+
other-modules: Paths_extensions_paths
34+
else:
35+
buildable: False
36+
37+
default-extensions:
38+
OverloadedLists
39+
RebindableSyntax
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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'.

0 commit comments

Comments
 (0)