make LTS branch pre-releases
[cabal.git] / Cabal-syntax / src / Distribution / Types / PkgconfigName.hs
blobc3a93dd27c1a8f6d2ebf8b64c67ef7c14c0f9d87
1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
3 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
5 module Distribution.Types.PkgconfigName
6 ( PkgconfigName
7 , unPkgconfigName
8 , mkPkgconfigName
9 ) where
11 import Distribution.Compat.Prelude
12 import Distribution.Utils.ShortText
13 import Prelude ()
15 import Distribution.Parsec
16 import Distribution.Pretty
18 import qualified Distribution.Compat.CharParsing as P
19 import qualified Text.PrettyPrint as Disp
21 -- | A pkg-config library name
23 -- This is parsed as any valid argument to the pkg-config utility.
25 -- @since 2.0.0.2
26 newtype PkgconfigName = PkgconfigName ShortText
27 deriving (Generic, Read, Show, Eq, Ord, Typeable, Data)
29 -- | Convert 'PkgconfigName' to 'String'
31 -- @since 2.0.0.2
32 unPkgconfigName :: PkgconfigName -> String
33 unPkgconfigName (PkgconfigName s) = fromShortText s
35 -- | Construct a 'PkgconfigName' from a 'String'
37 -- 'mkPkgconfigName' is the inverse to 'unPkgconfigName'
39 -- Note: No validations are performed to ensure that the resulting
40 -- 'PkgconfigName' is valid
42 -- @since 2.0.0.2
43 mkPkgconfigName :: String -> PkgconfigName
44 mkPkgconfigName = PkgconfigName . toShortText
46 -- | 'mkPkgconfigName'
48 -- @since 2.0.0.2
49 instance IsString PkgconfigName where
50 fromString = mkPkgconfigName
52 instance Binary PkgconfigName
53 instance Structured PkgconfigName
55 -- pkg-config allows versions and other letters in package names, eg
56 -- "gtk+-2.0" is a valid pkg-config package _name_. It then has a package
57 -- version number like 2.10.13
58 instance Pretty PkgconfigName where
59 pretty = Disp.text . unPkgconfigName
61 instance Parsec PkgconfigName where
62 parsec = mkPkgconfigName <$> P.munch1 isNameChar
63 where
64 -- https://gitlab.haskell.org/ghc/ghc/issues/17752
65 isNameChar '-' = True
66 isNameChar '_' = True
67 isNameChar '.' = True
68 isNameChar '+' = True
69 isNameChar c = isAlphaNum c
71 instance NFData PkgconfigName where
72 rnf (PkgconfigName pkg) = rnf pkg