From d625c97587e0f93f1d202bdb0de8f1eac70f5102 Mon Sep 17 00:00:00 2001 From: Liz Kammer Date: Thu, 26 May 2022 16:17:35 -0400 Subject: [PATCH] Allow users to specify extra json action data Test: m json-module-graph and validate output Change-Id: I7ff7c2c98e49f515efb19845aa3a860e14360a32 --- context.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/context.go b/context.go index 5d7ba32..80725ab 100644 --- a/context.go +++ b/context.go @@ -2284,6 +2284,18 @@ type JSONDataSupplier interface { AddJSONData(d *map[string]interface{}) } +// JSONAction contains the action-related info we expose to json module graph +type JSONAction struct { + Inputs []string + Outputs []string +} + +// JSONActionSupplier allows JSON representation of additional actions that are not registered in +// Ninja +type JSONActionSupplier interface { + JSONActions() []JSONAction +} + func jsonModuleFromModuleInfo(m *moduleInfo) *JsonModule { result := &JsonModule{ jsonModuleName: *jsonModuleNameFromModuleInfo(m), @@ -2313,17 +2325,27 @@ func jsonModuleWithActionsFromModuleInfo(m *moduleInfo) *JsonModule { Blueprint: m.relBlueprintsFile, Module: make(map[string]interface{}), } - var actions []map[string]interface{} + var actions []JSONAction for _, bDef := range m.actionDefs.buildDefs { - actions = append(actions, map[string]interface{}{ - "Inputs": append( + actions = append(actions, JSONAction{ + Inputs: append( getNinjaStringsWithNilPkgNames(bDef.Inputs), getNinjaStringsWithNilPkgNames(bDef.Implicits)...), - "Outputs": append( + Outputs: append( getNinjaStringsWithNilPkgNames(bDef.Outputs), getNinjaStringsWithNilPkgNames(bDef.ImplicitOutputs)...), }) } + + if j, ok := m.logicModule.(JSONActionSupplier); ok { + actions = append(actions, j.JSONActions()...) + } + for _, p := range m.providers { + if j, ok := p.(JSONActionSupplier); ok { + actions = append(actions, j.JSONActions()...) + } + } + result.Module["Actions"] = actions return result }