{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Types.PackageVersionConstraint (
PackageVersionConstraint(..),
thisPackageVersionConstraint,
simplifyPackageVersionConstraint,
) where
import Distribution.Compat.Prelude
import Prelude ()
import Distribution.Parsec
import Distribution.Pretty
import Distribution.Types.PackageId
import Distribution.Types.PackageName
import Distribution.Types.Version
import Distribution.Types.VersionRange.Internal
import Distribution.Version (simplifyVersionRange)
import qualified Distribution.Compat.CharParsing as P
data PackageVersionConstraint = PackageVersionConstraint PackageName VersionRange
deriving ((forall x.
PackageVersionConstraint -> Rep PackageVersionConstraint x)
-> (forall x.
Rep PackageVersionConstraint x -> PackageVersionConstraint)
-> Generic PackageVersionConstraint
forall x.
Rep PackageVersionConstraint x -> PackageVersionConstraint
forall x.
PackageVersionConstraint -> Rep PackageVersionConstraint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep PackageVersionConstraint x -> PackageVersionConstraint
$cfrom :: forall x.
PackageVersionConstraint -> Rep PackageVersionConstraint x
Generic, ReadPrec [PackageVersionConstraint]
ReadPrec PackageVersionConstraint
Int -> ReadS PackageVersionConstraint
ReadS [PackageVersionConstraint]
(Int -> ReadS PackageVersionConstraint)
-> ReadS [PackageVersionConstraint]
-> ReadPrec PackageVersionConstraint
-> ReadPrec [PackageVersionConstraint]
-> Read PackageVersionConstraint
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PackageVersionConstraint]
$creadListPrec :: ReadPrec [PackageVersionConstraint]
readPrec :: ReadPrec PackageVersionConstraint
$creadPrec :: ReadPrec PackageVersionConstraint
readList :: ReadS [PackageVersionConstraint]
$creadList :: ReadS [PackageVersionConstraint]
readsPrec :: Int -> ReadS PackageVersionConstraint
$creadsPrec :: Int -> ReadS PackageVersionConstraint
Read, Int -> PackageVersionConstraint -> ShowS
[PackageVersionConstraint] -> ShowS
PackageVersionConstraint -> String
(Int -> PackageVersionConstraint -> ShowS)
-> (PackageVersionConstraint -> String)
-> ([PackageVersionConstraint] -> ShowS)
-> Show PackageVersionConstraint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PackageVersionConstraint] -> ShowS
$cshowList :: [PackageVersionConstraint] -> ShowS
show :: PackageVersionConstraint -> String
$cshow :: PackageVersionConstraint -> String
showsPrec :: Int -> PackageVersionConstraint -> ShowS
$cshowsPrec :: Int -> PackageVersionConstraint -> ShowS
Show, PackageVersionConstraint -> PackageVersionConstraint -> Bool
(PackageVersionConstraint -> PackageVersionConstraint -> Bool)
-> (PackageVersionConstraint -> PackageVersionConstraint -> Bool)
-> Eq PackageVersionConstraint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PackageVersionConstraint -> PackageVersionConstraint -> Bool
$c/= :: PackageVersionConstraint -> PackageVersionConstraint -> Bool
== :: PackageVersionConstraint -> PackageVersionConstraint -> Bool
$c== :: PackageVersionConstraint -> PackageVersionConstraint -> Bool
Eq, Typeable, Typeable PackageVersionConstraint
DataType
Constr
Typeable PackageVersionConstraint
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PackageVersionConstraint
-> c PackageVersionConstraint)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageVersionConstraint)
-> (PackageVersionConstraint -> Constr)
-> (PackageVersionConstraint -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c PackageVersionConstraint))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageVersionConstraint))
-> ((forall b. Data b => b -> b)
-> PackageVersionConstraint -> PackageVersionConstraint)
-> (forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> PackageVersionConstraint
-> r)
-> (forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> PackageVersionConstraint
-> r)
-> (forall u.
(forall d. Data d => d -> u) -> PackageVersionConstraint -> [u])
-> (forall u.
Int
-> (forall d. Data d => d -> u) -> PackageVersionConstraint -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> PackageVersionConstraint -> m PackageVersionConstraint)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PackageVersionConstraint -> m PackageVersionConstraint)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PackageVersionConstraint -> m PackageVersionConstraint)
-> Data PackageVersionConstraint
PackageVersionConstraint -> DataType
PackageVersionConstraint -> Constr
(forall b. Data b => b -> b)
-> PackageVersionConstraint -> PackageVersionConstraint
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PackageVersionConstraint
-> c PackageVersionConstraint
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageVersionConstraint
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int
-> (forall d. Data d => d -> u) -> PackageVersionConstraint -> u
forall u.
(forall d. Data d => d -> u) -> PackageVersionConstraint -> [u]
forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> PackageVersionConstraint
-> r
forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> PackageVersionConstraint
-> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> PackageVersionConstraint -> m PackageVersionConstraint
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PackageVersionConstraint -> m PackageVersionConstraint
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageVersionConstraint
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PackageVersionConstraint
-> c PackageVersionConstraint
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PackageVersionConstraint)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageVersionConstraint)
$cPackageVersionConstraint :: Constr
$tPackageVersionConstraint :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> PackageVersionConstraint -> m PackageVersionConstraint
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PackageVersionConstraint -> m PackageVersionConstraint
gmapMp :: (forall d. Data d => d -> m d)
-> PackageVersionConstraint -> m PackageVersionConstraint
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> PackageVersionConstraint -> m PackageVersionConstraint
gmapM :: (forall d. Data d => d -> m d)
-> PackageVersionConstraint -> m PackageVersionConstraint
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> PackageVersionConstraint -> m PackageVersionConstraint
gmapQi :: Int
-> (forall d. Data d => d -> u) -> PackageVersionConstraint -> u
$cgmapQi :: forall u.
Int
-> (forall d. Data d => d -> u) -> PackageVersionConstraint -> u
gmapQ :: (forall d. Data d => d -> u) -> PackageVersionConstraint -> [u]
$cgmapQ :: forall u.
(forall d. Data d => d -> u) -> PackageVersionConstraint -> [u]
gmapQr :: (r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> PackageVersionConstraint
-> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> PackageVersionConstraint
-> r
gmapQl :: (r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> PackageVersionConstraint
-> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> PackageVersionConstraint
-> r
gmapT :: (forall b. Data b => b -> b)
-> PackageVersionConstraint -> PackageVersionConstraint
$cgmapT :: (forall b. Data b => b -> b)
-> PackageVersionConstraint -> PackageVersionConstraint
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageVersionConstraint)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c PackageVersionConstraint)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c PackageVersionConstraint)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c PackageVersionConstraint)
dataTypeOf :: PackageVersionConstraint -> DataType
$cdataTypeOf :: PackageVersionConstraint -> DataType
toConstr :: PackageVersionConstraint -> Constr
$ctoConstr :: PackageVersionConstraint -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageVersionConstraint
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c PackageVersionConstraint
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PackageVersionConstraint
-> c PackageVersionConstraint
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> PackageVersionConstraint
-> c PackageVersionConstraint
$cp1Data :: Typeable PackageVersionConstraint
Data)
instance Binary PackageVersionConstraint
instance Structured PackageVersionConstraint
instance NFData PackageVersionConstraint where rnf :: PackageVersionConstraint -> ()
rnf = PackageVersionConstraint -> ()
forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf
instance Pretty PackageVersionConstraint where
pretty :: PackageVersionConstraint -> Doc
pretty (PackageVersionConstraint PackageName
name VersionRange
ver) =
PackageName -> Doc
forall a. Pretty a => a -> Doc
pretty PackageName
name Doc -> Doc -> Doc
<+> VersionRange -> Doc
forall a. Pretty a => a -> Doc
pretty VersionRange
ver
instance Parsec PackageVersionConstraint where
parsec :: m PackageVersionConstraint
parsec = do
PackageIdentifier PackageName
name Version
ver <- m PackageIdentifier
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
parsec
if Version
ver Version -> Version -> Bool
forall a. Eq a => a -> a -> Bool
== Version
nullVersion
then do
m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
VersionRange
vr <- m VersionRange
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
parsec m VersionRange -> m VersionRange -> m VersionRange
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> VersionRange -> m VersionRange
forall (m :: * -> *) a. Monad m => a -> m a
return VersionRange
anyVersion
m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
PackageVersionConstraint -> m PackageVersionConstraint
forall (m :: * -> *) a. Monad m => a -> m a
return (PackageName -> VersionRange -> PackageVersionConstraint
PackageVersionConstraint PackageName
name VersionRange
vr)
else
PackageVersionConstraint -> m PackageVersionConstraint
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PackageName -> VersionRange -> PackageVersionConstraint
PackageVersionConstraint PackageName
name (Version -> VersionRange
thisVersion Version
ver))
thisPackageVersionConstraint :: PackageIdentifier -> PackageVersionConstraint
thisPackageVersionConstraint :: PackageIdentifier -> PackageVersionConstraint
thisPackageVersionConstraint (PackageIdentifier PackageName
pn Version
vr) =
PackageName -> VersionRange -> PackageVersionConstraint
PackageVersionConstraint PackageName
pn (Version -> VersionRange
thisVersion Version
vr)
simplifyPackageVersionConstraint :: PackageVersionConstraint -> PackageVersionConstraint
simplifyPackageVersionConstraint :: PackageVersionConstraint -> PackageVersionConstraint
simplifyPackageVersionConstraint (PackageVersionConstraint PackageName
pn VersionRange
vr) =
PackageName -> VersionRange -> PackageVersionConstraint
PackageVersionConstraint PackageName
pn (VersionRange -> VersionRange
simplifyVersionRange VersionRange
vr)