bpfix: Remove local_include_dirs if we remove the last entry

This still leaves a blank line in it's place, but that's a more general
problem.

Test: m blueprint_tools
Test: Run bpfix over AOSP, diff.
Change-Id: I55c1d1c183cfa49beeca07abd539348bc2524c5a
This commit is contained in:
Dan Willemsen 2018-05-07 13:32:09 -07:00
parent 028f42f002
commit dde8cb9615
2 changed files with 21 additions and 9 deletions

View File

@ -389,7 +389,7 @@ func (f *Fixer) removeMatchingModuleListProperties(canonicalName string, legacyN
continue continue
} }
legacyList, ok := getLiteralListProperty(mod, legacyName) legacyList, ok := getLiteralListProperty(mod, legacyName)
if !ok { if !ok || len(legacyList.Values) == 0 {
continue continue
} }
canonicalList, ok := getLiteralListProperty(mod, canonicalName) canonicalList, ok := getLiteralListProperty(mod, canonicalName)
@ -397,6 +397,10 @@ func (f *Fixer) removeMatchingModuleListProperties(canonicalName string, legacyN
continue continue
} }
filterExpressionList(legacyList, canonicalList) filterExpressionList(legacyList, canonicalList)
if len(legacyList.Values) == 0 {
removeProperty(mod, legacyName)
}
} }
return nil return nil
} }

View File

@ -73,20 +73,24 @@ func implFilterListTest(t *testing.T, local_include_dirs []string, export_includ
// lookup legacy property // lookup legacy property
mod := fixer.tree.Defs[0].(*parser.Module) mod := fixer.tree.Defs[0].(*parser.Module)
_, found := mod.GetProperty("local_include_dirs")
if !found { expectedResultString := fmt.Sprintf("%q", expectedResult)
t.Fatalf("failed to include key local_include_dirs in parse tree") if expectedResult == nil {
expectedResultString = "unset"
} }
// check that the value for the legacy property was updated to the correct value // check that the value for the legacy property was updated to the correct value
errorHeader := fmt.Sprintf("\nFailed to correctly simplify key 'local_include_dirs' in the presence of 'export_include_dirs.'\n"+ errorHeader := fmt.Sprintf("\nFailed to correctly simplify key 'local_include_dirs' in the presence of 'export_include_dirs.'\n"+
"original local_include_dirs: %q\n"+ "original local_include_dirs: %q\n"+
"original export_include_dirs: %q\n"+ "original export_include_dirs: %q\n"+
"expected result: %q\n"+ "expected result: %s\n"+
"actual result: ", "actual result: ",
local_include_dirs, export_include_dirs, expectedResult) local_include_dirs, export_include_dirs, expectedResultString)
result, ok := mod.GetProperty("local_include_dirs") result, found := mod.GetProperty("local_include_dirs")
if !ok { if !found {
if expectedResult == nil {
return
}
t.Fatal(errorHeader + "property not found") t.Fatal(errorHeader + "property not found")
} }
@ -95,6 +99,10 @@ func implFilterListTest(t *testing.T, local_include_dirs []string, export_includ
t.Fatalf("%sproperty is not a list: %v", errorHeader, listResult) t.Fatalf("%sproperty is not a list: %v", errorHeader, listResult)
} }
if expectedResult == nil {
t.Fatalf("%sproperty exists: %v", errorHeader, listResult)
}
actualExpressions := listResult.Values actualExpressions := listResult.Values
actualValues := make([]string, 0) actualValues := make([]string, 0)
for _, expr := range actualExpressions { for _, expr := range actualExpressions {
@ -109,7 +117,7 @@ func implFilterListTest(t *testing.T, local_include_dirs []string, export_includ
func TestSimplifyKnownVariablesDuplicatingEachOther(t *testing.T) { func TestSimplifyKnownVariablesDuplicatingEachOther(t *testing.T) {
// TODO use []Expression{} once buildTree above can support it (which is after b/38325146 is done) // TODO use []Expression{} once buildTree above can support it (which is after b/38325146 is done)
implFilterListTest(t, []string{"include"}, []string{"include"}, []string{}) implFilterListTest(t, []string{"include"}, []string{"include"}, nil)
implFilterListTest(t, []string{"include1"}, []string{"include2"}, []string{"include1"}) implFilterListTest(t, []string{"include1"}, []string{"include2"}, []string{"include1"})
implFilterListTest(t, []string{"include1", "include2", "include3", "include4"}, []string{"include2"}, implFilterListTest(t, []string{"include1", "include2", "include3", "include4"}, []string{"include2"},
[]string{"include1", "include3", "include4"}) []string{"include1", "include3", "include4"})