Skip to content

Commit bba31e6

Browse files
authored
Merge pull request #5659 from DanielG/plan-json-req-by-default
Add 'optional-target' field to plan.json
2 parents f4d41dd + b20f3f5 commit bba31e6

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

cabal-install/Distribution/Client/ProjectPlanOutput.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
155155
let components = J.object $
156156
[ comp2str c J..= (J.object $
157157
[ "depends" J..= map (jdisplay . confInstId) ldeps
158-
, "exe-depends" J..= map (jdisplay . confInstId) edeps ] ++
158+
, "exe-depends" J..= map (jdisplay . confInstId) edeps
159+
] ++
160+
optionalTargetJ c ++
159161
bin_file c)
160162
| (c,(ldeps,edeps))
161163
<- ComponentDeps.toList $
@@ -167,8 +169,14 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
167169
,"exe-depends" J..= map jdisplay (elabExeDependencies elab)
168170
,"component-name" J..= J.String (comp2str (compSolverName comp))
169171
] ++
172+
optionalTargetJ (compSolverName comp) ++
170173
bin_file (compSolverName comp)
171174
where
175+
optionalTargetJ comp =
176+
case componentOptionalStanza comp of
177+
Nothing -> []
178+
Just _ -> [ "optional-target" J..= J.Bool True ]
179+
172180
packageLocationToJ :: PackageLocation (Maybe FilePath) -> J.Value
173181
packageLocationToJ pkgloc =
174182
case pkgloc of

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@ availableSourceTargets elab =
24242424
componentAvailableTargetStatus
24252425
:: Component -> AvailableTargetStatus (UnitId, ComponentName)
24262426
componentAvailableTargetStatus component =
2427-
case componentOptionalStanza (componentName component) of
2427+
case componentOptionalStanza $ CD.componentNameToComponent cname of
24282428
-- it is not an optional stanza, so a library, exe or foreign lib
24292429
Nothing
24302430
| not buildable -> TargetNotBuildable
@@ -2744,7 +2744,9 @@ pruneInstallPlanPass1 pkgs =
27442744
++ elabBenchTargets pkg
27452745
++ maybeToList (elabReplTarget pkg)
27462746
++ elabHaddockTargets pkg
2747-
, stanza <- maybeToList (componentOptionalStanza cname)
2747+
, stanza <- maybeToList $
2748+
componentOptionalStanza $
2749+
CD.componentNameToComponent cname
27482750
]
27492751

27502752
availablePkgs =
@@ -2874,11 +2876,6 @@ mapConfiguredPackage f (InstallPlan.Installed pkg) =
28742876
mapConfiguredPackage _ (InstallPlan.PreExisting pkg) =
28752877
InstallPlan.PreExisting pkg
28762878

2877-
componentOptionalStanza :: Cabal.ComponentName -> Maybe OptionalStanza
2878-
componentOptionalStanza (Cabal.CTestName _) = Just TestStanzas
2879-
componentOptionalStanza (Cabal.CBenchName _) = Just BenchStanzas
2880-
componentOptionalStanza _ = Nothing
2881-
28822879
------------------------------------
28832880
-- Support for --only-dependencies
28842881
--

cabal-install/Distribution/Client/ProjectPlanning/Types.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ module Distribution.Client.ProjectPlanning.Types (
5454
isTestComponentTarget,
5555
isBenchComponentTarget,
5656

57+
componentOptionalStanza,
58+
5759
-- * Setup script
5860
SetupScriptStyle(..),
5961
) where
@@ -780,6 +782,11 @@ isSubLibComponentTarget :: ComponentTarget -> Bool
780782
isSubLibComponentTarget (ComponentTarget (CLibName (LSubLibName _)) _) = True
781783
isSubLibComponentTarget _ = False
782784

785+
componentOptionalStanza :: CD.Component -> Maybe OptionalStanza
786+
componentOptionalStanza (CD.ComponentTest _) = Just TestStanzas
787+
componentOptionalStanza (CD.ComponentBench _) = Just BenchStanzas
788+
componentOptionalStanza _ = Nothing
789+
783790
---------------------------
784791
-- Setup.hs script policy
785792
--

cabal-install/Distribution/Solver/Types/ComponentDeps.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ instance Traversable ComponentDeps where
9191
instance Binary a => Binary (ComponentDeps a)
9292

9393
componentNameToComponent :: CN.ComponentName -> Component
94-
componentNameToComponent (CN.CLibName LN.LMainLibName ) = ComponentLib
94+
componentNameToComponent (CN.CLibName LN.LMainLibName) = ComponentLib
9595
componentNameToComponent (CN.CLibName (LN.LSubLibName s)) = ComponentSubLib s
96-
componentNameToComponent (CN.CFLibName s) = ComponentFLib s
97-
componentNameToComponent (CN.CExeName s) = ComponentExe s
98-
componentNameToComponent (CN.CTestName s) = ComponentTest s
99-
componentNameToComponent (CN.CBenchName s) = ComponentBench s
96+
componentNameToComponent (CN.CFLibName s) = ComponentFLib s
97+
componentNameToComponent (CN.CExeName s) = ComponentExe s
98+
componentNameToComponent (CN.CTestName s) = ComponentTest s
99+
componentNameToComponent (CN.CBenchName s) = ComponentBench s
100100

101101
{-------------------------------------------------------------------------------
102102
Construction

0 commit comments

Comments
 (0)