{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric      #-}
module Distribution.Types.LegacyExeDependency
  ( LegacyExeDependency(..)
  ) where

import Distribution.Compat.Prelude
import Prelude ()

import Distribution.Parsec
import Distribution.Pretty
import Distribution.Version (VersionRange, anyVersion)

import qualified Distribution.Compat.CharParsing as P
import qualified Text.PrettyPrint                as Disp

-- | Describes a legacy `build-tools`-style dependency on an executable
--
-- It is "legacy" because we do not know what the build-tool referred to. It
-- could refer to a pkg-config executable (PkgconfigName), or an internal
-- executable (UnqualComponentName). Thus the name is stringly typed.
--
-- @since 2.0.0.2
data LegacyExeDependency = LegacyExeDependency
                           String
                           VersionRange
                         deriving ((forall x. LegacyExeDependency -> Rep LegacyExeDependency x)
-> (forall x. Rep LegacyExeDependency x -> LegacyExeDependency)
-> Generic LegacyExeDependency
forall x. Rep LegacyExeDependency x -> LegacyExeDependency
forall x. LegacyExeDependency -> Rep LegacyExeDependency x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. LegacyExeDependency -> Rep LegacyExeDependency x
from :: forall x. LegacyExeDependency -> Rep LegacyExeDependency x
$cto :: forall x. Rep LegacyExeDependency x -> LegacyExeDependency
to :: forall x. Rep LegacyExeDependency x -> LegacyExeDependency
Generic, ReadPrec [LegacyExeDependency]
ReadPrec LegacyExeDependency
Int -> ReadS LegacyExeDependency
ReadS [LegacyExeDependency]
(Int -> ReadS LegacyExeDependency)
-> ReadS [LegacyExeDependency]
-> ReadPrec LegacyExeDependency
-> ReadPrec [LegacyExeDependency]
-> Read LegacyExeDependency
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS LegacyExeDependency
readsPrec :: Int -> ReadS LegacyExeDependency
$creadList :: ReadS [LegacyExeDependency]
readList :: ReadS [LegacyExeDependency]
$creadPrec :: ReadPrec LegacyExeDependency
readPrec :: ReadPrec LegacyExeDependency
$creadListPrec :: ReadPrec [LegacyExeDependency]
readListPrec :: ReadPrec [LegacyExeDependency]
Read, Int -> LegacyExeDependency -> ShowS
[LegacyExeDependency] -> ShowS
LegacyExeDependency -> String
(Int -> LegacyExeDependency -> ShowS)
-> (LegacyExeDependency -> String)
-> ([LegacyExeDependency] -> ShowS)
-> Show LegacyExeDependency
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LegacyExeDependency -> ShowS
showsPrec :: Int -> LegacyExeDependency -> ShowS
$cshow :: LegacyExeDependency -> String
show :: LegacyExeDependency -> String
$cshowList :: [LegacyExeDependency] -> ShowS
showList :: [LegacyExeDependency] -> ShowS
Show, LegacyExeDependency -> LegacyExeDependency -> Bool
(LegacyExeDependency -> LegacyExeDependency -> Bool)
-> (LegacyExeDependency -> LegacyExeDependency -> Bool)
-> Eq LegacyExeDependency
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LegacyExeDependency -> LegacyExeDependency -> Bool
== :: LegacyExeDependency -> LegacyExeDependency -> Bool
$c/= :: LegacyExeDependency -> LegacyExeDependency -> Bool
/= :: LegacyExeDependency -> LegacyExeDependency -> Bool
Eq, Eq LegacyExeDependency
Eq LegacyExeDependency =>
(LegacyExeDependency -> LegacyExeDependency -> Ordering)
-> (LegacyExeDependency -> LegacyExeDependency -> Bool)
-> (LegacyExeDependency -> LegacyExeDependency -> Bool)
-> (LegacyExeDependency -> LegacyExeDependency -> Bool)
-> (LegacyExeDependency -> LegacyExeDependency -> Bool)
-> (LegacyExeDependency
    -> LegacyExeDependency -> LegacyExeDependency)
-> (LegacyExeDependency
    -> LegacyExeDependency -> LegacyExeDependency)
-> Ord LegacyExeDependency
LegacyExeDependency -> LegacyExeDependency -> Bool
LegacyExeDependency -> LegacyExeDependency -> Ordering
LegacyExeDependency -> LegacyExeDependency -> LegacyExeDependency
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: LegacyExeDependency -> LegacyExeDependency -> Ordering
compare :: LegacyExeDependency -> LegacyExeDependency -> Ordering
$c< :: LegacyExeDependency -> LegacyExeDependency -> Bool
< :: LegacyExeDependency -> LegacyExeDependency -> Bool
$c<= :: LegacyExeDependency -> LegacyExeDependency -> Bool
<= :: LegacyExeDependency -> LegacyExeDependency -> Bool
$c> :: LegacyExeDependency -> LegacyExeDependency -> Bool
> :: LegacyExeDependency -> LegacyExeDependency -> Bool
$c>= :: LegacyExeDependency -> LegacyExeDependency -> Bool
>= :: LegacyExeDependency -> LegacyExeDependency -> Bool
$cmax :: LegacyExeDependency -> LegacyExeDependency -> LegacyExeDependency
max :: LegacyExeDependency -> LegacyExeDependency -> LegacyExeDependency
$cmin :: LegacyExeDependency -> LegacyExeDependency -> LegacyExeDependency
min :: LegacyExeDependency -> LegacyExeDependency -> LegacyExeDependency
Ord, Typeable, Typeable LegacyExeDependency
Typeable LegacyExeDependency =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g)
 -> LegacyExeDependency
 -> c LegacyExeDependency)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c LegacyExeDependency)
-> (LegacyExeDependency -> Constr)
-> (LegacyExeDependency -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c LegacyExeDependency))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c LegacyExeDependency))
-> ((forall b. Data b => b -> b)
    -> LegacyExeDependency -> LegacyExeDependency)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> LegacyExeDependency -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> LegacyExeDependency -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> LegacyExeDependency -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> LegacyExeDependency -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> LegacyExeDependency -> m LegacyExeDependency)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> LegacyExeDependency -> m LegacyExeDependency)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> LegacyExeDependency -> m LegacyExeDependency)
-> Data LegacyExeDependency
LegacyExeDependency -> Constr
LegacyExeDependency -> DataType
(forall b. Data b => b -> b)
-> LegacyExeDependency -> LegacyExeDependency
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) -> LegacyExeDependency -> u
forall u.
(forall d. Data d => d -> u) -> LegacyExeDependency -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LegacyExeDependency -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LegacyExeDependency -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> LegacyExeDependency -> m LegacyExeDependency
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LegacyExeDependency -> m LegacyExeDependency
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LegacyExeDependency
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> LegacyExeDependency
-> c LegacyExeDependency
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LegacyExeDependency)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c LegacyExeDependency)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> LegacyExeDependency
-> c LegacyExeDependency
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> LegacyExeDependency
-> c LegacyExeDependency
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LegacyExeDependency
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LegacyExeDependency
$ctoConstr :: LegacyExeDependency -> Constr
toConstr :: LegacyExeDependency -> Constr
$cdataTypeOf :: LegacyExeDependency -> DataType
dataTypeOf :: LegacyExeDependency -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LegacyExeDependency)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LegacyExeDependency)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c LegacyExeDependency)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c LegacyExeDependency)
$cgmapT :: (forall b. Data b => b -> b)
-> LegacyExeDependency -> LegacyExeDependency
gmapT :: (forall b. Data b => b -> b)
-> LegacyExeDependency -> LegacyExeDependency
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LegacyExeDependency -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LegacyExeDependency -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LegacyExeDependency -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LegacyExeDependency -> r
$cgmapQ :: forall u.
(forall d. Data d => d -> u) -> LegacyExeDependency -> [u]
gmapQ :: forall u.
(forall d. Data d => d -> u) -> LegacyExeDependency -> [u]
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> LegacyExeDependency -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> LegacyExeDependency -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> LegacyExeDependency -> m LegacyExeDependency
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> LegacyExeDependency -> m LegacyExeDependency
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LegacyExeDependency -> m LegacyExeDependency
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LegacyExeDependency -> m LegacyExeDependency
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LegacyExeDependency -> m LegacyExeDependency
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LegacyExeDependency -> m LegacyExeDependency
Data)

instance Binary LegacyExeDependency
instance Structured LegacyExeDependency
instance NFData LegacyExeDependency where rnf :: LegacyExeDependency -> ()
rnf = LegacyExeDependency -> ()
forall a. (Generic a, GNFData (Rep a)) => a -> ()
genericRnf

instance Pretty LegacyExeDependency where
    pretty :: LegacyExeDependency -> Doc
pretty (LegacyExeDependency String
name VersionRange
ver) =
        String -> Doc
Disp.text String
name Doc -> Doc -> Doc
<+> VersionRange -> Doc
forall a. Pretty a => a -> Doc
pretty VersionRange
ver

instance Parsec LegacyExeDependency where
    parsec :: forall (m :: * -> *). CabalParsing m => m LegacyExeDependency
parsec = do
        String
name <- m String -> m String
forall (m :: * -> *) a. CabalParsing m => m a -> m a
parsecMaybeQuoted m String
nameP
        m ()
forall (m :: * -> *). CharParsing m => m ()
P.spaces
        VersionRange
verRange <- m VersionRange -> m VersionRange
forall (m :: * -> *) a. CabalParsing m => m a -> m a
parsecMaybeQuoted m VersionRange
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
forall (m :: * -> *). CabalParsing m => m VersionRange
parsec m VersionRange -> m VersionRange -> m VersionRange
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> VersionRange -> m VersionRange
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure VersionRange
anyVersion
        LegacyExeDependency -> m LegacyExeDependency
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (LegacyExeDependency -> m LegacyExeDependency)
-> LegacyExeDependency -> m LegacyExeDependency
forall a b. (a -> b) -> a -> b
$ String -> VersionRange -> LegacyExeDependency
LegacyExeDependency String
name VersionRange
verRange
      where
        nameP :: m String
nameP = String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
"-" ([String] -> String)
-> (NonEmpty String -> [String]) -> NonEmpty String -> String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty String -> [String]
forall a. NonEmpty a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (NonEmpty String -> String) -> m (NonEmpty String) -> m String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m String -> m Char -> m (NonEmpty String)
forall (m :: * -> *) a sep.
Alternative m =>
m a -> m sep -> m (NonEmpty a)
P.sepByNonEmpty m String
component (Char -> m Char
forall (m :: * -> *). CharParsing m => Char -> m Char
P.char Char
'-')
        component :: m String
component = do
            String
cs <- (Char -> Bool) -> m String
forall (m :: * -> *). CharParsing m => (Char -> Bool) -> m String
P.munch1 (\Char
c -> Char -> Bool
isAlphaNum Char
c Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'+' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_')
            if (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isDigit String
cs then String -> m String
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid component" else String -> m String
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return String
cs