refactoring only: use the parameterised InstalledPackageInfo
[ghc-hetmet.git] / compiler / main / PackageConfig.hs
1 --
2 -- (c) The University of Glasgow, 2004
3 --
4
5 module PackageConfig (
6         -- * PackageId
7         mkPackageId, packageConfigId, unpackPackageId,
8         
9         -- * The PackageConfig type: information about a package
10         PackageConfig,
11         InstalledPackageInfo_(..), showPackageId,
12         Version(..),
13         PackageIdentifier(..),
14         defaultPackageConfig,
15   ) where
16
17 #include "HsVersions.h"
18
19 import Module 
20 import Distribution.InstalledPackageInfo
21 import Distribution.Package
22 import Distribution.Version
23 import Distribution.Compat.ReadP ( readP_to_S )
24
25 -- warning suppression
26 _unused :: FS.FastString
27 _unused = FSLIT("")
28
29 -- -----------------------------------------------------------------------------
30 -- Our PackageConfig type is just InstalledPackageInfo from Cabal.  Later we
31 -- might need to extend it with some GHC-specific stuff, but for now it's fine.
32
33 type PackageConfig = InstalledPackageInfo_ ModuleName
34 defaultPackageConfig :: PackageConfig
35 defaultPackageConfig = emptyInstalledPackageInfo
36
37 -- -----------------------------------------------------------------------------
38 -- PackageId (package names with versions)
39
40 -- Mostly the compiler deals in terms of PackageNames, which don't
41 -- have the version suffix.  This is so that we don't need to know the
42 -- version for the -package-name flag, or know the versions of
43 -- wired-in packages like base & rts.  Versions are confined to the
44 -- package sub-system.
45 --
46 -- This means that in theory you could have multiple base packages installed
47 -- (for example), and switch between them using -package/-hide-package.
48 --
49 -- A PackageId is a string of the form <pkg>-<version>.
50
51 mkPackageId :: PackageIdentifier -> PackageId
52 mkPackageId = stringToPackageId . showPackageId
53
54 packageConfigId :: PackageConfig -> PackageId
55 packageConfigId = mkPackageId . package
56
57 unpackPackageId :: PackageId -> Maybe PackageIdentifier
58 unpackPackageId p
59   = case [ pid | (pid,"") <- readP_to_S parsePackageId str ] of
60         []      -> Nothing
61         (pid:_) -> Just pid
62   where str = packageIdString p