Fix a bug to do with recursive modules in one-shot mode
[ghc-hetmet.git] / compiler / main / PackageConfig.hs
1 --
2 -- (c) The University of Glasgow, 2004
3 --
4
5 module PackageConfig (
6         -- * PackageId
7         mkPackageId, packageConfigId, unpackPackageId,
8         
9         -- * The PackageConfig type: information about a package
10         PackageConfig,
11         InstalledPackageInfo_(..), display,
12         Version(..),
13         PackageIdentifier(..),
14         defaultPackageConfig,
15   ) where
16
17 #include "HsVersions.h"
18
19 import Module
20 import Distribution.InstalledPackageInfo
21 import Distribution.Package
22 import Distribution.Text
23 import Distribution.Version
24 import Distribution.Compat.ReadP ( readP_to_S )
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_ ModuleName
31 defaultPackageConfig :: PackageConfig
32 defaultPackageConfig = emptyInstalledPackageInfo
33
34 -- -----------------------------------------------------------------------------
35 -- PackageId (package names with versions)
36
37 -- Mostly the compiler deals in terms of PackageNames, which don't
38 -- have the version suffix.  This is so that we don't need to know the
39 -- version for the -package-name flag, or know the versions of
40 -- wired-in packages like base & rts.  Versions are confined to the
41 -- package sub-system.
42 --
43 -- This means that in theory you could have multiple base packages installed
44 -- (for example), and switch between them using -package/-hide-package.
45 --
46 -- A PackageId is a string of the form <pkg>-<version>.
47
48 mkPackageId :: PackageIdentifier -> PackageId
49 mkPackageId = stringToPackageId . display
50
51 packageConfigId :: PackageConfig -> PackageId
52 packageConfigId = mkPackageId . package
53
54 unpackPackageId :: PackageId -> Maybe PackageIdentifier
55 unpackPackageId p
56   = case [ pid | (pid,"") <- readP_to_S parse str ] of
57         []      -> Nothing
58         (pid:_) -> Just pid
59   where str = packageIdString p