2 -- (c) The University of Glasgow, 2004
7 mkPackageId, packageConfigId, unpackPackageId,
9 -- * The PackageConfig type: information about a package
11 InstalledPackageInfo_(..), display,
13 PackageIdentifier(..),
15 packageConfigToInstalledPackageInfo,
16 installedPackageInfoToPackageConfig,
19 #include "HsVersions.h"
23 import Distribution.InstalledPackageInfo
24 import Distribution.ModuleName
25 import Distribution.Package
26 import Distribution.Text
27 import Distribution.Version
28 import Distribution.Compat.ReadP
30 -- -----------------------------------------------------------------------------
31 -- Our PackageConfig type is just InstalledPackageInfo from Cabal. Later we
32 -- might need to extend it with some GHC-specific stuff, but for now it's fine.
34 type PackageConfig = InstalledPackageInfo_ Module.ModuleName
35 defaultPackageConfig :: PackageConfig
36 defaultPackageConfig = emptyInstalledPackageInfo
38 -- -----------------------------------------------------------------------------
39 -- PackageId (package names with versions)
41 -- Mostly the compiler deals in terms of PackageNames, which don't
42 -- have the version suffix. This is so that we don't need to know the
43 -- version for the -package-name flag, or know the versions of
44 -- wired-in packages like base & rts. Versions are confined to the
45 -- package sub-system.
47 -- This means that in theory you could have multiple base packages installed
48 -- (for example), and switch between them using -package/-hide-package.
50 -- A PackageId is a string of the form <pkg>-<version>.
52 mkPackageId :: PackageIdentifier -> PackageId
53 mkPackageId = stringToPackageId . display
55 packageConfigId :: PackageConfig -> PackageId
56 packageConfigId = mkPackageId . package
58 unpackPackageId :: PackageId -> Maybe PackageIdentifier
60 = case [ pid | (pid,"") <- readP_to_S parse str ] of
63 where str = packageIdString p
65 packageConfigToInstalledPackageInfo :: PackageConfig -> InstalledPackageInfo
66 packageConfigToInstalledPackageInfo
67 (pkgconf@(InstalledPackageInfo { exposedModules = e,
68 hiddenModules = h })) =
69 pkgconf{ exposedModules = map convert e,
70 hiddenModules = map convert h }
71 where convert :: Module.ModuleName -> Distribution.ModuleName.ModuleName
72 convert = fromJust . simpleParse . moduleNameString
74 installedPackageInfoToPackageConfig :: InstalledPackageInfo -> PackageConfig
75 installedPackageInfoToPackageConfig
76 (pkgconf@(InstalledPackageInfo { exposedModules = e,
77 hiddenModules = h })) =
78 pkgconf{ exposedModules = map convert e,
79 hiddenModules = map convert h }
80 where convert :: Distribution.ModuleName.ModuleName -> Module.ModuleName
81 convert = mkModuleName . display