Commit d2f7845d authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

Add more fields to plan.json schema

This adds the following new fields:

 - `.compiler-id`
 - `.os`
 - `.arch`
 - `.install-plan[].pkg-name`
 - `.install-plan[].pkg-version`
 - `.install-plan[].pkg-src-sha256`

Having separate "pkg-{name,version}" fields is desirable because the "id"-field
is actually a UnitId which is supposed to be an opaque id which may not
always be easily convertible into a PackageId via string operations.

The "pkg-src-sha256" is generally useful to uniquely identify a
source-tarball (when the package-id is not exact enough).

Finally, the compiler-id/os/arch information is needed to determine the
values of the respective impl()/os()/arch() predicates used in
conditionals in .cabal files.

Here's an example demonstrating the new fields:

    {
      "cabal-version": "1.25.0.0",
      "cabal-lib-version": "1.25.0.0",
      "compiler-id": "ghc-8.0.1",
      "os": "linux",
      "arch": "x86_64",
      "install-plan": [
	{
	  "type": "configured",
	  "id": "StateVar-1.1.0.4-048d5d25d5813f17f152f9e766fe3ea0ef6f5317439aa115f3fc24e53a0e3c17",
	  "pkg-name": "StateVar",
	  "pkg-version": "1.1.0.4",
	  "flags": {},
	  "style": "global",
	  "pkg-src-sha256": "7ad68decb5c9a76f83c95ece5fa13d1b053e4fb1079bd2d3538f6b05014dffb7",
	  "depends": [
	    "base-4.9.0.0",
	    "stm-2.4.4.1-2c7789312d2396a91db173e1ae8cf3a9af3dd18de42bb1021c4978fbab49c191",
	    "transformers-0.5.2.0"
	  ],
	  "exe-depends": [],
	  "component-name": "lib"
	},
        {
          "type": "pre-existing",
          "id": "rts",
          "pkg-name": "rts",
          "pkg-version": "1.0",
          "depends": []
        },
	{
	  "type": "configured",
	  "id": "hackage-matrix-builder3-0.3-inplace-matrix-lib",
	  "pkg-name": "hackage-matrix-builder3",
	  "pkg-version": "0.3",
	  "component-name": "lib:matrix-lib"
	  ...
	}
	...
    }
parent ebcae71d
...@@ -19,6 +19,7 @@ import Distribution.Client.ProjectPlanning.Types ...@@ -19,6 +19,7 @@ import Distribution.Client.ProjectPlanning.Types
import Distribution.Client.ProjectBuilding.Types import Distribution.Client.ProjectBuilding.Types
import Distribution.Client.DistDirLayout import Distribution.Client.DistDirLayout
import Distribution.Client.Types (confInstId) import Distribution.Client.Types (confInstId)
import Distribution.Client.PackageHash (showHashValue)
import qualified Distribution.Client.InstallPlan as InstallPlan import qualified Distribution.Client.InstallPlan as InstallPlan
import qualified Distribution.Client.Utils.Json as J import qualified Distribution.Client.Utils.Json as J
...@@ -27,12 +28,13 @@ import qualified Distribution.Simple.InstallDirs as InstallDirs ...@@ -27,12 +28,13 @@ import qualified Distribution.Simple.InstallDirs as InstallDirs
import qualified Distribution.Solver.Types.ComponentDeps as ComponentDeps import qualified Distribution.Solver.Types.ComponentDeps as ComponentDeps
import Distribution.Package import Distribution.Package
import Distribution.System
import Distribution.InstalledPackageInfo (InstalledPackageInfo) import Distribution.InstalledPackageInfo (InstalledPackageInfo)
import qualified Distribution.PackageDescription as PD import qualified Distribution.PackageDescription as PD
import Distribution.Compiler (CompilerFlavor(GHC)) import Distribution.Compiler (CompilerFlavor(GHC))
import Distribution.Simple.Compiler import Distribution.Simple.Compiler
( PackageDBStack, PackageDB(..) ( PackageDBStack, PackageDB(..)
, compilerVersion, compilerFlavor ) , compilerVersion, compilerFlavor, showCompilerId )
import Distribution.Simple.GHC import Distribution.Simple.GHC
( getImplInfo, GhcImplInfo(supportsPkgEnvFiles) ( getImplInfo, GhcImplInfo(supportsPkgEnvFiles)
, GhcEnvironmentFileEntry(..), simpleGhcEnvironmentFile , GhcEnvironmentFileEntry(..), simpleGhcEnvironmentFile
...@@ -87,9 +89,15 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig = ...@@ -87,9 +89,15 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
-- the parts of the elaboratedInstallPlan -- the parts of the elaboratedInstallPlan
J.object [ "cabal-version" J..= jdisplay Our.version J.object [ "cabal-version" J..= jdisplay Our.version
, "cabal-lib-version" J..= jdisplay cabalVersion , "cabal-lib-version" J..= jdisplay cabalVersion
, "compiler-id" J..= (J.String . showCompilerId . pkgConfigCompiler)
elaboratedSharedConfig
, "os" J..= jdisplay os
, "arch" J..= jdisplay arch
, "install-plan" J..= installPlanToJ elaboratedInstallPlan , "install-plan" J..= installPlanToJ elaboratedInstallPlan
] ]
where where
Platform arch os = pkgConfigPlatform elaboratedSharedConfig
installPlanToJ :: ElaboratedInstallPlan -> [J.Value] installPlanToJ :: ElaboratedInstallPlan -> [J.Value]
installPlanToJ = map planPackageToJ . InstallPlan.toList installPlanToJ = map planPackageToJ . InstallPlan.toList
...@@ -113,8 +121,10 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig = ...@@ -113,8 +121,10 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
-- --
J.object J.object
[ "type" J..= J.String "pre-existing" [ "type" J..= J.String "pre-existing"
, "id" J..= jdisplay (installedUnitId ipi) , "id" J..= (jdisplay . installedUnitId) ipi
, "depends" J..= map jdisplay (installedDepends ipi) , "pkg-name" J..= (jdisplay . pkgName . packageId) ipi
, "pkg-version" J..= (jdisplay . pkgVersion . packageId) ipi
, "depends" J..= map jdisplay (installedDepends ipi)
] ]
elaboratedPackageToJ :: Bool -> ElaboratedConfiguredPackage -> J.Value elaboratedPackageToJ :: Bool -> ElaboratedConfiguredPackage -> J.Value
...@@ -123,10 +133,14 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig = ...@@ -123,10 +133,14 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
[ "type" J..= J.String (if isInstalled then "installed" [ "type" J..= J.String (if isInstalled then "installed"
else "configured") else "configured")
, "id" J..= (jdisplay . installedUnitId) elab , "id" J..= (jdisplay . installedUnitId) elab
, "pkg-name" J..= (jdisplay . pkgName . packageId) elab
, "pkg-version" J..= (jdisplay . pkgVersion . packageId) elab
, "flags" J..= J.object [ PD.unFlagName fn J..= v , "flags" J..= J.object [ PD.unFlagName fn J..= v
| (fn,v) <- elabFlagAssignment elab ] | (fn,v) <- elabFlagAssignment elab ]
, "style" J..= J.String (style2str (elabLocalToProject elab) (elabBuildStyle elab)) , "style" J..= J.String (style2str (elabLocalToProject elab) (elabBuildStyle elab))
] ++ ] ++
[ "pkg-src-sha256" J..= J.String (showHashValue hash)
| Just hash <- [elabPkgSourceHash elab] ] ++
(case elabBuildStyle elab of (case elabBuildStyle elab of
BuildInplaceOnly -> BuildInplaceOnly ->
["dist-dir" J..= J.String dist_dir] ["dist-dir" J..= J.String dist_dir]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment