Skip to content

Commit a0eec76

Browse files
solalt-romes
authored andcommitted
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 #8114]
1 parent d89087b commit a0eec76

File tree

9 files changed

+170
-131
lines changed

9 files changed

+170
-131
lines changed

Cabal/src/Distribution/Simple/GHC.hs

Lines changed: 11 additions & 3 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

@@ -81,7 +82,8 @@ module Distribution.Simple.GHC
8182
import Distribution.Compat.Prelude
8283
import Prelude ()
8384

84-
import Control.Monad (forM_)
85+
import Control.Monad (forM_, msum)
86+
import Data.List (stripPrefix)
8587
import qualified Data.Map as Map
8688
import Distribution.CabalSpecVersion
8789
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
@@ -236,10 +238,16 @@ configure verbosity hcPath hcPkgPath conf0 = do
236238

237239
filterExt ext = filter ((/= EnableExtension ext) . fst)
238240

241+
compilerId :: CompilerId
242+
compilerId = CompilerId GHC ghcVersion
243+
244+
compilerAbiTag :: AbiTag
245+
compilerAbiTag = maybe NoAbiTag AbiTag (Map.lookup "Project Unit Id" ghcInfoMap >>= stripPrefix (prettyShow compilerId <> "-"))
246+
239247
let comp =
240248
Compiler
241-
{ compilerId = CompilerId GHC ghcVersion
242-
, compilerAbiTag = NoAbiTag
249+
{ compilerId
250+
, compilerAbiTag
243251
, compilerCompat = []
244252
, compilerLanguages = languages
245253
, compilerExtensions = extensions

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ import Distribution.Client.TargetProblem (TargetProblem (..))
5454
import Distribution.Simple.Command
5555
( CommandUI (..)
5656
)
57-
import Distribution.Simple.Compiler
58-
( Compiler (..)
59-
)
6057
import Distribution.Simple.Flag
6158
( Flag (..)
6259
, fromFlag
@@ -319,7 +316,7 @@ haddockProjectAction flags _extraArgs globalFlags = do
319316
packageDir =
320317
storePackageDirectory
321318
(cabalStoreDirLayout cabalLayout)
322-
(compilerId (pkgConfigCompiler sharedConfig'))
319+
(pkgConfigCompiler sharedConfig')
323320
(elabUnitId package)
324321
docDir = packageDir </> "share" </> "doc" </> "html"
325322
destDir = outputDir </> packageName

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

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

524524
-- progDb is a program database with compiler tools configured properly
525525
( compiler@Compiler
526-
{ compilerId =
527-
compilerId@(CompilerId compilerFlavor compilerVersion)
526+
{ compilerId = CompilerId compilerFlavor compilerVersion
528527
}
529528
, platform
530529
, progDb
@@ -537,7 +536,7 @@ installAction flags@NixStyleFlags{extraFlags = clientInstallFlags', ..} targetSt
537536
envFile <- getEnvFile clientInstallFlags platform compilerVersion
538537
existingEnvEntries <-
539538
getExistingEnvEntries verbosity compilerFlavor supportsPkgEnvFiles envFile
540-
packageDbs <- getPackageDbStack compilerId projectConfigStoreDir projectConfigLogsDir
539+
packageDbs <- getPackageDbStack compiler projectConfigStoreDir projectConfigLogsDir
541540
installedIndex <- getInstalledPackages verbosity compiler packageDbs progDb
542541

543542
let
@@ -846,7 +845,7 @@ prepareExeInstall
846845
mkUnitBinDir :: UnitId -> FilePath
847846
mkUnitBinDir =
848847
InstallDirs.bindir
849-
. storePackageInstallDirs' storeDirLayout (compilerId compiler)
848+
. storePackageInstallDirs' storeDirLayout compiler
850849

851850
mkExeName :: UnqualComponentName -> FilePath
852851
mkExeName exe = unUnqualComponentName exe <.> exeExtension platform
@@ -1218,16 +1217,16 @@ getLocalEnv dir platform compilerVersion =
12181217
<> ghcPlatformAndVersionString platform compilerVersion
12191218

12201219
getPackageDbStack
1221-
:: CompilerId
1220+
:: Compiler
12221221
-> Flag FilePath
12231222
-> Flag FilePath
12241223
-> IO PackageDBStack
1225-
getPackageDbStack compilerId storeDirFlag logsDirFlag = do
1224+
getPackageDbStack compiler storeDirFlag logsDirFlag = do
12261225
mstoreDir <- traverse makeAbsolute $ flagToMaybe storeDirFlag
12271226
let
12281227
mlogsDir = flagToMaybe logsDirFlag
12291228
cabalLayout <- mkCabalDirLayout mstoreDir mlogsDir
1230-
pure $ storePackageDBStack (cabalStoreDirLayout cabalLayout) compilerId
1229+
pure $ storePackageDBStack (cabalStoreDirLayout cabalLayout) compiler
12311230

12321231
-- | This defines what a 'TargetSelector' means for the @bench@ command.
12331232
-- 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/UnpackedPackage.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,12 +675,12 @@ buildAndInstallUnpackedPackage
675675
| otherwise = do
676676
assert
677677
( elabRegisterPackageDBStack pkg
678-
== storePackageDBStack compid
678+
== storePackageDBStack compiler
679679
)
680680
(return ())
681681
_ <-
682682
runRegister
683-
(storePackageDBStack compid)
683+
(storePackageDBStack compiler)
684684
Cabal.defaultRegisterOptions
685685
{ Cabal.registerMultiInstance = True
686686
, Cabal.registerSuppressFilesCheck = True
@@ -692,7 +692,7 @@ buildAndInstallUnpackedPackage
692692
newStoreEntry
693693
verbosity
694694
storeDirLayout
695-
compid
695+
compiler
696696
uid
697697
(copyPkgFiles verbosity pkgshared pkg runCopy)
698698
registerPkg
@@ -729,7 +729,6 @@ buildAndInstallUnpackedPackage
729729
where
730730
uid = installedUnitId rpkg
731731
pkgid = packageId rpkg
732-
compid = compilerId compiler
733732

734733
dispname :: String
735734
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
@@ -861,7 +861,7 @@ rebuildInstallPlan
861861
-> Rebuild ElaboratedInstallPlan
862862
phaseImprovePlan elaboratedPlan elaboratedShared = do
863863
liftIO $ debug verbosity "Improving the install plan..."
864-
storePkgIdSet <- getStoreEntries cabalStoreDirLayout compid
864+
storePkgIdSet <- getStoreEntries cabalStoreDirLayout compiler
865865
let improvedPlan =
866866
improveInstallPlanWithInstalledPackages
867867
storePkgIdSet
@@ -873,7 +873,7 @@ rebuildInstallPlan
873873
-- matches up as expected, e.g. no dangling deps, files deleted.
874874
return improvedPlan
875875
where
876-
compid = compilerId (pkgConfigCompiler elaboratedShared)
876+
compiler = pkgConfigCompiler elaboratedShared
877877

878878
-- | If a 'PackageSpecifier' refers to a single package, return Just that
879879
-- package.
@@ -2326,7 +2326,7 @@ elaborateInstallPlan
23262326

23272327
corePackageDbs =
23282328
applyPackageDbFlags
2329-
(storePackageDBStack (compilerId compiler))
2329+
(storePackageDBStack compiler)
23302330
(projectConfigPackageDBs sharedPackageConfig)
23312331

23322332
-- For this local build policy, every package that lives in a local source
@@ -3775,28 +3775,28 @@ userInstallDirTemplates compiler = do
37753775

37763776
storePackageInstallDirs
37773777
:: StoreDirLayout
3778-
-> CompilerId
3778+
-> Compiler
37793779
-> InstalledPackageId
37803780
-> InstallDirs.InstallDirs FilePath
3781-
storePackageInstallDirs storeDirLayout compid ipkgid =
3782-
storePackageInstallDirs' storeDirLayout compid $ newSimpleUnitId ipkgid
3781+
storePackageInstallDirs storeDirLayout compiler ipkgid =
3782+
storePackageInstallDirs' storeDirLayout compiler $ newSimpleUnitId ipkgid
37833783

37843784
storePackageInstallDirs'
37853785
:: StoreDirLayout
3786-
-> CompilerId
3786+
-> Compiler
37873787
-> UnitId
37883788
-> InstallDirs.InstallDirs FilePath
37893789
storePackageInstallDirs'
37903790
StoreDirLayout
37913791
{ storePackageDirectory
37923792
, storeDirectory
37933793
}
3794-
compid
3794+
compiler
37953795
unitid =
37963796
InstallDirs.InstallDirs{..}
37973797
where
3798-
store = storeDirectory compid
3799-
prefix = storePackageDirectory compid unitid
3798+
store = storeDirectory compiler
3799+
prefix = storePackageDirectory compiler unitid
38003800
bindir = prefix </> "bin"
38013801
libdir = prefix </> "lib"
38023802
libsubdir = ""
@@ -3846,7 +3846,7 @@ computeInstallDirs storeDirLayout defaultInstallDirs elaboratedShared elab
38463846
-- use special simplified install dirs
38473847
storePackageInstallDirs'
38483848
storeDirLayout
3849-
(compilerId (pkgConfigCompiler elaboratedShared))
3849+
(pkgConfigCompiler elaboratedShared)
38503850
(elabUnitId elab)
38513851

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

0 commit comments

Comments
 (0)