Remove res and assets in androidmk if default
Test: new tests in androidmk_test and bpfix_test. Ran against file. Fixes: 209019903 Change-Id: I5fc9005302c006b3205b4cbd04cef7c2aca40bc8
This commit is contained in:
parent
620dc3f4f9
commit
82cf9a7d4b
3 changed files with 162 additions and 4 deletions
|
@ -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",
|
||||
|
||||
}
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue