Skip to content

Commit 511d03d

Browse files
committed
Merge "Extend packages in plan.json with pkg-src field" #5487
2 parents 712d0d6 + 4216274 commit 511d03d

File tree

4 files changed

+76
-6
lines changed

4 files changed

+76
-6
lines changed

Cabal/doc/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
version = "2.5.0.0"
1717

18-
extensions = ['sphinx.ext.extlinks']
18+
extensions = ['sphinx.ext.extlinks', 'sphinx.ext.todo']
1919

2020
templates_path = ['_templates']
2121
source_suffix = '.rst'
@@ -120,6 +120,8 @@
120120
# If true, show page references after internal links.
121121
latex_show_pagerefs = True
122122

123+
# http://www.sphinx-doc.org/en/master/usage/extensions/todo.html
124+
todo_include_todos = True
123125

124126
# -- Options for manual page output ---------------------------------------
125127

Cabal/doc/nix-local-build.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,28 @@ this folder (the most important two are first):
235235
``improved-plan`` (binary)
236236
Like ``solver-plan``, but with all non-inplace packages improved
237237
into pre-existing copies from the store.
238+
``plan.json`` (JSON)
239+
A JSON serialization of the computed install plan intended
240+
for integrating ``cabal`` with external tooling.
241+
The `cabal-plan <http://hackage.haskell.org/package/cabal-plan>`__
242+
package provides a library for parsing ``plan.json`` files into a
243+
Haskell data structure as well as an example tool showing possible
244+
applications.
245+
246+
.. todo::
247+
248+
Document JSON schema (including version history of schema)
249+
238250

239251
Note that every package also has a local cache managed by the Cabal
240252
build system, e.g., in ``$distdir/cache``.
241253

242-
There is another useful file in ``dist-newstyle/cache``, ``plan.json``,
243-
which is a JSON serialization of the computed install plan. (TODO: docs)
254+
There is another useful file in ``dist-newstyle/cache``,
255+
``plan.json``, which is a JSON serialization of the computed install
256+
plan and is intended for integrating with external tooling.
257+
258+
259+
244260

245261
Commands
246262
========

cabal-install/Distribution/Client/ProjectPlanOutput.hs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Distribution.Client.ProjectPlanOutput (
1818
import Distribution.Client.ProjectPlanning.Types
1919
import Distribution.Client.ProjectBuilding.Types
2020
import Distribution.Client.DistDirLayout
21-
import Distribution.Client.Types (confInstId)
21+
import Distribution.Client.Types (Repo(..), RemoteRepo(..), PackageLocation(..), confInstId)
2222
import Distribution.Client.PackageHash (showHashValue)
2323

2424
import qualified Distribution.Client.InstallPlan as InstallPlan
@@ -139,6 +139,7 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
139139
, "flags" J..= J.object [ PD.unFlagName fn J..= v
140140
| (fn,v) <- PD.unFlagAssignment (elabFlagAssignment elab) ]
141141
, "style" J..= J.String (style2str (elabLocalToProject elab) (elabBuildStyle elab))
142+
, "pkg-src" J..= packageLocationToJ (elabPkgSourceLocation elab)
142143
] ++
143144
[ "pkg-src-sha256" J..= J.String (showHashValue hash)
144145
| Just hash <- [elabPkgSourceHash elab] ] ++
@@ -168,6 +169,57 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
168169
] ++
169170
bin_file (compSolverName comp)
170171
where
172+
packageLocationToJ :: PackageLocation (Maybe FilePath) -> J.Value
173+
packageLocationToJ pkgloc =
174+
case pkgloc of
175+
LocalUnpackedPackage local ->
176+
J.object [ "type" J..= J.String "local"
177+
, "path" J..= J.String local
178+
]
179+
LocalTarballPackage local ->
180+
J.object [ "type" J..= J.String "local-tar"
181+
, "path" J..= J.String local
182+
]
183+
RemoteTarballPackage uri _ ->
184+
J.object [ "type" J..= J.String "remote-tar"
185+
, "uri" J..= J.String (show uri)
186+
]
187+
RepoTarballPackage repo _ _ ->
188+
J.object [ "type" J..= J.String "repo-tar"
189+
, "repo" J..= repoToJ repo
190+
]
191+
RemoteSourceRepoPackage srcRepo _ ->
192+
J.object [ "type" J..= J.String "source-repo"
193+
, "source-repo" J..= sourceRepoToJ srcRepo
194+
]
195+
196+
repoToJ :: Repo -> J.Value
197+
repoToJ repo =
198+
case repo of
199+
RepoLocal{..} ->
200+
J.object [ "type" J..= J.String "local-repo"
201+
, "path" J..= J.String repoLocalDir
202+
]
203+
RepoRemote{..} ->
204+
J.object [ "type" J..= J.String "remote-repo"
205+
, "uri" J..= J.String (show (remoteRepoURI repoRemote))
206+
]
207+
RepoSecure{..} ->
208+
J.object [ "type" J..= J.String "secure-repo"
209+
, "uri" J..= J.String (show (remoteRepoURI repoRemote))
210+
]
211+
212+
sourceRepoToJ :: PD.SourceRepo -> J.Value
213+
sourceRepoToJ PD.SourceRepo{..} =
214+
J.object $ filter ((/= J.Null) . snd) $
215+
[ "type" J..= fmap jdisplay repoType
216+
, "location" J..= fmap J.String repoLocation
217+
, "module" J..= fmap J.String repoModule
218+
, "branch" J..= fmap J.String repoBranch
219+
, "tag" J..= fmap J.String repoTag
220+
, "subdir" J..= fmap J.String repoSubdir
221+
]
222+
171223
dist_dir = distBuildDirectory distDirLayout
172224
(elabDistDirParams elaboratedSharedConfig elab)
173225

@@ -510,7 +562,7 @@ postBuildProjectStatus plan previousPackagesUpToDate
510562
Graph.revClosure packagesLibDepGraph
511563
( Map.keys
512564
. Map.filter (uncurry buildAttempted)
513-
$ Map.intersectionWith (,) pkgBuildStatus buildOutcomes
565+
$ Map.intersectionWith (,) pkgBuildStatus buildOutcomes
514566
)
515567

516568
-- The plan graph but only counting dependency-on-library edges
@@ -881,4 +933,3 @@ relativePackageDBPath relroot pkgdb =
881933
UserPackageDB -> UserPackageDB
882934
SpecificPackageDB path -> SpecificPackageDB relpath
883935
where relpath = makeRelative relroot path
884-

cabal-install/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Drop support for GHC 7.4, since it is out of our support window
2727
(and has been for over a year!).
2828
* 'new-update' now works outside of projects. (#5096)
29+
* Extend `plan.json` with `pkg-src` provenance information. (#5487)
2930
* Add 'new-sdist' command (#5389). Creates stable archives based on
3031
cabal projects in '.zip' and '.tar.gz' formats.
3132
* Add '--repl-options' flag to 'cabal repl' and 'cabal new-repl'

0 commit comments

Comments
 (0)