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