Merge changes I61fdd945,I746a00a3
* changes: bpfix: Convert local_include_dirs removal to PatchList bpfix: Add reorderCommonProperties
This commit is contained in:
@@ -49,6 +49,7 @@ type FixRequest struct {
|
|||||||
rewriteIncorrectAndroidmkPrebuilts bool
|
rewriteIncorrectAndroidmkPrebuilts bool
|
||||||
rewriteIncorrectAndroidmkAndroidLibraries bool
|
rewriteIncorrectAndroidmkAndroidLibraries bool
|
||||||
mergeMatchingModuleProperties bool
|
mergeMatchingModuleProperties bool
|
||||||
|
reorderCommonProperties bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFixRequest() FixRequest {
|
func NewFixRequest() FixRequest {
|
||||||
@@ -61,6 +62,7 @@ func (r FixRequest) AddAll() (result FixRequest) {
|
|||||||
result.rewriteIncorrectAndroidmkPrebuilts = true
|
result.rewriteIncorrectAndroidmkPrebuilts = true
|
||||||
result.rewriteIncorrectAndroidmkAndroidLibraries = true
|
result.rewriteIncorrectAndroidmkAndroidLibraries = true
|
||||||
result.mergeMatchingModuleProperties = true
|
result.mergeMatchingModuleProperties = true
|
||||||
|
result.reorderCommonProperties = true
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,11 +147,12 @@ func parse(name string, r io.Reader) (*parser.File, error) {
|
|||||||
|
|
||||||
func (f *Fixer) fixTreeOnce(config FixRequest) error {
|
func (f *Fixer) fixTreeOnce(config FixRequest) error {
|
||||||
if config.simplifyKnownRedundantVariables {
|
if config.simplifyKnownRedundantVariables {
|
||||||
err := f.simplifyKnownPropertiesDuplicatingEachOther()
|
err := f.runPatchListMod(simplifyKnownPropertiesDuplicatingEachOther)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.rewriteIncorrectAndroidmkPrebuilts {
|
if config.rewriteIncorrectAndroidmkPrebuilts {
|
||||||
err := f.rewriteIncorrectAndroidmkPrebuilts()
|
err := f.rewriteIncorrectAndroidmkPrebuilts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -165,7 +168,14 @@ func (f *Fixer) fixTreeOnce(config FixRequest) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.mergeMatchingModuleProperties {
|
if config.mergeMatchingModuleProperties {
|
||||||
err := f.mergeMatchingModuleProperties()
|
err := f.runPatchListMod(mergeMatchingModuleProperties)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.reorderCommonProperties {
|
||||||
|
err := f.runPatchListMod(reorderCommonProperties)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -173,9 +183,10 @@ func (f *Fixer) fixTreeOnce(config FixRequest) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fixer) simplifyKnownPropertiesDuplicatingEachOther() error {
|
func simplifyKnownPropertiesDuplicatingEachOther(mod *parser.Module, buf []byte, patchList *parser.PatchList) error {
|
||||||
// remove from local_include_dirs anything in export_include_dirs
|
// remove from local_include_dirs anything in export_include_dirs
|
||||||
return f.removeMatchingModuleListProperties("export_include_dirs", "local_include_dirs")
|
return removeMatchingModuleListProperties(mod, patchList,
|
||||||
|
"export_include_dirs", "local_include_dirs")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fixer) rewriteIncorrectAndroidmkPrebuilts() error {
|
func (f *Fixer) rewriteIncorrectAndroidmkPrebuilts() error {
|
||||||
@@ -249,7 +260,7 @@ func (f *Fixer) rewriteIncorrectAndroidmkAndroidLibraries() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Fixer) mergeMatchingModuleProperties() error {
|
func (f *Fixer) runPatchListMod(modFunc func(mod *parser.Module, buf []byte, patchlist *parser.PatchList) error) error {
|
||||||
// Make sure all the offsets are accurate
|
// Make sure all the offsets are accurate
|
||||||
buf, err := f.reparse()
|
buf, err := f.reparse()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -263,7 +274,7 @@ func (f *Fixer) mergeMatchingModuleProperties() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err := mergeMatchingProperties(&mod.Properties, buf, &patchlist)
|
err := modFunc(mod, buf, &patchlist)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -275,9 +286,12 @@ func (f *Fixer) mergeMatchingModuleProperties() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save a copy of the buffer to print for errors below
|
||||||
|
bufCopy := append([]byte(nil), newBuf.Bytes()...)
|
||||||
|
|
||||||
newTree, err := parse(f.tree.Name, newBuf)
|
newTree, err := parse(f.tree.Name, newBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("Failed to parse: %v\nBuffer:\n%s", err, string(bufCopy))
|
||||||
}
|
}
|
||||||
|
|
||||||
f.tree = newTree
|
f.tree = newTree
|
||||||
@@ -285,6 +299,63 @@ func (f *Fixer) mergeMatchingModuleProperties() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var commonPropertyPriorities = []string{
|
||||||
|
"name",
|
||||||
|
"defaults",
|
||||||
|
"device_supported",
|
||||||
|
"host_supported",
|
||||||
|
}
|
||||||
|
|
||||||
|
func reorderCommonProperties(mod *parser.Module, buf []byte, patchlist *parser.PatchList) error {
|
||||||
|
if len(mod.Properties) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
pos := mod.LBracePos.Offset + 1
|
||||||
|
stage := ""
|
||||||
|
|
||||||
|
for _, name := range commonPropertyPriorities {
|
||||||
|
idx := propertyIndex(mod.Properties, name)
|
||||||
|
if idx == -1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if idx == 0 {
|
||||||
|
err := patchlist.Add(pos, pos, stage)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
stage = ""
|
||||||
|
|
||||||
|
pos = mod.Properties[0].End().Offset + 1
|
||||||
|
mod.Properties = mod.Properties[1:]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
prop := mod.Properties[idx]
|
||||||
|
mod.Properties = append(mod.Properties[:idx], mod.Properties[idx+1:]...)
|
||||||
|
|
||||||
|
stage += string(buf[prop.Pos().Offset : prop.End().Offset+1])
|
||||||
|
|
||||||
|
err := patchlist.Add(prop.Pos().Offset, prop.End().Offset+2, "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if stage != "" {
|
||||||
|
err := patchlist.Add(pos, pos, stage)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mergeMatchingModuleProperties(mod *parser.Module, buf []byte, patchlist *parser.PatchList) error {
|
||||||
|
return mergeMatchingProperties(&mod.Properties, buf, patchlist)
|
||||||
|
}
|
||||||
|
|
||||||
func mergeMatchingProperties(properties *[]*parser.Property, buf []byte, patchlist *parser.PatchList) error {
|
func mergeMatchingProperties(properties *[]*parser.Property, buf []byte, patchlist *parser.PatchList) error {
|
||||||
seen := make(map[string]*parser.Property)
|
seen := make(map[string]*parser.Property)
|
||||||
for i := 0; i < len(*properties); i++ {
|
for i := 0; i < len(*properties); i++ {
|
||||||
@@ -359,7 +430,7 @@ func mergeListProperties(a, b *parser.Property, buf []byte, patchlist *parser.Pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// removes from <items> every item present in <removals>
|
// removes from <items> every item present in <removals>
|
||||||
func filterExpressionList(items *parser.List, removals *parser.List) {
|
func filterExpressionList(patchList *parser.PatchList, items *parser.List, removals *parser.List) {
|
||||||
writeIndex := 0
|
writeIndex := 0
|
||||||
for _, item := range items.Values {
|
for _, item := range items.Values {
|
||||||
included := true
|
included := true
|
||||||
@@ -376,32 +447,39 @@ func filterExpressionList(items *parser.List, removals *parser.List) {
|
|||||||
if included {
|
if included {
|
||||||
items.Values[writeIndex] = item
|
items.Values[writeIndex] = item
|
||||||
writeIndex++
|
writeIndex++
|
||||||
|
} else {
|
||||||
|
patchList.Add(item.Pos().Offset, item.End().Offset+2, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
items.Values = items.Values[:writeIndex]
|
items.Values = items.Values[:writeIndex]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove each modules[i].Properties[<legacyName>][j] that matches a modules[i].Properties[<canonicalName>][k]
|
// Remove each modules[i].Properties[<legacyName>][j] that matches a modules[i].Properties[<canonicalName>][k]
|
||||||
func (f *Fixer) removeMatchingModuleListProperties(canonicalName string, legacyName string) error {
|
func removeMatchingModuleListProperties(mod *parser.Module, patchList *parser.PatchList, canonicalName string, legacyName string) error {
|
||||||
for _, def := range f.tree.Defs {
|
legacyProp, ok := mod.GetProperty(legacyName)
|
||||||
mod, ok := def.(*parser.Module)
|
if !ok {
|
||||||
if !ok {
|
return nil
|
||||||
continue
|
}
|
||||||
}
|
legacyList, ok := legacyProp.Value.(*parser.List)
|
||||||
legacyList, ok := getLiteralListProperty(mod, legacyName)
|
if !ok || len(legacyList.Values) == 0 {
|
||||||
if !ok || len(legacyList.Values) == 0 {
|
return nil
|
||||||
continue
|
}
|
||||||
}
|
canonicalList, ok := getLiteralListProperty(mod, canonicalName)
|
||||||
canonicalList, ok := getLiteralListProperty(mod, canonicalName)
|
if !ok {
|
||||||
if !ok {
|
return nil
|
||||||
continue
|
}
|
||||||
}
|
|
||||||
filterExpressionList(legacyList, canonicalList)
|
|
||||||
|
|
||||||
if len(legacyList.Values) == 0 {
|
localPatches := parser.PatchList{}
|
||||||
removeProperty(mod, legacyName)
|
filterExpressionList(&localPatches, legacyList, canonicalList)
|
||||||
|
|
||||||
|
if len(legacyList.Values) == 0 {
|
||||||
|
patchList.Add(legacyProp.Pos().Offset, legacyProp.End().Offset+2, "")
|
||||||
|
} else {
|
||||||
|
for _, p := range localPatches {
|
||||||
|
patchList.Add(p.Start, p.End, p.Replacement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -419,6 +497,15 @@ func getLiteralListProperty(mod *parser.Module, name string) (list *parser.List,
|
|||||||
return list, ok
|
return list, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func propertyIndex(props []*parser.Property, propertyName string) int {
|
||||||
|
for i, prop := range props {
|
||||||
|
if prop.Name == propertyName {
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
func renameProperty(mod *parser.Module, from, to string) {
|
func renameProperty(mod *parser.Module, from, to string) {
|
||||||
for _, prop := range mod.Properties {
|
for _, prop := range mod.Properties {
|
||||||
if prop.Name == from {
|
if prop.Name == from {
|
||||||
|
@@ -66,7 +66,7 @@ func implFilterListTest(t *testing.T, local_include_dirs []string, export_includ
|
|||||||
fixer := NewFixer(tree)
|
fixer := NewFixer(tree)
|
||||||
|
|
||||||
// apply simplifications
|
// apply simplifications
|
||||||
err := fixer.simplifyKnownPropertiesDuplicatingEachOther()
|
err := fixer.runPatchListMod(simplifyKnownPropertiesDuplicatingEachOther)
|
||||||
if len(errs) > 0 {
|
if len(errs) > 0 {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -125,6 +125,49 @@ func TestSimplifyKnownVariablesDuplicatingEachOther(t *testing.T) {
|
|||||||
implFilterListTest(t, []string{}, []string{}, []string{})
|
implFilterListTest(t, []string{}, []string{}, []string{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func runPass(t *testing.T, in, out string, innerTest func(*Fixer) error) {
|
||||||
|
expected, err := Reformat(out)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
in, err = Reformat(in)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tree, errs := parser.Parse("<testcase>", bytes.NewBufferString(in), parser.NewScope(nil))
|
||||||
|
if errs != nil {
|
||||||
|
t.Fatal(errs)
|
||||||
|
}
|
||||||
|
|
||||||
|
fixer := NewFixer(tree)
|
||||||
|
|
||||||
|
got := ""
|
||||||
|
prev := "foo"
|
||||||
|
passes := 0
|
||||||
|
for got != prev && passes < 10 {
|
||||||
|
err := innerTest(fixer)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err := parser.Print(fixer.tree)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
prev = got
|
||||||
|
got = string(out)
|
||||||
|
passes++
|
||||||
|
}
|
||||||
|
|
||||||
|
if got != expected {
|
||||||
|
t.Errorf("output didn't match:\ninput:\n%s\n\nexpected:\n%s\ngot:\n%s\n",
|
||||||
|
in, expected, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestMergeMatchingProperties(t *testing.T) {
|
func TestMergeMatchingProperties(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -207,47 +250,250 @@ func TestMergeMatchingProperties(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
expected, err := Reformat(test.out)
|
runPass(t, test.in, test.out, func(fixer *Fixer) error {
|
||||||
if err != nil {
|
return fixer.runPatchListMod(mergeMatchingModuleProperties)
|
||||||
t.Error(err)
|
})
|
||||||
}
|
})
|
||||||
|
}
|
||||||
in, err := Reformat(test.in)
|
}
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
func TestReorderCommonProperties(t *testing.T) {
|
||||||
}
|
var tests = []struct {
|
||||||
|
name string
|
||||||
tree, errs := parser.Parse("<testcase>", bytes.NewBufferString(in), parser.NewScope(nil))
|
in string
|
||||||
if errs != nil {
|
out string
|
||||||
t.Fatal(errs)
|
}{
|
||||||
}
|
{
|
||||||
|
name: "empty",
|
||||||
fixer := NewFixer(tree)
|
in: `cc_library {}`,
|
||||||
|
out: `cc_library {}`,
|
||||||
got := ""
|
},
|
||||||
prev := "foo"
|
{
|
||||||
passes := 0
|
name: "only priority",
|
||||||
for got != prev && passes < 10 {
|
in: `
|
||||||
err := fixer.mergeMatchingModuleProperties()
|
cc_library {
|
||||||
if err != nil {
|
name: "foo",
|
||||||
t.Fatal(err)
|
}
|
||||||
}
|
`,
|
||||||
|
out: `
|
||||||
out, err := parser.Print(fixer.tree)
|
cc_library {
|
||||||
if err != nil {
|
name: "foo",
|
||||||
t.Fatal(err)
|
}
|
||||||
}
|
`,
|
||||||
|
},
|
||||||
prev = got
|
{
|
||||||
got = string(out)
|
name: "already in order",
|
||||||
passes++
|
in: `
|
||||||
}
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
if got != expected {
|
defaults: ["bar"],
|
||||||
t.Errorf("failed testcase '%s'\ninput:\n%s\n\nexpected:\n%s\ngot:\n%s\n",
|
}
|
||||||
test.name, in, expected, got)
|
`,
|
||||||
}
|
out: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
defaults: ["bar"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "reorder only priority",
|
||||||
|
in: `
|
||||||
|
cc_library {
|
||||||
|
defaults: ["bar"],
|
||||||
|
name: "foo",
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
out: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
defaults: ["bar"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "reorder",
|
||||||
|
in: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
srcs: ["a.c"],
|
||||||
|
host_supported: true,
|
||||||
|
defaults: ["bar"],
|
||||||
|
shared_libs: ["baz"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
out: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
defaults: ["bar"],
|
||||||
|
host_supported: true,
|
||||||
|
srcs: ["a.c"],
|
||||||
|
shared_libs: ["baz"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
runPass(t, test.in, test.out, func(fixer *Fixer) error {
|
||||||
|
return fixer.runPatchListMod(reorderCommonProperties)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRemoveMatchingModuleListProperties(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
name string
|
||||||
|
in string
|
||||||
|
out string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "simple",
|
||||||
|
in: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
foo: ["a"],
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
out: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "long",
|
||||||
|
in: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
foo: [
|
||||||
|
"a",
|
||||||
|
"b",
|
||||||
|
],
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
out: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
foo: [
|
||||||
|
"b",
|
||||||
|
],
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "long fully removed",
|
||||||
|
in: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
foo: [
|
||||||
|
"a",
|
||||||
|
],
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
out: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "comment",
|
||||||
|
in: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
|
||||||
|
// comment
|
||||||
|
foo: ["a"],
|
||||||
|
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
out: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
|
||||||
|
// comment
|
||||||
|
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "inner comment",
|
||||||
|
in: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
foo: [
|
||||||
|
// comment
|
||||||
|
"a",
|
||||||
|
],
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
out: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "eol comment",
|
||||||
|
in: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
foo: ["a"], // comment
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
out: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
// comment
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "eol comment with blank lines",
|
||||||
|
in: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
|
||||||
|
foo: ["a"], // comment
|
||||||
|
|
||||||
|
// bar
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
out: `
|
||||||
|
cc_library {
|
||||||
|
name: "foo",
|
||||||
|
|
||||||
|
// comment
|
||||||
|
|
||||||
|
// bar
|
||||||
|
bar: ["a"],
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
runPass(t, test.in, test.out, func(fixer *Fixer) error {
|
||||||
|
return fixer.runPatchListMod(func(mod *parser.Module, buf []byte, patchList *parser.PatchList) error {
|
||||||
|
return removeMatchingModuleListProperties(mod, patchList, "bar", "foo")
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user