Skip to content
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

Resolve #6589: Remove -any and -none syntax #6786

Merged
merged 1 commit into from
May 12, 2020
Merged
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
10 changes: 8 additions & 2 deletions Cabal/Cabal-quickcheck/src/Test/QuickCheck/Instances/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Distribution.Simple.Flag (Flag (..))
import Distribution.SPDX
import Distribution.System
import Distribution.Types.Dependency
import Distribution.Types.Flag (FlagAssignment, FlagName, mkFlagAssignment, mkFlagName)
import Distribution.Types.Flag (FlagAssignment, FlagName, mkFlagAssignment, mkFlagName, unFlagAssignment)
import Distribution.Types.LibraryName
import Distribution.Types.PackageId
import Distribution.Types.PackageName
Expand Down Expand Up @@ -243,14 +243,20 @@ instance Arbitrary1 Flag where
-------------------------------------------------------------------------------

instance Arbitrary FlagName where
arbitrary = mkFlagName <$> flagident
arbitrary = mkFlagName <$> frequency
[ (20, flagident)
-- special nasty cases
, (1, pure "none")
, (1, pure "any")
]
where
flagident = lowercase <$> shortListOf1 5 (elements flagChars)
`suchThat` (("-" /=) . take 1)
flagChars = "-_" ++ ['a'..'z']

instance Arbitrary FlagAssignment where
arbitrary = mkFlagAssignment <$> arbitrary
shrink x = mkFlagAssignment <$> shrink (unFlagAssignment x)

-------------------------------------------------------------------------------
-- Verbosity
Expand Down
8 changes: 8 additions & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ extra-source-files:
-- BEGIN gen-extra-source-files
tests/ParserTests/errors/MiniAgda.cabal
tests/ParserTests/errors/MiniAgda.errors
tests/ParserTests/errors/anynone.cabal
tests/ParserTests/errors/anynone.errors
tests/ParserTests/errors/big-version.cabal
tests/ParserTests/errors/big-version.errors
tests/ParserTests/errors/common1.cabal
Expand Down Expand Up @@ -110,6 +112,9 @@ extra-source-files:
tests/ParserTests/regressions/Octree-0.5.cabal
tests/ParserTests/regressions/Octree-0.5.expr
tests/ParserTests/regressions/Octree-0.5.format
tests/ParserTests/regressions/anynone.cabal
tests/ParserTests/regressions/anynone.expr
tests/ParserTests/regressions/anynone.format
tests/ParserTests/regressions/assoc-cpp-options.cabal
tests/ParserTests/regressions/assoc-cpp-options.check
tests/ParserTests/regressions/bad-glob-syntax.cabal
Expand Down Expand Up @@ -200,6 +205,9 @@ extra-source-files:
tests/ParserTests/regressions/mixin-3.cabal
tests/ParserTests/regressions/mixin-3.expr
tests/ParserTests/regressions/mixin-3.format
tests/ParserTests/regressions/monad-param.cabal
tests/ParserTests/regressions/monad-param.expr
tests/ParserTests/regressions/monad-param.format
tests/ParserTests/regressions/multiple-libs-2.cabal
tests/ParserTests/regressions/multiple-libs-2.check
tests/ParserTests/regressions/multiple-libs-2.expr
Expand Down
3 changes: 2 additions & 1 deletion Cabal/Distribution/PackageDescription/Parsec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ parseGenericPackageDescription' scannedVer lexWarnings utf8WarnPos fs = do
-- version will be parsed twice, therefore we parse without warnings.
v <- withoutWarnings $
Newtype.unpack' SpecVersion <$>
runFieldParser pos parsec cabalSpecLatest fls
-- Use version with || and && but before addition of ^>= and removal of -any
runFieldParser pos parsec CabalSpecV1_24 fls

-- if it were at the beginning, scanner would found it
when (v >= CabalSpecV2_2) $ parseFailure pos $
Expand Down
8 changes: 2 additions & 6 deletions Cabal/Distribution/Types/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,8 @@ instance Described Dependency where
, reChar '}'
]
]
-- TODO: RESpaces1 should be just RESpaces, but we are able
-- to generate non-parseable strings without mandatory space
--
-- https://github.com/haskell/cabal/issues/6589
--
, REOpt $ RESpaces1 <> vr

, REOpt $ RESpaces <> vr
]
where
vr = RENamed "version-range" (describe (Proxy :: Proxy VersionRange))
Expand Down
4 changes: 1 addition & 3 deletions Cabal/Distribution/Types/PackageVersionConstraint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ instance Parsec PackageVersionConstraint where
instance Described PackageVersionConstraint where
describe _ = describe (Proxy :: Proxy PackageName) <> REUnion
[ fromString "-" <> describe (Proxy :: Proxy Version)
-- TODO: change to RESpaces when -any and -none are removed
-- Related https://github.com/haskell/cabal/issues/6760
, RESpaces1 <> describe (Proxy :: Proxy VersionRange)
, RESpaces <> describe (Proxy :: Proxy VersionRange)
]

thisPackageVersionConstraint :: PackageIdentifier -> PackageVersionConstraint
Expand Down
13 changes: 12 additions & 1 deletion Cabal/Distribution/Types/VersionRange/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ prettyVersionRange16 vr = prettyVersionRange vr
--
-- Small history:
--
-- @-any@ and @-none@ removed in 3.4
-- Use @>=0@ and @<0@ instead.
--
-- >>> map (`simpleParsec'` "-none") [CabalSpecV3_0, CabalSpecV3_4] :: [Maybe VersionRange]
-- [Just (EarlierVersion (mkVersion [0])),Nothing]
--
-- Set operations are introduced in 3.0
--
-- >>> map (`simpleParsec'` "^>= { 1.2 , 1.3 }") [CabalSpecV2_4, CabalSpecV3_0] :: [Maybe VersionRange]
Expand Down Expand Up @@ -432,7 +438,12 @@ versionRangeParser digitParser csv = expr
isOpChar '=' = True
isOpChar '>' = True
isOpChar '^' = True
isOpChar '-' = True
isOpChar '-' = csv < CabalSpecV3_4
-- https://github.com/haskell/cabal/issues/6589
-- Unfortunately we have must not consume the dash,
-- as otherwise following parts may not be parsed.
--
-- i.e. we cannot fail here with good error.
isOpChar _ = False

-- -none version range is available since 1.22
Expand Down
4 changes: 4 additions & 0 deletions Cabal/doc/file-format-changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ relative to the respective preceding *published* version.
``cabal-version: 3.4``
----------------------


* License fields use identifiers from SPDX License List version
``3.8 2020-02-09``

* Remove ``-any`` and ``-none`` syntax for version ranges
Use ``>=0`` and ``<0`` respectively.

``cabal-version: 3.0``
----------------------

Expand Down
14 changes: 10 additions & 4 deletions Cabal/tests/ParserTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import Distribution.Fields (runParseResult)
import Distribution.PackageDescription (GenericPackageDescription)
import Distribution.PackageDescription.Parsec (parseGenericPackageDescription)
import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription)
import Distribution.Parsec
(PWarnType (..), PWarning (..), showPError, showPWarning)
import Distribution.Parsec (PWarnType (..), PWarning (..), showPError, showPWarning)
import Distribution.Pretty (prettyShow)
import Distribution.Utils.Generic (fromUTF8BS, toUTF8BS)
import System.Directory (setCurrentDirectory)
import System.Environment (getArgs, withArgs)
Expand Down Expand Up @@ -129,6 +129,7 @@ errorTests = testGroup "errors"
, errorTest "libpq2.cabal"
, errorTest "MiniAgda.cabal"
, errorTest "big-version.cabal"
, errorTest "anynone.cabal"
]

errorTest :: FilePath -> TestTree
Expand Down Expand Up @@ -189,6 +190,8 @@ regressionTests = testGroup "regressions"
, regressionTest "indentation2.cabal"
, regressionTest "indentation3.cabal"
, regressionTest "big-version.cabal"
, regressionTest "anynone.cabal"
, regressionTest "monad-param.cabal"
]

regressionTest :: FilePath -> TestTree
Expand All @@ -210,8 +213,11 @@ formatGoldenTest fp = cabalGoldenTest "format" correct $ do
Right gpd ->
unlines (map (showPWarning fp) warns)
++ showGenericPackageDescription gpd
Left (_, errs) ->
unlines $ "ERROR" : map (showPError fp) (NE.toList errs)
Left (csv, errs) ->
unlines $
"ERROR" :
maybe "unknown-version" prettyShow csv :
map (showPError fp) (NE.toList errs)
where
input = "tests" </> "ParserTests" </> "regressions" </> fp
correct = replaceExtension input "format"
Expand Down
10 changes: 10 additions & 0 deletions Cabal/tests/ParserTests/errors/anynone.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cabal-version: 3.4
name: anynone
version: 0
synopsis: The -any none demo
build-type: Simple

library
default-language: Haskell2010
exposed-modules: AnyNone
build-depends: base -any
5 changes: 5 additions & 0 deletions Cabal/tests/ParserTests/errors/anynone.errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VERSION: Just (mkVersion [3,4])
anynone.cabal:10:26:
unexpected '-'
expecting space, white space, opening paren, operator, comma or end of input

10 changes: 10 additions & 0 deletions Cabal/tests/ParserTests/regressions/anynone.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cabal-version: 3.0
name: anynone
version: 0
synopsis: The -any none demo
build-type: Simple

library
default-language: Haskell2010
exposed-modules: AnyNone
build-depends: base -any
104 changes: 104 additions & 0 deletions Cabal/tests/ParserTests/regressions/anynone.expr
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
GenericPackageDescription
{condBenchmarks = [],
condExecutables = [],
condForeignLibs = [],
condLibrary = Just
CondNode
{condTreeComponents = [],
condTreeConstraints = [Dependency
`PackageName "base"`
(OrLaterVersion `mkVersion [0]`)
(Set.fromList [LMainLibName])],
condTreeData = Library
{exposedModules = [`ModuleName "AnyNone"`],
libBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenIncludes = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
buildable = True,
cSources = [],
ccOptions = [],
cmmOptions = [],
cmmSources = [],
cppOptions = [],
customFieldsBI = [],
cxxOptions = [],
cxxSources = [],
defaultExtensions = [],
defaultLanguage = Just Haskell2010,
extraBundledLibs = [],
extraDynLibFlavours = [],
extraFrameworkDirs = [],
extraGHCiLibs = [],
extraLibDirs = [],
extraLibFlavours = [],
extraLibs = [],
frameworks = [],
hsSourceDirs = [],
includeDirs = [],
includes = [],
installIncludes = [],
jsSources = [],
ldOptions = [],
mixins = [],
oldExtensions = [],
options = PerCompilerFlavor [] [],
otherExtensions = [],
otherLanguages = [],
otherModules = [],
pkgconfigDepends = [],
profOptions = PerCompilerFlavor [] [],
sharedOptions = PerCompilerFlavor [] [],
staticOptions = PerCompilerFlavor [] [],
targetBuildDepends = [Dependency
`PackageName "base"`
(OrLaterVersion
`mkVersion [0]`)
(Set.fromList
[LMainLibName])],
virtualModules = []},
libExposed = True,
libName = LMainLibName,
libVisibility = LibraryVisibilityPublic,
reexportedModules = [],
signatures = []}},
condSubLibraries = [],
condTestSuites = [],
genPackageFlags = [],
gpdScannedVersion = Nothing,
packageDescription = PackageDescription
{author = "",
benchmarks = [],
bugReports = "",
buildTypeRaw = Just Simple,
category = "",
copyright = "",
customFieldsPD = [],
dataDir = "",
dataFiles = [],
description = "",
executables = [],
extraDocFiles = [],
extraSrcFiles = [],
extraTmpFiles = [],
foreignLibs = [],
homepage = "",
library = Nothing,
licenseFiles = [],
licenseRaw = Left NONE,
maintainer = "",
package = PackageIdentifier
{pkgName = `PackageName "anynone"`,
pkgVersion = `mkVersion [0]`},
pkgUrl = "",
setupBuildInfo = Nothing,
sourceRepos = [],
specVersion = CabalSpecV3_0,
stability = "",
subLibraries = [],
synopsis = "The -any none demo",
testSuites = [],
testedWith = []}}
10 changes: 10 additions & 0 deletions Cabal/tests/ParserTests/regressions/anynone.format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cabal-version: 3.0
name: anynone
version: 0
synopsis: The -any none demo
build-type: Simple

library
exposed-modules: AnyNone
default-language: Haskell2010
build-depends: base
25 changes: 25 additions & 0 deletions Cabal/tests/ParserTests/regressions/monad-param.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: monad-param
category: Control
version: 0.0.1
synopsis: Parameterized monads
description: Implements parameterized monads by overloading the monad sugar with more liberal types.
stability: alpha
author: Edward Kmett <[email protected]>
maintainer: Edward Kmett <[email protected]>
copyright: Copyright (C) 2006-2007, Edward Kmett
homepage: http://comonad.com/haskell/monad-param/dist/doc/html/Control-Monad-Parameterized.html
package-url: http://comonad.com/haskell/monad-param
build-depends: base -any, mtl -any, stm -any
cabal-version: -any
license: BSD3
license-file: LICENSE
buildable: True
extensions: MultiParamTypeClasses
FunctionalDependencies
OverlappingInstances
UndecidableInstances
EmptyDataDecls
NoImplicitPrelude
exposed-modules: Control.Monad.Parameterized
ghc-options: -funbox-strict-fields -threaded -fasm
hs-source-dirs: src
Loading