Skip to content

Commit 83e8616

Browse files
committed
plan.json: Include store-dir and compiler-abi fields
The plan.json file was missing crucial information needed to locate packages in the store directory structure. When cabal-install stores packages, it uses a full compiler identifier including an ABI tag (e.g., "ghc-9.10.1-69c3") but plan.json only included the basic compiler ID ("ghc-9.10.1"). This made it impossible for external tools like cabal-plan to correctly locate packages and their files in the store. This commit adds: 1. A new "compiler-abi" field with the ABI tag string 2. A "store-dir" section containing: - The complete store directory path (with full compiler ID) - The store package database path - The store incoming directory path These additions allow tools to accurately locate packages in the store without having to guess or reconstruct the paths themselves. The StoreDirLayout is now passed to the JSON encoder, making all store-related paths available in plan.json. The issue reported in the original ticket seems to be about the location of LICENSE files, but the plan.json may still lack sufficient information to locate all license files since the packages may not be located in the store, but in different package databases given by the --package-db flag. This will do for now. Fixes #10726
1 parent d4d92e9 commit 83e8616

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

+15-3
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,24 @@ import Distribution.Simple.Program.GHC (packageDbArgsDb)
8585
-- This is for the benefit of debugging and external tools like editors.
8686
writePlanExternalRepresentation
8787
:: DistDirLayout
88+
-> StoreDirLayout
8889
-> ElaboratedInstallPlan
8990
-> ElaboratedSharedConfig
9091
-> IO ()
9192
writePlanExternalRepresentation
9293
distDirLayout
94+
storeDirLayout
9395
elaboratedInstallPlan
9496
elaboratedSharedConfig =
9597
writeFileAtomic (distProjectCacheFile distDirLayout "plan.json")
9698
$ BB.toLazyByteString
9799
. J.encodeToBuilder
98-
$ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig
100+
$ encodePlanAsJson distDirLayout storeDirLayout elaboratedInstallPlan elaboratedSharedConfig
99101

100102
-- | Renders a subset of the elaborated install plan in a semi-stable JSON
101103
-- format.
102-
encodePlanAsJson :: DistDirLayout -> ElaboratedInstallPlan -> ElaboratedSharedConfig -> J.Value
103-
encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
104+
encodePlanAsJson :: DistDirLayout -> StoreDirLayout -> ElaboratedInstallPlan -> ElaboratedSharedConfig -> J.Value
105+
encodePlanAsJson distDirLayout storeDirLayout elaboratedInstallPlan elaboratedSharedConfig =
104106
-- TODO: [nice to have] include all of the sharedPackageConfig and all of
105107
-- the parts of the elaboratedInstallPlan
106108
J.object
@@ -109,9 +111,11 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
109111
, "compiler-id"
110112
J..= (J.String . showCompilerId . pkgConfigCompiler)
111113
elaboratedSharedConfig
114+
, "compiler-abi" J..= J.String (prettyShow (compilerAbiTag (pkgConfigCompiler elaboratedSharedConfig)))
112115
, "os" J..= jdisplay os
113116
, "arch" J..= jdisplay arch
114117
, "install-plan" J..= installPlanToJ elaboratedInstallPlan
118+
, "store-dir" J..= storeDirToJ storeDirLayout
115119
]
116120
where
117121
plat :: Platform
@@ -120,6 +124,14 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
120124
installPlanToJ :: ElaboratedInstallPlan -> [J.Value]
121125
installPlanToJ = map planPackageToJ . InstallPlan.toList
122126

127+
storeDirToJ :: StoreDirLayout -> J.Value
128+
storeDirToJ storeLayout =
129+
J.object
130+
[ "store-dir" J..= J.String (storeDirectory storeLayout (pkgConfigCompiler elaboratedSharedConfig))
131+
, "store-package-db" J..= J.String (storePackageDBPath storeLayout (pkgConfigCompiler elaboratedSharedConfig))
132+
, "store-incoming-dir" J..= J.String (storeIncomingDirectory storeLayout (pkgConfigCompiler elaboratedSharedConfig))
133+
]
134+
123135
planPackageToJ :: ElaboratedPlanPackage -> J.Value
124136
planPackageToJ pkg =
125137
case pkg of

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

+1
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ rebuildInstallPlan
908908
debug verbosity "Updating plan.json"
909909
writePlanExternalRepresentation
910910
distDirLayout
911+
cabalStoreDirLayout
911912
elaboratedPlan
912913
elaboratedShared
913914

0 commit comments

Comments
 (0)