Commit 60ce97d2 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Update encodePlanAsJson for Installed package state

The change in how we use the PreExisting vs Installed states means that
we'll now have full details for all packages, rather than installed
ones having only the subset of info available from the
InstalledPackageInfo. So the 'type' field now can take the values
"pre-existing", "configured" or "installed".

Also do a little bit of tidying up.
parent 492db5b5
......@@ -2,8 +2,6 @@
DeriveGeneric, DeriveDataTypeable, GeneralizedNewtypeDeriving,
ScopedTypeVariables #-}
-- | An experimental new UI for cabal for working with multiple packages
module Distribution.Client.ProjectPlanOutput (
) where
......@@ -19,6 +17,7 @@ import qualified Distribution.Simple.InstallDirs as InstallDirs
import qualified Distribution.Solver.Types.ComponentDeps as ComponentDeps
import Distribution.Package
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
import qualified Distribution.PackageDescription as PD
import Distribution.Text
import Distribution.Simple.Utils
......@@ -29,6 +28,10 @@ import qualified Data.ByteString.Builder as BB
import System.FilePath
-- Writing plan.json files
-- | Write out a representation of the elaborated install plan.
-- This is for the benefit of debugging and external tools like editors.
......@@ -53,27 +56,37 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
-- the parts of the elaboratedInstallPlan
J.object [ "cabal-version" J..= jdisplay Our.version
, "cabal-lib-version" J..= jdisplay cabalVersion
, "install-plan" J..= jsonIPlan
, "install-plan" J..= installPlanToJ elaboratedInstallPlan
jsonIPlan = map toJ (InstallPlan.toList elaboratedInstallPlan)
-- ipi :: InstalledPackageInfo
toJ (InstallPlan.PreExisting ipi) =
-- installed packages currently lack configuration information
-- such as their flag settings or non-lib components.
installPlanToJ :: ElaboratedInstallPlan -> [J.Value]
installPlanToJ = map planPackageToJ . InstallPlan.toList
planPackageToJ :: ElaboratedPlanPackage -> J.Value
planPackageToJ pkg =
case pkg of
InstallPlan.PreExisting ipi -> installedPackageInfoToJ ipi
InstallPlan.Configured elab -> elaboratedPackageToJ False elab
InstallPlan.Installed elab -> elaboratedPackageToJ True elab
installedPackageInfoToJ :: InstalledPackageInfo -> J.Value
installedPackageInfoToJ ipi =
-- Pre-existing packages lack configuration information such as their flag
-- settings or non-lib components. We only get pre-existing packages for
-- the global/core packages however, so this isn't generally a problem.
-- So these packages are never local to the project.
-- TODO: how to find out whether package is "local"?
[ "type" J..= J.String "pre-existing"
, "id" J..= jdisplay (installedUnitId ipi)
, "depends" J..= map jdisplay (installedDepends ipi)
-- pkg :: ElaboratedPackage
toJ (InstallPlan.Configured elab) =
elaboratedPackageToJ :: Bool -> ElaboratedConfiguredPackage -> J.Value
elaboratedPackageToJ isInstalled elab =
J.object $
[ "type" J..= J.String "configured"
[ "type" J..= J.String (if isInstalled then "installed"
else "configured")
, "id" J..= (jdisplay . installedUnitId) elab
, "flags" J..= J.object [ fn J..= v
| (PD.FlagName fn,v) <-
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