Skip to content

Commit 7c04a29

Browse files
committed
Add revision information to plan.json
Closes #6186
1 parent d643706 commit 7c04a29

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ import Distribution.Verbosity
6666
import Distribution.Client.Compat.Prelude
6767
import Prelude ()
6868

69+
import Control.Monad ((<=<))
70+
6971
import qualified Data.ByteString.Builder as BB
7072
import qualified Data.ByteString.Lazy as BS
7173
import qualified Data.Map as Map
@@ -259,13 +261,24 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
259261
J.object
260262
[ "type" J..= J.String "remote-repo"
261263
, "uri" J..= J.String (show (remoteRepoURI repoRemote))
264+
, -- The x-revision field is a feature of remote repos,
265+
-- so we only output it for remote/secure repos, in the "repo" object.
266+
"pkg-revision" J..= J.Number (elaboratedPackageToRevision elab)
262267
]
263268
RepoSecure{..} ->
264269
J.object
265270
[ "type" J..= J.String "secure-repo"
266271
, "uri" J..= J.String (show (remoteRepoURI repoRemote))
272+
, "pkg-revision" J..= J.Number (elaboratedPackageToRevision elab)
267273
]
268274

275+
elaboratedPackageToRevision :: ElaboratedConfiguredPackage -> Double
276+
elaboratedPackageToRevision =
277+
fromMaybe 0
278+
. (readMaybe <=< lookup "x-revision")
279+
. PD.customFieldsPD
280+
. elabPkgDescription
281+
269282
sourceRepoToJ :: SourceRepoMaybe -> J.Value
270283
sourceRepoToJ SourceRepositoryPackage{..} =
271284
J.object $

changelog.d/pr-10980

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
synopsis: Added revision information to `plan.json`
2+
packages: cabal-install
3+
prs: #10980
4+
issues: #6186
5+
6+
description: {
7+
The contents of `x-revision` `.cabal` fields are now available in `plan.json`.
8+
They are located under `pkg-src.repo.pkg-revision`, have type `Number`, and are only available for `repo-tar` repositories of type `remote-repo` or `secure-repo`.
9+
}

0 commit comments

Comments
 (0)