module Distribution.Version (
Version,
version0,
mkVersion,
mkVersion',
versionNumbers,
nullVersion,
alterVersion,
VersionRange,
anyVersion, noVersion,
thisVersion, notThisVersion,
laterVersion, earlierVersion,
orLaterVersion, orEarlierVersion,
unionVersionRanges, intersectVersionRanges,
withinVersion,
majorBoundVersion,
withinRange,
isAnyVersion,
isNoVersion,
isSpecificVersion,
simplifyVersionRange,
foldVersionRange,
normaliseVersionRange,
stripParensVersionRange,
hasUpperBound,
hasLowerBound,
VersionRangeF (..),
cataVersionRange,
anaVersionRange,
hyloVersionRange,
projectVersionRange,
embedVersionRange,
wildcardUpperBound,
majorUpperBound,
removeUpperBound,
removeLowerBound,
transformCaret,
transformCaretUpper,
transformCaretLower,
asVersionIntervals,
VersionInterval(..),
LowerBound(..),
UpperBound(..),
Bound(..),
VersionIntervals,
toVersionIntervals,
fromVersionIntervals,
unVersionIntervals,
) where
import Distribution.Types.Version
import Distribution.Types.VersionRange
import Distribution.Types.VersionInterval
isNoVersion :: VersionRange -> Bool
isNoVersion :: VersionRange -> Bool
isNoVersion VersionRange
vr = case VersionRange -> [VersionInterval]
asVersionIntervals VersionRange
vr of
[] -> Bool
True
[VersionInterval]
_ -> Bool
False
isSpecificVersion :: VersionRange -> Maybe Version
isSpecificVersion :: VersionRange -> Maybe Version
isSpecificVersion VersionRange
vr = case VersionRange -> [VersionInterval]
asVersionIntervals VersionRange
vr of
[VersionInterval (LowerBound Version
v Bound
InclusiveBound) (UpperBound Version
v' Bound
InclusiveBound)]
| Version
v forall a. Eq a => a -> a -> Bool
== Version
v' -> forall a. a -> Maybe a
Just Version
v
[VersionInterval]
_ -> forall a. Maybe a
Nothing
simplifyVersionRange :: VersionRange -> VersionRange
simplifyVersionRange :: VersionRange -> VersionRange
simplifyVersionRange VersionRange
vr
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null (VersionIntervals -> [VersionInterval]
unVersionIntervals VersionIntervals
vi) = VersionRange
vr
| Bool
otherwise = VersionIntervals -> VersionRange
fromVersionIntervals VersionIntervals
vi
where
vi :: VersionIntervals
vi = VersionRange -> VersionIntervals
toVersionIntervals VersionRange
vr
removeUpperBound :: VersionRange -> VersionRange
removeUpperBound :: VersionRange -> VersionRange
removeUpperBound = VersionIntervals -> VersionRange
fromVersionIntervals forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionIntervals -> VersionIntervals
relaxLastInterval forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionRange -> VersionIntervals
toVersionIntervals
removeLowerBound :: VersionRange -> VersionRange
removeLowerBound :: VersionRange -> VersionRange
removeLowerBound = VersionIntervals -> VersionRange
fromVersionIntervals forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionIntervals -> VersionIntervals
relaxHeadInterval forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionRange -> VersionIntervals
toVersionIntervals
transformCaret :: VersionRange -> VersionRange
transformCaret :: VersionRange -> VersionRange
transformCaret = (VersionRangeF VersionRange -> VersionRange)
-> (VersionRange -> VersionRangeF VersionRange)
-> VersionRange
-> VersionRange
hyloVersionRange VersionRangeF VersionRange -> VersionRange
embed VersionRange -> VersionRangeF VersionRange
projectVersionRange where
embed :: VersionRangeF VersionRange -> VersionRange
embed (MajorBoundVersionF Version
v) = Version -> VersionRange
orLaterVersion Version
v VersionRange -> VersionRange -> VersionRange
`intersectVersionRanges` Version -> VersionRange
earlierVersion (Version -> Version
majorUpperBound Version
v)
embed VersionRangeF VersionRange
vr = VersionRangeF VersionRange -> VersionRange
embedVersionRange VersionRangeF VersionRange
vr
transformCaretUpper :: VersionRange -> VersionRange
transformCaretUpper :: VersionRange -> VersionRange
transformCaretUpper = (VersionRangeF VersionRange -> VersionRange)
-> (VersionRange -> VersionRangeF VersionRange)
-> VersionRange
-> VersionRange
hyloVersionRange VersionRangeF VersionRange -> VersionRange
embed VersionRange -> VersionRangeF VersionRange
projectVersionRange where
embed :: VersionRangeF VersionRange -> VersionRange
embed (MajorBoundVersionF Version
v) = Version -> VersionRange
orLaterVersion Version
v
embed VersionRangeF VersionRange
vr = VersionRangeF VersionRange -> VersionRange
embedVersionRange VersionRangeF VersionRange
vr
transformCaretLower :: VersionRange -> VersionRange
transformCaretLower :: VersionRange -> VersionRange
transformCaretLower = (VersionRangeF VersionRange -> VersionRange)
-> (VersionRange -> VersionRangeF VersionRange)
-> VersionRange
-> VersionRange
hyloVersionRange VersionRangeF VersionRange -> VersionRange
embed VersionRange -> VersionRangeF VersionRange
projectVersionRange where
embed :: VersionRangeF VersionRange -> VersionRange
embed (MajorBoundVersionF Version
v) = Version -> VersionRange
earlierVersion (Version -> Version
majorUpperBound Version
v)
embed VersionRangeF VersionRange
vr = VersionRangeF VersionRange -> VersionRange
embedVersionRange VersionRangeF VersionRange
vr