Merge changes I046d75db,Ie13817dc am: d2aa190bdc am: f2c86c8c76 am: 1a3ea67458

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2058908

Change-Id: I9ab91976903abbb4e3ec17b3d26db15447f074d6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Colin Cross
2022-04-12 00:58:51 +00:00
committed by Automerger Merge Worker
5 changed files with 76 additions and 42 deletions

View File

@@ -644,7 +644,21 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
}
certificates := processMainCert(a.ModuleBase, a.getCertString(ctx), certificateDeps, ctx)
a.certificate = certificates[0]
// This can be reached with an empty certificate list if AllowMissingDependencies is set
// and the certificate property for this module is a module reference to a missing module.
if len(certificates) > 0 {
a.certificate = certificates[0]
} else {
if !ctx.Config().AllowMissingDependencies() && len(ctx.GetMissingDependencies()) > 0 {
panic("Should only get here if AllowMissingDependencies set and there are missing dependencies")
}
// Set a certificate to avoid panics later when accessing it.
a.certificate = Certificate{
Key: android.PathForModuleOut(ctx, "missing.pk8"),
Pem: android.PathForModuleOut(ctx, "missing.pem"),
}
}
// Build a final signed app package.
packageFile := android.PathForModuleOut(ctx, a.installApkName+".apk")

View File

@@ -3009,3 +3009,24 @@ func TestTargetSdkVersionManifestFixer(t *testing.T) {
android.AssertStringDoesContain(t, testCase.name, manifestFixerArgs, "--targetSdkVersion "+testCase.targetSdkVersionExpected)
}
}
func TestAppMissingCertificateAllowMissingDependencies(t *testing.T) {
result := android.GroupFixturePreparers(
PrepareForTestWithJavaDefaultModules,
android.PrepareForTestWithAllowMissingDependencies,
android.PrepareForTestWithAndroidMk,
).RunTestWithBp(t, `
android_app {
name: "foo",
srcs: ["a.java"],
certificate: ":missing_certificate",
sdk_version: "current",
}`)
foo := result.ModuleForTests("foo", "android_common")
fooApk := foo.Output("foo.apk")
if fooApk.Rule != android.ErrorRule {
t.Fatalf("expected ErrorRule for foo.apk, got %s", fooApk.Rule.String())
}
android.AssertStringDoesContain(t, "expected error rule message", fooApk.Args["error"], "missing dependencies: missing_certificate\n")
}

View File

@@ -72,6 +72,10 @@ var PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd = android.GroupFixtu
defaultJavaDir + "/framework/aidl": nil,
// Needed for various deps defined in GatherRequiredDepsForTest()
defaultJavaDir + "/a.java": nil,
// Needed for R8 rules on apps
"build/make/core/proguard.flags": nil,
"build/make/core/proguard_basic_keeps.flags": nil,
}.AddToFixture(),
// The java default module definitions.
android.FixtureAddTextFile(defaultJavaDir+"/Android.bp", gatherRequiredDepsForTest()),