Skip to content

Commit f830ff4

Browse files
authored
Add GHC Unit ID store to cabal path output (#11266)
* Add GHC Unit ID store to `cabal path` output The GHC "Project Unit ID" store path has been used in cabal-install since 3.12.1.0. Resolves: #10165 * Add a changelog entry for PR #11266 This change modifies the output of `cabal path`, and therefore requires a changelog entry. * Rename compiler-project-unit-id in `cabal path` Update `compiler-project-unit-id` to `compiler-store-path` in the `cabal path` output, as it is much more clear. * Add another Path test This adds a new test that verifies the output of `compiler-store-path` when the store-dir is explicitly configured. * Add compiler-abi-tag to path command
1 parent fbc055e commit f830ff4

File tree

5 files changed

+63
-10
lines changed

5 files changed

+63
-10
lines changed

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import Distribution.Client.Config
2525
, defaultStoreDir
2626
, getConfigFilePath
2727
)
28-
import Distribution.Client.DistDirLayout (CabalDirLayout (..), distProjectRootDirectory)
28+
import Distribution.Client.DistDirLayout (CabalDirLayout (..), StoreDirLayout (..), distProjectRootDirectory)
2929
import Distribution.Client.Errors
3030
import Distribution.Client.GlobalFlags
3131
import Distribution.Client.NixStyleOptions
@@ -244,10 +244,17 @@ pathAction flags@NixStyleFlags{extraFlags = pathFlags'} cliTargetStrings globalF
244244
if not $ fromFlagOrDefault False (pathCompiler pathFlags)
245245
then pure Nothing
246246
else do
247-
(compiler, _, progDb) <- runRebuild (distProjectRootDirectory . distDirLayout $ baseCtx) $ configureCompiler verbosity (distDirLayout baseCtx) (projectConfig baseCtx)
247+
(compiler, _, progDb) <-
248+
runRebuild (distProjectRootDirectory . distDirLayout $ baseCtx) $
249+
configureCompiler verbosity (distDirLayout baseCtx) (projectConfig baseCtx)
248250
compilerProg <- requireCompilerProg verbosity compiler
249251
(configuredCompilerProg, _) <- requireProgram verbosity compilerProg progDb
250-
pure $ Just $ mkCompilerInfo configuredCompilerProg compiler
252+
253+
let compilerInfo' =
254+
mkCompilerInfo configuredCompilerProg compiler $
255+
cabalStoreDirLayout (cabalDirLayout baseCtx)
256+
257+
pure $ Just compilerInfo'
251258

252259
paths <- for (fromFlagOrDefault [] $ pathDirectories pathFlags) $ \p -> do
253260
t <- getPathLocation verbosity baseCtx p
@@ -317,16 +324,20 @@ data PathOutputs = PathOutputs
317324
data PathCompilerInfo = PathCompilerInfo
318325
{ pathCompilerInfoFlavour :: CompilerFlavor
319326
, pathCompilerInfoId :: CompilerId
327+
, pathCompilerInfoAbiTag :: String
320328
, pathCompilerInfoPath :: FilePath
329+
, pathCompilerInfoStorePath :: FilePath
321330
}
322331
deriving (Show, Eq, Ord)
323332

324-
mkCompilerInfo :: ConfiguredProgram -> Compiler -> PathCompilerInfo
325-
mkCompilerInfo compilerProgram compiler =
333+
mkCompilerInfo :: ConfiguredProgram -> Compiler -> StoreDirLayout -> PathCompilerInfo
334+
mkCompilerInfo compilerProgram compiler storeLayout =
326335
PathCompilerInfo
327336
{ pathCompilerInfoFlavour = compilerFlavor compiler
328337
, pathCompilerInfoId = compilerId compiler
338+
, pathCompilerInfoAbiTag = showCompilerIdWithAbi compiler
329339
, pathCompilerInfoPath = programPath compilerProgram
340+
, pathCompilerInfoStorePath = storeDirectory storeLayout compiler
330341
}
331342

332343
-- ----------------------------------------------------------------------------
@@ -371,7 +382,9 @@ compilerInfoToJson pci =
371382
.= Json.object
372383
[ "flavour" .= jdisplay (pathCompilerInfoFlavour pci)
373384
, "id" .= jdisplay (pathCompilerInfoId pci)
385+
, "abi-tag" .= Json.String (pathCompilerInfoAbiTag pci)
374386
, "path" .= Json.String (pathCompilerInfoPath pci)
387+
, "store-path" .= Json.String (pathCompilerInfoStorePath pci)
375388
]
376389
]
377390

@@ -400,5 +413,7 @@ compilerInfoToKeyValue :: PathCompilerInfo -> [(String, String)]
400413
compilerInfoToKeyValue pci =
401414
[ ("compiler-flavour", prettyShow $ pathCompilerInfoFlavour pci)
402415
, ("compiler-id", prettyShow $ pathCompilerInfoId pci)
416+
, ("compiler-abi-tag", pathCompilerInfoAbiTag pci)
403417
, ("compiler-path", pathCompilerInfoPath pci)
418+
, ("compiler-store-path", pathCompilerInfoStorePath pci)
404419
]

cabal-testsuite/PackageTests/Path/All/cabal.out

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# cabal path
2-
{"cabal-version":"<CABAL_INSTALL_VER>","compiler":{"flavour":"ghc","id":"ghc-<GHCVER>","path":"<GHCPATH>"},"logs-dir":"<ROOT>/cabal.dist/home/.cabal/logs","installdir":"<ROOT>/cabal.dist/home/.cabal/bin"}
2+
{"cabal-version":"<CABAL_INSTALL_VER>","compiler":{"flavour":"ghc","id":"ghc-<GHCVER>","abi-tag":"ghc-<GHCVER>","path":"<GHCPATH>","store-path":"<ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>"},"logs-dir":"<ROOT>/cabal.dist/home/.cabal/logs","installdir":"<ROOT>/cabal.dist/home/.cabal/bin"}
33
# cabal path
4-
{"cabal-version":"<CABAL_INSTALL_VER>","compiler":{"flavour":"ghc","id":"ghc-<GHCVER>","path":"<GHCPATH>"},"store-dir":"<ROOT>/cabal.dist/home/.cabal/store","config-file":"<ROOT>/cabal.dist/home/.cabal/config"}
4+
{"cabal-version":"<CABAL_INSTALL_VER>","compiler":{"flavour":"ghc","id":"ghc-<GHCVER>","abi-tag":"ghc-<GHCVER>","path":"<GHCPATH>","store-path":"<ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>"},"store-dir":"<ROOT>/cabal.dist/home/.cabal/store","config-file":"<ROOT>/cabal.dist/home/.cabal/config"}
55
# cabal path
6-
{"cabal-version":"<CABAL_INSTALL_VER>","compiler":{"flavour":"ghc","id":"ghc-<GHCVER>","path":"<GHCPATH>"},"remote-repo-cache":"<ROOT>/cabal.dist/home/.cabal/packages"}
6+
{"cabal-version":"<CABAL_INSTALL_VER>","compiler":{"flavour":"ghc","id":"ghc-<GHCVER>","abi-tag":"ghc-<GHCVER>","path":"<GHCPATH>","store-path":"<ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>"},"remote-repo-cache":"<ROOT>/cabal.dist/home/.cabal/packages"}
77
# cabal path
8-
{"cabal-version":"<CABAL_INSTALL_VER>","compiler":{"flavour":"ghc","id":"ghc-<GHCVER>","path":"<GHCPATH>"},"cache-home":"<ROOT>/cabal.dist/home/.cabal","remote-repo-cache":"<ROOT>/cabal.dist/home/.cabal/packages","logs-dir":"<ROOT>/cabal.dist/home/.cabal/logs","store-dir":"<ROOT>/cabal.dist/home/.cabal/store","config-file":"<ROOT>/cabal.dist/home/.cabal/config","installdir":"<ROOT>/cabal.dist/home/.cabal/bin"}
8+
{"cabal-version":"<CABAL_INSTALL_VER>","compiler":{"flavour":"ghc","id":"ghc-<GHCVER>","abi-tag":"ghc-<GHCVER>","path":"<GHCPATH>","store-path":"<ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>"},"cache-home":"<ROOT>/cabal.dist/home/.cabal","remote-repo-cache":"<ROOT>/cabal.dist/home/.cabal/packages","logs-dir":"<ROOT>/cabal.dist/home/.cabal/logs","store-dir":"<ROOT>/cabal.dist/home/.cabal/store","config-file":"<ROOT>/cabal.dist/home/.cabal/config","installdir":"<ROOT>/cabal.dist/home/.cabal/bin"}
99
# cabal path
1010
{"cabal-version":"<CABAL_INSTALL_VER>","cache-home":"<ROOT>/cabal.dist/home/.cabal"}
1111
# cabal path
@@ -21,24 +21,32 @@
2121
# cabal path
2222
compiler-flavour: ghc
2323
compiler-id: ghc-<GHCVER>
24+
compiler-abi-tag: ghc-<GHCVER>
2425
compiler-path: <GHCPATH>
26+
compiler-store-path: <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>
2527
logs-dir: <ROOT>/cabal.dist/home/.cabal/logs
2628
installdir: <ROOT>/cabal.dist/home/.cabal/bin
2729
# cabal path
2830
compiler-flavour: ghc
2931
compiler-id: ghc-<GHCVER>
32+
compiler-abi-tag: ghc-<GHCVER>
3033
compiler-path: <GHCPATH>
34+
compiler-store-path: <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>
3135
store-dir: <ROOT>/cabal.dist/home/.cabal/store
3236
config-file: <ROOT>/cabal.dist/home/.cabal/config
3337
# cabal path
3438
compiler-flavour: ghc
3539
compiler-id: ghc-<GHCVER>
40+
compiler-abi-tag: ghc-<GHCVER>
3641
compiler-path: <GHCPATH>
42+
compiler-store-path: <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>
3743
remote-repo-cache: <ROOT>/cabal.dist/home/.cabal/packages
3844
# cabal path
3945
compiler-flavour: ghc
4046
compiler-id: ghc-<GHCVER>
47+
compiler-abi-tag: ghc-<GHCVER>
4148
compiler-path: <GHCPATH>
49+
compiler-store-path: <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>
4250
cache-home: <ROOT>/cabal.dist/home/.cabal
4351
remote-repo-cache: <ROOT>/cabal.dist/home/.cabal/packages
4452
logs-dir: <ROOT>/cabal.dist/home/.cabal/logs
@@ -60,24 +68,32 @@ installdir: <ROOT>/cabal.dist/home/.cabal/bin
6068
# cabal path
6169
compiler-flavour: ghc
6270
compiler-id: ghc-<GHCVER>
71+
compiler-abi-tag: ghc-<GHCVER>
6372
compiler-path: <GHCPATH>
73+
compiler-store-path: <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>
6474
logs-dir: <ROOT>/cabal.dist/home/.cabal/logs
6575
installdir: <ROOT>/cabal.dist/home/.cabal/bin
6676
# cabal path
6777
compiler-flavour: ghc
6878
compiler-id: ghc-<GHCVER>
79+
compiler-abi-tag: ghc-<GHCVER>
6980
compiler-path: <GHCPATH>
81+
compiler-store-path: <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>
7082
store-dir: <ROOT>/cabal.dist/home/.cabal/store
7183
config-file: <ROOT>/cabal.dist/home/.cabal/config
7284
# cabal path
7385
compiler-flavour: ghc
7486
compiler-id: ghc-<GHCVER>
87+
compiler-abi-tag: ghc-<GHCVER>
7588
compiler-path: <GHCPATH>
89+
compiler-store-path: <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>
7690
remote-repo-cache: <ROOT>/cabal.dist/home/.cabal/packages
7791
# cabal path
7892
compiler-flavour: ghc
7993
compiler-id: ghc-<GHCVER>
94+
compiler-abi-tag: ghc-<GHCVER>
8095
compiler-path: <GHCPATH>
96+
compiler-store-path: <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>
8197
cache-home: <ROOT>/cabal.dist/home/.cabal
8298
remote-repo-cache: <ROOT>/cabal.dist/home/.cabal/packages
8399
logs-dir: <ROOT>/cabal.dist/home/.cabal/logs
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# cabal path
22
compiler-flavour: ghc
33
compiler-id: ghc-<GHCVER>
4+
compiler-abi-tag: ghc-<GHCVER>
45
compiler-path: <GHCPATH>
6+
compiler-store-path: <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>
57
# cabal path
6-
{"cabal-version":"<CABAL_INSTALL_VER>","compiler":{"flavour":"ghc","id":"ghc-<GHCVER>","path":"<GHCPATH>"}}
8+
{"cabal-version":"<CABAL_INSTALL_VER>","compiler":{"flavour":"ghc","id":"ghc-<GHCVER>","abi-tag":"ghc-<GHCVER>","path":"<GHCPATH>","store-path":"<ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>"}}
79
# cabal path
810
compiler-flavour: ghc
911
compiler-id: ghc-<GHCVER>
12+
compiler-abi-tag: ghc-<GHCVER>
1013
compiler-path: <GHCPATH>
14+
compiler-store-path: <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>
15+
# cabal path
16+
compiler-flavour: ghc
17+
compiler-id: ghc-<GHCVER>
18+
compiler-abi-tag: ghc-<GHCVER>
19+
compiler-path: <GHCPATH>
20+
compiler-store-path: fake-dir/ghc-<GHCVER>

cabal-testsuite/PackageTests/Path/Compiler/cabal.test.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ main = cabalTest $ do
55
void $ cabal "path" ["-z", "--output-format=key-value", "--compiler-info"]
66
void $ cabal "path" ["-z", "--output-format=json", "--compiler-info"]
77
void $ cabal "path" ["-z", "--compiler-info"]
8+
void $ cabalG ["--store-dir=fake-dir"] "path" ["-z", "--compiler-info"]

changelog.d/pr-11266

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
synopsis: "Add GHC Project Unit ID store to `cabal path` output"
2+
packages: cabal-install
3+
prs: #11266
4+
issues: #10165
5+
description: {
6+
7+
This addds the GHC Project Unit ID store path to the cabal path output as
8+
"project-unit-id". The GHC Project Unit ID store path has been used in cabal-install
9+
since 3.12.1.0.
10+
11+
}

0 commit comments

Comments
 (0)