2 -- (c) The University of Glasgow, 2004
8 mkPackageId, stringToPackageId, packageIdString, packageConfigId,
9 packageIdFS, fsToPackageId, unpackPackageId,
11 -- * The PackageConfig type: information about a package
13 InstalledPackageInfo(..), showPackageId,
15 PackageIdentifier(..),
18 -- * Wired-in PackageIds
26 #include "HsVersions.h"
28 import Distribution.InstalledPackageInfo
29 import Distribution.Package
30 import Distribution.Version
32 import Distribution.Compat.ReadP ( readP_to_S )
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.
38 type PackageConfig = InstalledPackageInfo
39 defaultPackageConfig = emptyInstalledPackageInfo
41 -- -----------------------------------------------------------------------------
42 -- PackageId (package names with versions)
44 -- Mostly the compiler deals in terms of PackageNames, which don't
45 -- have the version suffix. This is so that we don't need to know the
46 -- version for the -package-name flag, or know the versions of
47 -- wired-in packages like base & rts. Versions are confined to the
48 -- package sub-system.
50 -- This means that in theory you could have multiple base packages installed
51 -- (for example), and switch between them using -package/-hide-package.
53 -- A PackageId is a string of the form <pkg>-<version>.
55 newtype PackageId = PId FastString deriving( Eq, Ord ) -- includes the version
56 -- easier not to use a newtype here, because we need instances of
57 -- Binary & Outputable, and we're too early to define them
59 fsToPackageId :: FastString -> PackageId
62 packageIdFS :: PackageId -> FastString
63 packageIdFS (PId fs) = fs
65 stringToPackageId :: String -> PackageId
66 stringToPackageId = fsToPackageId . mkFastString
68 packageIdString :: PackageId -> String
69 packageIdString = unpackFS . packageIdFS
71 mkPackageId :: PackageIdentifier -> PackageId
72 mkPackageId = stringToPackageId . showPackageId
74 packageConfigId :: PackageConfig -> PackageId
75 packageConfigId = mkPackageId . package
77 unpackPackageId :: PackageId -> Maybe PackageIdentifier
79 = case [ pid | (pid,"") <- readP_to_S parsePackageId str ] of
82 where str = packageIdString p
84 -- -----------------------------------------------------------------------------
85 -- Package Ids that are wired in
87 -- Certain packages are "known" to the compiler, in that we know about certain
88 -- entities that reside in these packages, and the compiler needs to
89 -- declare static Modules and Names that refer to these packages. Hence
90 -- the wired-in packages can't include version numbers, since we don't want
91 -- to bake the version numbers of these packages into GHC.
93 -- So here's the plan. Wired-in packages are still versioned as
94 -- normal in the packages database, and you can still have multiple
95 -- versions of them installed. However, for each invocation of GHC,
96 -- only a single instance of each wired-in package will be recognised
97 -- (the desired one is selected via -package/-hide-package), and GHC
98 -- will use the unversioned PackageId below when referring to it,
99 -- including in .hi files and object file symbols. Unselected
100 -- versions of wired-in packages will be ignored, as will any other
101 -- package that depends directly or indirectly on it (much as if you
102 -- had used -ignore-package).
104 basePackageId = fsToPackageId FSLIT("base")
105 rtsPackageId = fsToPackageId FSLIT("rts")
106 haskell98PackageId = fsToPackageId FSLIT("haskell98")
107 thPackageId = fsToPackageId FSLIT("template-haskell")
109 -- This is the package Id for the program. It is the default package
110 -- Id if you don't specify a package name. We don't add this prefix
111 -- to symbol name, since there can be only one main package per program.
112 mainPackageId = fsToPackageId FSLIT("main")