fix haddock submodule pointer
[ghc-hetmet.git] / compiler / main / PackageConfig.hs
1 --
2 -- (c) The University of Glasgow, 2004
3 --
4
5 -- | Package configuration information: essentially the interface to Cabal, with some utilities
6 module PackageConfig (
7     -- $package_naming
8     
9         -- * PackageId
10         mkPackageId, packageConfigId,
11         
12         -- * The PackageConfig type: information about a package
13         PackageConfig,
14         InstalledPackageInfo_(..), display,
15         Version(..),
16         PackageIdentifier(..),
17         defaultPackageConfig,
18         packageConfigToInstalledPackageInfo,
19         installedPackageInfoToPackageConfig,
20   ) where
21
22 #include "HsVersions.h"
23
24 import Maybes
25 import Module
26 import Distribution.InstalledPackageInfo
27 import Distribution.ModuleName
28 import Distribution.Package hiding (PackageId)
29 import Distribution.Text
30 import Distribution.Version
31
32 -- -----------------------------------------------------------------------------
33 -- Our PackageConfig type is just InstalledPackageInfo from Cabal.  Later we
34 -- might need to extend it with some GHC-specific stuff, but for now it's fine.
35
36 type PackageConfig = InstalledPackageInfo_ Module.ModuleName
37 defaultPackageConfig :: PackageConfig
38 defaultPackageConfig = emptyInstalledPackageInfo
39
40 -- -----------------------------------------------------------------------------
41 -- PackageId (package names with versions)
42
43 -- $package_naming
44 -- #package_naming#
45 -- Mostly the compiler deals in terms of 'PackageName's, which don't
46 -- have the version suffix.  This is so that we don't need to know the
47 -- version for the @-package-name@ flag, or know the versions of
48 -- wired-in packages like @base@ & @rts@.  Versions are confined to the
49 -- package sub-system.
50 --
51 -- This means that in theory you could have multiple base packages installed
52 -- (for example), and switch between them using @-package@\/@-hide-package@.
53 --
54 -- A 'PackageId' is a string of the form @<pkg>-<version>@.
55
56 -- | Turn a Cabal 'PackageIdentifier' into a GHC 'PackageId'
57 mkPackageId :: PackageIdentifier -> PackageId
58 mkPackageId = stringToPackageId . display
59
60 -- | Get the GHC 'PackageId' right out of a Cabalish 'PackageConfig'
61 packageConfigId :: PackageConfig -> PackageId
62 packageConfigId = mkPackageId . sourcePackageId
63
64 -- | Turn a 'PackageConfig', which contains GHC 'Module.ModuleName's into a Cabal specific
65 -- 'InstalledPackageInfo' which contains Cabal 'Distribution.ModuleName.ModuleName's
66 packageConfigToInstalledPackageInfo :: PackageConfig -> InstalledPackageInfo
67 packageConfigToInstalledPackageInfo
68     (pkgconf@(InstalledPackageInfo { exposedModules = e,
69                                      hiddenModules = h })) =
70         pkgconf{ exposedModules = map convert e,
71                  hiddenModules  = map convert h }
72     where convert :: Module.ModuleName -> Distribution.ModuleName.ModuleName
73           convert = (expectJust "packageConfigToInstalledPackageInfo") . simpleParse . moduleNameString
74
75 -- | Turn an 'InstalledPackageInfo', which contains Cabal 'Distribution.ModuleName.ModuleName's
76 -- into a GHC specific 'PackageConfig' which contains GHC 'Module.ModuleName's
77 installedPackageInfoToPackageConfig :: InstalledPackageInfo_ String -> PackageConfig
78 installedPackageInfoToPackageConfig
79     (pkgconf@(InstalledPackageInfo { exposedModules = e,
80                                      hiddenModules = h })) =
81         pkgconf{ exposedModules = map mkModuleName e,
82                  hiddenModules  = map mkModuleName h }