Skip to content

caret operator accepts a set of versions #5906

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

Merged
merged 2 commits into from
Mar 2, 2019
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
11 changes: 11 additions & 0 deletions Cabal/Cabal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ extra-source-files:
tests/ParserTests/errors/spdx-2.errors
tests/ParserTests/errors/spdx-3.cabal
tests/ParserTests/errors/spdx-3.errors
tests/ParserTests/errors/version-sets-1.cabal
tests/ParserTests/errors/version-sets-1.errors
tests/ParserTests/errors/version-sets-2.cabal
tests/ParserTests/errors/version-sets-2.errors
tests/ParserTests/errors/version-sets-3.cabal
tests/ParserTests/errors/version-sets-3.errors
tests/ParserTests/errors/version-sets-4.cabal
tests/ParserTests/errors/version-sets-4.errors
tests/ParserTests/ipi/Includes2.cabal
tests/ParserTests/ipi/Includes2.expr
tests/ParserTests/ipi/Includes2.format
Expand Down Expand Up @@ -172,6 +180,9 @@ extra-source-files:
tests/ParserTests/regressions/th-lift-instances.cabal
tests/ParserTests/regressions/th-lift-instances.expr
tests/ParserTests/regressions/th-lift-instances.format
tests/ParserTests/regressions/version-sets.cabal
tests/ParserTests/regressions/version-sets.expr
tests/ParserTests/regressions/version-sets.format
tests/ParserTests/regressions/wl-pprint-indef.cabal
tests/ParserTests/regressions/wl-pprint-indef.expr
tests/ParserTests/regressions/wl-pprint-indef.format
Expand Down
1 change: 1 addition & 0 deletions Cabal/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 2.6.0.0 (current development version)
* TODO
* Introduce set notation for `^>=` and `==` operators.
* 'check' reports warnings for various ghc-\*-options fields separately
([#5342](https://github.com/haskell/cabal/issues/5432)).
* `KnownExtension`: added new extension `DerivingVia`.
Expand Down
44 changes: 41 additions & 3 deletions Cabal/Distribution/Types/VersionRange.hs
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,19 @@ instance Parsec VersionRange where

"==" -> do
P.spaces
(wild, v) <- verOrWild
pure $ (if wild then withinVersion else thisVersion) v
(do (wild, v) <- verOrWild
pure $ (if wild then withinVersion else thisVersion) v
<|>
(verSet' thisVersion =<< verSet))

"^>=" -> do
P.spaces
(do (wild, v) <- verOrWild
when wild $ P.unexpected $
"wild-card version after ^>= operator"
majorBoundVersion' v
<|>
(verSet' majorBoundVersion =<< verSet))

_ -> do
P.spaces
Expand All @@ -431,7 +442,6 @@ instance Parsec VersionRange where
case op of
">=" -> pure $ orLaterVersion v
"<" -> pure $ earlierVersion v
"^>=" -> majorBoundVersion' v
"<=" -> pure $ orEarlierVersion v
">" -> pure $ laterVersion v
_ -> fail $ "Unknown version operator " ++ show op
Expand Down Expand Up @@ -469,6 +479,34 @@ instance Parsec VersionRange where
(orLaterVersion u) (earlierVersion (majorUpperBound u))
embed vr = embedVersionRange vr

-- version set notation (e.g. "== { 0.0.1.0, 0.0.2.0, 0.1.0.0 }")
verSet' op vs = do
csv <- askCabalSpecVersion
if csv >= CabalSpecV3_0
then pure $ foldr1 unionVersionRanges (map op vs)
else fail $ unwords
[ "version set syntax used."
, "To use this syntax the package needs to specify at least 'cabal-version: 3.0'."
, "Alternatively, if broader compatibility is important then use"
, "a series of single version constraints joined with the || operator:"
, prettyShow (foldr1 unionVersionRanges (map op vs))
]

verSet :: CabalParsing m => m [Version]
verSet = do
_ <- P.char '{'
P.spaces
vs <- P.sepBy1 (verPlain <* P.spaces) (P.char ',' *> P.spaces)
_ <- P.char '}'
pure vs

-- a plain version without tags or wildcards
-- note: this uses P.integral which allows redundant zeros.
-- This is not a problem because 'verPlain' is only used by
-- 'verSet' which requires cabal > 3
verPlain :: CabalParsing m => m Version
verPlain = mkVersion <$> P.sepBy1 P.integral (P.char '.')

-- either wildcard or normal version
verOrWild :: CabalParsing m => m (Bool, Version)
verOrWild = do
Copy link
Collaborator

Choose a reason for hiding this comment

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

@hvr if you look at this, this doesn't differentiate between 01.02.03 and 1.2.3 given different cabal-version.

I'll change that, hopefully nothing slipped on Hackage

http://hackage.haskell.org/package/Cabal-2.4.1.0/docs/src/Distribution.Types.Version.html#line-99

Copy link
Member

Choose a reason for hiding this comment

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

See also #5138 where we took some measures to prevent denorm versions hitting hackage

Expand Down
19 changes: 19 additions & 0 deletions Cabal/doc/developing-packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,25 @@ system-dependent values for these fields.
renaming in ``build-depends``; however, this support has since been
removed and should not be used.

Starting with Cabal 3.0, a set notation for the ``==`` and ``^>=`` operator
is available. For instance,

::

tested-with: GHC == 8.6.3, GHC == 8.4.4, GHC == 8.2.2, GHC == 8.0.2,
GHC == 7.10.3, GHC == 7.8.4, GHC == 7.6.3, GHC == 7.4.2

build-depends: network ^>= 2.6.3.6 || ^>= 2.7.0.2 || ^>= 2.8.0.0 || ^>= 3.0.1.0

can be then written in a more convenient and concise form

::

tested-with: GHC == { 8.6.3, 8.4.4, 8.2.2, 8.0.2, 7.10.3, 7.8.4, 7.6.3, 7.4.2 }

build-depends: network ^>= { 2.6.3.6, 2.7.0.2, 2.8.0.0, 3.0.1.0 }


.. pkg-field:: other-modules: identifier list

A list of modules used by the component but not exposed to users.
Expand Down
5 changes: 5 additions & 0 deletions Cabal/tests/ParserTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ errorTests = testGroup "errors"
, errorTest "spdx-2.cabal"
, errorTest "spdx-3.cabal"
, errorTest "removed-fields.cabal"
, errorTest "version-sets-1.cabal"
, errorTest "version-sets-2.cabal"
, errorTest "version-sets-3.cabal"
, errorTest "version-sets-4.cabal"
]

errorTest :: FilePath -> TestTree
Expand Down Expand Up @@ -159,6 +163,7 @@ regressionTests = testGroup "regressions"
, regressionTest "spdx-3.cabal"
, regressionTest "hidden-main-lib.cabal"
, regressionTest "jaeger-flamegraph.cabal"
, regressionTest "version-sets.cabal"
]

regressionTest :: FilePath -> TestTree
Expand Down
8 changes: 8 additions & 0 deletions Cabal/tests/ParserTests/errors/version-sets-1.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cabal-version: 2.5
name: version-sets
version: 0
synopsis: version set notation

library
default-language: Haskell2010
build-depends: network == { }
5 changes: 5 additions & 0 deletions Cabal/tests/ParserTests/errors/version-sets-1.errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VERSION: Just (mkVersion [2,5])
version-sets-1.cabal:8:31:
unexpected "}"
expecting space or integral

8 changes: 8 additions & 0 deletions Cabal/tests/ParserTests/errors/version-sets-2.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cabal-version: 2.5
name: version-sets
version: 0
synopsis: version set notation

library
default-language: Haskell2010
build-depends: network >= { 2.8.0.0 }
5 changes: 5 additions & 0 deletions Cabal/tests/ParserTests/errors/version-sets-2.errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VERSION: Just (mkVersion [2,5])
version-sets-2.cabal:8:29:
unexpected "{"
expecting space or integral

8 changes: 8 additions & 0 deletions Cabal/tests/ParserTests/errors/version-sets-3.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cabal-version: 2.5
name: version-sets
version: 0
synopsis: version set notation

library
default-language: Haskell2010
build-depends: network == { 2.8.0.0, }
5 changes: 5 additions & 0 deletions Cabal/tests/ParserTests/errors/version-sets-3.errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VERSION: Just (mkVersion [2,5])
version-sets-3.cabal:8:40:
unexpected "}"
expecting space or integral

8 changes: 8 additions & 0 deletions Cabal/tests/ParserTests/errors/version-sets-4.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cabal-version: 2.5
name: version-sets
version: 0
synopsis: version set notation

library
default-language: Haskell2010
build-depends: network == { 2.8.* }
5 changes: 5 additions & 0 deletions Cabal/tests/ParserTests/errors/version-sets-4.errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VERSION: Just (mkVersion [2,5])
version-sets-4.cabal:8:35:
unexpected "*"
expecting integral

18 changes: 18 additions & 0 deletions Cabal/tests/ParserTests/regressions/version-sets.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cabal-version: 2.5
name: version-sets
version: 0
synopsis: version set notation
tested-with: GHC == { 8.6.3, 8.4.4, 8.2.2, 8.0.2, 7.10.3, 7.8.4, 7.6.3, 7.4.2 }

library
default-language: Haskell2010
build-depends: network ^>= {0}
build-depends: base == {1}, base == { 1 }, base == {1,2}, base == {1.2}, base == {1.2,3.4}
build-depends: ghc == {
8.6.3
,
8.4.4 ,8.2.2 ,
8.0.2,7.10.3
, 7.8.4, 7.6.3, 7.4.2
}
build-depends: Cabal ^>= { 2.4.1.1, 2.2.0.0 }
Loading