Add JSON data related struct and function into context. am: 20f19a5d9b
am: d7fda94073
am: 5d6e46e687
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/1942213 Change-Id: I41c304f46ce6be200bcdb69bf7a696f1978c057b
This commit is contained in:
commit
1ef2a6ecfe
2 changed files with 53 additions and 0 deletions
20
context.go
20
context.go
|
@ -2300,6 +2300,26 @@ type JSONDataSupplier interface {
|
|||
AddJSONData(d *map[string]interface{})
|
||||
}
|
||||
|
||||
// A JSONDataAction contains the inputs and outputs of actions of a module. Which helps pass such
|
||||
// data to be included in the JSON module graph.
|
||||
type JSONDataAction struct {
|
||||
Inputs []string
|
||||
Outputs []string
|
||||
}
|
||||
|
||||
// FormatJSONDataActions puts the content of a list of JSONDataActions into a standard format to be
|
||||
// appended into the JSON module graph.
|
||||
func FormatJSONDataActions(jsonDataActions []JSONDataAction) []map[string]interface{} {
|
||||
var actions []map[string]interface{}
|
||||
for _, jsonDataAction := range jsonDataActions {
|
||||
actions = append(actions, map[string]interface{}{
|
||||
"Inputs": jsonDataAction.Inputs,
|
||||
"Outputs": jsonDataAction.Outputs,
|
||||
})
|
||||
}
|
||||
return actions
|
||||
}
|
||||
|
||||
func jsonModuleFromModuleInfo(m *moduleInfo) *JsonModule {
|
||||
result := &JsonModule{
|
||||
jsonModuleName: *jsonModuleNameFromModuleInfo(m),
|
||||
|
|
|
@ -607,6 +607,39 @@ func TestParseFailsForModuleWithoutName(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFormatJSONDataActions(t *testing.T) {
|
||||
inputs := []string{"fake/input/1", "fake/input/2"}
|
||||
outputs := []string{"fake/output/1", "fake/output/2"}
|
||||
jsonDataActionEmptyInputs := JSONDataAction{
|
||||
Outputs: outputs,
|
||||
}
|
||||
jsonDataActionEmptyOutputs := JSONDataAction{
|
||||
Inputs: inputs,
|
||||
}
|
||||
jsonDataAction := JSONDataAction{
|
||||
Inputs: inputs,
|
||||
Outputs: outputs,
|
||||
}
|
||||
formatData := FormatJSONDataActions([]JSONDataAction{
|
||||
jsonDataActionEmptyInputs, jsonDataActionEmptyOutputs, jsonDataAction})
|
||||
if fmt.Sprint(formatData) != fmt.Sprint([]map[string]interface{}{
|
||||
map[string]interface{}{
|
||||
"Inputs": []string{},
|
||||
"Outputs": outputs,
|
||||
},
|
||||
map[string]interface{}{
|
||||
"Inputs": inputs,
|
||||
"Outputs": []string{},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"Inputs": inputs,
|
||||
"Outputs": outputs,
|
||||
},
|
||||
}) {
|
||||
t.Errorf("The formatted JSON data %s isn't expected.", formatData)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_findVariant(t *testing.T) {
|
||||
module := &moduleInfo{
|
||||
variant: variant{
|
||||
|
|
Loading…
Reference in a new issue