Module reexports, fixing #8407.
[ghc.git] / compiler / main / PackageConfig.hs
1 {-# LANGUAGE CPP #-}
2
3 -- |
4 -- Package configuration information: essentially the interface to Cabal, with
5 -- some utilities
6 --
7 -- (c) The University of Glasgow, 2004
8 --
9 module PackageConfig (
10 -- $package_naming
11
12 -- * PackageKey
13 mkPackageKey, packageConfigId,
14
15 -- * The PackageConfig type: information about a package
16 PackageConfig,
17 InstalledPackageInfo_(..), display,
18 Version(..),
19 PackageIdentifier(..),
20 defaultPackageConfig,
21 packageConfigToInstalledPackageInfo,
22 installedPackageInfoToPackageConfig
23 ) where
24
25 #include "HsVersions.h"
26
27 import Distribution.InstalledPackageInfo
28 import Distribution.ModuleName
29 import Distribution.Package
30 import Distribution.Text
31 import Distribution.Version
32
33 import Maybes
34 import Module
35
36 -- -----------------------------------------------------------------------------
37 -- Our PackageConfig type is just InstalledPackageInfo from Cabal. Later we
38 -- might need to extend it with some GHC-specific stuff, but for now it's fine.
39
40 type PackageConfig = InstalledPackageInfo_ Module.ModuleName
41
42 defaultPackageConfig :: PackageConfig
43 defaultPackageConfig = emptyInstalledPackageInfo
44
45 -- -----------------------------------------------------------------------------
46 -- PackageKey (package names with versions)
47
48 -- $package_naming
49 -- #package_naming#
50 -- Mostly the compiler deals in terms of 'PackageKey's, which have the
51 -- form @<pkg>-<version>@. You're expected to pass in the version for
52 -- the @-package-name@ flag. However, for wired-in packages like @base@
53 -- & @rts@, we don't necessarily know what the version is, so these are
54 -- handled specially; see #wired_in_packages#.
55
56 -- | Turn a Cabal 'PackageIdentifier' into a GHC 'PackageKey'
57 mkPackageKey :: PackageIdentifier -> PackageKey
58 mkPackageKey = stringToPackageKey . display
59
60 -- | Get the GHC 'PackageKey' right out of a Cabalish 'PackageConfig'
61 packageConfigId :: PackageConfig -> PackageKey
62 packageConfigId = mkPackageKey . 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 reexportedModules = r,
70 hiddenModules = h })) =
71 pkgconf{ exposedModules = map convert e,
72 reexportedModules = map (fmap convert) r,
73 hiddenModules = map convert h }
74 where convert :: Module.ModuleName -> Distribution.ModuleName.ModuleName
75 convert = (expectJust "packageConfigToInstalledPackageInfo") . simpleParse . moduleNameString
76
77 -- | Turn an 'InstalledPackageInfo', which contains Cabal 'Distribution.ModuleName.ModuleName's
78 -- into a GHC specific 'PackageConfig' which contains GHC 'Module.ModuleName's
79 installedPackageInfoToPackageConfig :: InstalledPackageInfo_ String -> PackageConfig
80 installedPackageInfoToPackageConfig
81 (pkgconf@(InstalledPackageInfo { exposedModules = e,
82 reexportedModules = r,
83 hiddenModules = h })) =
84 pkgconf{ exposedModules = map mkModuleName e,
85 reexportedModules = map (fmap mkModuleName) r,
86 hiddenModules = map mkModuleName h }
87