2 -- (c) The University of Glasgow, 2004
6 -- The above warning supression flag is a temporary kludge.
7 -- While working on this module you are encouraged to remove it and fix
8 -- any warnings in the module. See
9 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
12 module PackageConfig (
15 mkPackageId, stringToPackageId, packageIdString, packageConfigId,
16 packageIdFS, fsToPackageId, unpackPackageId,
18 -- * The PackageConfig type: information about a package
20 InstalledPackageInfo(..), showPackageId,
22 PackageIdentifier(..),
25 -- * Wired-in PackageIds
34 #include "HsVersions.h"
36 import Distribution.InstalledPackageInfo
37 import Distribution.Package
38 import Distribution.Version
40 import Distribution.Compat.ReadP ( readP_to_S )
42 -- -----------------------------------------------------------------------------
43 -- Our PackageConfig type is just InstalledPackageInfo from Cabal. Later we
44 -- might need to extend it with some GHC-specific stuff, but for now it's fine.
46 type PackageConfig = InstalledPackageInfo
47 defaultPackageConfig = emptyInstalledPackageInfo
49 -- -----------------------------------------------------------------------------
50 -- PackageId (package names with versions)
52 -- Mostly the compiler deals in terms of PackageNames, which don't
53 -- have the version suffix. This is so that we don't need to know the
54 -- version for the -package-name flag, or know the versions of
55 -- wired-in packages like base & rts. Versions are confined to the
56 -- package sub-system.
58 -- This means that in theory you could have multiple base packages installed
59 -- (for example), and switch between them using -package/-hide-package.
61 -- A PackageId is a string of the form <pkg>-<version>.
63 newtype PackageId = PId FastString deriving( Eq, Ord ) -- includes the version
64 -- easier not to use a newtype here, because we need instances of
65 -- Binary & Outputable, and we're too early to define them
67 fsToPackageId :: FastString -> PackageId
70 packageIdFS :: PackageId -> FastString
71 packageIdFS (PId fs) = fs
73 stringToPackageId :: String -> PackageId
74 stringToPackageId = fsToPackageId . mkFastString
76 packageIdString :: PackageId -> String
77 packageIdString = unpackFS . packageIdFS
79 mkPackageId :: PackageIdentifier -> PackageId
80 mkPackageId = stringToPackageId . showPackageId
82 packageConfigId :: PackageConfig -> PackageId
83 packageConfigId = mkPackageId . package
85 unpackPackageId :: PackageId -> Maybe PackageIdentifier
87 = case [ pid | (pid,"") <- readP_to_S parsePackageId str ] of
90 where str = packageIdString p
92 -- -----------------------------------------------------------------------------
93 -- Package Ids that are wired in
95 -- Certain packages are "known" to the compiler, in that we know about certain
96 -- entities that reside in these packages, and the compiler needs to
97 -- declare static Modules and Names that refer to these packages. Hence
98 -- the wired-in packages can't include version numbers, since we don't want
99 -- to bake the version numbers of these packages into GHC.
101 -- So here's the plan. Wired-in packages are still versioned as
102 -- normal in the packages database, and you can still have multiple
103 -- versions of them installed. However, for each invocation of GHC,
104 -- only a single instance of each wired-in package will be recognised
105 -- (the desired one is selected via -package/-hide-package), and GHC
106 -- will use the unversioned PackageId below when referring to it,
107 -- including in .hi files and object file symbols. Unselected
108 -- versions of wired-in packages will be ignored, as will any other
109 -- package that depends directly or indirectly on it (much as if you
110 -- had used -ignore-package).
112 basePackageId = fsToPackageId FSLIT("base")
113 rtsPackageId = fsToPackageId FSLIT("rts")
114 haskell98PackageId = fsToPackageId FSLIT("haskell98")
115 thPackageId = fsToPackageId FSLIT("template-haskell")
116 ndpPackageId = fsToPackageId FSLIT("ndp")
118 -- This is the package Id for the program. It is the default package
119 -- Id if you don't specify a package name. We don't add this prefix
120 -- to symbol name, since there can be only one main package per program.
121 mainPackageId = fsToPackageId FSLIT("main")