[project @ 2004-11-30 16:05:15 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / PackageConfig.hs
1 --
2 -- (c) The University of Glasgow, 2004
3 --
4
5 module PackageConfig (
6         -- * PackageId
7         PackageId, 
8         mkPackageId, stringToPackageId, packageIdString, packageConfigId,
9         
10         -- * The PackageConfig type: information about a package
11         PackageConfig,
12         InstalledPackageInfo(..), showPackageId,
13         Version(..),
14         PackageIdentifier(..),
15         defaultPackageConfig
16   ) where
17
18 #include "HsVersions.h"
19
20 import Distribution.InstalledPackageInfo
21 import Distribution.Package
22 import Distribution.Version
23 import FastString
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
30 defaultPackageConfig = emptyInstalledPackageInfo
31
32 -- -----------------------------------------------------------------------------
33 -- PackageId (package names with versions)
34
35 -- Mostly the compiler deals in terms of PackageNames, which don't
36 -- have the version suffix.  This is so that we don't need to know the
37 -- version for the -package-name flag, or know the versions of
38 -- wired-in packages like base & rts.  Versions are confined to the
39 -- package sub-system.
40 --
41 -- This means that in theory you could have multiple base packages installed
42 -- (for example), and switch between them using -package/-hide-package.
43 --
44 -- A PackageId is a string of the form <pkg>-<version>.
45
46 type PackageId = FastString  -- includes the version
47         -- easier not to use a newtype here, because we need instances of
48         -- Binary & Outputable, and we're too early to define them
49
50 stringToPackageId :: String -> PackageId
51 stringToPackageId = mkFastString
52
53 mkPackageId :: PackageIdentifier -> PackageId
54 mkPackageId = stringToPackageId . showPackageId
55
56 packageConfigId :: PackageConfig -> PackageId
57 packageConfigId = mkPackageId . package
58
59 packageIdString :: PackageId -> String
60 packageIdString = unpackFS