Skip to content

Commit 54228c3

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 df5e188 commit 54228c3

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
@@ -686,12 +686,12 @@ buildAndInstallUnpackedPackage
686686
| otherwise = do
687687
assert
688688
( elabRegisterPackageDBStack pkg
689-
== storePackageDBStack compid
689+
== storePackageDBStack compiler
690690
)
691691
(return ())
692692
_ <-
693693
runRegister
694-
(storePackageDBStack compid)
694+
(storePackageDBStack compiler)
695695
Cabal.defaultRegisterOptions
696696
{ Cabal.registerMultiInstance = True
697697
, Cabal.registerSuppressFilesCheck = True
@@ -703,7 +703,7 @@ buildAndInstallUnpackedPackage
703703
newStoreEntry
704704
verbosity
705705
storeDirLayout
706-
compid
706+
compiler
707707
uid
708708
(copyPkgFiles verbosity pkgshared pkg runCopy)
709709
registerPkg
@@ -740,7 +740,6 @@ buildAndInstallUnpackedPackage
740740
where
741741
uid = installedUnitId rpkg
742742
pkgid = packageId rpkg
743-
compid = compilerId compiler
744743

745744
dispname :: String
746745
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
@@ -860,7 +860,7 @@ rebuildInstallPlan
860860
-> Rebuild ElaboratedInstallPlan
861861
phaseImprovePlan elaboratedPlan elaboratedShared = do
862862
liftIO $ debug verbosity "Improving the install plan..."
863-
storePkgIdSet <- getStoreEntries cabalStoreDirLayout compid
863+
storePkgIdSet <- getStoreEntries cabalStoreDirLayout compiler
864864
let improvedPlan =
865865
improveInstallPlanWithInstalledPackages
866866
storePkgIdSet
@@ -872,7 +872,7 @@ rebuildInstallPlan
872872
-- matches up as expected, e.g. no dangling deps, files deleted.
873873
return improvedPlan
874874
where
875-
compid = compilerId (pkgConfigCompiler elaboratedShared)
875+
compiler = pkgConfigCompiler elaboratedShared
876876

877877
-- | If a 'PackageSpecifier' refers to a single package, return Just that
878878
-- package.
@@ -2318,7 +2318,7 @@ elaborateInstallPlan
23182318

23192319
corePackageDbs =
23202320
applyPackageDbFlags
2321-
(storePackageDBStack (compilerId compiler))
2321+
(storePackageDBStack compiler)
23222322
(projectConfigPackageDBs sharedPackageConfig)
23232323

23242324
-- For this local build policy, every package that lives in a local source
@@ -3767,28 +3767,28 @@ userInstallDirTemplates compiler = do
37673767

37683768
storePackageInstallDirs
37693769
:: StoreDirLayout
3770-
-> CompilerId
3770+
-> Compiler
37713771
-> InstalledPackageId
37723772
-> InstallDirs.InstallDirs FilePath
3773-
storePackageInstallDirs storeDirLayout compid ipkgid =
3774-
storePackageInstallDirs' storeDirLayout compid $ newSimpleUnitId ipkgid
3773+
storePackageInstallDirs storeDirLayout compiler ipkgid =
3774+
storePackageInstallDirs' storeDirLayout compiler $ newSimpleUnitId ipkgid
37753775

37763776
storePackageInstallDirs'
37773777
:: StoreDirLayout
3778-
-> CompilerId
3778+
-> Compiler
37793779
-> UnitId
37803780
-> InstallDirs.InstallDirs FilePath
37813781
storePackageInstallDirs'
37823782
StoreDirLayout
37833783
{ storePackageDirectory
37843784
, storeDirectory
37853785
}
3786-
compid
3786+
compiler
37873787
unitid =
37883788
InstallDirs.InstallDirs{..}
37893789
where
3790-
store = storeDirectory compid
3791-
prefix = storePackageDirectory compid unitid
3790+
store = storeDirectory compiler
3791+
prefix = storePackageDirectory compiler unitid
37923792
bindir = prefix </> "bin"
37933793
libdir = prefix </> "lib"
37943794
libsubdir = ""
@@ -3838,7 +3838,7 @@ computeInstallDirs storeDirLayout defaultInstallDirs elaboratedShared elab
38383838
-- use special simplified install dirs
38393839
storePackageInstallDirs'
38403840
storeDirLayout
3841-
(compilerId (pkgConfigCompiler elaboratedShared))
3841+
(pkgConfigCompiler elaboratedShared)
38423842
(elabUnitId elab)
38433843

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

0 commit comments

Comments
 (0)