From 5892457a68eeae9477dc32d8c1f9ab654788ead6 Mon Sep 17 00:00:00 2001 From: Matt Banda Date: Fri, 1 Apr 2022 17:48:31 +0000 Subject: Surface Java APIs Used By APK-only Modules. Previously we were only generating used-by API-coverage for APEX modules. This change adds support for APK-only modules such as NetworkStack and DocumentsUI. Bug: b/216313756 Forrest Run: https://android-build.googleplex.com/builds/abtd/run/L10800000953846781 Test: TARGET_BUILD_VARIANT=userdebug PRODUCT=mainline_modules_x86 ./vendor/google/build/build_unbundled_coverage_mainline_module.sh -j16 Change-Id: Id17e4a55c2a52e9903632a654e778f8d54982dfc Merged-In: Id17e4a55c2a52e9903632a654e778f8d54982dfc (cherry picked from commit 56d75785bd52c8a8f684935eed67fceb2c0e6850) --- apex/testing.go | 1 - java/androidmk.go | 4 ++++ java/app.go | 3 +++ java/app_builder.go | 12 ++++++++++++ java/testing.go | 2 ++ 5 files changed, 21 insertions(+), 1 deletion(-) 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(), ) -- cgit v1.2.3 From 9d0f2c1c445c9520c6825b7564e2991e2c566368 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 6 Apr 2022 12:48:09 +0000 Subject: Copy the out/soong/build_number.txt file into sdk snapshots This change adds the build_number.txt file into the sdk snapshot to make it easier to debug issues arising in partner builds caused by the snapshots. The file is added to the root of the snapshot and is called: snapshot-creation-build-number.txt Bug: 201295663 Test: m nothing packages/modules/common/build/mainline_modules_sdks.sh # Check the contents of various snapshots. Merged-In: Ib3ac0cea5c9315cad0b9a3c25d88759097e37163 Change-Id: Ib3ac0cea5c9315cad0b9a3c25d88759097e37163 (cherry picked from commit 51509a156bf8fcc5d413459d3edb69a330391e5f) --- sdk/testing.go | 23 +++++++++++++++++++++-- sdk/update.go | 7 +++++++ 2 files changed, 28 insertions(+), 2 deletions(-) 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 // / // 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 -- cgit v1.2.3