diff --git a/Cabal/doc/conf.py b/Cabal/doc/conf.py index 408a683c933..dd540ef6dd6 100644 --- a/Cabal/doc/conf.py +++ b/Cabal/doc/conf.py @@ -15,7 +15,7 @@ version = "2.5.0.0" -extensions = ['sphinx.ext.extlinks'] +extensions = ['sphinx.ext.extlinks', 'sphinx.ext.todo'] templates_path = ['_templates'] source_suffix = '.rst' @@ -120,6 +120,8 @@ # If true, show page references after internal links. latex_show_pagerefs = True +# http://www.sphinx-doc.org/en/master/usage/extensions/todo.html +todo_include_todos = True # -- Options for manual page output --------------------------------------- diff --git a/Cabal/doc/nix-local-build.rst b/Cabal/doc/nix-local-build.rst index dd25aea9732..2d647b021d6 100644 --- a/Cabal/doc/nix-local-build.rst +++ b/Cabal/doc/nix-local-build.rst @@ -235,12 +235,28 @@ this folder (the most important two are first): ``improved-plan`` (binary) Like ``solver-plan``, but with all non-inplace packages improved into pre-existing copies from the store. +``plan.json`` (JSON) + A JSON serialization of the computed install plan intended + for integrating ``cabal`` with external tooling. + The `cabal-plan `__ + package provides a library for parsing ``plan.json`` files into a + Haskell data structure as well as an example tool showing possible + applications. + + .. todo:: + + Document JSON schema (including version history of schema) + Note that every package also has a local cache managed by the Cabal build system, e.g., in ``$distdir/cache``. -There is another useful file in ``dist-newstyle/cache``, ``plan.json``, -which is a JSON serialization of the computed install plan. (TODO: docs) +There is another useful file in ``dist-newstyle/cache``, +``plan.json``, which is a JSON serialization of the computed install +plan and is intended for integrating with external tooling. + + + Commands ======== diff --git a/cabal-install/Distribution/Client/ProjectPlanOutput.hs b/cabal-install/Distribution/Client/ProjectPlanOutput.hs index 8eb5eed4e5a..1e0eb764148 100644 --- a/cabal-install/Distribution/Client/ProjectPlanOutput.hs +++ b/cabal-install/Distribution/Client/ProjectPlanOutput.hs @@ -18,7 +18,7 @@ module Distribution.Client.ProjectPlanOutput ( import Distribution.Client.ProjectPlanning.Types import Distribution.Client.ProjectBuilding.Types import Distribution.Client.DistDirLayout -import Distribution.Client.Types (confInstId) +import Distribution.Client.Types (Repo(..), RemoteRepo(..), PackageLocation(..), confInstId) import Distribution.Client.PackageHash (showHashValue) import qualified Distribution.Client.InstallPlan as InstallPlan @@ -139,6 +139,7 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig = , "flags" J..= J.object [ PD.unFlagName fn J..= v | (fn,v) <- PD.unFlagAssignment (elabFlagAssignment elab) ] , "style" J..= J.String (style2str (elabLocalToProject elab) (elabBuildStyle elab)) + , "pkg-src" J..= packageLocationToJ (elabPkgSourceLocation elab) ] ++ [ "pkg-src-sha256" J..= J.String (showHashValue hash) | Just hash <- [elabPkgSourceHash elab] ] ++ @@ -168,6 +169,57 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig = ] ++ bin_file (compSolverName comp) where + packageLocationToJ :: PackageLocation (Maybe FilePath) -> J.Value + packageLocationToJ pkgloc = + case pkgloc of + LocalUnpackedPackage local -> + J.object [ "type" J..= J.String "local" + , "path" J..= J.String local + ] + LocalTarballPackage local -> + J.object [ "type" J..= J.String "local-tar" + , "path" J..= J.String local + ] + RemoteTarballPackage uri _ -> + J.object [ "type" J..= J.String "remote-tar" + , "uri" J..= J.String (show uri) + ] + RepoTarballPackage repo _ _ -> + J.object [ "type" J..= J.String "repo-tar" + , "repo" J..= repoToJ repo + ] + RemoteSourceRepoPackage srcRepo _ -> + J.object [ "type" J..= J.String "source-repo" + , "source-repo" J..= sourceRepoToJ srcRepo + ] + + repoToJ :: Repo -> J.Value + repoToJ repo = + case repo of + RepoLocal{..} -> + J.object [ "type" J..= J.String "local-repo" + , "path" J..= J.String repoLocalDir + ] + RepoRemote{..} -> + J.object [ "type" J..= J.String "remote-repo" + , "uri" J..= J.String (show (remoteRepoURI repoRemote)) + ] + RepoSecure{..} -> + J.object [ "type" J..= J.String "secure-repo" + , "uri" J..= J.String (show (remoteRepoURI repoRemote)) + ] + + sourceRepoToJ :: PD.SourceRepo -> J.Value + sourceRepoToJ PD.SourceRepo{..} = + J.object $ filter ((/= J.Null) . snd) $ + [ "type" J..= fmap jdisplay repoType + , "location" J..= fmap J.String repoLocation + , "module" J..= fmap J.String repoModule + , "branch" J..= fmap J.String repoBranch + , "tag" J..= fmap J.String repoTag + , "subdir" J..= fmap J.String repoSubdir + ] + dist_dir = distBuildDirectory distDirLayout (elabDistDirParams elaboratedSharedConfig elab) @@ -510,7 +562,7 @@ postBuildProjectStatus plan previousPackagesUpToDate Graph.revClosure packagesLibDepGraph ( Map.keys . Map.filter (uncurry buildAttempted) - $ Map.intersectionWith (,) pkgBuildStatus buildOutcomes + $ Map.intersectionWith (,) pkgBuildStatus buildOutcomes ) -- The plan graph but only counting dependency-on-library edges @@ -881,4 +933,3 @@ relativePackageDBPath relroot pkgdb = UserPackageDB -> UserPackageDB SpecificPackageDB path -> SpecificPackageDB relpath where relpath = makeRelative relroot path - diff --git a/cabal-install/changelog b/cabal-install/changelog index f0f36d56f3b..a937c3db447 100644 --- a/cabal-install/changelog +++ b/cabal-install/changelog @@ -22,6 +22,7 @@ * Drop support for GHC 7.4, since it is out of our support window (and has been for over a year!). * 'new-update' now works outside of projects. (#5096) + * Extend `plan.json` with `pkg-src` provenance information. (#5487) * Add 'new-sdist' command (#5389). Creates stable archives based on cabal projects in '.zip' and '.tar.gz' formats. * Add '--repl-options' flag to 'cabal repl' and 'cabal new-repl'