Add functionality for replacing string values. am: c93385a75a am: e1055bb941 am: 63dab80715

Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2181015

Change-Id: Ic19ea3c050fd9ebf4200ec1e71c70df5d17b3e26
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
MarkDacek 2022-08-10 16:26:27 +00:00 committed by Automerger Merge Worker
commit 5bdbfb1e06
2 changed files with 53 additions and 5 deletions

View file

@ -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)

View file

@ -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",
}, },
} }