Merge "Edit bpmodify to check Android. files and use '=' as the separator for replacements. Test: go test -v and running bpmodify with the LSC tool" am: 513e27a6a6
Original change: https://android-review.googlesource.com/c/platform/build/blueprint/+/2181555 Change-Id: I2ad2ad8d3422fd109898fa0b42f6777a84e84c93 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
d9a1e7d66b
2 changed files with 32 additions and 10 deletions
|
@ -46,7 +46,7 @@ func init() {
|
||||||
flag.Var(stringPtrFlag{&addLiteral}, "add-literal", "a literal to add")
|
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(removeIdents, "r", "comma or whitespace separated list of identifiers to remove")
|
||||||
flag.Var(stringPtrFlag{&setString}, "str", "set a string property")
|
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
|
flag.Usage = usage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,7 +301,8 @@ func targetedModule(name string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
func visitFile(path string, f os.FileInfo, err error) error {
|
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)
|
err = processFile(path, nil, os.Stdout)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -374,6 +375,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func diff(b1, b2 []byte) (data []byte, err error) {
|
func diff(b1, b2 []byte) (data []byte, err error) {
|
||||||
f1, err := ioutil.TempFile("", "bpfmt")
|
f1, err := ioutil.TempFile("", "bpfmt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -438,7 +440,7 @@ func (m *replacements) Set(s string) error {
|
||||||
m.oldNameToNewName = make(map[string]string)
|
m.oldNameToNewName = make(map[string]string)
|
||||||
for i := 0; i < length; i++ {
|
for i := 0; i < length; i++ {
|
||||||
|
|
||||||
pair := strings.SplitN(pairs[i], ":", 2)
|
pair := strings.SplitN(pairs[i], "=", 2)
|
||||||
if len(pair) != 2 {
|
if len(pair) != 2 {
|
||||||
return fmt.Errorf("Invalid replacement pair %s", pairs[i])
|
return fmt.Errorf("Invalid replacement pair %s", pairs[i])
|
||||||
}
|
}
|
||||||
|
|
|
@ -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",
|
name: "replace property multiple modules",
|
||||||
property: "deps,required",
|
property: "deps,required",
|
||||||
|
@ -396,7 +396,7 @@ var testCases = []struct {
|
||||||
required: ["foobar_lib"],
|
required: ["foobar_lib"],
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
replaceProperty: "baz:baz_lib,foobar:foobar_lib",
|
replaceProperty: "baz=baz_lib,foobar=foobar_lib",
|
||||||
}, {
|
}, {
|
||||||
name: "replace property string value",
|
name: "replace property string value",
|
||||||
property: "name",
|
property: "name",
|
||||||
|
@ -416,7 +416,7 @@ var testCases = []struct {
|
||||||
required: ["foobar"],
|
required: ["foobar"],
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
replaceProperty: "foo:foo_lib",
|
replaceProperty: "foo=foo_lib",
|
||||||
}, {
|
}, {
|
||||||
name: "replace property string and list values",
|
name: "replace property string and list values",
|
||||||
property: "name,deps",
|
property: "name,deps",
|
||||||
|
@ -436,7 +436,7 @@ var testCases = []struct {
|
||||||
required: ["foobar"],
|
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",
|
name: "move contents of property into non-existing property",
|
||||||
input: `
|
input: `
|
||||||
|
@ -476,6 +476,26 @@ var testCases = []struct {
|
||||||
property: "bar",
|
property: "bar",
|
||||||
moveProperty: true,
|
moveProperty: true,
|
||||||
newLocation: "baz",
|
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) {
|
func TestReplacementsCycleError(t *testing.T) {
|
||||||
cycleString := "old1:new1,new1:old1"
|
cycleString := "old1=new1,new1=old1"
|
||||||
err := replaceProperty.Set(cycleString)
|
err := replaceProperty.Set(cycleString)
|
||||||
|
|
||||||
if err.Error() != "Duplicated replacement name new1" {
|
if err.Error() != "Duplicated replacement name new1" {
|
||||||
|
@ -550,7 +570,7 @@ func TestReplacementsCycleError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReplacementsDuplicatedError(t *testing.T) {
|
func TestReplacementsDuplicatedError(t *testing.T) {
|
||||||
cycleString := "a:b,a:c"
|
cycleString := "a=b,a=c"
|
||||||
err := replaceProperty.Set(cycleString)
|
err := replaceProperty.Set(cycleString)
|
||||||
|
|
||||||
if err.Error() != "Duplicated replacement name a" {
|
if err.Error() != "Duplicated replacement name a" {
|
||||||
|
@ -564,7 +584,7 @@ func TestReplacementsDuplicatedError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReplacementsMultipleReplacedToSame(t *testing.T) {
|
func TestReplacementsMultipleReplacedToSame(t *testing.T) {
|
||||||
cycleString := "a:c,d:c"
|
cycleString := "a=c,d=c"
|
||||||
err := replaceProperty.Set(cycleString)
|
err := replaceProperty.Set(cycleString)
|
||||||
|
|
||||||
if err.Error() != "Duplicated replacement name c" {
|
if err.Error() != "Duplicated replacement name c" {
|
||||||
|
|
Loading…
Reference in a new issue