Add functionality for replacing string values. am: c93385a75a
am: e1055bb941
am: 63dab80715
am: 5bdbfb1e06
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2181015 Change-Id: Ibf113047432d79570b9a8447165657c672a20ffa Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
fe8582acc3
2 changed files with 53 additions and 5 deletions
|
@ -230,12 +230,20 @@ func processParameter(value parser.Expression, paramName, moduleName string,
|
|||
}
|
||||
|
||||
if (*replaceProperty).size() != 0 {
|
||||
list, ok := value.Eval().(*parser.List)
|
||||
if !ok {
|
||||
return false, []error{fmt.Errorf("expected parameter %s in module %s to be a list, found %s",
|
||||
paramName, moduleName, value.Type().String())}
|
||||
if list, ok := value.Eval().(*parser.List); ok {
|
||||
return parser.ReplaceStringsInList(list, (*replaceProperty).oldNameToNewName), nil
|
||||
} else if str, ok := value.Eval().(*parser.String); ok {
|
||||
oldVal := str.Value
|
||||
replacementValue := (*replaceProperty).oldNameToNewName[oldVal]
|
||||
if replacementValue != "" {
|
||||
str.Value = replacementValue
|
||||
return true, nil
|
||||
} else {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return parser.ReplaceStringsInList(list, (*replaceProperty).oldNameToNewName), nil
|
||||
return false, []error{fmt.Errorf("expected parameter %s in module %s to be a list or string, found %s",
|
||||
paramName, moduleName, value.Type().String())}
|
||||
}
|
||||
if len(addIdents.idents) > 0 || len(removeIdents.idents) > 0 {
|
||||
list, ok := value.(*parser.List)
|
||||
|
|
|
@ -395,6 +395,46 @@ var testCases = []struct {
|
|||
}
|
||||
`,
|
||||
replaceProperty: "baz:baz_lib,foobar:foobar_lib",
|
||||
}, {
|
||||
name: "replace property string value",
|
||||
property: "name",
|
||||
input: `
|
||||
cc_foo {
|
||||
name: "foo",
|
||||
deps: ["baz"],
|
||||
unchanged: ["baz"],
|
||||
required: ["foobar"],
|
||||
}
|
||||
`,
|
||||
output: `
|
||||
cc_foo {
|
||||
name: "foo_lib",
|
||||
deps: ["baz"],
|
||||
unchanged: ["baz"],
|
||||
required: ["foobar"],
|
||||
}
|
||||
`,
|
||||
replaceProperty: "foo:foo_lib",
|
||||
}, {
|
||||
name: "replace property string and list values",
|
||||
property: "name,deps",
|
||||
input: `
|
||||
cc_foo {
|
||||
name: "foo",
|
||||
deps: ["baz"],
|
||||
unchanged: ["baz"],
|
||||
required: ["foobar"],
|
||||
}
|
||||
`,
|
||||
output: `
|
||||
cc_foo {
|
||||
name: "foo_lib",
|
||||
deps: ["baz_lib"],
|
||||
unchanged: ["baz"],
|
||||
required: ["foobar"],
|
||||
}
|
||||
`,
|
||||
replaceProperty: "foo:foo_lib,baz:baz_lib",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue