diff --git a/Cabal/Distribution/CabalSpecVersion.hs b/Cabal/Distribution/CabalSpecVersion.hs index 5a503c31d88..0031897c9a6 100644 --- a/Cabal/Distribution/CabalSpecVersion.hs +++ b/Cabal/Distribution/CabalSpecVersion.hs @@ -16,10 +16,11 @@ data CabalSpecVersion | CabalSpecV1_24 | CabalSpecV2_0 | CabalSpecV2_2 + | CabalSpecV3_0 deriving (Eq, Ord, Show, Read, Enum, Bounded, Typeable, Data, Generic) cabalSpecLatest :: CabalSpecVersion -cabalSpecLatest = CabalSpecV2_2 +cabalSpecLatest = CabalSpecV3_0 cabalSpecFeatures :: CabalSpecVersion -> Set.Set CabalFeature cabalSpecFeatures CabalSpecOld = Set.empty @@ -30,13 +31,15 @@ cabalSpecFeatures CabalSpecV2_2 = Set.fromList [ Elif , CommonStanzas ] +cabalSpecFeatures CabalSpecV3_0 = cabalSpecFeatures CabalSpecV2_2 cabalSpecSupports :: CabalSpecVersion -> [Int] -> Bool cabalSpecSupports CabalSpecOld v = v < [1,21] cabalSpecSupports CabalSpecV1_22 v = v < [1,23] cabalSpecSupports CabalSpecV1_24 v = v < [1,25] cabalSpecSupports CabalSpecV2_0 v = v < [2,1] -cabalSpecSupports CabalSpecV2_2 _ = True +cabalSpecSupports CabalSpecV2_2 v = v < [2,3] +cabalSpecSupports CabalSpecV3_0 _ = True specHasCommonStanzas :: CabalSpecVersion -> HasCommonStanzas specHasCommonStanzas CabalSpecV2_2 = HasCommonStanzas diff --git a/Cabal/Distribution/PackageDescription/Parsec.hs b/Cabal/Distribution/PackageDescription/Parsec.hs index e3e32ea48a0..79dcf267524 100644 --- a/Cabal/Distribution/PackageDescription/Parsec.hs +++ b/Cabal/Distribution/PackageDescription/Parsec.hs @@ -125,7 +125,7 @@ parseGenericPackageDescription bs = do setCabalSpecVersion ver -- if we get too new version, fail right away case ver of - Just v | v > mkVersion [2,2] -> parseFailure zeroPos + Just v | v > mkVersion [3,0] -> parseFailure zeroPos "Unsupported cabal-version. See https://github.com/haskell/cabal/issues/4899." _ -> pure () diff --git a/Cabal/Distribution/Types/ModuleRenaming.hs b/Cabal/Distribution/Types/ModuleRenaming.hs index c0be560f9da..67060466712 100644 --- a/Cabal/Distribution/Types/ModuleRenaming.hs +++ b/Cabal/Distribution/Types/ModuleRenaming.hs @@ -8,6 +8,7 @@ module Distribution.Types.ModuleRenaming ( isDefaultRenaming, ) where +import Distribution.CabalSpecVersion import Distribution.Compat.Prelude hiding (empty) import Prelude () @@ -67,6 +68,19 @@ isDefaultRenaming :: ModuleRenaming -> Bool isDefaultRenaming DefaultRenaming = True isDefaultRenaming _ = False +-- | For versions < 3.0 white spaces were not skipped after the '(' +-- and ')' tokens in the mixin field. This parser checks the cabal file version +-- and does the correct skipping of spaces. +betweenParens :: CabalParsing m => m a -> m a +betweenParens p = do + csv <- askCabalSpecVersion + if csv >= CabalSpecV3_0 + then P.between (P.char '(' >> P.spaces) (P.char ')' >> P.spaces) p + else P.between (P.char '(') (P.char ')') p + +-- TODO: Give a sensible error on input "( A as B) instead of (A as B) +-- for cabal files that are declared to be older than 3.0. + instance Binary ModuleRenaming where instance NFData ModuleRenaming where rnf = genericRnf @@ -87,18 +101,18 @@ instance Parsec ModuleRenaming where -- NB: try not necessary as the first token is obvious parsec = P.choice [ parseRename, parseHiding, return DefaultRenaming ] where + cma = P.char ',' >> P.spaces parseRename = do - rns <- P.between (P.char '(') (P.char ')') parseList + rns <- betweenParens parseList P.spaces return (ModuleRenaming rns) parseHiding = do _ <- P.string "hiding" P.spaces - hides <- P.between (P.char '(') (P.char ')') - (P.sepBy parsec (P.char ',' >> P.spaces)) + hides <- betweenParens (P.sepBy parsec cma) return (HidingRenaming hides) parseList = - P.sepBy parseEntry (P.char ',' >> P.spaces) + P.sepBy parseEntry cma parseEntry = do orig <- parsec P.spaces