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
This commit is contained in:
Jaewoong Jung
2019-02-22 16:28:40 -08:00
parent 6bd446620c
commit aa65e17016
7 changed files with 171 additions and 3 deletions

View File

@@ -392,7 +392,7 @@ func (a *AndroidApp) collectAppDeps(ctx android.ModuleContext) ([]jniLib, []Cert
func (a *AndroidApp) getCertString(ctx android.BaseContext) string {
certificate, overridden := ctx.DeviceConfig().OverrideCertificateFor(ctx.ModuleName())
if overridden {
return ":" + certificate
return certificate
}
return String(a.appProperties.Certificate)
}

View File

@@ -747,3 +747,57 @@ func TestPackageNameOverride(t *testing.T) {
})
}
}
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)
}
}

View File

@@ -81,11 +81,13 @@ func testContext(config android.Config, bp string,
ctx.RegisterModuleType("droiddoc_host", android.ModuleFactoryAdaptor(DroiddocHostFactory))
ctx.RegisterModuleType("droiddoc_template", android.ModuleFactoryAdaptor(ExportedDroiddocDirFactory))
ctx.RegisterModuleType("java_sdk_library", android.ModuleFactoryAdaptor(SdkLibraryFactory))
ctx.RegisterModuleType("override_module", android.ModuleFactoryAdaptor(android.OverrideModuleFactory))
ctx.RegisterModuleType("prebuilt_apis", android.ModuleFactoryAdaptor(PrebuiltApisFactory))
ctx.PreArchMutators(android.RegisterPrebuiltsPreArchMutators)
ctx.PreArchMutators(android.RegisterPrebuiltsPostDepsMutators)
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
ctx.PreArchMutators(func(ctx android.RegisterMutatorsContext) {
ctx.TopDown("load_hooks", android.LoadHookMutator).Parallel()
ctx.TopDown("prebuilt_apis", PrebuiltApisMutator).Parallel()
ctx.TopDown("java_sdk_library", SdkLibraryMutator).Parallel()
})