{-# 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. 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
$cto :: forall x. Rep LegacyExeDependency x -> LegacyExeDependency
$cfrom :: forall x. LegacyExeDependency -> Rep LegacyExeDependency x
Generic, ReadPrec [LegacyExeDependency]
ReadPrec LegacyExeDependency
Int -> ReadS LegacyExeDependency
ReadS [LegacyExeDependency]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LegacyExeDependency]
$creadListPrec :: ReadPrec [LegacyExeDependency]
readPrec :: ReadPrec LegacyExeDependency
$creadPrec :: ReadPrec LegacyExeDependency
readList :: ReadS [LegacyExeDependency]
$creadList :: ReadS [LegacyExeDependency]
readsPrec :: Int -> ReadS LegacyExeDependency
$creadsPrec :: Int -> ReadS LegacyExeDependency
Read, Int -> LegacyExeDependency -> ShowS
[LegacyExeDependency] -> ShowS
LegacyExeDependency -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LegacyExeDependency] -> ShowS
$cshowList :: [LegacyExeDependency] -> ShowS
show :: LegacyExeDependency -> String
$cshow :: LegacyExeDependency -> String
showsPrec :: Int -> LegacyExeDependency -> ShowS
$cshowsPrec :: Int -> LegacyExeDependency -> ShowS
Show, LegacyExeDependency -> LegacyExeDependency -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LegacyExeDependency -> LegacyExeDependency -> Bool
$c/= :: LegacyExeDependency -> LegacyExeDependency -> Bool
== :: LegacyExeDependency -> LegacyExeDependency -> Bool
$c== :: LegacyExeDependency -> LegacyExeDependency -> Bool
Eq, Eq 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
min :: LegacyExeDependency -> LegacyExeDependency -> LegacyExeDependency
$cmin :: LegacyExeDependency -> LegacyExeDependency -> LegacyExeDependency
max :: LegacyExeDependency -> LegacyExeDependency -> LegacyExeDependency
$cmax :: LegacyExeDependency -> LegacyExeDependency -> LegacyExeDependency
>= :: LegacyExeDependency -> LegacyExeDependency -> Bool
$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
compare :: LegacyExeDependency -> LegacyExeDependency -> Ordering
$ccompare :: LegacyExeDependency -> LegacyExeDependency -> Ordering
Ord, Typeable, Typeable LegacyExeDependency
LegacyExeDependency -> DataType
LegacyExeDependency -> Constr
(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)
gmapMo :: 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
gmapMp :: forall (m :: * -> *).
MonadPlus 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
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> LegacyExeDependency -> m LegacyExeDependency
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> LegacyExeDependency -> m LegacyExeDependency
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> LegacyExeDependency -> u
$cgmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> LegacyExeDependency -> u
gmapQ :: forall u.
(forall d. Data d => d -> u) -> LegacyExeDependency -> [u]
$cgmapQ :: forall u.
(forall d. Data d => d -> u) -> LegacyExeDependency -> [u]
gmapQr :: 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
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LegacyExeDependency -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LegacyExeDependency -> r
gmapT :: (forall b. Data b => b -> b)
-> LegacyExeDependency -> LegacyExeDependency
$cgmapT :: (forall b. Data b => b -> b)
-> LegacyExeDependency -> LegacyExeDependency
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c LegacyExeDependency)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c LegacyExeDependency)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LegacyExeDependency)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c LegacyExeDependency)
dataTypeOf :: LegacyExeDependency -> DataType
$cdataTypeOf :: LegacyExeDependency -> DataType
toConstr :: LegacyExeDependency -> Constr
$ctoConstr :: LegacyExeDependency -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LegacyExeDependency
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c LegacyExeDependency
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> LegacyExeDependency
-> c LegacyExeDependency
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> LegacyExeDependency
-> c LegacyExeDependency
Data)

instance Binary LegacyExeDependency
instance Structured LegacyExeDependency
instance NFData LegacyExeDependency where rnf :: LegacyExeDependency -> ()
rnf = 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
<+> forall a. Pretty a => a -> Doc
pretty VersionRange
ver

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