Commit 9d6205e6 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 435725ef
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
DeriveGeneric, DeriveDataTypeable, GeneralizedNewtypeDeriving, DeriveGeneric, DeriveDataTypeable, GeneralizedNewtypeDeriving,
ScopedTypeVariables #-} ScopedTypeVariables #-}
-- | An experimental new UI for cabal for working with multiple packages
-----------------------------------------------------------------------------
module Distribution.Client.ProjectPlanOutput ( module Distribution.Client.ProjectPlanOutput (
writePlanExternalRepresentation, writePlanExternalRepresentation,
) where ) where
...@@ -19,6 +17,7 @@ import qualified Distribution.Simple.InstallDirs as InstallDirs ...@@ -19,6 +17,7 @@ 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.InstalledPackageInfo (InstalledPackageInfo)
import qualified Distribution.PackageDescription as PD import qualified Distribution.PackageDescription as PD
import Distribution.Text import Distribution.Text
import Distribution.Simple.Utils import Distribution.Simple.Utils
...@@ -29,6 +28,10 @@ import qualified Data.ByteString.Builder as BB ...@@ -29,6 +28,10 @@ import qualified Data.ByteString.Builder as BB
import System.FilePath import System.FilePath
-----------------------------------------------------------------------------
-- Writing plan.json files
--
-- | Write out a representation of the elaborated install plan. -- | Write out a representation of the elaborated install plan.
-- --
-- This is for the benefit of debugging and external tools like editors. -- This is for the benefit of debugging and external tools like editors.
...@@ -53,27 +56,37 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig = ...@@ -53,27 +56,37 @@ 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
, "install-plan" J..= jsonIPlan , "install-plan" J..= installPlanToJ elaboratedInstallPlan
] ]
where where
jsonIPlan = map toJ (InstallPlan.toList elaboratedInstallPlan) installPlanToJ :: ElaboratedInstallPlan -> [J.Value]
installPlanToJ = map planPackageToJ . InstallPlan.toList
-- ipi :: InstalledPackageInfo
toJ (InstallPlan.PreExisting ipi) = planPackageToJ :: ElaboratedPlanPackage -> J.Value
-- installed packages currently lack configuration information planPackageToJ pkg =
-- such as their flag settings or non-lib components. 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"?
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) , "depends" J..= map jdisplay (installedDepends ipi)
] ]
-- pkg :: ElaboratedPackage elaboratedPackageToJ :: Bool -> ElaboratedConfiguredPackage -> J.Value
toJ (InstallPlan.Configured elab) = elaboratedPackageToJ isInstalled elab =
J.object $ J.object $
[ "type" J..= J.String "configured" [ "type" J..= J.String (if isInstalled then "installed"
else "configured")
, "id" J..= (jdisplay . installedUnitId) elab , "id" J..= (jdisplay . installedUnitId) elab
, "flags" J..= J.object [ fn J..= v , "flags" J..= J.object [ fn J..= v
| (PD.FlagName fn,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