Commit f9e0fab9 authored by Oleg Grenrus's avatar Oleg Grenrus
Browse files

Recognise but warn about other-extensions

When cabal-version is old.

Fixes https://github.com/haskell/cabal/issues/7234
parent 13eab4ed
......@@ -146,6 +146,19 @@ class
-> g s a
-> g s a
-- | Annotate field with since spec-version.
-- This is used to recognise, but warn about the field.
-- It is used to process @other-extensions@ field.
--
-- Default implementation is to not warn.
--
-- @since 3.4.0.0
availableSinceWarn
:: CabalSpecVersion -- ^ spec version
-> g s a
-> g s a
availableSinceWarn _ = id
-- | Field which can be defined at most once.
uniqueField
:: (FieldGrammar c g, c (Identity a))
......
......@@ -287,6 +287,20 @@ instance FieldGrammar Parsec ParsecFieldGrammar where
pure def
availableSinceWarn vs (ParsecFG names prefixes parser) = ParsecFG names prefixes parser'
where
parser' v values
| v >= vs = parser v values
| otherwise = do
let unknownFields = Map.intersection values $ Map.fromSet (const ()) names
for_ (Map.toList unknownFields) $ \(name, fields) ->
for_ fields $ \(MkNamelessField pos _) ->
parseWarning pos PWTUnknownField $
"The field " <> show name <> " is available only since the Cabal specification version " ++ showCabalSpecVersion vs ++ "."
parser v values
-- todo we know about this field
deprecatedSince vs msg (ParsecFG names prefixes parser) = ParsecFG names prefixes parser'
where
......
......@@ -554,7 +554,7 @@ buildInfoFieldGrammar = BuildInfo
<*> monoidalFieldAla "default-extensions" (alaList' FSep MQuoted) L.defaultExtensions
^^^ availableSince CabalSpecV1_10 []
<*> monoidalFieldAla "other-extensions" formatOtherExtensions L.otherExtensions
^^^ availableSince CabalSpecV1_10 []
^^^ availableSinceWarn CabalSpecV1_10
<*> monoidalFieldAla "extensions" (alaList' FSep MQuoted) L.oldExtensions
^^^ deprecatedSince CabalSpecV1_12
"Please use 'default-extensions' or 'other-extensions' fields."
......
# cabal v2-build
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] next goal: issue7234 (user goal)
[__0] rejecting: issue7234-0 (conflict: requires HopefullyThisExtensionWontOccur)
[__0] fail (backjumping, conflict set: issue7234)
After searching the rest of the dependency tree exhaustively, these were the goals I've had most trouble fulfilling: issue7234 (2)
import Test.Cabal.Prelude
main = cabalTest $
-- this should fail,
-- none of GHC have extension declared in other-extensions
fails $ cabal "v2-build" ["all"]
cabal-version: >=1.8
name: issue7234
version: 0
synopsis: Old cabal-version package
description: But we have other-extensions to guide solver
author: Oleg Grenrus
category: Tests
maintainer: oleg.grenrus@iki.fi
build-type: Simple
library
build-depends: base <5
other-extensions: HopefullyThisExtensionWontOccur
exposed-modules: M
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- issue7234-0 (lib) (first run)
Warning: issue7234.cabal:14:3: The field "other-extensions" is available only since the Cabal specification version 1.10.
Configuring library for issue7234-0..
Preprocessing library for issue7234-0..
Building library for issue7234-0..
import Test.Cabal.Prelude
main = cabalTest $
-- this should not fail, just warn.
cabal "v2-build" ["all"]
cabal-version: >=1.8
name: issue7234
version: 0
synopsis: Old cabal-version package
description: But we have other-extensions to guide solver
author: Oleg Grenrus
category: Tests
maintainer: oleg.grenrus@iki.fi
build-type: Simple
library
build-depends: base <5
-- this extension is in virtually all GHCs, but there should be a warning
other-extensions: GADTs
exposed-modules: M
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment