diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-04-09 12:00:47 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-04-09 12:00:47 +0000 |
commit | 683232d2f30c75e750fe3c5cc67fcc3c396ad063 (patch) | |
tree | 2c5e59cc5ae051d5af7ad536482ae11a497b9f2b | |
parent | 51005c9b76faae79d939d28ef47f553b7ce058fc (diff) | |
parent | e42d92f4c1eff825fe57846c2177e108794584b1 (diff) | |
download | soong-683232d2f30c75e750fe3c5cc67fcc3c396ad063.tar.gz |
Snap for 8431613 from e42d92f4c1eff825fe57846c2177e108794584b1 to mainline-media-swcodec-releaseandroid-mainline-12.0.0_r120
Change-Id: Ic5cce26a542f40ddd3f597526572e44f0501b9d9
-rw-r--r-- | apex/apex.go | 31 | ||||
-rw-r--r-- | apex/apex_test.go | 57 | ||||
-rw-r--r-- | apex/testing.go | 1 | ||||
-rw-r--r-- | java/androidmk.go | 4 | ||||
-rwxr-xr-x | java/app.go | 3 | ||||
-rw-r--r-- | java/app_builder.go | 12 | ||||
-rw-r--r-- | java/testing.go | 2 | ||||
-rw-r--r-- | sdk/testing.go | 23 | ||||
-rw-r--r-- | sdk/update.go | 7 |
9 files changed, 121 insertions, 19 deletions
diff --git a/apex/apex.go b/apex/apex.go index e1bc030c5..81599027a 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -19,6 +19,7 @@ package apex import ( "fmt" "path/filepath" + "regexp" "sort" "strings" @@ -1537,13 +1538,33 @@ type androidApp interface { var _ androidApp = (*java.AndroidApp)(nil) var _ androidApp = (*java.AndroidAppImport)(nil) +func sanitizedBuildIdForPath(ctx android.BaseModuleContext) string { + buildId := ctx.Config().BuildId() + + // The build ID is used as a suffix for a filename, so ensure that + // the set of characters being used are sanitized. + // - any word character: [a-zA-Z0-9_] + // - dots: . + // - dashes: - + validRegex := regexp.MustCompile(`^[\w\.\-\_]+$`) + if !validRegex.MatchString(buildId) { + ctx.ModuleErrorf("Unable to use build id %s as filename suffix, valid characters are [a-z A-Z 0-9 _ . -].", buildId) + } + return buildId +} + func apexFileForAndroidApp(ctx android.BaseModuleContext, aapp androidApp) apexFile { appDir := "app" if aapp.Privileged() { appDir = "priv-app" } - dirInApex := filepath.Join(appDir, aapp.InstallApkName()) + + // TODO(b/224589412, b/226559955): Ensure that the subdirname is suffixed + // so that PackageManager correctly invalidates the existing installed apk + // in favour of the new APK-in-APEX. See bugs for more information. + dirInApex := filepath.Join(appDir, aapp.InstallApkName()+"@"+sanitizedBuildIdForPath(ctx)) fileToCopy := aapp.OutputFile() + af := newApexFile(ctx, fileToCopy, aapp.BaseModuleName(), dirInApex, app, aapp) af.jacocoReportClassesFile = aapp.JacocoReportClassesFile() af.lintDepSets = aapp.LintDepSets() @@ -1756,8 +1777,12 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { if ap.Privileged() { appDir = "priv-app" } - af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), - filepath.Join(appDir, ap.BaseModuleName()), appSet, ap) + // TODO(b/224589412, b/226559955): Ensure that the dirname is + // suffixed so that PackageManager correctly invalidates the + // existing installed apk in favour of the new APK-in-APEX. + // See bugs for more information. + appDirName := filepath.Join(appDir, ap.BaseModuleName()+"@"+sanitizedBuildIdForPath(ctx)) + af := newApexFile(ctx, ap.OutputFile(), ap.BaseModuleName(), appDirName, appSet, ap) af.certificate = java.PresignedCertificate filesInfo = append(filesInfo, af) } else { diff --git a/apex/apex_test.go b/apex/apex_test.go index f3c3b44c5..4ded4fd36 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -217,6 +217,7 @@ var prepareForApexTest = android.GroupFixturePreparers( variables.Platform_sdk_final = proptools.BoolPtr(false) variables.Platform_version_active_codenames = []string{"Q"} variables.Platform_vndk_version = proptools.StringPtr("29") + variables.BuildId = proptools.StringPtr("TEST.BUILD_ID") }), ) @@ -686,7 +687,7 @@ func TestDefaults(t *testing.T) { "etc/myetc", "javalib/myjar.jar", "lib64/mylib.so", - "app/AppFoo/AppFoo.apk", + "app/AppFoo@TEST.BUILD_ID/AppFoo.apk", "overlay/blue/rro.apk", "etc/bpf/bpf.o", "etc/bpf/bpf2.o", @@ -5124,8 +5125,8 @@ func TestApexWithApps(t *testing.T) { apexRule := module.Rule("apexRule") copyCmds := apexRule.Args["copy_commands"] - ensureContains(t, copyCmds, "image.apex/app/AppFoo/AppFoo.apk") - ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv/AppFooPriv.apk") + ensureContains(t, copyCmds, "image.apex/app/AppFoo@TEST.BUILD_ID/AppFoo.apk") + ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPriv@TEST.BUILD_ID/AppFooPriv.apk") appZipRule := ctx.ModuleForTests("AppFoo", "android_common_apex10000").Description("zip jni libs") // JNI libraries are uncompressed @@ -5142,6 +5143,36 @@ func TestApexWithApps(t *testing.T) { } } +func TestApexWithAppImportBuildId(t *testing.T) { + invalidBuildIds := []string{"../", "a b", "a/b", "a/b/../c", "/a"} + for _, id := range invalidBuildIds { + message := fmt.Sprintf("Unable to use build id %s as filename suffix", id) + fixture := android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.BuildId = proptools.StringPtr(id) + }) + testApexError(t, message, `apex { + name: "myapex", + key: "myapex.key", + apps: ["AppFooPrebuilt"], + updatable: false, + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + android_app_import { + name: "AppFooPrebuilt", + apk: "PrebuiltAppFoo.apk", + presigned: true, + apex_available: ["myapex"], + } + `, fixture) + } +} + func TestApexWithAppImports(t *testing.T) { ctx := testApex(t, ` apex { @@ -5187,8 +5218,8 @@ func TestApexWithAppImports(t *testing.T) { apexRule := module.Rule("apexRule") copyCmds := apexRule.Args["copy_commands"] - ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt/AppFooPrebuilt.apk") - ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AwesomePrebuiltAppFooPriv.apk") + ensureContains(t, copyCmds, "image.apex/app/AppFooPrebuilt@TEST.BUILD_ID/AppFooPrebuilt.apk") + ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt@TEST.BUILD_ID/AwesomePrebuiltAppFooPriv.apk") } func TestApexWithAppImportsPrefer(t *testing.T) { @@ -5229,7 +5260,7 @@ func TestApexWithAppImportsPrefer(t *testing.T) { })) ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{ - "app/AppFoo/AppFooPrebuilt.apk", + "app/AppFoo@TEST.BUILD_ID/AppFooPrebuilt.apk", }) } @@ -5262,7 +5293,7 @@ func TestApexWithTestHelperApp(t *testing.T) { apexRule := module.Rule("apexRule") copyCmds := apexRule.Args["copy_commands"] - ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo/TesterHelpAppFoo.apk") + ensureContains(t, copyCmds, "image.apex/app/TesterHelpAppFoo@TEST.BUILD_ID/TesterHelpAppFoo.apk") } func TestApexPropertiesShouldBeDefaultable(t *testing.T) { @@ -5609,8 +5640,8 @@ func TestOverrideApex(t *testing.T) { apexRule := module.Rule("apexRule") copyCmds := apexRule.Args["copy_commands"] - ensureNotContains(t, copyCmds, "image.apex/app/app/app.apk") - ensureContains(t, copyCmds, "image.apex/app/override_app/override_app.apk") + ensureNotContains(t, copyCmds, "image.apex/app/app@TEST.BUILD_ID/app.apk") + ensureContains(t, copyCmds, "image.apex/app/override_app@TEST.BUILD_ID/override_app.apk") apexBundle := module.Module().(*apexBundle) name := apexBundle.Name() @@ -6349,7 +6380,7 @@ func TestAppBundle(t *testing.T) { content := bundleConfigRule.Args["content"] ensureContains(t, content, `"compression":{"uncompressed_glob":["apex_payload.img","apex_manifest.*"]}`) - ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo/AppFoo.apk"}]}`) + ensureContains(t, content, `"apex_config":{"apex_embedded_apk_config":[{"package_name":"com.android.foo","path":"app/AppFoo@TEST.BUILD_ID/AppFoo.apk"}]}`) } func TestAppSetBundle(t *testing.T) { @@ -6380,9 +6411,9 @@ func TestAppSetBundle(t *testing.T) { if len(copyCmds) != 3 { t.Fatalf("Expected 3 commands, got %d in:\n%s", len(copyCmds), s) } - ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet$") - ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet$") - ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet .*/AppSet.zip$") + ensureMatches(t, copyCmds[0], "^rm -rf .*/app/AppSet@TEST.BUILD_ID$") + ensureMatches(t, copyCmds[1], "^mkdir -p .*/app/AppSet@TEST.BUILD_ID$") + ensureMatches(t, copyCmds[2], "^unzip .*-d .*/app/AppSet@TEST.BUILD_ID .*/AppSet.zip$") } func TestAppSetBundlePrebuilt(t *testing.T) { diff --git a/apex/testing.go b/apex/testing.go index 337c86210..69bd73e5d 100644 --- a/apex/testing.go +++ b/apex/testing.go @@ -24,7 +24,6 @@ var PrepareForTestWithApexBuildComponents = android.GroupFixturePreparers( android.MockFS{ // Needed by apex. "system/core/rootdir/etc/public.libraries.android.txt": nil, - "build/soong/scripts/gen_java_usedby_apex.sh": nil, "build/soong/scripts/gen_ndk_backedby_apex.sh": nil, // Needed by prebuilt_apex. "build/soong/scripts/unpack-prebuilt-apex.sh": nil, diff --git a/java/androidmk.go b/java/androidmk.go index 04357e066..43214e586 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -423,6 +423,10 @@ func (app *AndroidApp) AndroidMkEntries() []android.AndroidMkEntries { fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s)\n", app.installApkName, app.noticeOutputs.HtmlOutput.String(), app.installApkName+"_NOTICE.html") } + if app.javaApiUsedByOutputFile.String() != "" { + fmt.Fprintf(w, "$(call dist-for-goals,%s,%s:%s/$(notdir %s))\n", + app.installApkName, app.javaApiUsedByOutputFile.String(), "java_apis_used_by_apex", app.javaApiUsedByOutputFile.String()) + } }, }, }} diff --git a/java/app.go b/java/app.go index 06967690b..cdbea2e42 100755 --- a/java/app.go +++ b/java/app.go @@ -167,6 +167,8 @@ type AndroidApp struct { overriddenManifestPackageName string android.ApexBundleDepsInfo + + javaApiUsedByOutputFile android.ModuleOutPath } func (a *AndroidApp) IsInstallable() bool { @@ -275,6 +277,7 @@ func (a *AndroidTestHelperApp) GenerateAndroidBuildActions(ctx android.ModuleCon func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.checkAppSdkVersions(ctx) a.generateAndroidBuildActions(ctx) + a.generateJavaUsedByApex(ctx) } func (a *AndroidApp) checkAppSdkVersions(ctx android.ModuleContext) { diff --git a/java/app_builder.go b/java/app_builder.go index 4a18dcada..bafc98054 100644 --- a/java/app_builder.go +++ b/java/app_builder.go @@ -254,6 +254,18 @@ func TransformJniLibsToJar(ctx android.ModuleContext, outputFile android.Writabl }) } +func (a *AndroidApp) generateJavaUsedByApex(ctx android.ModuleContext) { + javaApiUsedByOutputFile := android.PathForModuleOut(ctx, a.installApkName+"_using.xml") + javaUsedByRule := android.NewRuleBuilder(pctx, ctx) + javaUsedByRule.Command(). + Tool(android.PathForSource(ctx, "build/soong/scripts/gen_java_usedby_apex.sh")). + BuiltTool("dexdeps"). + Output(javaApiUsedByOutputFile). + Input(a.Library.Module.outputFile) + javaUsedByRule.Build("java_usedby_list", "Generate Java APIs used by Apex") + a.javaApiUsedByOutputFile = javaApiUsedByOutputFile +} + func targetToJniDir(target android.Target) string { return filepath.Join("lib", target.Arch.Abi[0]) } diff --git a/java/testing.go b/java/testing.go index d5c464dd8..243e5e849 100644 --- a/java/testing.go +++ b/java/testing.go @@ -54,6 +54,8 @@ var PrepareForTestWithJavaBuildComponents = android.GroupFixturePreparers( "build/soong/java/lint_defaults.txt": nil, // Needed for apps that do not provide their own. "build/make/target/product/security": nil, + // Required to generate Java used-by API coverage + "build/soong/scripts/gen_java_usedby_apex.sh": nil, }.AddToFixture(), ) diff --git a/sdk/testing.go b/sdk/testing.go index 294f1a57d..062f2000e 100644 --- a/sdk/testing.go +++ b/sdk/testing.go @@ -25,6 +25,8 @@ import ( "android/soong/cc" "android/soong/genrule" "android/soong/java" + + "github.com/google/blueprint/proptools" ) // Prepare for running an sdk test with an apex. @@ -81,6 +83,11 @@ var prepareForSdkTest = android.GroupFixturePreparers( } }), + // Add a build number file. + android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) { + variables.BuildNumberFile = proptools.StringPtr(BUILD_NUMBER_FILE) + }), + // Make sure that every test provides all the source files. android.PrepareForTestDisallowNonExistentPaths, android.MockFS{ @@ -143,6 +150,8 @@ func getSdkSnapshotBuildInfo(t *testing.T, result *android.TestResult, sdk *sdk) copyRules := &strings.Builder{} otherCopyRules := &strings.Builder{} snapshotDirPrefix := sdk.builderForTests.snapshotDir.String() + "/" + + seenBuildNumberFile := false for _, bp := range buildParams { switch bp.Rule.String() { case android.Cp.String(): @@ -152,8 +161,14 @@ func getSdkSnapshotBuildInfo(t *testing.T, result *android.TestResult, sdk *sdk) src := android.NormalizePathForTesting(bp.Input) // We differentiate between copy rules for the snapshot, and copy rules for the install file. if strings.HasPrefix(output.String(), snapshotDirPrefix) { - // Get source relative to build directory. - _, _ = fmt.Fprintf(copyRules, "%s -> %s\n", src, dest) + // Don't include the build-number.txt file in the copy rules as that would break lots of + // tests, just verify that it is copied here as it should appear in every snapshot. + if output.Base() == BUILD_NUMBER_FILE { + seenBuildNumberFile = true + } else { + // Get source relative to build directory. + _, _ = fmt.Fprintf(copyRules, "%s -> %s\n", src, dest) + } info.snapshotContents = append(info.snapshotContents, dest) } else { _, _ = fmt.Fprintf(otherCopyRules, "%s -> %s\n", src, dest) @@ -189,6 +204,10 @@ func getSdkSnapshotBuildInfo(t *testing.T, result *android.TestResult, sdk *sdk) } } + if !seenBuildNumberFile { + panic(fmt.Sprintf("Every snapshot must include the %s file", BUILD_NUMBER_FILE)) + } + info.copyRules = copyRules.String() info.otherCopyRules = otherCopyRules.String() diff --git a/sdk/update.go b/sdk/update.go index d9c57c375..a3d94ed86 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -242,6 +242,10 @@ func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAwa return append(variants, newVariant) } +// BUILD_NUMBER_FILE is the name of the file in the snapshot zip that will contain the number of +// the build from which the snapshot was produced. +const BUILD_NUMBER_FILE = "snapshot-creation-build-number.txt" + // SDK directory structure // <sdk_root>/ // Android.bp : definition of a 'sdk' module is here. This is a hand-made one. @@ -432,6 +436,9 @@ be unnecessary as every module in the sdk already has its own licenses property. bp.build(pctx, ctx, nil) + // Copy the build number file into the snapshot. + builder.CopyToSnapshot(ctx.Config().BuildNumberFile(ctx), BUILD_NUMBER_FILE) + filesToZip := builder.filesToZip // zip them all |