Merge "Add preprocessed property for android_test_import" into rvc-dev

This commit is contained in:
TreeHugger Robot 2020-05-27 17:21:19 +00:00 committed by Android (Google) Code Review
commit 753c739e2f
2 changed files with 59 additions and 4 deletions

View File

@ -1231,6 +1231,8 @@ type AndroidAppImport struct {
usesLibrary usesLibrary
preprocessed bool
installPath android.InstallPath
}
@ -1323,7 +1325,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,
@ -1344,7 +1346,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
}
@ -1436,9 +1438,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)
@ -1573,15 +1579,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)
@ -1599,6 +1614,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

@ -2308,6 +2308,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) {