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

Add 'optional-target' field to plan.json #5659

Merged
merged 4 commits into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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