make LTS branch pre-releases
[cabal.git] / Cabal-syntax / src / Distribution / Types / LegacyExeDependency.hs
blob7acf028d0b3c81b323bb8ffc68166272b1861787
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
4 module Distribution.Types.LegacyExeDependency
5 ( LegacyExeDependency (..)
6 ) where
8 import Distribution.Compat.Prelude
9 import Prelude ()
11 import Distribution.Parsec
12 import Distribution.Pretty
13 import Distribution.Version (VersionRange, anyVersion)
15 import qualified Distribution.Compat.CharParsing as P
16 import qualified Text.PrettyPrint as Disp
18 -- | Describes a legacy `build-tools`-style dependency on an executable
20 -- It is "legacy" because we do not know what the build-tool referred to. It
21 -- could refer to a pkg-config executable (PkgconfigName), or an internal
22 -- executable (UnqualComponentName). Thus the name is stringly typed.
24 -- @since 2.0.0.2
25 data LegacyExeDependency
26 = LegacyExeDependency
27 String
28 VersionRange
29 deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
31 instance Binary LegacyExeDependency
32 instance Structured LegacyExeDependency
33 instance NFData LegacyExeDependency where rnf = genericRnf
35 instance Pretty LegacyExeDependency where
36 pretty (LegacyExeDependency name ver) =
37 Disp.text name <+> pretty ver
39 instance Parsec LegacyExeDependency where
40 parsec = do
41 name <- parsecMaybeQuoted nameP
42 P.spaces
43 verRange <- parsecMaybeQuoted parsec <|> pure anyVersion
44 pure $ LegacyExeDependency name verRange
45 where
46 nameP = intercalate "-" <$> toList <$> P.sepByNonEmpty component (P.char '-')
47 component = do
48 cs <- P.munch1 (\c -> isAlphaNum c || c == '+' || c == '_')
49 if all isDigit cs then fail "invalid component" else return cs