Skip to content

Commit face11c

Browse files
committed
Include the GHC "Project Unit Id" in the cabal store path
- This allows the use of several **API incompatible builds of the same version of GHC** without corrupting the cabal store. - This relies on the "Project Unit Id" which is available since GHC 9.8.1, older versions of GHC do not benefit from this change. [fixes haskell#8114]
1 parent 2794dd8 commit face11c

File tree

8 files changed

+104
-82
lines changed

8 files changed

+104
-82
lines changed

Cabal/src/Distribution/Simple/GHC.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE FlexibleContexts #-}
33
{-# LANGUAGE MultiWayIf #-}
4+
{-# LANGUAGE NamedFieldPuns #-}
45
{-# LANGUAGE RankNTypes #-}
56
{-# LANGUAGE TupleSections #-}
67

@@ -83,6 +84,7 @@ import Prelude ()
8384

8485
import Control.Monad (forM_, msum)
8586
import Data.Char (isLower)
87+
import Data.List (stripPrefix)
8688
import qualified Data.Map as Map
8789
import Distribution.CabalSpecVersion
8890
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
@@ -246,10 +248,16 @@ configure verbosity hcPath hcPkgPath conf0 = do
246248

247249
filterExt ext = filter ((/= EnableExtension ext) . fst)
248250

251+
compilerId :: CompilerId
252+
compilerId = CompilerId GHC ghcVersion
253+
254+
compilerAbiTag :: AbiTag
255+
compilerAbiTag = maybe NoAbiTag AbiTag (Map.lookup "Project Unit Id" ghcInfoMap >>= stripPrefix (prettyShow compilerId <> "-"))
256+
249257
let comp =
250258
Compiler
251-
{ compilerId = CompilerId GHC ghcVersion
252-
, compilerAbiTag = NoAbiTag
259+
{ compilerId
260+
, compilerAbiTag
253261
, compilerCompat = []
254262
, compilerLanguages = languages
255263
, compilerExtensions = extensions

cabal-install/src/Distribution/Client/CmdHaddockProject.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ haddockProjectAction flags _extraArgs globalFlags = do
318318
packageDir =
319319
storePackageDirectory
320320
(cabalStoreDirLayout cabalLayout)
321-
(compilerId (pkgConfigCompiler sharedConfig'))
321+
(pkgConfigCompiler sharedConfig')
322322
(elabUnitId package)
323323
docDir = packageDir </> "share" </> "doc" </> "html"
324324
destDir = outputDir </> packageName

cabal-install/src/Distribution/Client/CmdInstall.hs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,7 @@ installAction flags@NixStyleFlags{extraFlags = clientInstallFlags', ..} targetSt
484484

485485
-- progDb is a program database with compiler tools configured properly
486486
( compiler@Compiler
487-
{ compilerId =
488-
compilerId@(CompilerId compilerFlavor compilerVersion)
489-
}
487+
{ compilerId = CompilerId compilerFlavor compilerVersion }
490488
, platform
491489
, progDb
492490
) <-
@@ -498,7 +496,7 @@ installAction flags@NixStyleFlags{extraFlags = clientInstallFlags', ..} targetSt
498496
envFile <- getEnvFile clientInstallFlags platform compilerVersion
499497
existingEnvEntries <-
500498
getExistingEnvEntries verbosity compilerFlavor supportsPkgEnvFiles envFile
501-
packageDbs <- getPackageDbStack compilerId projectConfigStoreDir projectConfigLogsDir
499+
packageDbs <- getPackageDbStack compiler projectConfigStoreDir projectConfigLogsDir
502500
installedIndex <- getInstalledPackages verbosity compiler packageDbs progDb
503501

504502
let
@@ -824,7 +822,7 @@ installExes
824822
mkUnitBinDir :: UnitId -> FilePath
825823
mkUnitBinDir =
826824
InstallDirs.bindir
827-
. storePackageInstallDirs' storeDirLayout (compilerId compiler)
825+
. storePackageInstallDirs' storeDirLayout compiler
828826

829827
mkExeName :: UnqualComponentName -> FilePath
830828
mkExeName exe = unUnqualComponentName exe <.> exeExtension platform
@@ -1204,16 +1202,16 @@ getLocalEnv dir platform compilerVersion =
12041202
<> ghcPlatformAndVersionString platform compilerVersion
12051203

12061204
getPackageDbStack
1207-
:: CompilerId
1205+
:: Compiler
12081206
-> Flag FilePath
12091207
-> Flag FilePath
12101208
-> IO PackageDBStack
1211-
getPackageDbStack compilerId storeDirFlag logsDirFlag = do
1209+
getPackageDbStack compiler storeDirFlag logsDirFlag = do
12121210
mstoreDir <- traverse makeAbsolute $ flagToMaybe storeDirFlag
12131211
let
12141212
mlogsDir = flagToMaybe logsDirFlag
12151213
cabalLayout <- mkCabalDirLayout mstoreDir mlogsDir
1216-
pure $ storePackageDBStack (cabalStoreDirLayout cabalLayout) compilerId
1214+
pure $ storePackageDBStack (cabalStoreDirLayout cabalLayout) compiler
12171215

12181216
-- | This defines what a 'TargetSelector' means for the @bench@ command.
12191217
-- It selects the 'AvailableTarget's that the 'TargetSelector' refers to,

cabal-install/src/Distribution/Client/DistDirLayout.hs

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import Distribution.Package
4141
, UnitId
4242
)
4343
import Distribution.Simple.Compiler
44-
( OptimisationLevel (..)
44+
( Compiler (..)
45+
, OptimisationLevel (..)
4546
, PackageDB (..)
4647
, PackageDBStack
4748
)
@@ -116,13 +117,13 @@ data DistDirLayout = DistDirLayout
116117

117118
-- | The layout of a cabal nix-style store.
118119
data StoreDirLayout = StoreDirLayout
119-
{ storeDirectory :: CompilerId -> FilePath
120-
, storePackageDirectory :: CompilerId -> UnitId -> FilePath
121-
, storePackageDBPath :: CompilerId -> FilePath
122-
, storePackageDB :: CompilerId -> PackageDB
123-
, storePackageDBStack :: CompilerId -> PackageDBStack
124-
, storeIncomingDirectory :: CompilerId -> FilePath
125-
, storeIncomingLock :: CompilerId -> UnitId -> FilePath
120+
{ storeDirectory :: Compiler -> FilePath
121+
, storePackageDirectory :: Compiler -> UnitId -> FilePath
122+
, storePackageDBPath :: Compiler -> FilePath
123+
, storePackageDB :: Compiler -> PackageDB
124+
, storePackageDBStack :: Compiler -> PackageDBStack
125+
, storeIncomingDirectory :: Compiler -> FilePath
126+
, storeIncomingLock :: Compiler -> UnitId -> FilePath
126127
}
127128

128129
-- TODO: move to another module, e.g. CabalDirLayout?
@@ -267,33 +268,35 @@ defaultStoreDirLayout :: FilePath -> StoreDirLayout
267268
defaultStoreDirLayout storeRoot =
268269
StoreDirLayout{..}
269270
where
270-
storeDirectory :: CompilerId -> FilePath
271-
storeDirectory compid =
272-
storeRoot </> prettyShow compid
273-
274-
storePackageDirectory :: CompilerId -> UnitId -> FilePath
275-
storePackageDirectory compid ipkgid =
276-
storeDirectory compid </> prettyShow ipkgid
277-
278-
storePackageDBPath :: CompilerId -> FilePath
279-
storePackageDBPath compid =
280-
storeDirectory compid </> "package.db"
281-
282-
storePackageDB :: CompilerId -> PackageDB
283-
storePackageDB compid =
284-
SpecificPackageDB (storePackageDBPath compid)
285-
286-
storePackageDBStack :: CompilerId -> PackageDBStack
287-
storePackageDBStack compid =
288-
[GlobalPackageDB, storePackageDB compid]
289-
290-
storeIncomingDirectory :: CompilerId -> FilePath
291-
storeIncomingDirectory compid =
292-
storeDirectory compid </> "incoming"
293-
294-
storeIncomingLock :: CompilerId -> UnitId -> FilePath
295-
storeIncomingLock compid unitid =
296-
storeIncomingDirectory compid </> prettyShow unitid <.> "lock"
271+
storeDirectory :: Compiler -> FilePath
272+
storeDirectory compiler =
273+
storeRoot </> case compilerAbiTag compiler of
274+
NoAbiTag -> prettyShow (compilerId compiler)
275+
AbiTag tag -> prettyShow (compilerId compiler) <> "-" <> tag
276+
277+
storePackageDirectory :: Compiler -> UnitId -> FilePath
278+
storePackageDirectory compiler ipkgid =
279+
storeDirectory compiler </> prettyShow ipkgid
280+
281+
storePackageDBPath :: Compiler -> FilePath
282+
storePackageDBPath compiler =
283+
storeDirectory compiler </> "package.db"
284+
285+
storePackageDB :: Compiler -> PackageDB
286+
storePackageDB compiler =
287+
SpecificPackageDB (storePackageDBPath compiler)
288+
289+
storePackageDBStack :: Compiler -> PackageDBStack
290+
storePackageDBStack compiler =
291+
[GlobalPackageDB, storePackageDB compiler]
292+
293+
storeIncomingDirectory :: Compiler -> FilePath
294+
storeIncomingDirectory compiler =
295+
storeDirectory compiler </> "incoming"
296+
297+
storeIncomingLock :: Compiler -> UnitId -> FilePath
298+
storeIncomingLock compiler unitid =
299+
storeIncomingDirectory compiler </> prettyShow unitid <.> "lock"
297300

298301
defaultCabalDirLayout :: IO CabalDirLayout
299302
defaultCabalDirLayout =

cabal-install/src/Distribution/Client/ProjectBuilding.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,15 +1280,15 @@ buildAndInstallUnpackedPackage
12801280
let ipkg = ipkg0{Installed.installedUnitId = uid}
12811281
assert
12821282
( elabRegisterPackageDBStack pkg
1283-
== storePackageDBStack compid
1283+
== storePackageDBStack compiler
12841284
)
12851285
(return ())
12861286
criticalSection registerLock $
12871287
Cabal.registerPackage
12881288
verbosity
12891289
compiler
12901290
progdb
1291-
(storePackageDBStack compid)
1291+
(storePackageDBStack compiler)
12921292
ipkg
12931293
Cabal.defaultRegisterOptions
12941294
{ Cabal.registerMultiInstance = True
@@ -1300,7 +1300,7 @@ buildAndInstallUnpackedPackage
13001300
newStoreEntry
13011301
verbosity
13021302
storeDirLayout
1303-
compid
1303+
compiler
13041304
uid
13051305
copyPkgFiles
13061306
registerPkg
@@ -1330,7 +1330,6 @@ buildAndInstallUnpackedPackage
13301330
where
13311331
pkgid = packageId rpkg
13321332
uid = installedUnitId rpkg
1333-
compid = compilerId compiler
13341333

13351334
dispname :: String
13361335
dispname = case elabPkgOrComp pkg of

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ rebuildInstallPlan
897897
-> Rebuild ElaboratedInstallPlan
898898
phaseImprovePlan elaboratedPlan elaboratedShared = do
899899
liftIO $ debug verbosity "Improving the install plan..."
900-
storePkgIdSet <- getStoreEntries cabalStoreDirLayout compid
900+
storePkgIdSet <- getStoreEntries cabalStoreDirLayout compiler
901901
let improvedPlan =
902902
improveInstallPlanWithInstalledPackages
903903
storePkgIdSet
@@ -909,7 +909,7 @@ rebuildInstallPlan
909909
-- matches up as expected, e.g. no dangling deps, files deleted.
910910
return improvedPlan
911911
where
912-
compid = compilerId (pkgConfigCompiler elaboratedShared)
912+
compiler = pkgConfigCompiler elaboratedShared
913913

914914
-- | If a 'PackageSpecifier' refers to a single package, return Just that
915915
-- package.
@@ -2349,7 +2349,7 @@ elaborateInstallPlan
23492349

23502350
corePackageDbs =
23512351
applyPackageDbFlags
2352-
(storePackageDBStack (compilerId compiler))
2352+
(storePackageDBStack compiler)
23532353
(projectConfigPackageDBs sharedPackageConfig)
23542354

23552355
-- For this local build policy, every package that lives in a local source
@@ -4026,28 +4026,28 @@ userInstallDirTemplates compiler = do
40264026

40274027
storePackageInstallDirs
40284028
:: StoreDirLayout
4029-
-> CompilerId
4029+
-> Compiler
40304030
-> InstalledPackageId
40314031
-> InstallDirs.InstallDirs FilePath
4032-
storePackageInstallDirs storeDirLayout compid ipkgid =
4033-
storePackageInstallDirs' storeDirLayout compid $ newSimpleUnitId ipkgid
4032+
storePackageInstallDirs storeDirLayout compiler ipkgid =
4033+
storePackageInstallDirs' storeDirLayout compiler $ newSimpleUnitId ipkgid
40344034

40354035
storePackageInstallDirs'
40364036
:: StoreDirLayout
4037-
-> CompilerId
4037+
-> Compiler
40384038
-> UnitId
40394039
-> InstallDirs.InstallDirs FilePath
40404040
storePackageInstallDirs'
40414041
StoreDirLayout
40424042
{ storePackageDirectory
40434043
, storeDirectory
40444044
}
4045-
compid
4045+
compiler
40464046
unitid =
40474047
InstallDirs.InstallDirs{..}
40484048
where
4049-
store = storeDirectory compid
4050-
prefix = storePackageDirectory compid unitid
4049+
store = storeDirectory compiler
4050+
prefix = storePackageDirectory compiler unitid
40514051
bindir = prefix </> "bin"
40524052
libdir = prefix </> "lib"
40534053
libsubdir = ""
@@ -4097,7 +4097,7 @@ computeInstallDirs storeDirLayout defaultInstallDirs elaboratedShared elab
40974097
-- use special simplified install dirs
40984098
storePackageInstallDirs'
40994099
storeDirLayout
4100-
(compilerId (pkgConfigCompiler elaboratedShared))
4100+
(pkgConfigCompiler elaboratedShared)
41014101
(elabUnitId elab)
41024102

41034103
-- TODO: [code cleanup] perhaps reorder this code

0 commit comments

Comments
 (0)