From 0ddae7fddd510b514f39a7f476f053ece7b420ea Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 7 Feb 2019 15:30:01 -0800 Subject: [PATCH] Allow disabling implicit resource_dirs and asset_dirs Specifying [] for resource_dirs or asset_dirs will prevent using the default "res" or "assets" directories. Test: TestResourceDirs Bug: 124035856 Change-Id: I96e38ac1319260db43950299a8b1774da68ea85e --- android/paths.go | 4 ++-- java/aar.go | 6 +++-- java/app_test.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) diff --git a/android/paths.go b/android/paths.go index 4b84c97c2..4b35fef08 100644 --- a/android/paths.go +++ b/android/paths.go @@ -263,9 +263,9 @@ func pathsForModuleSrcFromFullPath(ctx ModuleContext, paths []string, incDirs bo } // PathsWithOptionalDefaultForModuleSrc returns Paths rooted from the module's -// local source directory. If none are provided, use the default if it exists. +// local source directory. If input is nil, use the default if it exists. If input is empty, returns nil. func PathsWithOptionalDefaultForModuleSrc(ctx ModuleContext, input []string, def string) Paths { - if len(input) > 0 { + if input != nil { return PathsForModuleSrc(ctx, input) } // Use Glob so that if the default doesn't exist, a dependency is added so that when it diff --git a/java/aar.go b/java/aar.go index b01962a3f..0d38e9f85 100644 --- a/java/aar.go +++ b/java/aar.go @@ -53,11 +53,13 @@ type aaptProperties struct { Aapt_include_all_resources *bool // list of directories relative to the Blueprints file containing assets. - // Defaults to "assets" + // Defaults to ["assets"] if a directory called assets exists. Set to [] + // to disable the default. Asset_dirs []string // list of directories relative to the Blueprints file containing - // Android resources + // Android resources. Defaults to ["res"] if a directory called res exists. + // Set to [] to disable the default. Resource_dirs []string // path to AndroidManifest.xml. If unset, defaults to "AndroidManifest.xml". diff --git a/java/app_test.go b/java/app_test.go index 93d20d09a..103f24bdb 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -106,6 +106,64 @@ func TestApp(t *testing.T) { } } +func TestResourceDirs(t *testing.T) { + testCases := []struct { + name string + prop string + resources []string + }{ + { + name: "no resource_dirs", + prop: "", + resources: []string{"res/res/values/strings.xml"}, + }, + { + name: "resource_dirs", + prop: `resource_dirs: ["res"]`, + resources: []string{"res/res/values/strings.xml"}, + }, + { + name: "empty resource_dirs", + prop: `resource_dirs: []`, + resources: nil, + }, + } + + fs := map[string][]byte{ + "res/res/values/strings.xml": nil, + } + + bp := ` + android_app { + name: "foo", + %s + } + ` + + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + config := testConfig(nil) + ctx := testContext(config, fmt.Sprintf(bp, testCase.prop), fs) + run(t, ctx, config) + + module := ctx.ModuleForTests("foo", "android_common") + resourceList := module.MaybeOutput("aapt2/res.list") + + var resources []string + if resourceList.Rule != nil { + for _, compiledResource := range resourceList.Inputs.Strings() { + resources = append(resources, module.Output(compiledResource).Inputs.Strings()...) + } + } + + if !reflect.DeepEqual(resources, testCase.resources) { + t.Errorf("expected resource files %q, got %q", + testCase.resources, resources) + } + }) + } +} + func TestEnforceRRO(t *testing.T) { testCases := []struct { name string