Skip to content

Commit

Permalink
Merge pull request #5659 from DanielG/plan-json-req-by-default
Browse files Browse the repository at this point in the history
Add 'optional-target' field to plan.json

(cherry picked from commit bba31e6)
  • Loading branch information
23Skidoo committed Nov 11, 2018
1 parent 832a19b commit 8b7e60a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
10 changes: 9 additions & 1 deletion cabal-install/Distribution/Client/ProjectPlanOutput.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
let components = J.object $
[ comp2str c J..= (J.object $
[ "depends" J..= map (jdisplay . confInstId) ldeps
, "exe-depends" J..= map (jdisplay . confInstId) edeps ] ++
, "exe-depends" J..= map (jdisplay . confInstId) edeps
] ++
optionalTargetJ c ++
bin_file c)
| (c,(ldeps,edeps))
<- ComponentDeps.toList $
Expand All @@ -167,8 +169,14 @@ encodePlanAsJson distDirLayout elaboratedInstallPlan elaboratedSharedConfig =
,"exe-depends" J..= map jdisplay (elabExeDependencies elab)
,"component-name" J..= J.String (comp2str (compSolverName comp))
] ++
optionalTargetJ (compSolverName comp) ++
bin_file (compSolverName comp)
where
optionalTargetJ comp =
case componentOptionalStanza comp of
Nothing -> []
Just _ -> [ "optional-target" J..= J.Bool True ]

packageLocationToJ :: PackageLocation (Maybe FilePath) -> J.Value
packageLocationToJ pkgloc =
case pkgloc of
Expand Down
11 changes: 4 additions & 7 deletions cabal-install/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2415,7 +2415,7 @@ availableSourceTargets elab =
componentAvailableTargetStatus
:: Component -> AvailableTargetStatus (UnitId, ComponentName)
componentAvailableTargetStatus component =
case componentOptionalStanza (componentName component) of
case componentOptionalStanza $ CD.componentNameToComponent cname of
-- it is not an optional stanza, so a library, exe or foreign lib
Nothing
| not buildable -> TargetNotBuildable
Expand Down Expand Up @@ -2731,7 +2731,9 @@ pruneInstallPlanPass1 pkgs =
++ elabBenchTargets pkg
++ maybeToList (elabReplTarget pkg)
++ elabHaddockTargets pkg
, stanza <- maybeToList (componentOptionalStanza cname)
, stanza <- maybeToList $
componentOptionalStanza $
CD.componentNameToComponent cname
]

availablePkgs =
Expand Down Expand Up @@ -2861,11 +2863,6 @@ mapConfiguredPackage f (InstallPlan.Installed pkg) =
mapConfiguredPackage _ (InstallPlan.PreExisting pkg) =
InstallPlan.PreExisting pkg

componentOptionalStanza :: Cabal.ComponentName -> Maybe OptionalStanza
componentOptionalStanza (Cabal.CTestName _) = Just TestStanzas
componentOptionalStanza (Cabal.CBenchName _) = Just BenchStanzas
componentOptionalStanza _ = Nothing

------------------------------------
-- Support for --only-dependencies
--
Expand Down
7 changes: 7 additions & 0 deletions cabal-install/Distribution/Client/ProjectPlanning/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ module Distribution.Client.ProjectPlanning.Types (
isTestComponentTarget,
isBenchComponentTarget,

componentOptionalStanza,

-- * Setup script
SetupScriptStyle(..),
) where
Expand Down Expand Up @@ -779,6 +781,11 @@ isSubLibComponentTarget :: ComponentTarget -> Bool
isSubLibComponentTarget (ComponentTarget (CSubLibName _) _) = True
isSubLibComponentTarget _ = False

componentOptionalStanza :: CD.Component -> Maybe OptionalStanza
componentOptionalStanza (CD.ComponentTest _) = Just TestStanzas
componentOptionalStanza (CD.ComponentBench _) = Just BenchStanzas
componentOptionalStanza _ = Nothing

---------------------------
-- Setup.hs script policy
--
Expand Down

0 comments on commit 8b7e60a

Please sign in to comment.