Skip to content

Commit ecd4760

Browse files
committed
Merge pull request #3047 from ezyang/cabal-ghcup
Distinguish between component ID and unit ID.
2 parents 8787fa8 + fb629e3 commit ecd4760

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+471
-683
lines changed

Cabal/Cabal.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ library
275275
Distribution.GetOpt
276276
Distribution.Lex
277277
Distribution.Simple.GHC.Internal
278-
Distribution.Simple.GHC.IPI641
279278
Distribution.Simple.GHC.IPI642
280279
Distribution.Simple.GHC.IPIConvert
281280
Distribution.Simple.GHC.ImplInfo

Cabal/Distribution/InstalledPackageInfo.hs

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
module Distribution.InstalledPackageInfo (
3030
InstalledPackageInfo(..),
31+
installedComponentId,
3132
OriginalModule(..), ExposedModule(..),
3233
ParseResult(..), PError(..), PWarning,
3334
emptyInstalledPackageInfo,
@@ -40,7 +41,7 @@ module Distribution.InstalledPackageInfo (
4041

4142
import Distribution.ParseUtils
4243
import Distribution.License
43-
import Distribution.Package hiding (installedComponentId)
44+
import Distribution.Package hiding (installedUnitId)
4445
import qualified Distribution.Package as Package
4546
import Distribution.ModuleName
4647
import Distribution.Version
@@ -60,9 +61,9 @@ import GHC.Generics (Generic)
6061
data InstalledPackageInfo
6162
= InstalledPackageInfo {
6263
-- these parts are exactly the same as PackageDescription
63-
sourcePackageId :: PackageId,
64-
installedComponentId:: ComponentId,
65-
compatPackageKey :: ComponentId,
64+
sourcePackageId :: PackageId,
65+
installedUnitId :: UnitId,
66+
compatPackageKey :: String,
6667
license :: License,
6768
copyright :: String,
6869
maintainer :: String,
@@ -77,7 +78,6 @@ data InstalledPackageInfo
7778
abiHash :: AbiHash,
7879
exposed :: Bool,
7980
exposedModules :: [ExposedModule],
80-
installedInstantiatedWith :: [(ModuleName, OriginalModule)],
8181
hiddenModules :: [ModuleName],
8282
trusted :: Bool,
8383
importDirs :: [FilePath],
@@ -88,7 +88,7 @@ data InstalledPackageInfo
8888
extraGHCiLibraries:: [String], -- overrides extraLibraries for GHCi
8989
includeDirs :: [FilePath],
9090
includes :: [String],
91-
depends :: [ComponentId],
91+
depends :: [UnitId],
9292
ccOptions :: [String],
9393
ldOptions :: [String],
9494
frameworkDirs :: [FilePath],
@@ -99,23 +99,27 @@ data InstalledPackageInfo
9999
}
100100
deriving (Eq, Generic, Read, Show)
101101

102+
installedComponentId :: InstalledPackageInfo -> ComponentId
103+
installedComponentId ipi = case installedUnitId ipi of
104+
SimpleUnitId cid -> cid
105+
102106
instance Binary InstalledPackageInfo
103107

104108
instance Package.Package InstalledPackageInfo where
105109
packageId = sourcePackageId
106110

107-
instance Package.HasComponentId InstalledPackageInfo where
108-
installedComponentId = installedComponentId
111+
instance Package.HasUnitId InstalledPackageInfo where
112+
installedUnitId = installedUnitId
109113

110114
instance Package.PackageInstalled InstalledPackageInfo where
111115
installedDepends = depends
112116

113117
emptyInstalledPackageInfo :: InstalledPackageInfo
114118
emptyInstalledPackageInfo
115119
= InstalledPackageInfo {
116-
sourcePackageId = PackageIdentifier (PackageName "") (Version [] []),
117-
installedComponentId = ComponentId "",
118-
compatPackageKey = ComponentId "",
120+
sourcePackageId = PackageIdentifier (PackageName "") (Version [] []),
121+
installedUnitId = mkUnitId "",
122+
compatPackageKey = "",
119123
license = UnspecifiedLicense,
120124
copyright = "",
121125
maintainer = "",
@@ -130,7 +134,6 @@ emptyInstalledPackageInfo
130134
exposed = False,
131135
exposedModules = [],
132136
hiddenModules = [],
133-
installedInstantiatedWith = [],
134137
trusted = False,
135138
importDirs = [],
136139
libraryDirs = [],
@@ -155,16 +158,15 @@ emptyInstalledPackageInfo
155158

156159
data OriginalModule
157160
= OriginalModule {
158-
originalPackageId :: ComponentId,
161+
originalPackageId :: UnitId,
159162
originalModuleName :: ModuleName
160163
}
161164
deriving (Generic, Eq, Read, Show)
162165

163166
data ExposedModule
164167
= ExposedModule {
165168
exposedName :: ModuleName,
166-
exposedReexport :: Maybe OriginalModule,
167-
exposedSignature :: Maybe OriginalModule -- This field is unused for now.
169+
exposedReexport :: Maybe OriginalModule
168170
}
169171
deriving (Eq, Generic, Read, Show)
170172

@@ -178,14 +180,11 @@ instance Text OriginalModule where
178180
return (OriginalModule ipi m)
179181

180182
instance Text ExposedModule where
181-
disp (ExposedModule m reexport signature) =
183+
disp (ExposedModule m reexport) =
182184
Disp.sep [ disp m
183185
, case reexport of
184186
Just m' -> Disp.sep [Disp.text "from", disp m']
185187
Nothing -> Disp.empty
186-
, case signature of
187-
Just m' -> Disp.sep [Disp.text "is", disp m']
188-
Nothing -> Disp.empty
189188
]
190189
parse = do
191190
m <- parseModuleNameQ
@@ -194,12 +193,7 @@ instance Text ExposedModule where
194193
_ <- Parse.string "from"
195194
Parse.skipSpaces
196195
fmap Just parse
197-
Parse.skipSpaces
198-
signature <- Parse.option Nothing $ do
199-
_ <- Parse.string "is"
200-
Parse.skipSpaces
201-
fmap Just parse
202-
return (ExposedModule m reexport signature)
196+
return (ExposedModule m reexport)
203197

204198

205199
instance Binary OriginalModule
@@ -215,7 +209,7 @@ showExposedModules :: [ExposedModule] -> Disp.Doc
215209
showExposedModules xs
216210
| all isExposedModule xs = fsep (map disp xs)
217211
| otherwise = fsep (Disp.punctuate comma (map disp xs))
218-
where isExposedModule (ExposedModule _ Nothing Nothing) = True
212+
where isExposedModule (ExposedModule _ Nothing) = True
219213
isExposedModule _ = False
220214

221215
parseExposedModules :: Parse.ReadP r [ExposedModule]
@@ -229,14 +223,6 @@ parseInstalledPackageInfo =
229223
parseFieldsFlat (fieldsInstalledPackageInfo ++ deprecatedFieldDescrs)
230224
emptyInstalledPackageInfo
231225

232-
parseInstantiatedWith :: Parse.ReadP r (ModuleName, OriginalModule)
233-
parseInstantiatedWith = do k <- parse
234-
_ <- Parse.char '='
235-
n <- parse
236-
_ <- Parse.char '@'
237-
p <- parse
238-
return (k, OriginalModule p n)
239-
240226
-- -----------------------------------------------------------------------------
241227
-- Pretty-printing
242228

@@ -249,9 +235,6 @@ showInstalledPackageInfoField = showSingleNamedField fieldsInstalledPackageInfo
249235
showSimpleInstalledPackageInfoField :: String -> Maybe (InstalledPackageInfo -> String)
250236
showSimpleInstalledPackageInfoField = showSimpleSingleNamedField fieldsInstalledPackageInfo
251237

252-
showInstantiatedWith :: (ModuleName, OriginalModule) -> Doc
253-
showInstantiatedWith (k, OriginalModule p m) = disp k <> text "=" <> disp m <> text "@" <> disp p
254-
255238
-- -----------------------------------------------------------------------------
256239
-- Description of the fields, for parsing/printing
257240

@@ -268,9 +251,10 @@ basicFieldDescrs =
268251
packageVersion (\ver pkg -> pkg{sourcePackageId=(sourcePackageId pkg){pkgVersion=ver}})
269252
, simpleField "id"
270253
disp parse
271-
installedComponentId (\pk pkg -> pkg{installedComponentId=pk})
254+
installedUnitId (\pk pkg -> pkg{installedUnitId=pk})
255+
-- NB: parse these as component IDs
272256
, simpleField "key"
273-
disp parse
257+
(disp . ComponentId) (fmap (\(ComponentId s) -> s) parse)
274258
compatPackageKey (\pk pkg -> pkg{compatPackageKey=pk})
275259
, simpleField "license"
276260
disp parseLicenseQ
@@ -317,9 +301,6 @@ installedFieldDescrs = [
317301
, simpleField "abi"
318302
disp parse
319303
abiHash (\abi pkg -> pkg{abiHash=abi})
320-
, listField "instantiated-with"
321-
showInstantiatedWith parseInstantiatedWith
322-
installedInstantiatedWith (\xs pkg -> pkg{installedInstantiatedWith=xs})
323304
, boolField "trusted"
324305
trusted (\val pkg -> pkg{trusted=val})
325306
, listField "import-dirs"

Cabal/Distribution/Package.hs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE DeriveDataTypeable #-}
22
{-# LANGUAGE DeriveGeneric #-}
3+
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
34

45
-----------------------------------------------------------------------------
56
-- |
@@ -23,6 +24,9 @@ module Distribution.Package (
2324

2425
-- * Package keys/installed package IDs (used for linker symbols)
2526
ComponentId(..),
27+
UnitId(..),
28+
mkUnitId,
29+
mkLegacyUnitId,
2630
getHSLibraryName,
2731
InstalledPackageId, -- backwards compat
2832

@@ -37,7 +41,7 @@ module Distribution.Package (
3741

3842
-- * Package classes
3943
Package(..), packageName, packageVersion,
40-
HasComponentId(..),
44+
HasUnitId(..),
4145
PackageInstalled(..),
4246
) where
4347

@@ -132,8 +136,21 @@ instance NFData ComponentId where
132136
rnf (ComponentId pk) = rnf pk
133137

134138
-- | Returns library name prefixed with HS, suitable for filenames
135-
getHSLibraryName :: ComponentId -> String
136-
getHSLibraryName (ComponentId s) = "HS" ++ s
139+
getHSLibraryName :: UnitId -> String
140+
getHSLibraryName (SimpleUnitId (ComponentId s)) = "HS" ++ s
141+
142+
-- | For now, there is no distinction between component IDs
143+
-- and unit IDs in Cabal.
144+
newtype UnitId = SimpleUnitId ComponentId
145+
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data, Binary, Text, NFData)
146+
147+
-- | Makes a simple-style UnitId from a string.
148+
mkUnitId :: String -> UnitId
149+
mkUnitId = SimpleUnitId . ComponentId
150+
151+
-- | Make an old-style UnitId from a package identifier
152+
mkLegacyUnitId :: PackageId -> UnitId
153+
mkLegacyUnitId = SimpleUnitId . ComponentId . display
137154

138155
-- ------------------------------------------------------------
139156
-- * Package source dependencies
@@ -194,17 +211,17 @@ instance Package PackageIdentifier where
194211
packageId = id
195212

196213
-- | Packages that have an installed package ID
197-
class Package pkg => HasComponentId pkg where
198-
installedComponentId :: pkg -> ComponentId
214+
class Package pkg => HasUnitId pkg where
215+
installedUnitId :: pkg -> UnitId
199216

200217
-- | Class of installed packages.
201218
--
202219
-- The primary data type which is an instance of this package is
203220
-- 'InstalledPackageInfo', but when we are doing install plans in Cabal install
204221
-- we may have other, installed package-like things which contain more metadata.
205222
-- Installed packages have exact dependencies 'installedDepends'.
206-
class (HasComponentId pkg) => PackageInstalled pkg where
207-
installedDepends :: pkg -> [ComponentId]
223+
class (HasUnitId pkg) => PackageInstalled pkg where
224+
installedDepends :: pkg -> [UnitId]
208225

209226
-- -----------------------------------------------------------------------------
210227
-- ABI hash

Cabal/Distribution/Simple/Bench.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@ benchOption pkg_descr lbi bm template =
118118
fromPathTemplate $ substPathTemplate env template
119119
where
120120
env = initialPathTemplateEnv
121-
(PD.package pkg_descr) (LBI.localComponentId lbi)
121+
(PD.package pkg_descr) (LBI.localUnitId lbi)
122122
(compilerInfo $ LBI.compiler lbi) (LBI.hostPlatform lbi) ++
123123
[(BenchmarkNameVar, toPathTemplate $ PD.benchmarkName bm)]

Cabal/Distribution/Simple/Build.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,19 +381,22 @@ testSuiteLibV09AsLibAndExe pkg_descr
381381
libExposed = True,
382382
libBuildInfo = bi
383383
}
384+
-- NB: temporary hack; I have a refactor which solves this
384385
cid = computeComponentId (package pkg_descr)
385386
(CTestName (testName test))
386-
(map fst (componentPackageDeps clbi))
387+
(map ((\(SimpleUnitId cid0) -> cid0) . fst)
388+
(componentPackageDeps clbi))
387389
(flagAssignment lbi)
390+
uid = SimpleUnitId cid
388391
(pkg_name, compat_key) = computeCompatPackageKey
389392
(compiler lbi) (package pkg_descr)
390-
(CTestName (testName test)) cid
393+
(CTestName (testName test)) uid
391394
libClbi = LibComponentLocalBuildInfo
392395
{ componentPackageDeps = componentPackageDeps clbi
393396
, componentPackageRenaming = componentPackageRenaming clbi
394-
, componentId = cid
397+
, componentUnitId = uid
395398
, componentCompatPackageKey = compat_key
396-
, componentExposedModules = [IPI.ExposedModule m Nothing Nothing]
399+
, componentExposedModules = [IPI.ExposedModule m Nothing]
397400
}
398401
pkg = pkg_descr {
399402
package = (package pkg_descr) { pkgName = pkg_name }
@@ -420,7 +423,7 @@ testSuiteLibV09AsLibAndExe pkg_descr
420423
-- that exposes the relevant test suite library.
421424
exeClbi = ExeComponentLocalBuildInfo {
422425
componentPackageDeps =
423-
(IPI.installedComponentId ipi, packageId ipi)
426+
(IPI.installedUnitId ipi, packageId ipi)
424427
: (filter (\(_, x) -> let PackageName name = pkgName x
425428
in name == "Cabal" || name == "base")
426429
(componentPackageDeps clbi)),

Cabal/Distribution/Simple/Build/Macros.hs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ import Distribution.Version
3030
( Version(versionBranch) )
3131
import Distribution.PackageDescription
3232
( PackageDescription )
33-
import Distribution.Simple.Compiler
34-
( packageKeySupported )
3533
import Distribution.Simple.LocalBuildInfo
36-
( LocalBuildInfo(compiler, withPrograms), externalPackageDeps, localComponentId )
34+
( LocalBuildInfo(withPrograms), externalPackageDeps, localComponentId, localCompatPackageKey )
3735
import Distribution.Simple.Program.Db
3836
( configuredPrograms )
3937
import Distribution.Simple.Program.Types
@@ -96,14 +94,14 @@ generateMacros prefix name version =
9694
where
9795
(major1:major2:minor:_) = map show (versionBranch version ++ repeat 0)
9896

99-
-- | Generate the @CURRENT_PACKAGE_KEY@ definition for the package key
100-
-- of the current package, if supported by the compiler.
101-
-- NB: this only makes sense for definite packages.
97+
-- | Generate the @CURRENT_COMPONENT_ID@ definition for the component ID
98+
-- of the current package.
10299
generateComponentIdMacro :: LocalBuildInfo -> String
103-
generateComponentIdMacro lbi
104-
| packageKeySupported (compiler lbi) =
105-
"#define CURRENT_PACKAGE_KEY \"" ++ display (localComponentId lbi) ++ "\"\n\n"
106-
| otherwise = ""
100+
generateComponentIdMacro lbi =
101+
concat
102+
[ "#define CURRENT_COMPONENT_ID \"" ++ display (localComponentId lbi) ++ "\"\n\n"
103+
, "#define CURRENT_PACKAGE_KEY \"" ++ localCompatPackageKey lbi ++ "\"\n\n"
104+
]
107105

108106
fixchar :: Char -> Char
109107
fixchar '-' = '_'

Cabal/Distribution/Simple/BuildPaths.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ haddockName pkg_descr = display (packageName pkg_descr) <.> "haddock"
7676
-- ---------------------------------------------------------------------------
7777
-- Library file names
7878

79-
mkLibName :: ComponentId -> String
79+
mkLibName :: UnitId -> String
8080
mkLibName lib = "lib" ++ getHSLibraryName lib <.> "a"
8181

82-
mkProfLibName :: ComponentId -> String
82+
mkProfLibName :: UnitId -> String
8383
mkProfLibName lib = "lib" ++ getHSLibraryName lib ++ "_p" <.> "a"
8484

8585
-- Implement proper name mangling for dynamical shared objects
8686
-- libHS<packagename>-<compilerFlavour><compilerVersion>
8787
-- e.g. libHSbase-2.1-ghc6.6.1.so
88-
mkSharedLibName :: CompilerId -> ComponentId -> String
88+
mkSharedLibName :: CompilerId -> UnitId -> String
8989
mkSharedLibName (CompilerId compilerFlavor compilerVersion) lib
9090
= "lib" ++ getHSLibraryName lib ++ "-" ++ comp <.> dllExtension
9191
where comp = display compilerFlavor ++ display compilerVersion

Cabal/Distribution/Simple/Compiler.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module Distribution.Simple.Compiler (
5555
renamingPackageFlagsSupported,
5656
unifiedIPIDRequired,
5757
packageKeySupported,
58+
unitIdSupported,
5859

5960
-- * Support for profiling detail levels
6061
ProfDetailLevel(..),
@@ -286,6 +287,10 @@ unifiedIPIDRequired = ghcSupported "Requires unified installed package IDs"
286287
packageKeySupported :: Compiler -> Bool
287288
packageKeySupported = ghcSupported "Uses package keys"
288289

290+
-- | Does this compiler support unit IDs?
291+
unitIdSupported :: Compiler -> Bool
292+
unitIdSupported = ghcSupported "Uses unit IDs"
293+
289294
-- | Utility function for GHC only features
290295
ghcSupported :: String -> Compiler -> Bool
291296
ghcSupported key comp =

0 commit comments

Comments
 (0)