Skip to content

Commit c67c365

Browse files
committed
caret / pvp operator accepts a set of versions. For example
build-depends: network ^>= { 2.6.3.6, 2.7.0.2, 2.8.0.0, 3.0.1.0 }
1 parent e17b8e5 commit c67c365

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

Cabal/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# 2.6.0.0 (current development version)
22
* TODO
3+
* `^>=` takes multiple parameters
34
* 'check' reports warnings for various ghc-\*-options fields separately
45
([#5342](https://github.com/haskell/cabal/issues/5432)).
56
* `KnownExtension`: added new extension `DerivingVia`.

Cabal/Distribution/Types/VersionRange.hs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,19 @@ instance Parsec VersionRange where
420420

421421
"==" -> do
422422
P.spaces
423-
(wild, v) <- verOrWild
424-
pure $ (if wild then withinVersion else thisVersion) v
423+
(do (wild, v) <- verOrWild
424+
pure $ (if wild then withinVersion else thisVersion) v
425+
<|>
426+
(verSet' thisVersion =<< verSet))
427+
428+
"^>=" -> do
429+
P.spaces
430+
(do (wild, v) <- verOrWild
431+
when wild $ P.unexpected $
432+
"wild-card version after ^>= operator"
433+
majorBoundVersion' v
434+
<|>
435+
(verSet' majorBoundVersion =<< verSet))
425436

426437
_ -> do
427438
P.spaces
@@ -431,7 +442,6 @@ instance Parsec VersionRange where
431442
case op of
432443
">=" -> pure $ orLaterVersion v
433444
"<" -> pure $ earlierVersion v
434-
"^>=" -> majorBoundVersion' v
435445
"<=" -> pure $ orEarlierVersion v
436446
">" -> pure $ laterVersion v
437447
_ -> fail $ "Unknown version operator " ++ show op
@@ -469,6 +479,31 @@ instance Parsec VersionRange where
469479
(orLaterVersion u) (earlierVersion (majorUpperBound u))
470480
embed vr = embedVersionRange vr
471481

482+
-- version set notation (e.g. "== { 0.0.1.0, 0.0.2.0, 0.1.0.0 }")
483+
verSet' op vs = do
484+
csv <- askCabalSpecVersion
485+
if csv >= CabalSpecV3_0
486+
then pure $ foldr1 unionVersionRanges (map op vs)
487+
else fail $ unwords
488+
[ "version set syntax used."
489+
, "To use this syntax the package needs to specify at least 'cabal-version: 3.0'."
490+
, "Alternatively, if broader compatibility is important then use"
491+
, "a series of single version constraints joined with the || operator:"
492+
, prettyShow (foldr1 unionVersionRanges (map op vs))
493+
]
494+
495+
verSet :: CabalParsing m => m [Version]
496+
verSet = do
497+
_ <- P.char '{'
498+
vs <- P.sepBy1 (P.spaces *> verPlain) (P.try (P.spaces *> P.char ','))
499+
P.spaces
500+
_ <- P.char '}'
501+
pure vs
502+
503+
-- plain version without tags or wildcards
504+
verPlain :: CabalParsing m => m Version
505+
verPlain = mkVersion <$> P.sepBy1 P.integral (P.char '.')
506+
472507
-- either wildcard or normal version
473508
verOrWild :: CabalParsing m => m (Bool, Version)
474509
verOrWild = do

Cabal/doc/developing-packages.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,25 @@ system-dependent values for these fields.
21342134
renaming in ``build-depends``; however, this support has since been
21352135
removed and should not be used.
21362136

2137+
Starting with Cabal 3.0, a set notation for the ``==`` and ``^>=`` operator
2138+
is available. For instance,
2139+
2140+
::
2141+
2142+
tested-with: GHC == 8.6.3, GHC == 8.4.4, GHC == 8.2.2, GHC == 8.0.2,
2143+
GHC == 7.10.3, GHC == 7.8.4, GHC == 7.6.3, GHC == 7.4.2
2144+
2145+
build-depends: network ^>= 2.6.3.6 || ^>= 2.7.0.2 || ^>= 2.8.0.0 || ^>= 3.0.1.0
2146+
2147+
can be then written in a more convenient and concise form
2148+
2149+
::
2150+
2151+
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 }
2152+
2153+
build-depends: network ^>= { 2.6.3.6, 2.7.0.2, 2.8.0.0, 3.0.1.0 }
2154+
2155+
21372156
.. pkg-field:: other-modules: identifier list
21382157

21392158
A list of modules used by the component but not exposed to users.

0 commit comments

Comments
 (0)