Skip to content

Issue 5086 #5087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -421,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:
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,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 [
Expand Down
12 changes: 3 additions & 9 deletions Cabal/Distribution/Simple/Build/PathsModule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = ""
Expand Down Expand Up @@ -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])

Expand Down
22 changes: 1 addition & 21 deletions Cabal/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot foreign libraries :-).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libraries

--
-- 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}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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.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.
Expand Down