55module Stack.Types.DumpPackage
66 ( DumpPackage (.. )
77 , SublibDump (.. )
8- , dpParentLibIdent
8+ , DumpedGlobalPackage
9+ , sublibParentPkgId
910 ) where
1011
1112import qualified Distribution.License as C
@@ -14,17 +15,17 @@ import Stack.Prelude
1415import Stack.Types.Component ( StackUnqualCompName )
1516import Stack.Types.GhcPkgId ( GhcPkgId )
1617
17- -- | Type representing dump information for a single package, as output by the
18- -- @ghc-pkg describe@ command.
18+ -- | Type representing dump information for a single installed package, as
19+ -- output by the @ghc-pkg describe@ command.
1920data DumpPackage = DumpPackage
2021 { ghcPkgId :: ! GhcPkgId
2122 -- ^ The @id@ field.
2223 , packageIdent :: ! PackageIdentifier
2324 -- ^ The @name@ and @version@ fields. The @name@ field is the munged package
24- -- name. If the package is not for a sub library, its munged name is its
25+ -- name. If the package is not for a sub- library, its munged name is its
2526 -- name.
2627 , sublib :: ! (Maybe SublibDump )
27- -- ^ The sub library information if it's a sub-library.
28+ -- ^ The sub- library information, if it is a sub-library.
2829 , license :: ! (Maybe C. License )
2930 , libDirs :: ! [FilePath ]
3031 -- ^ The @library-dirs@ field.
@@ -40,20 +41,22 @@ data DumpPackage = DumpPackage
4041 }
4142 deriving (Eq , Read , Show )
4243
43- -- | ghc-pkg has a notion of sublibraries when using ghc-pkg dump. We can only
44- -- know it's different through the fields it shows .
44+ -- | An installed package for a sub-library of a Cabal package has additional
45+ -- fields.
4546data SublibDump = SublibDump
4647 { packageName :: PackageName
47- -- ^ " package-name" field from ghc-pkg
48+ -- ^ The @ package-name@ field.
4849 , libraryName :: StackUnqualCompName
49- -- ^ " lib-name" field from ghc-pkg
50+ -- ^ The @ lib-name@ field.
5051 }
5152 deriving (Eq , Read , Show )
5253
53- dpParentLibIdent :: DumpPackage -> Maybe PackageIdentifier
54- dpParentLibIdent dp = case (dp. sublib, dp. packageIdent) of
55- (Nothing , _) -> Nothing
56- (Just sublibDump, PackageIdentifier _ v) ->
57- Just $ PackageIdentifier libParentPackageName v
58- where
59- SublibDump { packageName = libParentPackageName } = sublibDump
54+ -- | Type synonym representing dump information for a single installed package
55+ -- in the global package database.
56+ type DumpedGlobalPackage = DumpPackage
57+
58+ -- | If the given 'DumpPackage' is for a sub-library of a Cabal package, yields
59+ -- the package identifier of the Cabal package.
60+ sublibParentPkgId :: DumpPackage -> Maybe PackageIdentifier
61+ sublibParentPkgId dp = dp. sublib <&> \ subLibDump ->
62+ PackageIdentifier subLibDump. packageName dp. packageIdent. pkgVersion
0 commit comments