Reorganisation of the source tree
[ghc-hetmet.git] / 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         packageIdFS, fsToPackageId, 
10         
11         -- * The PackageConfig type: information about a package
12         PackageConfig,
13         InstalledPackageInfo(..), showPackageId,
14         Version(..),
15         PackageIdentifier(..),
16         defaultPackageConfig
17   ) where
18
19 #include "HsVersions.h"
20
21 import Distribution.InstalledPackageInfo
22 import Distribution.Package
23 import Distribution.Version
24 import FastString
25
26 -- -----------------------------------------------------------------------------
27 -- Our PackageConfig type is just InstalledPackageInfo from Cabal.  Later we
28 -- might need to extend it with some GHC-specific stuff, but for now it's fine.
29
30 type PackageConfig = InstalledPackageInfo
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 newtype PackageId = PId FastString deriving( Eq, Ord )  -- includes the version
48         -- easier not to use a newtype here, because we need instances of
49         -- Binary & Outputable, and we're too early to define them
50
51 fsToPackageId :: FastString -> PackageId
52 fsToPackageId = PId
53
54 packageIdFS :: PackageId -> FastString
55 packageIdFS (PId fs) = fs
56
57 stringToPackageId :: String -> PackageId
58 stringToPackageId = fsToPackageId . mkFastString
59
60 packageIdString :: PackageId -> String
61 packageIdString = unpackFS . packageIdFS
62
63 mkPackageId :: PackageIdentifier -> PackageId
64 mkPackageId = stringToPackageId . showPackageId
65
66 packageConfigId :: PackageConfig -> PackageId
67 packageConfigId = mkPackageId . package
68
69