1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE DeriveGeneric #-}
4 module Distribution
.Types
.MungedPackageId
6 , computeCompatPackageId
9 import Distribution
.Compat
.Prelude
12 import Distribution
.Parsec
13 import Distribution
.Pretty
14 import Distribution
.Types
.LibraryName
15 import Distribution
.Types
.MungedPackageName
16 import Distribution
.Types
.PackageId
17 import Distribution
.Version
(Version
, nullVersion
)
19 import qualified Text
.PrettyPrint
as Disp
21 -- | A simple pair of a 'MungedPackageName' and 'Version'. 'MungedPackageName' is to
22 -- 'MungedPackageId' as 'PackageName' is to 'PackageId'. See 'MungedPackageName' for more
24 data MungedPackageId
= MungedPackageId
25 { mungedName
:: MungedPackageName
26 -- ^ The combined package and component name. see documentation for
27 -- 'MungedPackageName'.
28 , mungedVersion
:: Version
29 -- ^ The version of this package / component, eg 1.2
31 deriving (Generic
, Read, Show, Eq
, Ord
, Typeable
, Data
)
33 instance Binary MungedPackageId
34 instance Structured MungedPackageId
38 -- >>> prettyShow $ MungedPackageId (MungedPackageName "servant" LMainLibName) (mkVersion [1,2,3])
41 -- >>> prettyShow $ MungedPackageId (MungedPackageName "servant" (LSubLibName "lackey")) (mkVersion [0,1,2])
42 -- "z-servant-z-lackey-0.1.2"
43 instance Pretty MungedPackageId
where
44 pretty
(MungedPackageId n v
)
45 | v
== nullVersion
= pretty n
-- if no version, don't show version.
46 |
otherwise = pretty n
<<>> Disp
.char
'-' <<>> pretty v
50 -- >>> simpleParsec "foo-bar-0" :: Maybe MungedPackageId
51 -- Just (MungedPackageId {mungedName = MungedPackageName (PackageName "foo-bar") LMainLibName, mungedVersion = mkVersion [0]})
53 -- >>> simpleParsec "foo-bar" :: Maybe MungedPackageId
54 -- Just (MungedPackageId {mungedName = MungedPackageName (PackageName "foo-bar") LMainLibName, mungedVersion = mkVersion []})
56 -- >>> simpleParsec "z-foo-bar-z-baz-0" :: Maybe MungedPackageId
57 -- Just (MungedPackageId {mungedName = MungedPackageName (PackageName "foo-bar") (LSubLibName (UnqualComponentName "baz")), mungedVersion = mkVersion [0]})
59 -- >>> simpleParsec "foo-bar-0-0" :: Maybe MungedPackageId
62 -- >>> simpleParsec "foo-bar.0" :: Maybe MungedPackageId
65 -- >>> simpleParsec "foo-bar.4-2" :: Maybe MungedPackageId
67 instance Parsec MungedPackageId
where
69 PackageIdentifier pn v
<- parsec
70 return $ MungedPackageId
(decodeCompatPackageName pn
) v
72 instance NFData MungedPackageId
where
73 rnf
(MungedPackageId name version
) = rnf name `
seq` rnf version
75 computeCompatPackageId
:: PackageId
-> LibraryName
-> MungedPackageId
76 computeCompatPackageId
(PackageIdentifier pn vr
) ln
=
77 MungedPackageId
(MungedPackageName pn ln
) vr
80 -- >>> :seti -XOverloadedStrings
81 -- >>> import Distribution.Types.Version