From 2621c909e5e3898025ed211399de8eb2edfa1491 Mon Sep 17 00:00:00 2001 From: Jeongik Cha Date: Sat, 8 Apr 2023 02:14:07 +0900 Subject: [PATCH] Replace GetOutputsFromModuleNames with GetWeightedOutputsFromPredicate Bug: 273282046 Test: m --ninja_weight_source=ninja_log Change-Id: I3f35406a7334f737ea010d5453c85e5f2d993708 --- context.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/context.go b/context.go index 17daa8a..3997633 100644 --- a/context.go +++ b/context.go @@ -2806,19 +2806,24 @@ func getNinjaStringsWithNilPkgNames(nStrs []ninjaString) []string { return strs } -func (c *Context) GetOutputsFromModuleNames(moduleNames []string) map[string][]string { - modulesToOutputs := make(map[string][]string) +func (c *Context) GetWeightedOutputsFromPredicate(predicate func(*JsonModule) (bool, int)) map[string]int { + outputToWeight := make(map[string]int) for _, m := range c.modulesSorted { - if inList(m.Name(), moduleNames) { - jmWithActions := jsonModuleWithActionsFromModuleInfo(m) + jmWithActions := jsonModuleWithActionsFromModuleInfo(m) + if ok, weight := predicate(jmWithActions); ok { for _, a := range jmWithActions.Module["Actions"].([]JSONAction) { - modulesToOutputs[m.Name()] = append(modulesToOutputs[m.Name()], a.Outputs...) + for _, o := range a.Outputs { + if val, ok := outputToWeight[o]; ok { + if val > weight { + continue + } + } + outputToWeight[o] = weight + } } - // There could be several modules with the same name, so keep looping } } - - return modulesToOutputs + return outputToWeight } func inList(s string, l []string) bool {