80488ec05f5a331545031c1ee02c7dbf651fee86
[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 -- -----------------------------------------------------------------------------
26 -- Our PackageConfig type is just InstalledPackageInfo from Cabal.  Later we
27 -- might need to extend it with some GHC-specific stuff, but for now it's fine.
28
29 type PackageConfig = InstalledPackageInfo_ ModuleName
30 defaultPackageConfig :: PackageConfig
31 defaultPackageConfig = emptyInstalledPackageInfo
32
33 -- -----------------------------------------------------------------------------
34 -- PackageId (package names with versions)
35
36 -- Mostly the compiler deals in terms of PackageNames, which don't
37 -- have the version suffix.  This is so that we don't need to know the
38 -- version for the -package-name flag, or know the versions of
39 -- wired-in packages like base & rts.  Versions are confined to the
40 -- package sub-system.
41 --
42 -- This means that in theory you could have multiple base packages installed
43 -- (for example), and switch between them using -package/-hide-package.
44 --
45 -- A PackageId is a string of the form <pkg>-<version>.
46
47 mkPackageId :: PackageIdentifier -> PackageId
48 mkPackageId = stringToPackageId . showPackageId
49
50 packageConfigId :: PackageConfig -> PackageId
51 packageConfigId = mkPackageId . package
52
53 unpackPackageId :: PackageId -> Maybe PackageIdentifier
54 unpackPackageId p
55   = case [ pid | (pid,"") <- readP_to_S parsePackageId str ] of
56         []      -> Nothing
57         (pid:_) -> Just pid
58   where str = packageIdString p