Skip to content

Commit 602dfdc

Browse files
authored
Merge pull request #5097 from haskell/issue-5086b
Issue 5086b
2 parents b36cf3c + 1a16e31 commit 602dfdc

File tree

10 files changed

+97
-32
lines changed

10 files changed

+97
-32
lines changed

Cabal/Cabal.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ extra-source-files:
8484
tests/ParserTests/regressions/encoding-0.8.cabal
8585
tests/ParserTests/regressions/encoding-0.8.expr
8686
tests/ParserTests/regressions/encoding-0.8.format
87+
tests/ParserTests/regressions/extensions-paths-5054.cabal
88+
tests/ParserTests/regressions/extensions-paths-5054.check
8789
tests/ParserTests/regressions/generics-sop.cabal
8890
tests/ParserTests/regressions/generics-sop.expr
8991
tests/ParserTests/regressions/generics-sop.format

Cabal/Distribution/PackageDescription/Check.hs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ checkPackage gpkg mpkg =
150150
++ checkFlagNames gpkg
151151
++ checkUnusedFlags gpkg
152152
++ checkUnicodeXFields gpkg
153+
++ checkPathsModuleExtensions pkg
153154
where
154155
pkg = fromMaybe (flattenPackageDescription gpkg) mpkg
155156

@@ -1657,6 +1658,36 @@ checkUnicodeXFields gpd
16571658
, toDListOf (L.buildInfos . L.customFieldsBI . traverse) gpd
16581659
]
16591660

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

Cabal/Distribution/Simple/Build/PathsModule.hs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ generate :: PackageDescription -> LocalBuildInfo -> ComponentLocalBuildInfo -> S
4141
generate pkg_descr lbi clbi =
4242
let pragmas =
4343
cpp_pragma
44-
++ no_overloaded_strings_pragma
4544
++ no_rebindable_syntax_pragma
4645
++ ffi_pragmas
4746
++ warning_pragmas
@@ -50,14 +49,10 @@ generate pkg_descr lbi clbi =
5049
| supports_cpp = "{-# LANGUAGE CPP #-}\n"
5150
| otherwise = ""
5251

53-
-- -XOverloadedStrings is problematic because 'fromString' is not
54-
-- in scope, so disable it.
55-
no_overloaded_strings_pragma
56-
| supports_overloaded_strings = "{-# LANGUAGE NoOverloadedStrings #-}\n"
57-
| otherwise = ""
58-
5952
-- -XRebindableSyntax is problematic because when paired with
60-
-- -XOverloadedLists, 'fromListN' is not in scope, so disable it.
53+
-- -XOverloadedLists, 'fromListN' is not in scope,
54+
-- or -XOverloadedStrings 'fromString' is not in scope,
55+
-- so we disable 'RebindableSyntax'.
6156
no_rebindable_syntax_pragma
6257
| supports_rebindable_syntax = "{-# LANGUAGE NoRebindableSyntax #-}\n"
6358
| otherwise = ""
@@ -253,7 +248,6 @@ generate pkg_descr lbi clbi =
253248
path_sep = show [pathSeparator]
254249

255250
supports_cpp = supports_language_pragma
256-
supports_overloaded_strings = supports_language_pragma
257251
supports_rebindable_syntax= ghc_newer_than (mkVersion [7,0,1])
258252
supports_language_pragma = ghc_newer_than (mkVersion [6,6,1])
259253

Cabal/Distribution/Types/PackageDescription.hs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -364,27 +364,21 @@ withForeignLib pkg_descr f =
364364
-- ---------------------------------------------------------------------------
365365
-- The BuildInfo type
366366

367-
-- | The 'BuildInfo' for the library (if there is one and it's buildable), and
368-
-- all buildable executables, test suites and benchmarks. Useful for gathering
369-
-- dependencies.
367+
-- | All 'BuildInfo' in the 'PackageDescription':
368+
-- libraries, executables, test-suites and benchmarks.
369+
--
370+
-- Useful for implementing package checks.
370371
allBuildInfo :: PackageDescription -> [BuildInfo]
371372
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
373+
, let bi = libBuildInfo lib ]
374+
++ [ bi | flib <- foreignLibs pkg_descr
375+
, let bi = foreignLibBuildInfo flib ]
376+
++ [ bi | exe <- executables pkg_descr
377+
, let bi = buildInfo exe ]
378+
++ [ bi | tst <- testSuites pkg_descr
379+
, let bi = testBuildInfo tst ]
380+
++ [ bi | tst <- benchmarks pkg_descr
381+
, let bi = benchmarkBuildInfo tst ]
388382

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

Cabal/changelog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* Use better defaulting for `build-type`; rename `PackageDescription`'s
1717
`buildType` field to `buildTypeRaw` and introduce new `buildType`
1818
function (#4958)
19+
* `D.T.PackageDescription.allBuildInfo` returns all build infos, not
20+
only for buildable components (#5087)
1921
* Removed `UnknownBuildType` constructor from `BuildType` (#5003).
2022
* Added `HexFloatLiterals` to `KnownExtension`.
2123
* Cabal will no longer try to build an empty set of `inputModules`

Cabal/tests/CheckTests.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ checkTests = testGroup "regressions"
2929
, checkTest "haddock-api-2.18.1-check.cabal"
3030
, checkTest "issue-774.cabal"
3131
, checkTest "MiniAgda.cabal"
32+
, checkTest "extensions-paths-5054.cabal"
3233
]
3334

3435
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'.

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ gen-extra-source-files:
3535
cabal new-run --builddir=dist-newstyle-meta --project-file=cabal.project.meta gen-extra-source-files -- cabal-install/cabal-install.cabal
3636

3737
cabal-install-test:
38-
cabal new-build cabal cabal-tests
39-
cd cabal-testsuite && `cabal-plan list-bin cabal-tests` --with-cabal=`cabal-plan list-bin cabal` --hide-successes -j3
38+
cabal new-build -j3 all --disable-tests --disable-benchmarks
39+
rm -rf .ghc.environment.*
40+
cd cabal-testsuite && `cabal-plan list-bin cabal-tests` --with-cabal=`cabal-plan list-bin cabal` --hide-successes -j3 ${TEST}

cabal-testsuite/PackageTests/PathsModule/Library/my.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
Cabal-version: 2.1
12
name: PathsModule
23
version: 0.1
3-
license: BSD3
4+
license: BSD-3-Clause
45
author: Johan Tibell
56
stability: stable
67
category: PackageTests
78
build-type: Simple
8-
Cabal-version: >= 1.10
99

1010
description:
1111
Check that the generated paths module compiles.

0 commit comments

Comments
 (0)