Edit bpmodify to check Android. files and use '=' as the separator for

replacements.
Test: go test -v and running bpmodify with the LSC tool

Change-Id: I63741cce66179962e454f9a002bf358bf054c267
This commit is contained in:
MarkDacek 2022-08-10 15:32:29 +00:00
parent 30751b313c
commit 2b70006b32
2 changed files with 32 additions and 10 deletions

View file

@ -46,7 +46,7 @@ func init() {
flag.Var(stringPtrFlag{&addLiteral}, "add-literal", "a literal to add")
flag.Var(removeIdents, "r", "comma or whitespace separated list of identifiers to remove")
flag.Var(stringPtrFlag{&setString}, "str", "set a string property")
flag.Var(replaceProperty, "replace-property", "property names to be replaced, in the form of oldName1:newName1,oldName2:newName2")
flag.Var(replaceProperty, "replace-property", "property names to be replaced, in the form of oldName1=newName1,oldName2=newName2")
flag.Usage = usage
}
@ -301,7 +301,8 @@ func targetedModule(name string) bool {
return false
}
func visitFile(path string, f os.FileInfo, err error) error {
if err == nil && f.Name() == "Blueprints" {
//TODO(dacek): figure out a better way to target intended .bp files without parsing errors
if err == nil && (f.Name() == "Blueprints" || strings.HasSuffix(f.Name(), ".bp")) {
err = processFile(path, nil, os.Stdout)
}
if err != nil {
@ -374,6 +375,7 @@ func main() {
}
}
}
func diff(b1, b2 []byte) (data []byte, err error) {
f1, err := ioutil.TempFile("", "bpfmt")
if err != nil {
@ -438,7 +440,7 @@ func (m *replacements) Set(s string) error {
m.oldNameToNewName = make(map[string]string)
for i := 0; i < length; i++ {
pair := strings.SplitN(pairs[i], ":", 2)
pair := strings.SplitN(pairs[i], "=", 2)
if len(pair) != 2 {
return fmt.Errorf("Invalid replacement pair %s", pairs[i])
}

View file

@ -373,7 +373,7 @@ var testCases = []struct {
],
}
`,
replaceProperty: "baz:baz_lib,foobar:foobar_lib",
replaceProperty: "baz=baz_lib,foobar=foobar_lib",
}, {
name: "replace property multiple modules",
property: "deps,required",
@ -396,7 +396,7 @@ var testCases = []struct {
required: ["foobar_lib"],
}
`,
replaceProperty: "baz:baz_lib,foobar:foobar_lib",
replaceProperty: "baz=baz_lib,foobar=foobar_lib",
}, {
name: "replace property string value",
property: "name",
@ -416,7 +416,7 @@ var testCases = []struct {
required: ["foobar"],
}
`,
replaceProperty: "foo:foo_lib",
replaceProperty: "foo=foo_lib",
}, {
name: "replace property string and list values",
property: "name,deps",
@ -436,7 +436,7 @@ var testCases = []struct {
required: ["foobar"],
}
`,
replaceProperty: "foo:foo_lib,baz:baz_lib",
replaceProperty: "foo=foo_lib,baz=baz_lib",
}, {
name: "move contents of property into non-existing property",
input: `
@ -476,6 +476,26 @@ var testCases = []struct {
property: "bar",
moveProperty: true,
newLocation: "baz",
}, {
name: "replace nested",
input: `
cc_foo {
name: "foo",
foo: {
bar: "baz",
},
}
`,
output: `
cc_foo {
name: "foo",
foo: {
bar: "baz2",
},
}
`,
property: "foo.bar",
replaceProperty: "baz=baz2",
},
}
@ -536,7 +556,7 @@ func TestProcessModule(t *testing.T) {
}
func TestReplacementsCycleError(t *testing.T) {
cycleString := "old1:new1,new1:old1"
cycleString := "old1=new1,new1=old1"
err := replaceProperty.Set(cycleString)
if err.Error() != "Duplicated replacement name new1" {
@ -550,7 +570,7 @@ func TestReplacementsCycleError(t *testing.T) {
}
func TestReplacementsDuplicatedError(t *testing.T) {
cycleString := "a:b,a:c"
cycleString := "a=b,a=c"
err := replaceProperty.Set(cycleString)
if err.Error() != "Duplicated replacement name a" {
@ -564,7 +584,7 @@ func TestReplacementsDuplicatedError(t *testing.T) {
}
func TestReplacementsMultipleReplacedToSame(t *testing.T) {
cycleString := "a:c,d:c"
cycleString := "a=c,d=c"
err := replaceProperty.Set(cycleString)
if err.Error() != "Duplicated replacement name c" {