From ca095d786acf53a2b628f44791e4ba954aeba169 Mon Sep 17 00:00:00 2001 From: Jaewoong Jung Date: Thu, 9 Apr 2020 16:15:30 -0700 Subject: [PATCH] Add libs properties to runtime_resource_overlay. Test: app_test.go Test: Converted an existing RRO module. Bug: 148788111 Change-Id: I723c7175760da019d38893e54f236c45f4c973ea --- java/app.go | 9 +++++++++ java/app_test.go | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/java/app.go b/java/app.go index c64f1f73c..1ad81fe84 100755 --- a/java/app.go +++ b/java/app.go @@ -1345,6 +1345,12 @@ type RuntimeResourceOverlayProperties struct { // if not blank, set the minimum version of the sdk that the compiled artifacts will run against. // Defaults to sdk_version if not set. Min_sdk_version *string + + // list of android_library modules whose resources are extracted and linked against statically + Static_libs []string + + // list of android_app modules whose resources are extracted and linked against + Resource_libs []string } func (r *RuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) { @@ -1357,6 +1363,9 @@ func (r *RuntimeResourceOverlay) DepsMutator(ctx android.BottomUpMutatorContext) if cert != "" { ctx.AddDependency(ctx.Module(), certificateTag, cert) } + + ctx.AddVariationDependencies(nil, staticLibTag, r.properties.Static_libs...) + ctx.AddVariationDependencies(nil, libTag, r.properties.Resource_libs...) } func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleContext) { diff --git a/java/app_test.go b/java/app_test.go index 10503e727..c259fe2d7 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -2342,11 +2342,17 @@ func checkAapt2LinkFlag(t *testing.T, aapt2Flags, flagName, expectedValue string } func TestRuntimeResourceOverlay(t *testing.T) { - ctx, config := testJava(t, ` + fs := map[string][]byte{ + "baz/res/res/values/strings.xml": nil, + "bar/res/res/values/strings.xml": nil, + } + bp := ` runtime_resource_overlay { name: "foo", certificate: "platform", product_specific: true, + static_libs: ["bar"], + resource_libs: ["baz"], aaptflags: ["--keep-raw-values"], } @@ -2356,7 +2362,21 @@ func TestRuntimeResourceOverlay(t *testing.T) { product_specific: true, theme: "faza", } - `) + + android_library { + name: "bar", + resource_dirs: ["bar/res"], + } + + android_app { + name: "baz", + sdk_version: "current", + resource_dirs: ["baz/res"], + } + ` + config := testAppConfig(nil, bp, fs) + ctx := testContext() + run(t, ctx, config) m := ctx.ModuleForTests("foo", "android_common") @@ -2368,6 +2388,19 @@ func TestRuntimeResourceOverlay(t *testing.T) { t.Errorf("expected values, %q are missing in aapt2 link flags, %q", absentFlags, aapt2Flags) } + // Check overlay.list output for static_libs dependency. + overlayList := m.Output("aapt2/overlay.list").Inputs.Strings() + staticLibPackage := buildDir + "/.intermediates/bar/android_common/package-res.apk" + if !inList(staticLibPackage, overlayList) { + t.Errorf("Stactic lib res package %q missing in overlay list: %q", staticLibPackage, overlayList) + } + + // Check AAPT2 link flags for resource_libs dependency. + resourceLibFlag := "-I " + buildDir + "/.intermediates/baz/android_common/package-res.apk" + if !strings.Contains(aapt2Flags, resourceLibFlag) { + t.Errorf("Resource lib flag %q missing in aapt2 link flags: %q", resourceLibFlag, aapt2Flags) + } + // Check cert signing flag. signedApk := m.Output("signed/foo.apk") signingFlag := signedApk.Args["certificates"]