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
27 #include "HsVersions.h"
29 import Distribution.InstalledPackageInfo
30 import Distribution.Package
31 import Distribution.Version
33 import Distribution.Compat.ReadP ( readP_to_S )
35 -- -----------------------------------------------------------------------------
36 -- Our PackageConfig type is just InstalledPackageInfo from Cabal. Later we
37 -- might need to extend it with some GHC-specific stuff, but for now it's fine.
39 type PackageConfig = InstalledPackageInfo
40 defaultPackageConfig = emptyInstalledPackageInfo
42 -- -----------------------------------------------------------------------------
43 -- PackageId (package names with versions)
45 -- Mostly the compiler deals in terms of PackageNames, which don't
46 -- have the version suffix. This is so that we don't need to know the
47 -- version for the -package-name flag, or know the versions of
48 -- wired-in packages like base & rts. Versions are confined to the
49 -- package sub-system.
51 -- This means that in theory you could have multiple base packages installed
52 -- (for example), and switch between them using -package/-hide-package.
54 -- A PackageId is a string of the form <pkg>-<version>.
56 newtype PackageId = PId FastString deriving( Eq, Ord ) -- includes the version
57 -- easier not to use a newtype here, because we need instances of
58 -- Binary & Outputable, and we're too early to define them
60 fsToPackageId :: FastString -> PackageId
63 packageIdFS :: PackageId -> FastString
64 packageIdFS (PId fs) = fs
66 stringToPackageId :: String -> PackageId
67 stringToPackageId = fsToPackageId . mkFastString
69 packageIdString :: PackageId -> String
70 packageIdString = unpackFS . packageIdFS
72 mkPackageId :: PackageIdentifier -> PackageId
73 mkPackageId = stringToPackageId . showPackageId
75 packageConfigId :: PackageConfig -> PackageId
76 packageConfigId = mkPackageId . package
78 unpackPackageId :: PackageId -> Maybe PackageIdentifier
80 = case [ pid | (pid,"") <- readP_to_S parsePackageId str ] of
83 where str = packageIdString p
85 -- -----------------------------------------------------------------------------
86 -- Package Ids that are wired in
88 -- Certain packages are "known" to the compiler, in that we know about certain
89 -- entities that reside in these packages, and the compiler needs to
90 -- declare static Modules and Names that refer to these packages. Hence
91 -- the wired-in packages can't include version numbers, since we don't want
92 -- to bake the version numbers of these packages into GHC.
94 -- So here's the plan. Wired-in packages are still versioned as
95 -- normal in the packages database, and you can still have multiple
96 -- versions of them installed. However, for each invocation of GHC,
97 -- only a single instance of each wired-in package will be recognised
98 -- (the desired one is selected via -package/-hide-package), and GHC
99 -- will use the unversioned PackageId below when referring to it,
100 -- including in .hi files and object file symbols. Unselected
101 -- versions of wired-in packages will be ignored, as will any other
102 -- package that depends directly or indirectly on it (much as if you
103 -- had used -ignore-package).
105 basePackageId = fsToPackageId FSLIT("base")
106 rtsPackageId = fsToPackageId FSLIT("rts")
107 haskell98PackageId = fsToPackageId FSLIT("haskell98")
108 thPackageId = fsToPackageId FSLIT("template-haskell")
109 ndpPackageId = fsToPackageId FSLIT("ndp")
111 -- This is the package Id for the program. It is the default package
112 -- Id if you don't specify a package name. We don't add this prefix
113 -- to symbol name, since there can be only one main package per program.
114 mainPackageId = fsToPackageId FSLIT("main")