Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Private Dependencies #9743

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
private deps: Support for plan.json
alt-romes committed Apr 30, 2024
commit 97fbc907fe87c280acb173ec358745d1d8b7a2d8
31 changes: 23 additions & 8 deletions cabal-install/src/Distribution/Client/ProjectPlanOutput.hs
Original file line number Diff line number Diff line change
@@ -21,11 +21,12 @@ module Distribution.Client.ProjectPlanOutput
, argsEquivalentOfGhcEnvironmentFile
) where

import Data.Either
import Distribution.Client.DistDirLayout
import Distribution.Client.HashValue (hashValue, showHashValue)
import Distribution.Client.ProjectBuilding.Types
import Distribution.Client.ProjectPlanning.Types
import Distribution.Client.Types.ConfiguredId (confInstId)
import Distribution.Client.Types.ConfiguredId (ConfiguredId, confInstId)
import Distribution.Client.Types.PackageLocation (PackageLocation (..))
import Distribution.Client.Types.Repo (RemoteRepo (..), Repo (..))
import Distribution.Client.Types.SourceRepo (SourceRepoMaybe, SourceRepositoryPackage (..))
@@ -199,9 +200,9 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
J.object $
[ comp2str c
J..= J.object
( [ "depends" J..= map (jdisplay . confInstId) (map (\(p, _, _) -> p) ldeps)
, "exe-depends" J..= map (jdisplay . confInstId) edeps
]
( handleLibDepends ldeps
++ [ "exe-depends" J..= map (jdisplay . confInstId) edeps
]
++ bin_file c
)
| (c, (ldeps, edeps)) <-
@@ -212,10 +213,10 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
]
in ["components" J..= components]
ElabComponent comp ->
[ "depends" J..= map (jdisplay . confInstId) (map (\(p, _, _) -> p) $ elabLibDependencies elab)
, "exe-depends" J..= map jdisplay (elabExeDependencies elab)
, "component-name" J..= J.String (comp2str (compSolverName comp))
]
handleLibDepends (elabLibDependencies elab)
++ [ "exe-depends" J..= map jdisplay (elabExeDependencies elab)
, "component-name" J..= J.String (comp2str (compSolverName comp))
]
++ bin_file (compSolverName comp)
where
-- \| Only add build-info file location if the Setup.hs CLI
@@ -321,6 +322,20 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
then dist_dir </> "build" </> prettyShow s </> ("lib" ++ prettyShow s) <.> dllExtension plat
else InstallDirs.bindir (elabInstallDirs elab) </> ("lib" ++ prettyShow s) <.> dllExtension plat

handleLibDepends :: [(ConfiguredId, Bool, Maybe PrivateAlias)] -> [J.Pair]
handleLibDepends deps =
let (publicDeps, privateDeps) =
partitionEithers $
map
( \(p, _, mb) -> case mb of
Nothing -> Left p
Just alias -> Right (alias, p)
)
deps
in [ "depends" J..= map (jdisplay . confInstId) publicDeps
, "private-depends" J..= J.object (map (\(al, p) -> prettyShow al J..= (jdisplay . confInstId) p) privateDeps)
]

comp2str :: ComponentDeps.Component -> String
comp2str = prettyShow