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
  • Loading branch information
23Skidoo committed Nov 11, 2018
2 parents f4d41dd + b20f3f5 commit bba31e6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 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 @@ -2424,7 +2424,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 @@ -2744,7 +2744,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 @@ -2874,11 +2876,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 @@ -780,6 +782,11 @@ isSubLibComponentTarget :: ComponentTarget -> Bool
isSubLibComponentTarget (ComponentTarget (CLibName (LSubLibName _)) _) = 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
10 changes: 5 additions & 5 deletions cabal-install/Distribution/Solver/Types/ComponentDeps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ instance Traversable ComponentDeps where
instance Binary a => Binary (ComponentDeps a)

componentNameToComponent :: CN.ComponentName -> Component
componentNameToComponent (CN.CLibName LN.LMainLibName ) = ComponentLib
componentNameToComponent (CN.CLibName LN.LMainLibName) = ComponentLib
componentNameToComponent (CN.CLibName (LN.LSubLibName s)) = ComponentSubLib s
componentNameToComponent (CN.CFLibName s) = ComponentFLib s
componentNameToComponent (CN.CExeName s) = ComponentExe s
componentNameToComponent (CN.CTestName s) = ComponentTest s
componentNameToComponent (CN.CBenchName s) = ComponentBench s
componentNameToComponent (CN.CFLibName s) = ComponentFLib s
componentNameToComponent (CN.CExeName s) = ComponentExe s
componentNameToComponent (CN.CTestName s) = ComponentTest s
componentNameToComponent (CN.CBenchName s) = ComponentBench s

{-------------------------------------------------------------------------------
Construction
Expand Down

0 comments on commit bba31e6

Please sign in to comment.