Add functionality for replacing string values. am: c93385a75a
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2181015 Change-Id: I01d17d6316210bed552ebcb77372380ca32ab301 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
e1055bb941
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 {
|
if (*replaceProperty).size() != 0 {
|
||||||
list, ok := value.Eval().(*parser.List)
|
if list, ok := value.Eval().(*parser.List); ok {
|
||||||
if !ok {
|
return parser.ReplaceStringsInList(list, (*replaceProperty).oldNameToNewName), nil
|
||||||
return false, []error{fmt.Errorf("expected parameter %s in module %s to be a list, found %s",
|
} else if str, ok := value.Eval().(*parser.String); ok {
|
||||||
paramName, moduleName, value.Type().String())}
|
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 {
|
if len(addIdents.idents) > 0 || len(removeIdents.idents) > 0 {
|
||||||
list, ok := value.(*parser.List)
|
list, ok := value.(*parser.List)
|
||||||
|
|
|
@ -395,6 +395,46 @@ var testCases = []struct {
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
replaceProperty: "baz:baz_lib,foobar:foobar_lib",
|
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