Merge "Add preprocessed property for android_test_import" am: 42ada5cff3

Change-Id: Ie29e07ede82444235182a79aa74939e9358e7389
This commit is contained in:
Treehugger Robot 2020-05-21 22:38:18 +00:00 committed by Automerger Merge Worker
commit 3d075275c2
2 changed files with 59 additions and 4 deletions

View File

@ -1257,6 +1257,8 @@ type AndroidAppImport struct {
usesLibrary usesLibrary
preprocessed bool
installPath android.InstallPath
}
@ -1349,7 +1351,7 @@ func (a *AndroidAppImport) uncompressEmbeddedJniLibs(
ctx android.ModuleContext, inputPath android.Path, outputPath android.OutputPath) {
// Test apps don't need their JNI libraries stored uncompressed. As a matter of fact, messing
// with them may invalidate pre-existing signature data.
if ctx.InstallInTestcases() && Bool(a.properties.Presigned) {
if ctx.InstallInTestcases() && (Bool(a.properties.Presigned) || a.preprocessed) {
ctx.Build(pctx, android.BuildParams{
Rule: android.Cp,
Output: outputPath,
@ -1370,7 +1372,7 @@ func (a *AndroidAppImport) uncompressEmbeddedJniLibs(
// Returns whether this module should have the dex file stored uncompressed in the APK.
func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool {
if ctx.Config().UnbundledBuild() {
if ctx.Config().UnbundledBuild() || a.preprocessed {
return false
}
@ -1462,9 +1464,13 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext
apkFilename := proptools.StringDefault(a.properties.Filename, a.BaseModuleName()+".apk")
// Sign or align the package
// TODO: Handle EXTERNAL
if !Bool(a.properties.Presigned) {
// Sign or align the package if package has not been preprocessed
if a.preprocessed {
a.outputFile = srcApk
a.certificate = presignedCertificate
} else if !Bool(a.properties.Presigned) {
// If the certificate property is empty at this point, default_dev_cert must be set to true.
// Which makes processMainCert's behavior for the empty cert string WAI.
certificates = processMainCert(a.ModuleBase, String(a.properties.Certificate), certificates, ctx)
@ -1609,15 +1615,24 @@ func AndroidAppImportFactory() android.Module {
return module
}
type androidTestImportProperties struct {
// Whether the prebuilt apk can be installed without additional processing. Default is false.
Preprocessed *bool
}
type AndroidTestImport struct {
AndroidAppImport
testProperties testProperties
testImportProperties androidTestImportProperties
data android.Paths
}
func (a *AndroidTestImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.preprocessed = Bool(a.testImportProperties.Preprocessed)
a.generateAndroidBuildActions(ctx)
a.data = android.PathsForModuleSrc(ctx, a.testProperties.Data)
@ -1635,6 +1650,7 @@ func AndroidTestImportFactory() android.Module {
module.AddProperties(&module.dexpreoptProperties)
module.AddProperties(&module.usesLibrary.usesLibraryProperties)
module.AddProperties(&module.testProperties)
module.AddProperties(&module.testImportProperties)
module.populateAllVariantStructs()
android.AddLoadHook(module, func(ctx android.LoadHookContext) {
module.processVariants(ctx)

View File

@ -2369,6 +2369,45 @@ func TestAndroidTestImport_NoJinUncompressForPresigned(t *testing.T) {
if jniRule != android.Cp.String() {
t.Errorf("Unexpected JNI uncompress rule: " + jniRule)
}
if variant.MaybeOutput("zip-aligned/foo_presigned.apk").Rule == nil {
t.Errorf("Presigned test apk should be aligned")
}
}
func TestAndroidTestImport_Preprocessed(t *testing.T) {
ctx, _ := testJava(t, `
android_test_import {
name: "foo",
apk: "prebuilts/apk/app.apk",
presigned: true,
preprocessed: true,
}
android_test_import {
name: "foo_cert",
apk: "prebuilts/apk/app.apk",
certificate: "cert/new_cert",
preprocessed: true,
}
`)
testModules := []string{"foo", "foo_cert"}
for _, m := range testModules {
apkName := m + ".apk"
variant := ctx.ModuleForTests(m, "android_common")
jniRule := variant.Output("jnis-uncompressed/" + apkName).BuildParams.Rule.String()
if jniRule != android.Cp.String() {
t.Errorf("Unexpected JNI uncompress rule: " + jniRule)
}
// Make sure signing and aligning were skipped.
if variant.MaybeOutput("signed/"+apkName).Rule != nil {
t.Errorf("signing rule shouldn't be included for preprocessed.")
}
if variant.MaybeOutput("zip-aligned/"+apkName).Rule != nil {
t.Errorf("aligning rule shouldn't be for preprocessed")
}
}
}
func TestStl(t *testing.T) {