diff --git a/androidmk/androidmk/androidmk_test.go b/androidmk/androidmk/androidmk_test.go index 3c3619769..abdbf5373 100644 --- a/androidmk/androidmk/androidmk_test.go +++ b/androidmk/androidmk/androidmk_test.go @@ -699,7 +699,7 @@ include $(call all-makefiles-under,$(LOCAL_PATH)) expected: ` android_library { srcs: ["test.java"], - resource_dirs: ["res"], + jacoco: { include_filter: ["foo.*"], }, @@ -1458,7 +1458,7 @@ include $(BUILD_RRO_PACKAGE) runtime_resource_overlay { name: "foo", product_specific: true, - resource_dirs: ["res"], + sdk_version: "current", theme: "FooTheme", @@ -1602,6 +1602,22 @@ cc_prebuilt_library_shared { check_elf_files: false, } +`, + }, + { + desc: "Drop default resource and asset dirs from bp", + in: ` +include $(CLEAR_VARS) +LOCAL_MODULE := foo +LOCAL_ASSET_DIR := $(LOCAL_PATH)/assets +LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res +include $(BUILD_PACKAGE) +`, + expected: ` +android_app { + name: "foo", + +} `, }, } diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go index a9a0b1f1e..4f7d88ce6 100644 --- a/bpfix/bpfix/bpfix.go +++ b/bpfix/bpfix/bpfix.go @@ -158,6 +158,10 @@ var fixSteps = []FixStep{ Name: "formatFlagProperties", Fix: runPatchListMod(formatFlagProperties), }, + { + Name: "removeResourcesAndAssetsIfDefault", + Fix: removeResourceAndAssetsIfDefault, + }, } // for fix that only need to run once @@ -886,6 +890,24 @@ func removeSoongConfigBoolVariable(f *Fixer) error { return nil } +func removeResourceAndAssetsIfDefault(f *Fixer) error { + for _, def := range f.tree.Defs { + mod, ok := def.(*parser.Module) + if !ok { + continue + } + resourceDirList, resourceDirFound := getLiteralListPropertyValue(mod, "resource_dirs") + if resourceDirFound && len(resourceDirList) == 1 && resourceDirList[0] == "res" { + removeProperty(mod, "resource_dirs") + } + assetDirList, assetDirFound := getLiteralListPropertyValue(mod, "asset_dirs") + if assetDirFound && len(assetDirList) == 1 && assetDirList[0] == "assets" { + removeProperty(mod, "asset_dirs") + } + } + return nil +} + // Converts the default source list property, 'srcs', to a single source property with a given name. // "LOCAL_MODULE" reference is also resolved during the conversion process. func convertToSingleSource(mod *parser.Module, srcPropertyName string) { diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go index 1941837bc..17b3c2444 100644 --- a/bpfix/bpfix/bpfix_test.go +++ b/bpfix/bpfix/bpfix_test.go @@ -19,11 +19,10 @@ package bpfix import ( "bytes" "fmt" + "reflect" "strings" "testing" - "reflect" - "github.com/google/blueprint/parser" "github.com/google/blueprint/pathtools" ) @@ -2063,3 +2062,124 @@ func TestHaveSameLicense(t *testing.T) { }) } } + +func TestRemoveResourceAndAssetsIfDefault(t *testing.T) { + tests := []struct { + name string + in string + out string + }{ + { + name: "resource_dirs default", + in: ` + android_app { + name: "foo", + resource_dirs: ["res"], + } + `, + out: ` + android_app { + name: "foo", + + } + `, + }, + { + name: "resource_dirs not default", + in: ` + android_app { + name: "foo", + resource_dirs: ["reso"], + } + `, + out: ` + android_app { + name: "foo", + resource_dirs: ["reso"], + } + `, + }, + { + name: "resource_dirs includes not default", + in: ` + android_app { + name: "foo", + resource_dirs: ["res", "reso"], + } + `, + out: ` + android_app { + name: "foo", + resource_dirs: ["res", "reso"], + } + `, + }, { + name: "asset_dirs default", + in: ` + android_app { + name: "foo", + asset_dirs: ["assets"], + } + `, + out: ` + android_app { + name: "foo", + + } + `, + }, + { + name: "asset_dirs not default", + in: ` + android_app { + name: "foo", + asset_dirs: ["assety"], + } + `, + out: ` + android_app { + name: "foo", + asset_dirs: ["assety"], + } + `, + }, + { + name: "asset_dirs includes not default", + in: ` + android_app { + name: "foo", + asset_dirs: ["assets", "assety"], + } + `, + out: ` + android_app { + name: "foo", + asset_dirs: ["assets", "assety"], + } + `, + }, + { + name: "resource_dirs and asset_dirs both default", + in: ` + android_app { + name: "foo", + asset_dirs: ["assets"], + resource_dirs: ["res"], + } + `, + out: ` + android_app { + name: "foo", + + } + `, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + runPassOnce(t, test.in, test.out, func(fixer *Fixer) error { + return removeResourceAndAssetsIfDefault(fixer) + }) + }) + } +}