Add override_module.
This new module type replaces the inherit-package function in make by
allowing developers to override the name, the certificate, and the
manifest package name of an android_app module.
Bug: 122957760
Fixes: 123640028
Test: app_test.go + BrowserGoogle
Change-Id: Iefe447e7078b25039233221361ef95c83a29973a
diff --git a/java/app_test.go b/java/app_test.go
index 317c752..313844f 100644
--- a/java/app_test.go
+++ b/java/app_test.go
@@ -747,3 +747,57 @@
})
}
}
+
+func TestOverrideModule(t *testing.T) {
+ ctx := testJava(t, `
+ android_app {
+ name: "foo",
+ srcs: ["a.java"],
+ }
+
+ override_module {
+ name: "bar",
+ base: "foo",
+ certificate: ":new_certificate",
+ manifest_package_name: "org.dandroid.bp",
+ }
+
+ android_app_certificate {
+ name: "new_certificate",
+ certificate: "cert/new_cert",
+ }
+ `)
+
+ // The base module still contains all the final outputs after overrides.
+ foo := ctx.ModuleForTests("foo", "android_common")
+
+ // Check the final apk name
+ outputs := foo.AllOutputs()
+ e := buildDir + "/target/product/test_device/system/app/bar/bar.apk"
+ found := false
+ for _, o := range outputs {
+ if o == e {
+ found = true
+ break
+ }
+ }
+ if !found {
+ t.Errorf("Can't find %q in output files.\nAll outputs:%v", e, outputs)
+ }
+
+ // Check the certificate paths
+ signapk := foo.Output("foo.apk")
+ signFlags := signapk.Args["certificates"]
+ e = "cert/new_cert.x509.pem cert/new_cert.pk8"
+ if e != signFlags {
+ t.Errorf("Incorrect signing flags, expected: %q, got: %q", e, signFlags)
+ }
+
+ // Check the manifest package name
+ res := foo.Output("package-res.apk")
+ aapt2Flags := res.Args["flags"]
+ e = "--rename-manifest-package org.dandroid.bp"
+ if !strings.Contains(aapt2Flags, e) {
+ t.Errorf("package renaming flag, %q is missing in aapt2 link flags, %q", e, aapt2Flags)
+ }
+}