From 40eab20c34ca2084d030f0af3ef3b5a237263df3 Mon Sep 17 00:00:00 2001 From: Eric Miao Date: Thu, 30 Mar 2023 16:57:17 +0000 Subject: Revert "Revert "Enable compact resource entries for aapt linking"" This reverts commit 825cff4169ef07880ae4ba51b978873ed276eb73. Reason for revert: Failed test has been fixed - b/275572186 Change-Id: I661206f4e0e783a5c403ac15ed33a93ba3acaf40 --- java/aar.go | 1 + 1 file changed, 1 insertion(+) (limited to 'java') diff --git a/java/aar.go b/java/aar.go index 47e6efae3..4fdcb80b8 100644 --- a/java/aar.go +++ b/java/aar.go @@ -176,6 +176,7 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkConte linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...) linkFlags = append(linkFlags, "--no-static-lib-packages") + linkFlags = append(linkFlags, "--enable-compact-entries") // Find implicit or explicit asset and resource dirs assetDirs := android.PathsWithOptionalDefaultForModuleSrc(ctx, a.aaptProperties.Asset_dirs, "assets") -- cgit v1.2.3-59-g8ed1b From 039d8dfb674057bfdafc702c9438a88d8a09c7fd Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 20 Jun 2023 22:40:02 -0700 Subject: Move android_library resource handling to Bazel's ResourceProcessorBusyBox The R.Java files generated by aapt2 link --no-static-lib-packages cause scaling problems by combining all resources into every package listed in a dependencies' AndroidManifest.xml file. For SystemUI-core this results in 74 R.java files, each with 76k lines, and takes 20 seconds to compile in javac. Both AGP and Bazel have workarounds for this that avoid using the R.java files generated by aapt2, instead generating more efficient R.class files directly based on the R.txt file. Bazel uses the ResourceProcessorBusyBox tool that is already present in our tree to process the resources. Reuse the same tool in Soong to create the R.jar. The more efficient R.class files require modifiying source files that use incorrect packages to refer to resources. Ignore-AOSP-First: merge conflict Bug: 284023594 Test: TestAndroidResourceProcessor Change-Id: I026073b40dabcfdb10e5d7a52e9348205b0e9a66 --- java/aar.go | 239 +++++++++++++++++++++++++++++++++++--------- java/androidmk.go | 2 + java/app.go | 18 +++- java/app_test.go | 269 +++++++++++++++++++++++++++++++++++++++++++++++--- java/base.go | 16 ++- java/config/config.go | 2 + java/java.go | 2 +- 7 files changed, 486 insertions(+), 62 deletions(-) (limited to 'java') diff --git a/java/aar.go b/java/aar.go index 95b9a67bb..fc039fa36 100644 --- a/java/aar.go +++ b/java/aar.go @@ -88,28 +88,40 @@ type aaptProperties struct { // do not include AndroidManifest from dependent libraries Dont_merge_manifests *bool + // If use_resource_processor is set, use Bazel's resource processor instead of aapt2 to generate R.class files. + // The resource processor produces more optimal R.class files that only list resources in the package of the + // library that provided them, as opposed to aapt2 which produces R.java files for every package containing + // every resource. Using the resource processor can provide significant build time speedups, but requires + // fixing the module to use the correct package to reference each resource, and to avoid having any other + // libraries in the tree that use the same package name. Defaults to false, but will default to true in the + // future. + Use_resource_processor *bool + // true if RRO is enforced for any of the dependent modules RROEnforcedForDependent bool `blueprint:"mutated"` } type aapt struct { - aaptSrcJar android.Path - exportPackage android.Path - manifestPath android.Path - proguardOptionsFile android.Path - rTxt android.Path - extraAaptPackagesFile android.Path - mergedManifestFile android.Path - noticeFile android.OptionalPath - assetPackage android.OptionalPath - isLibrary bool - defaultManifestVersion string - useEmbeddedNativeLibs bool - useEmbeddedDex bool - usesNonSdkApis bool - hasNoCode bool - LoggingParent string - resourceFiles android.Paths + aaptSrcJar android.Path + transitiveAaptRJars android.Paths + transitiveAaptResourcePackages android.Paths + exportPackage android.Path + manifestPath android.Path + proguardOptionsFile android.Path + rTxt android.Path + rJar android.Path + extraAaptPackagesFile android.Path + mergedManifestFile android.Path + noticeFile android.OptionalPath + assetPackage android.OptionalPath + isLibrary bool + defaultManifestVersion string + useEmbeddedNativeLibs bool + useEmbeddedDex bool + usesNonSdkApis bool + hasNoCode bool + LoggingParent string + resourceFiles android.Paths splitNames []string splits []split @@ -139,6 +151,10 @@ func propagateRROEnforcementMutator(ctx android.TopDownMutatorContext) { } } +func (a *aapt) useResourceProcessorBusyBox() bool { + return BoolDefault(a.aaptProperties.Use_resource_processor, false) +} + func (a *aapt) ExportPackage() android.Path { return a.exportPackage } @@ -175,7 +191,6 @@ func (a *aapt) aapt2Flags(ctx android.ModuleContext, sdkContext android.SdkConte // Flags specified in Android.bp linkFlags = append(linkFlags, a.aaptProperties.Aaptflags...) - linkFlags = append(linkFlags, "--no-static-lib-packages") linkFlags = append(linkFlags, "--enable-compact-entries") // Find implicit or explicit asset and resource dirs @@ -349,6 +364,19 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon linkFlags = append(linkFlags, "--static-lib") } + if a.isLibrary && a.useResourceProcessorBusyBox() { + // When building an android_library using ResourceProcessorBusyBox the resources are merged into + // package-res.apk with --merge-only, but --no-static-lib-packages is not used so that R.txt only + // contains resources from this library. + linkFlags = append(linkFlags, "--merge-only") + } else { + // When building and app or when building an android_library without ResourceProcessorBusyBox + // --no-static-lib-packages is used to put all the resources into the app. If ResourceProcessorBusyBox + // is used then the app's R.txt will be post-processed along with the R.txt files from dependencies to + // sort resources into the right packages in R.class. + linkFlags = append(linkFlags, "--no-static-lib-packages") + } + packageRes := android.PathForModuleOut(ctx, "package-res.apk") // the subdir "android" is required to be filtered by package names srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar") @@ -356,6 +384,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon rTxt := android.PathForModuleOut(ctx, "R.txt") // This file isn't used by Soong, but is generated for exporting extraPackages := android.PathForModuleOut(ctx, "extra_packages") + var transitiveRJars android.Paths var compiledResDirs []android.Paths for _, dir := range resDirs { @@ -375,7 +404,23 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon // of transitiveStaticLibs. transitiveStaticLibs := android.ReversePaths(staticDeps.resPackages()) - compiledOverlay = append(compiledOverlay, transitiveStaticLibs...) + if a.isLibrary && a.useResourceProcessorBusyBox() { + // When building an android_library with ResourceProcessorBusyBox enabled treat static library dependencies + // as imports. The resources from dependencies will not be merged into this module's package-res.apk, and + // instead modules depending on this module will reference package-res.apk from all transitive static + // dependencies. + for _, staticDep := range staticDeps { + linkDeps = append(linkDeps, staticDep.resPackage) + linkFlags = append(linkFlags, "-I "+staticDep.resPackage.String()) + if staticDep.usedResourceProcessor { + transitiveRJars = append(transitiveRJars, staticDep.rJar) + } + } + } else { + // When building an app or building a library without ResourceProcessorBusyBox enabled all static + // dependencies are compiled into this module's package-res.apk as overlays. + compiledOverlay = append(compiledOverlay, transitiveStaticLibs...) + } if len(transitiveStaticLibs) > 0 { // If we are using static android libraries, every source file becomes an overlay. @@ -438,7 +483,16 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon a.assetPackage = android.OptionalPathForPath(assets) } + if a.useResourceProcessorBusyBox() { + rJar := android.PathForModuleOut(ctx, "busybox/R.jar") + resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary) + transitiveRJars = append(transitiveRJars, rJar) + a.rJar = rJar + } + a.aaptSrcJar = srcJar + a.transitiveAaptRJars = transitiveRJars + a.transitiveAaptResourcePackages = staticDeps.resPackages() a.exportPackage = packageRes a.manifestPath = manifestPath a.proguardOptionsFile = proguardOptionsFile @@ -450,7 +504,11 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon resPackage: a.exportPackage, manifest: a.manifestPath, additionalManifests: additionalManifests, + rTxt: a.rTxt, + rJar: a.rJar, assets: a.assetPackage, + + usedResourceProcessor: a.useResourceProcessorBusyBox(), }). Transitive(staticResourcesNodesDepSet).Build() a.rroDirsDepSet = android.NewDepSetBuilder[rroDir](android.TOPOLOGICAL). @@ -462,34 +520,93 @@ func (a *aapt) buildActions(ctx android.ModuleContext, sdkContext android.SdkCon Transitive(staticManifestsDepSet).Build() } +var resourceProcessorBusyBox = pctx.AndroidStaticRule("resourceProcessorBusyBox", + blueprint.RuleParams{ + Command: "${config.JavaCmd} -cp ${config.ResourceProcessorBusyBox} " + + "com.google.devtools.build.android.ResourceProcessorBusyBox --tool=GENERATE_BINARY_R -- @${out}.args && " + + "if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out}; fi", + CommandDeps: []string{"${config.ResourceProcessorBusyBox}"}, + Rspfile: "${out}.args", + RspfileContent: "--primaryRTxt ${rTxt} --primaryManifest ${manifest} --classJarOutput ${out}.tmp ${args}", + Restat: true, + }, "rTxt", "manifest", "args") + +// resourceProcessorBusyBoxGenerateBinaryR converts the R.txt file produced by aapt2 into R.class files +// using Bazel's ResourceProcessorBusyBox tool, which is faster than compiling the R.java files and +// supports producing classes for static dependencies that only include resources from that dependency. +func resourceProcessorBusyBoxGenerateBinaryR(ctx android.ModuleContext, rTxt, manifest android.Path, + rJar android.WritablePath, transitiveDeps transitiveAarDeps, isLibrary bool) { + + var args []string + var deps android.Paths + + if !isLibrary { + // When compiling an app, pass all R.txt and AndroidManifest.xml from transitive static library dependencies + // to ResourceProcessorBusyBox so that it can regenerate R.class files with the final resource IDs for each + // package. + args, deps = transitiveDeps.resourceProcessorDeps() + } else { + // When compiling a library don't pass any dependencies as it only needs to generate an R.class file for this + // library. Pass --finalFields=false so that the R.class file contains non-final fields so they don't get + // inlined into the library before the final IDs are assigned during app compilation. + args = append(args, "--finalFields=false") + } + + deps = append(deps, rTxt, manifest) + + ctx.Build(pctx, android.BuildParams{ + Rule: resourceProcessorBusyBox, + Output: rJar, + Implicits: deps, + Description: "ResourceProcessorBusyBox", + Args: map[string]string{ + "rTxt": rTxt.String(), + "manifest": manifest.String(), + "args": strings.Join(args, " "), + }, + }) +} + type resourcesNode struct { resPackage android.Path manifest android.Path additionalManifests android.Paths + rTxt android.Path + rJar android.Path assets android.OptionalPath + + usedResourceProcessor bool } type transitiveAarDeps []*resourcesNode func (t transitiveAarDeps) resPackages() android.Paths { - var paths android.Paths + paths := make(android.Paths, 0, len(t)) for _, dep := range t { paths = append(paths, dep.resPackage) } - return android.FirstUniquePaths(paths) + return paths } func (t transitiveAarDeps) manifests() android.Paths { - var paths android.Paths + paths := make(android.Paths, 0, len(t)) for _, dep := range t { paths = append(paths, dep.manifest) paths = append(paths, dep.additionalManifests...) } - return android.FirstUniquePaths(paths) + return paths +} + +func (t transitiveAarDeps) resourceProcessorDeps() (args []string, deps android.Paths) { + for _, dep := range t { + args = append(args, "--library="+dep.rTxt.String()+","+dep.manifest.String()) + deps = append(deps, dep.rTxt, dep.manifest) + } + return args, deps } func (t transitiveAarDeps) assets() android.Paths { - var paths android.Paths + paths := make(android.Paths, 0, len(t)) for _, dep := range t { if dep.assets.Valid() { paths = append(paths, dep.assets.Path()) @@ -614,9 +731,12 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) a.stem = proptools.StringDefault(a.overridableDeviceProperties.Stem, ctx.ModuleName()) - ctx.CheckbuildFile(a.proguardOptionsFile) - ctx.CheckbuildFile(a.exportPackage) - ctx.CheckbuildFile(a.aaptSrcJar) + ctx.CheckbuildFile(a.aapt.proguardOptionsFile) + ctx.CheckbuildFile(a.aapt.exportPackage) + ctx.CheckbuildFile(a.aapt.aaptSrcJar) + if a.useResourceProcessorBusyBox() { + ctx.CheckbuildFile(a.aapt.rJar) + } // apps manifests are handled by aapt, don't let Module see them a.properties.Manifest = nil @@ -628,7 +748,22 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile) - a.Module.compile(ctx, a.aaptSrcJar) + var extraSrcJars android.Paths + var extraCombinedJars android.Paths + var extraClasspathJars android.Paths + if a.useResourceProcessorBusyBox() { + // When building a library with ResourceProcessorBusyBox enabled ResourceProcessorBusyBox for this + // library and each of the transitive static android_library dependencies has already created an + // R.class file for the appropriate package. Add all of those R.class files to the classpath. + extraClasspathJars = a.transitiveAaptRJars + } else { + // When building a library without ResourceProcessorBusyBox the aapt2 rule creates R.srcjar containing + // R.java files for the library's package and the packages from all transitive static android_library + // dependencies. Compile the srcjar alongside the rest of the sources. + extraSrcJars = android.Paths{a.aapt.aaptSrcJar} + } + + a.Module.compile(ctx, extraSrcJars, extraClasspathJars, extraCombinedJars) a.aarFile = android.PathForModuleOut(ctx, ctx.ModuleName()+".aar") var res android.Paths @@ -730,12 +865,15 @@ type AARImport struct { properties AARImportProperties - classpathFile android.WritablePath - proguardFlags android.WritablePath - exportPackage android.WritablePath - extraAaptPackagesFile android.WritablePath - manifest android.WritablePath - assetsPackage android.WritablePath + classpathFile android.WritablePath + proguardFlags android.WritablePath + exportPackage android.WritablePath + transitiveAaptResourcePackages android.Paths + extraAaptPackagesFile android.WritablePath + manifest android.WritablePath + assetsPackage android.WritablePath + rTxt android.WritablePath + rJar android.WritablePath resourcesNodesDepSet *android.DepSet[*resourcesNode] manifestsDepSet *android.DepSet[android.Path] @@ -904,12 +1042,13 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.classpathFile = extractedAARDir.Join(ctx, "classes-combined.jar") a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt") a.manifest = extractedAARDir.Join(ctx, "AndroidManifest.xml") + aarRTxt := extractedAARDir.Join(ctx, "R.txt") a.assetsPackage = android.PathForModuleOut(ctx, "assets.zip") ctx.Build(pctx, android.BuildParams{ Rule: unzipAAR, Input: a.aarPath, - Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest, a.assetsPackage}, + Outputs: android.WritablePaths{a.classpathFile, a.proguardFlags, a.manifest, a.assetsPackage, aarRTxt}, Description: "unzip AAR", Args: map[string]string{ "outDir": extractedAARDir.String(), @@ -929,14 +1068,14 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { // the subdir "android" is required to be filtered by package names srcJar := android.PathForModuleGen(ctx, "android", "R.srcjar") proguardOptionsFile := android.PathForModuleGen(ctx, "proguard.options") - rTxt := android.PathForModuleOut(ctx, "R.txt") + a.rTxt = android.PathForModuleOut(ctx, "R.txt") a.extraAaptPackagesFile = android.PathForModuleOut(ctx, "extra_packages") var linkDeps android.Paths linkFlags := []string{ "--static-lib", - "--no-static-lib-packages", + "--merge-only", "--auto-add-overlay", } @@ -949,25 +1088,35 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { _ = staticRRODirsDepSet staticDeps := transitiveAarDeps(staticResourcesNodesDepSet.ToList()) - // AAPT2 overlays are in lowest to highest priority order, reverse the topological order - // of transitiveStaticLibs. - transitiveStaticLibs := android.ReversePaths(staticDeps.resPackages()) - linkDeps = append(linkDeps, sharedLibs...) - linkDeps = append(linkDeps, transitiveStaticLibs...) + linkDeps = append(linkDeps, staticDeps.resPackages()...) linkFlags = append(linkFlags, libFlags...) - overlayRes := append(android.Paths{flata}, transitiveStaticLibs...) + overlayRes := android.Paths{flata} + + // Treat static library dependencies of static libraries as imports. + transitiveStaticLibs := staticDeps.resPackages() + linkDeps = append(linkDeps, transitiveStaticLibs...) + for _, staticLib := range transitiveStaticLibs { + linkFlags = append(linkFlags, "-I "+staticLib.String()) + } transitiveAssets := android.ReverseSliceInPlace(staticDeps.assets()) - aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, rTxt, a.extraAaptPackagesFile, + aapt2Link(ctx, a.exportPackage, srcJar, proguardOptionsFile, a.rTxt, a.extraAaptPackagesFile, linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil) + a.rJar = android.PathForModuleOut(ctx, "busybox/R.jar") + resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true) + resourcesNodesDepSetBuilder := android.NewDepSetBuilder[*resourcesNode](android.TOPOLOGICAL) resourcesNodesDepSetBuilder.Direct(&resourcesNode{ resPackage: a.exportPackage, manifest: a.manifest, + rTxt: a.rTxt, + rJar: a.rJar, assets: android.OptionalPathForPath(a.assetsPackage), + + usedResourceProcessor: true, }) resourcesNodesDepSetBuilder.Transitive(staticResourcesNodesDepSet) a.resourcesNodesDepSet = resourcesNodesDepSetBuilder.Build() @@ -982,6 +1131,8 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { _ = staticManifestsDepSet a.manifestsDepSet = manifestDepSetBuilder.Build() + a.transitiveAaptResourcePackages = staticDeps.resPackages() + a.collectTransitiveHeaderJars(ctx) ctx.SetProvider(JavaInfoProvider, JavaInfo{ HeaderJars: android.PathsIfNonNil(a.classpathFile), diff --git a/java/androidmk.go b/java/androidmk.go index 784fa29b5..113137609 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -265,6 +265,7 @@ func (prebuilt *AARImport) AndroidMkEntries() []android.AndroidMkEntries { entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.classpathFile) entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.classpathFile) entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", prebuilt.exportPackage) + entries.SetPaths("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", prebuilt.transitiveAaptResourcePackages) entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags) entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile) entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest) @@ -508,6 +509,7 @@ func (a *AndroidLibrary) AndroidMkEntries() []android.AndroidMkEntries { } entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", a.exportPackage) + entries.SetPaths("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", a.transitiveAaptResourcePackages) entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", a.extraAaptPackagesFile) entries.SetPath("LOCAL_FULL_MANIFEST_FILE", a.mergedManifestFile) entries.AddStrings("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", a.exportedProguardFlagFiles.Strings()...) diff --git a/java/app.go b/java/app.go index 8e4efd2b2..224bc8867 100755 --- a/java/app.go +++ b/java/app.go @@ -521,7 +521,23 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { a.dexpreopter.preventInstall = a.appProperties.PreventInstall if ctx.ModuleName() != "framework-res" { - a.Module.compile(ctx, a.aaptSrcJar) + var extraSrcJars android.Paths + var extraClasspathJars android.Paths + var extraCombinedJars android.Paths + if a.useResourceProcessorBusyBox() { + // When building an app with ResourceProcessorBusyBox enabled ResourceProcessorBusyBox has already + // created R.class files that provide IDs for resources in busybox/R.jar. Pass that file in the + // classpath when compiling everything else, and add it to the final classes jar. + extraClasspathJars = android.Paths{a.aapt.rJar} + extraCombinedJars = android.Paths{a.aapt.rJar} + } else { + // When building an app without ResourceProcessorBusyBox the aapt2 rule creates R.srcjar containing + // R.java files for the app's package and the packages from all transitive static android_library + // dependencies. Compile the srcjar alongside the rest of the sources. + extraSrcJars = android.Paths{a.aapt.aaptSrcJar} + } + + a.Module.compile(ctx, extraSrcJars, extraClasspathJars, extraCombinedJars) } return a.dexJarFile.PathOrNil() diff --git a/java/app_test.go b/java/app_test.go index c438b6cfa..4627ff6fc 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -722,7 +722,10 @@ func TestAppJavaResources(t *testing.T) { func TestAndroidResourceProcessor(t *testing.T) { testCases := []struct { - name string + name string + appUsesRP bool + directLibUsesRP bool + transitiveLibUsesRP bool dontVerifyApp bool appResources []string @@ -759,7 +762,12 @@ func TestAndroidResourceProcessor(t *testing.T) { transitiveImportImports []string }{ { - name: "legacy", + // Test with all modules set to use_resource_processor: false (except android_library_import modules, + // which always use resource processor). + name: "legacy", + appUsesRP: false, + directLibUsesRP: false, + transitiveLibUsesRP: false, appResources: nil, appOverlays: []string{ @@ -771,7 +779,6 @@ func TestAndroidResourceProcessor(t *testing.T) { "out/soong/.intermediates/direct_import/android_common/package-res.apk", "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat", }, - appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"}, appClasspath: []string{ @@ -792,7 +799,6 @@ func TestAndroidResourceProcessor(t *testing.T) { "out/soong/.intermediates/transitive_import/android_common/package-res.apk", "out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat", }, - directImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, directSrcJars: []string{"out/soong/.intermediates/direct/android_common/gen/android/R.srcjar"}, directClasspath: []string{ @@ -814,18 +820,256 @@ func TestAndroidResourceProcessor(t *testing.T) { transitiveCombined: nil, directImportResources: nil, - directImportOverlays: []string{ - "out/soong/.intermediates/direct_import/android_common/flat-res/gen_res.flata", + directImportOverlays: []string{"out/soong/.intermediates/direct_import/android_common/flat-res/gen_res.flata"}, + directImportImports: []string{ + "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", }, - directImportImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, transitiveImportResources: nil, - transitiveImportOverlays: []string{ - "out/soong/.intermediates/transitive_import/android_common/flat-res/gen_res.flata", + transitiveImportOverlays: []string{"out/soong/.intermediates/transitive_import/android_common/flat-res/gen_res.flata"}, + transitiveImportImports: []string{ + "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", + }, + }, + { + // Test with all modules set to use_resource_processor: true. + name: "resource_processor", + appUsesRP: true, + directLibUsesRP: true, + transitiveLibUsesRP: true, + + appResources: nil, + appOverlays: []string{ + "out/soong/.intermediates/transitive/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import/android_common/package-res.apk", + "out/soong/.intermediates/direct/android_common/package-res.apk", + "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", + "out/soong/.intermediates/direct_import/android_common/package-res.apk", + "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat", + }, + appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, + appSrcJars: nil, + appClasspath: []string{ + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/app/android_common/busybox/R.jar", + "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", + "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar", + }, + appCombined: []string{ + "out/soong/.intermediates/app/android_common/busybox/R.jar", + "out/soong/.intermediates/app/android_common/javac/app.jar", + "out/soong/.intermediates/direct/android_common/combined/direct.jar", + "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar", + }, + + directResources: nil, + directOverlays: []string{"out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat"}, + directImports: []string{ + "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", + "out/soong/.intermediates/transitive/android_common/package-res.apk", + }, + directSrcJars: nil, + directClasspath: []string{ + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/transitive_import/android_common/busybox/R.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/busybox/R.jar", + "out/soong/.intermediates/transitive/android_common/busybox/R.jar", + "out/soong/.intermediates/direct/android_common/busybox/R.jar", + "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar", + }, + directCombined: []string{ + "out/soong/.intermediates/direct/android_common/javac/direct.jar", + "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar", + }, + + transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"}, + transitiveOverlays: nil, + transitiveImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, + transitiveSrcJars: nil, + transitiveClasspath: []string{ + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/transitive/android_common/busybox/R.jar", + }, + transitiveCombined: nil, + + directImportResources: nil, + directImportOverlays: []string{"out/soong/.intermediates/direct_import/android_common/flat-res/gen_res.flata"}, + directImportImports: []string{ + "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", + "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", + }, + + transitiveImportResources: nil, + transitiveImportOverlays: []string{"out/soong/.intermediates/transitive_import/android_common/flat-res/gen_res.flata"}, + transitiveImportImports: []string{ + "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", + }, + }, { + // Test an app building with resource processor enabled but with dependencies built without + // resource processor. + name: "app_resource_processor", + appUsesRP: true, + directLibUsesRP: false, + transitiveLibUsesRP: false, + + appResources: nil, + appOverlays: []string{ + "out/soong/.intermediates/transitive/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import/android_common/package-res.apk", + "out/soong/.intermediates/direct/android_common/package-res.apk", + "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", + "out/soong/.intermediates/direct_import/android_common/package-res.apk", + "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat", + }, + appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, + appSrcJars: nil, + appClasspath: []string{ + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + // R.jar has to come before direct.jar + "out/soong/.intermediates/app/android_common/busybox/R.jar", + "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", + "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar", + }, + appCombined: []string{ + "out/soong/.intermediates/app/android_common/busybox/R.jar", + "out/soong/.intermediates/app/android_common/javac/app.jar", + "out/soong/.intermediates/direct/android_common/combined/direct.jar", + "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar", + }, + + dontVerifyDirect: true, + dontVerifyTransitive: true, + dontVerifyDirectImport: true, + dontVerifyTransitiveImport: true, + }, + { + // Test an app building without resource processor enabled but with a dependency built with + // resource processor. + name: "app_dependency_lib_resource_processor", + appUsesRP: false, + directLibUsesRP: true, + transitiveLibUsesRP: false, + + appOverlays: []string{ + "out/soong/.intermediates/transitive/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import/android_common/package-res.apk", + "out/soong/.intermediates/direct/android_common/package-res.apk", + "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", + "out/soong/.intermediates/direct_import/android_common/package-res.apk", + "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat", + }, + appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, + appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"}, + appClasspath: []string{ + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", + "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar", + }, + appCombined: []string{ + "out/soong/.intermediates/app/android_common/javac/app.jar", + "out/soong/.intermediates/direct/android_common/combined/direct.jar", + "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar", + }, + + directResources: nil, + directOverlays: []string{"out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat"}, + directImports: []string{ + "out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import/android_common/package-res.apk", "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", + "out/soong/.intermediates/transitive/android_common/package-res.apk", + }, + directSrcJars: nil, + directClasspath: []string{ + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/transitive_import/android_common/busybox/R.jar", + "out/soong/.intermediates/transitive_import_dep/android_common/busybox/R.jar", + "out/soong/.intermediates/direct/android_common/busybox/R.jar", + "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar", + }, + directCombined: []string{ + "out/soong/.intermediates/direct/android_common/javac/direct.jar", + "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar", }, - transitiveImportImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, + + dontVerifyTransitive: true, + dontVerifyDirectImport: true, + dontVerifyTransitiveImport: true, + }, + { + // Test a library building without resource processor enabled but with a dependency built with + // resource processor. + name: "lib_dependency_lib_resource_processor", + appUsesRP: false, + directLibUsesRP: false, + transitiveLibUsesRP: true, + + appOverlays: []string{ + "out/soong/.intermediates/transitive/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import/android_common/package-res.apk", + "out/soong/.intermediates/direct/android_common/package-res.apk", + "out/soong/.intermediates/direct_import_dep/android_common/package-res.apk", + "out/soong/.intermediates/direct_import/android_common/package-res.apk", + "out/soong/.intermediates/app/android_common/aapt2/app/res/values_strings.arsc.flat", + }, + appImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, + appSrcJars: []string{"out/soong/.intermediates/app/android_common/gen/android/R.srcjar"}, + appClasspath: []string{ + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/direct/android_common/turbine-combined/direct.jar", + "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar", + }, + appCombined: []string{ + "out/soong/.intermediates/app/android_common/javac/app.jar", + "out/soong/.intermediates/direct/android_common/combined/direct.jar", + "out/soong/.intermediates/direct_import/android_common/aar/classes-combined.jar", + }, + + directResources: nil, + directOverlays: []string{ + "out/soong/.intermediates/transitive/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import_dep/android_common/package-res.apk", + "out/soong/.intermediates/transitive_import/android_common/package-res.apk", + "out/soong/.intermediates/direct/android_common/aapt2/direct/res/values_strings.arsc.flat", + }, + directImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, + directSrcJars: []string{"out/soong/.intermediates/direct/android_common/gen/android/R.srcjar"}, + directClasspath: []string{ + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/transitive/android_common/turbine-combined/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar", + }, + directCombined: []string{ + "out/soong/.intermediates/direct/android_common/javac/direct.jar", + "out/soong/.intermediates/transitive/android_common/javac/transitive.jar", + "out/soong/.intermediates/transitive_import/android_common/aar/classes-combined.jar", + }, + + transitiveResources: []string{"out/soong/.intermediates/transitive/android_common/aapt2/transitive/res/values_strings.arsc.flat"}, + transitiveOverlays: nil, + transitiveImports: []string{"out/soong/.intermediates/default/java/framework-res/android_common/package-res.apk"}, + transitiveSrcJars: nil, + transitiveClasspath: []string{ + "out/soong/.intermediates/default/java/android_stubs_current/android_common/turbine-combined/android_stubs_current.jar", + "out/soong/.intermediates/transitive/android_common/busybox/R.jar", + }, + transitiveCombined: nil, + + dontVerifyDirectImport: true, + dontVerifyTransitiveImport: true, }, } @@ -839,6 +1083,7 @@ func TestAndroidResourceProcessor(t *testing.T) { resource_dirs: ["app/res"], manifest: "app/AndroidManifest.xml", static_libs: ["direct", "direct_import"], + use_resource_processor: %v, } android_library { @@ -848,6 +1093,7 @@ func TestAndroidResourceProcessor(t *testing.T) { resource_dirs: ["direct/res"], manifest: "direct/AndroidManifest.xml", static_libs: ["transitive", "transitive_import"], + use_resource_processor: %v, } android_library { @@ -856,6 +1102,7 @@ func TestAndroidResourceProcessor(t *testing.T) { srcs: ["transitive/transitive.java"], resource_dirs: ["transitive/res"], manifest: "transitive/AndroidManifest.xml", + use_resource_processor: %v, } android_library_import { @@ -883,7 +1130,7 @@ func TestAndroidResourceProcessor(t *testing.T) { sdk_version: "current", aars: ["transitive_import_dep.aar"], } - `) + `, testCase.appUsesRP, testCase.directLibUsesRP, testCase.transitiveLibUsesRP) fs := android.MockFS{ "app/res/values/strings.xml": nil, diff --git a/java/base.go b/java/base.go index 8db716256..ce94335d6 100644 --- a/java/base.go +++ b/java/base.go @@ -1057,7 +1057,7 @@ func (module *Module) addGeneratedSrcJars(path android.Path) { module.properties.Generated_srcjars = append(module.properties.Generated_srcjars, path) } -func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { +func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspathJars, extraCombinedJars android.Paths) { j.exportAidlIncludeDirs = android.PathsForModuleSrc(ctx, j.deviceProperties.Aidl.Export_include_dirs) deps := j.collectDeps(ctx) @@ -1095,9 +1095,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { srcJars := srcFiles.FilterByExt(".srcjar") srcJars = append(srcJars, deps.srcJars...) - if aaptSrcJar != nil { - srcJars = append(srcJars, aaptSrcJar) - } + srcJars = append(srcJars, extraSrcJars...) srcJars = append(srcJars, j.properties.Generated_srcjars...) srcFiles = srcFiles.FilterOutByExt(".srcjar") @@ -1140,6 +1138,11 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { var kotlinJars android.Paths var kotlinHeaderJars android.Paths + // Prepend extraClasspathJars to classpath so that the resource processor R.jar comes before + // any dependencies so that it can override any non-final R classes from dependencies with the + // final R classes from the app. + flags.classpath = append(android.CopyOf(extraClasspathJars), flags.classpath...) + if srcFiles.HasExt(".kt") { // When using kotlin sources turbine is used to generate annotation processor sources, // including for annotation processors that generate API, so we can use turbine for @@ -1233,8 +1236,9 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { // allow for the use of annotation processors that do function correctly // with sharding enabled. See: b/77284273. } + extraJars := append(android.CopyOf(extraCombinedJars), kotlinHeaderJars...) headerJarFileWithoutDepsOrJarjar, j.headerJarFile = - j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, kotlinHeaderJars) + j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, extraJars) if ctx.Failed() { return } @@ -1385,6 +1389,8 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { jars = append(jars, servicesJar) } + jars = append(android.CopyOf(extraCombinedJars), jars...) + // Combine the classes built from sources, any manifests, and any static libraries into // classes.jar. If there is only one input jar this step will be skipped. var outputFile android.OutputPath diff --git a/java/config/config.go b/java/config/config.go index 195dae16b..83c27d309 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -148,6 +148,8 @@ func init() { pctx.SourcePathVariable("JavaKytheExtractorJar", "prebuilts/build-tools/common/framework/javac_extractor.jar") pctx.SourcePathVariable("Ziptime", "prebuilts/build-tools/${hostPrebuiltTag}/bin/ziptime") + pctx.SourcePathVariable("ResourceProcessorBusyBox", "prebuilts/bazel/common/android_tools/android_tools/all_android_tools_deploy.jar") + pctx.HostBinToolVariable("GenKotlinBuildFileCmd", "gen-kotlin-build-file") pctx.SourcePathVariable("JarArgsCmd", "build/soong/scripts/jar-args.sh") diff --git a/java/java.go b/java/java.go index 6388d13e3..ce14df778 100644 --- a/java/java.go +++ b/java/java.go @@ -692,7 +692,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex j.classLoaderContexts = j.usesLibrary.classLoaderContextForUsesLibDeps(ctx) } - j.compile(ctx, nil) + j.compile(ctx, nil, nil, nil) // Collect the module directory for IDE info in java/jdeps.go. j.modulePaths = append(j.modulePaths, ctx.ModuleDir()) -- cgit v1.2.3-59-g8ed1b From 21862285ace046bc9d089984baa898ef21aff4c6 Mon Sep 17 00:00:00 2001 From: Rico Wind Date: Tue, 1 Aug 2023 14:38:36 +0200 Subject: Enable compact entries for resource shrunken apps For SystemUIGoogle this is a 2.3 MB reduction (17* of resources arsc) and for Traceur it is a 500k reduction (22% of resources.arsc) Bug: 294016857 Test: Existing Ignore-AOSP-First: The resource system support for this is not in AOSP yet Change-Id: I513078406494ad354c255afa0e829cbe10a9b07a --- java/aapt2.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'java') diff --git a/java/aapt2.go b/java/aapt2.go index 7845a0b23..abe154ea0 100644 --- a/java/aapt2.go +++ b/java/aapt2.go @@ -256,7 +256,8 @@ func aapt2Link(ctx android.ModuleContext, var aapt2ConvertRule = pctx.AndroidStaticRule("aapt2Convert", blueprint.RuleParams{ - Command: `${config.Aapt2Cmd} convert --output-format $format $in -o $out`, + Command: `${config.Aapt2Cmd} convert --enable-compact-entries ` + + `--output-format $format $in -o $out`, CommandDeps: []string{"${config.Aapt2Cmd}"}, }, "format", ) -- cgit v1.2.3-59-g8ed1b From beb6e9ffdb4e5aaa29e2916273f140f3f5d71926 Mon Sep 17 00:00:00 2001 From: Mark White Date: Thu, 10 Aug 2023 00:07:03 +0000 Subject: SdkTestCore for non-updatable modules Provides SdkTestCore/test_core_current sdk_version for non-updatable modules that have their test scope dependent on test apis from framework-minus-apex. Ignore-AOSP-First: Change in topic with internal-first projects Bug: 289776578 Test: m checkapi | go test ./java Change-Id: Iba3213e8c34ea75ac9dd8532a95ef62fb5455e6c --- android/sdk_version.go | 12 ++++++++++-- java/sdk.go | 5 +++-- java/sdk_library.go | 6 ++++++ java/sdk_library_test.go | 26 ++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) (limited to 'java') diff --git a/android/sdk_version.go b/android/sdk_version.go index 1fadda0ca..aafcee79a 100644 --- a/android/sdk_version.go +++ b/android/sdk_version.go @@ -48,6 +48,7 @@ const ( SdkPublic SdkSystem SdkTest + SdkTestFrameworksCore SdkModule SdkSystemServer SdkPrivate @@ -67,6 +68,8 @@ func (k SdkKind) String() string { return "system" case SdkTest: return "test" + case SdkTestFrameworksCore: + return "test_frameworks_core" case SdkCore: return "core" case SdkCorePlatform: @@ -92,6 +95,8 @@ func (k SdkKind) DefaultJavaLibraryName() string { return "android_system_stubs_current" case SdkTest: return "android_test_stubs_current" + case SdkTestFrameworksCore: + return "android_test_frameworks_core_stubs_current" case SdkCore: return "core.current.stubs" case SdkModule: @@ -137,7 +142,7 @@ func (s SdkSpec) Stable() bool { return true case SdkCore, SdkPublic, SdkSystem, SdkModule, SdkSystemServer: return true - case SdkCorePlatform, SdkTest, SdkPrivate: + case SdkCorePlatform, SdkTest, SdkTestFrameworksCore, SdkPrivate: return false default: panic(fmt.Errorf("unknown SdkKind=%v", s.Kind)) @@ -185,7 +190,8 @@ func (s SdkSpec) UsePrebuilt(ctx EarlyModuleContext) bool { return ctx.Config().AlwaysUsePrebuiltSdks() } else if !s.ApiLevel.IsPreview() { // validation check - if s.Kind != SdkPublic && s.Kind != SdkSystem && s.Kind != SdkTest && s.Kind != SdkModule && s.Kind != SdkSystemServer { + if s.Kind != SdkPublic && s.Kind != SdkSystem && s.Kind != SdkTest && + s.Kind != SdkTestFrameworksCore && s.Kind != SdkModule && s.Kind != SdkSystemServer { panic(fmt.Errorf("prebuilt SDK is not not available for SdkKind=%q", s.Kind)) return false } @@ -266,6 +272,8 @@ func SdkSpecFromWithConfig(config Config, str string) SdkSpec { kind = SdkSystem case "test": kind = SdkTest + case "test_frameworks_core": + kind = SdkTestFrameworksCore case "module": kind = SdkModule case "system_server": diff --git a/java/sdk.go b/java/sdk.go index 7c702c405..ddd99bb33 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -76,7 +76,8 @@ func systemModuleKind(sdkKind android.SdkKind, apiLevel android.ApiLevel) androi // Core is by definition what is included in the system module for the public API so should // just use its system modules. systemModuleKind = android.SdkPublic - } else if systemModuleKind == android.SdkSystem || systemModuleKind == android.SdkTest { + } else if systemModuleKind == android.SdkSystem || systemModuleKind == android.SdkTest || + systemModuleKind == android.SdkTestFrameworksCore { // The core system and test APIs are currently the same as the public API so they should use // its system modules. systemModuleKind = android.SdkPublic @@ -192,7 +193,7 @@ func decodeSdkDep(ctx android.EarlyModuleContext, sdkContext android.SdkContext) bootclasspath: corePlatformBootclasspathLibraries(ctx), noFrameworksLibs: true, } - case android.SdkPublic, android.SdkSystem, android.SdkTest: + case android.SdkPublic, android.SdkSystem, android.SdkTest, android.SdkTestFrameworksCore: return toModule(sdkVersion.Kind.DefaultJavaLibraryName(), sdkFrameworkAidlPath(ctx)) case android.SdkCore: return sdkDep{ diff --git a/java/sdk_library.go b/java/sdk_library.go index dbb2f0247..e7c84f6ff 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -442,6 +442,9 @@ type ApiScopeProperties struct { // or the API file. They both have to use the same sdk_version as is used for // compiling the implementation library. Sdk_version *string + + // Extra libs used when compiling stubs for this scope. + Libs []string } type sdkLibraryProperties struct { @@ -1602,6 +1605,7 @@ func (module *SdkLibrary) createStubsLibrary(mctx android.DefaultableHookContext props.Patch_module = module.properties.Patch_module props.Installable = proptools.BoolPtr(false) props.Libs = module.sdkLibraryProperties.Stub_only_libs + props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) props.Static_libs = module.sdkLibraryProperties.Stub_only_static_libs // The stub-annotations library contains special versions of the annotations // with CLASS retention policy, so that they're kept. @@ -1674,6 +1678,7 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC props.Libs = module.properties.Libs props.Libs = append(props.Libs, module.properties.Static_libs...) props.Libs = append(props.Libs, module.sdkLibraryProperties.Stub_only_libs...) + props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) props.Aidl.Include_dirs = module.deviceProperties.Aidl.Include_dirs props.Aidl.Local_include_dirs = module.deviceProperties.Aidl.Local_include_dirs props.Java_version = module.properties.Java_version @@ -1805,6 +1810,7 @@ func (module *SdkLibrary) createApiLibrary(mctx android.DefaultableHookContext, props.Api_contributions = apiContributions props.Libs = module.properties.Libs props.Libs = append(props.Libs, module.sdkLibraryProperties.Stub_only_libs...) + props.Libs = append(props.Libs, module.scopeToProperties[apiScope].Libs...) props.Libs = append(props.Libs, "stub-annotations") props.Static_libs = module.sdkLibraryProperties.Stub_only_static_libs props.Full_api_surface_stub = proptools.StringPtr(apiScope.kind.DefaultJavaLibraryName() + ".from-text") diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index c22b9809b..85bd04541 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -1416,6 +1416,32 @@ func TestJavaSdkLibrary_StubOnlyLibs_PassedToDroidstubs(t *testing.T) { android.AssertStringListContains(t, "foo stubs should depend on bar-lib", fooStubsSources.Javadoc.properties.Libs, "bar-lib") } +func TestJavaSdkLibrary_Scope_Libs_PassedToDroidstubs(t *testing.T) { + result := android.GroupFixturePreparers( + prepareForJavaTest, + PrepareForTestWithJavaSdkLibraryFiles, + FixtureWithLastReleaseApis("foo"), + ).RunTestWithBp(t, ` + java_sdk_library { + name: "foo", + srcs: ["a.java"], + public: { + enabled: true, + libs: ["bar-lib"], + }, + } + + java_library { + name: "bar-lib", + srcs: ["b.java"], + } + `) + + // The foo.stubs.source should depend on bar-lib + fooStubsSources := result.ModuleForTests("foo.stubs.source", "android_common").Module().(*Droidstubs) + android.AssertStringListContains(t, "foo stubs should depend on bar-lib", fooStubsSources.Javadoc.properties.Libs, "bar-lib") +} + func TestJavaSdkLibrary_ApiLibrary(t *testing.T) { result := android.GroupFixturePreparers( prepareForJavaTest, -- cgit v1.2.3-59-g8ed1b From 662e2c5e98f9a6833b779a4f8fde2c31f3d07e3a Mon Sep 17 00:00:00 2001 From: Jihoon Kang Date: Wed, 16 Aug 2023 19:06:32 +0000 Subject: Move from-text stub java_api_library modules closer to source This change moves java_api_library modules that were previously defined in build/orchestrator closer to where their from-source equivalents are defined. Ignore-AOSP-First: Resolve merge conflict Test: m (default to from-text stub build) Bug: 274805756 (cherry picked from https://android-review.googlesource.com/q/commit:fb5331fd3eff558b5f0751692db38cd77018f1b6) Change-Id: If66b5bba719bb389a69f2353d2218a89b2b96b90 --- java/core-libraries/Android.bp | 54 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'java') diff --git a/java/core-libraries/Android.bp b/java/core-libraries/Android.bp index de9a82d09..4380f4f5c 100644 --- a/java/core-libraries/Android.bp +++ b/java/core-libraries/Android.bp @@ -55,6 +55,19 @@ java_library { ], } +java_api_library { + name: "core.current.stubs.from-text", + api_surface: "core", + api_contributions: [ + "art.module.public.api.stubs.source.api.contribution", + "conscrypt.module.public.api.stubs.source.api.contribution", + "i18n.module.public.api.stubs.source.api.contribution", + ], + libs: [ + "stub-annotations", + ], +} + java_library { name: "core.current.stubs", defaults: [ @@ -153,7 +166,6 @@ java_defaults { system_modules: "none", } - // A stubs target containing the parts of the public SDK & @SystemApi(MODULE_LIBRARIES) API // provided by the core libraries. // @@ -265,6 +277,32 @@ java_library { ], } +java_defaults { + name: "android_core_platform_stubs_current_contributions", + api_surface: "core_platform", + api_contributions: [ + "art.module.public.api.stubs.source.api.contribution", + "art.module.public.api.stubs.source.system.api.contribution", + "art.module.public.api.stubs.source.module_lib.api.contribution", + "conscrypt.module.platform.api.stubs.source.api.contribution", + "i18n.module.public.api.stubs.source.api.contribution", + ], +} + +java_api_library { + name: "legacy.core.platform.api.stubs.from-text", + api_surface: "core_platform", + defaults: [ + "android_core_platform_stubs_current_contributions", + ], + api_contributions: [ + "legacy.i18n.module.platform.api.stubs.source.api.contribution", + ], + libs: [ + "stub-annotations", + ], +} + java_library { name: "legacy.core.platform.api.stubs", visibility: core_platform_visibility, @@ -328,6 +366,20 @@ java_library { ], } +java_api_library { + name: "stable.core.platform.api.stubs.from-text", + api_surface: "core_platform", + defaults: [ + "android_core_platform_stubs_current_contributions", + ], + api_contributions: [ + "stable.i18n.module.platform.api.stubs.source.api.contribution", + ], + libs: [ + "stub-annotations", + ], +} + java_library { name: "stable.core.platform.api.stubs", visibility: core_platform_visibility, -- cgit v1.2.3-59-g8ed1b From c9b16799b5088d6c101c56ce62d42d3da7ac641c Mon Sep 17 00:00:00 2001 From: Mark White Date: Thu, 10 Aug 2023 00:07:40 +0000 Subject: java_library support for building headers-only Flag for java_library modules to build just the Turbine headers and skip building an impl jar. Test: m framework-minus-apex-headers Bug: 289776578 Ignore-AOSP-First: Change stacked with changes in internal repos Change-Id: If8b4033462d39c689cba0ed38cc343e4786ea280 --- android/neverallow.go | 8 ++++++++ android/neverallow_test.go | 16 ++++++++++++++++ java/androidmk.go | 3 +++ java/base.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ java/java.go | 1 + java/java_test.go | 18 ++++++++++++++++++ 6 files changed, 90 insertions(+) (limited to 'java') diff --git a/android/neverallow.go b/android/neverallow.go index 24031ba39..2be6a74f5 100644 --- a/android/neverallow.go +++ b/android/neverallow.go @@ -60,6 +60,7 @@ func init() { AddNeverAllowRules(createBp2BuildRule()) AddNeverAllowRules(createCcStubsRule()) AddNeverAllowRules(createJavaExcludeStaticLibsRule()) + AddNeverAllowRules(createProhibitHeaderOnlyRule()) } // Add a NeverAllow rule to the set of rules to apply. @@ -264,6 +265,13 @@ func createJavaExcludeStaticLibsRule() Rule { Because("exclude_static_libs property is only allowed for java modules defined in build/soong, libcore, and frameworks/base/api") } +func createProhibitHeaderOnlyRule() Rule { + return NeverAllow(). + Without("name", "framework-minus-apex-headers"). + With("headers_only", "true"). + Because("headers_only can only be used for generating framework-minus-apex headers for non-updatable modules") +} + func neverallowMutator(ctx BottomUpMutatorContext) { m, ok := ctx.Module().(Module) if !ok { diff --git a/android/neverallow_test.go b/android/neverallow_test.go index 2a938b811..b2620ef92 100644 --- a/android/neverallow_test.go +++ b/android/neverallow_test.go @@ -361,6 +361,21 @@ var neverallowTests = []struct { `exclude_static_libs property is only allowed for java modules defined in build/soong, libcore, and frameworks/base/api`, }, }, + // Test for only allowing headers_only for framework-minus-apex-headers + { + name: `"headers_only" outside framework-minus-apex-headers modules`, + fs: map[string][]byte{ + "a/b/Android.bp": []byte(` + java_library { + name: "baz", + headers_only: true, + } + `), + }, + expectedErrors: []string{ + `headers_only can only be used for generating framework-minus-apex headers for non-updatable modules`, + }, + }, } var prepareForNeverAllowTest = GroupFixturePreparers( @@ -451,6 +466,7 @@ type mockJavaLibraryProperties struct { Sdk_version *string Uncompress_dex *bool Exclude_static_libs []string + Headers_only *bool } type mockJavaLibraryModule struct { diff --git a/java/androidmk.go b/java/androidmk.go index 82505e9e3..b7e2d2ff3 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -79,6 +79,9 @@ func (library *Library) AndroidMkEntries() []android.AndroidMkEntries { } else if !library.ApexModuleBase.AvailableFor(android.AvailableToPlatform) { // Platform variant. If not available for the platform, we don't need Make module. entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true}) + } else if library.properties.Headers_only { + // If generating headers only then don't expose to Make. + entriesList = append(entriesList, android.AndroidMkEntries{Disabled: true}) } else { entriesList = append(entriesList, android.AndroidMkEntries{ Class: "JAVA_LIBRARIES", diff --git a/java/base.go b/java/base.go index f5eb01c4b..58ba41098 100644 --- a/java/base.go +++ b/java/base.go @@ -192,6 +192,9 @@ type CommonProperties struct { // Additional srcJars tacked in by GeneratedJavaLibraryModule Generated_srcjars []android.Path `android:"mutated"` + + // If true, then only the headers are built and not the implementation jar. + Headers_only bool } // Properties that are specific to device modules. Host module factories should not add these when @@ -574,6 +577,17 @@ func (j *Module) checkPlatformAPI(ctx android.ModuleContext) { } } +func (j *Module) checkHeadersOnly(ctx android.ModuleContext) { + if _, ok := ctx.Module().(android.SdkContext); ok { + headersOnly := proptools.Bool(&j.properties.Headers_only) + installable := proptools.Bool(j.properties.Installable) + + if headersOnly && installable { + ctx.PropertyErrorf("headers_only", "This module has conflicting settings. headers_only is true which, which means this module doesn't generate an implementation jar. However installable is set to true.") + } + } +} + func (j *Module) addHostProperties() { j.AddProperties( &j.properties, @@ -1151,6 +1165,36 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath // final R classes from the app. flags.classpath = append(android.CopyOf(extraClasspathJars), flags.classpath...) + // If compiling headers then compile them and skip the rest + if j.properties.Headers_only { + if srcFiles.HasExt(".kt") { + ctx.ModuleErrorf("Compiling headers_only with .kt not supported") + } + if ctx.Config().IsEnvFalse("TURBINE_ENABLED") || disableTurbine { + ctx.ModuleErrorf("headers_only is enabled but Turbine is disabled.") + } + + _, j.headerJarFile = + j.compileJavaHeader(ctx, uniqueJavaFiles, srcJars, deps, flags, jarName, + extraCombinedJars) + if ctx.Failed() { + return + } + + ctx.SetProvider(JavaInfoProvider, JavaInfo{ + HeaderJars: android.PathsIfNonNil(j.headerJarFile), + TransitiveLibsHeaderJars: j.transitiveLibsHeaderJars, + TransitiveStaticLibsHeaderJars: j.transitiveStaticLibsHeaderJars, + AidlIncludeDirs: j.exportAidlIncludeDirs, + ExportedPlugins: j.exportedPluginJars, + ExportedPluginClasses: j.exportedPluginClasses, + ExportedPluginDisableTurbine: j.exportedDisableTurbine, + }) + + j.outputFile = j.headerJarFile + return + } + if srcFiles.HasExt(".kt") { // When using kotlin sources turbine is used to generate annotation processor sources, // including for annotation processors that generate API, so we can use turbine for diff --git a/java/java.go b/java/java.go index 70aba8e2c..c60226de6 100644 --- a/java/java.go +++ b/java/java.go @@ -692,6 +692,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { } j.checkSdkVersions(ctx) + j.checkHeadersOnly(ctx) if ctx.Device() { j.dexpreopter.installPath = j.dexpreopter.getInstallPath( ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) diff --git a/java/java_test.go b/java/java_test.go index 6110e21cb..27933c3bf 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -2370,3 +2370,21 @@ func TestJavaLibraryWithResourcesStem(t *testing.T) { t.Errorf("Module output does not contain expected jar %s", "test.jar") } } + +func TestHeadersOnly(t *testing.T) { + ctx, _ := testJava(t, ` + java_library { + name: "foo", + srcs: ["a.java"], + headers_only: true, + } + `) + + turbine := ctx.ModuleForTests("foo", "android_common").Rule("turbine") + if len(turbine.Inputs) != 1 || turbine.Inputs[0].String() != "a.java" { + t.Errorf(`foo inputs %v != ["a.java"]`, turbine.Inputs) + } + + javac := ctx.ModuleForTests("foo", "android_common").MaybeRule("javac") + android.AssertDeepEquals(t, "javac rule", nil, javac.Rule) +} -- cgit v1.2.3-59-g8ed1b From 8bf29fd473708efd44a7e7d05e0a64c1d4ddd5a2 Mon Sep 17 00:00:00 2001 From: Mark White Date: Sun, 6 Aug 2023 00:20:47 +0000 Subject: Created empty framework-location non-updatable module Ignore-AOSP-First: Change in topic with internal-first projects Bug: 289776578 Test: presubmit Change-Id: Iebc6d016b8313759ac1f6f3ab6f4834f5ad7b93e --- android/config.go | 1 + java/legacy_core_platform_api_usage.go | 1 + 2 files changed, 2 insertions(+) (limited to 'java') diff --git a/android/config.go b/android/config.go index 2e10ae90a..ec117d097 100644 --- a/android/config.go +++ b/android/config.go @@ -667,6 +667,7 @@ func NewConfig(cmdArgs CmdArgs, availableEnv map[string]string) (Config, error) "framework-devicelock": {}, "framework-graphics": {}, "framework-healthfitness": {}, + "framework-location": {}, "framework-media": {}, "framework-mediaprovider": {}, "framework-ondevicepersonalization": {}, diff --git a/java/legacy_core_platform_api_usage.go b/java/legacy_core_platform_api_usage.go index 6cb549eaf..4be7d0470 100644 --- a/java/legacy_core_platform_api_usage.go +++ b/java/legacy_core_platform_api_usage.go @@ -28,6 +28,7 @@ var legacyCorePlatformApiModules = []string{ "FloralClocks", "framework-jobscheduler", "framework-minus-apex", + "framework-minus-apex-headers", "framework-minus-apex-intdefs", "FrameworksCoreTests", "HelloOslo", -- cgit v1.2.3-59-g8ed1b From ea769bc5ec15c2503fe52505b64ca9fadfcc85ed Mon Sep 17 00:00:00 2001 From: Zhi Dou Date: Fri, 6 Oct 2023 07:21:52 +0000 Subject: Add UnsupportedAppUsage to java_aconfig_library dependency Generated flag requires UnsupportedAppUsage annotation to expose the flag to CTS tests. Bug: 301272559 Test: presubit Ignore-AOSP-First: Need to commit with changes in internal main. This change will be cherry picked to AOSP once merged in main Change-Id: I90c87596ca80766ece429ddee1b45723b01d2760 --- aconfig/java_aconfig_library.go | 2 ++ java/testing.go | 1 + 2 files changed, 3 insertions(+) (limited to 'java') diff --git a/aconfig/java_aconfig_library.go b/aconfig/java_aconfig_library.go index 48cfb7695..79573c787 100644 --- a/aconfig/java_aconfig_library.go +++ b/aconfig/java_aconfig_library.go @@ -58,6 +58,8 @@ func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) DepsMutator(module *ja // Add aconfig-annotations-lib as a dependency for the optimization / code stripping annotations module.AddSharedLibrary("aconfig-annotations-lib") + // TODO(b/303773055): Remove the annotation after access issue is resolved. + module.AddSharedLibrary("unsupportedappusage") } func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) GenerateSourceJarBuildActions(module *java.GeneratedJavaLibraryModule, ctx android.ModuleContext) android.Path { diff --git a/java/testing.go b/java/testing.go index 98bea7f14..0b7e68539 100644 --- a/java/testing.go +++ b/java/testing.go @@ -410,6 +410,7 @@ func gatherRequiredDepsForTest() string { "stub-annotations", "aconfig-annotations-lib", + "unsupportedappusage", } for _, extra := range extraModules { -- cgit v1.2.3-59-g8ed1b From 32eb1338f017df63a4c086df8b055d4abab08906 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Fri, 20 Oct 2023 10:42:47 -0700 Subject: Add `android_ravenwood_test` build rule Modeled after android_robolectric_test. Bug: 292141694 Test: m nothing --no-skip-soong-tests Test: m hoststubgen ravenwood-runtime tradefed atest && atest-dev HostStubGenTest-framework-test Change-Id: Ibef8953db45b86264c8a827868793b42f8f2d6ab --- android/test_suites.go | 26 ++++++- java/Android.bp | 2 + java/ravenwood.go | 183 +++++++++++++++++++++++++++++++++++++++++++++++++ java/ravenwood_test.go | 113 ++++++++++++++++++++++++++++++ tradefed/config.go | 1 + 5 files changed, 324 insertions(+), 1 deletion(-) create mode 100644 java/ravenwood.go create mode 100644 java/ravenwood_test.go (limited to 'java') diff --git a/android/test_suites.go b/android/test_suites.go index 9ded99832..adcc15a6e 100644 --- a/android/test_suites.go +++ b/android/test_suites.go @@ -24,6 +24,7 @@ func testSuiteFilesFactory() Singleton { type testSuiteFiles struct { robolectric WritablePath + ravenwood WritablePath } type TestSuiteModule interface { @@ -47,12 +48,15 @@ func (t *testSuiteFiles) GenerateBuildActions(ctx SingletonContext) { }) t.robolectric = robolectricTestSuite(ctx, files["robolectric-tests"]) - ctx.Phony("robolectric-tests", t.robolectric) + + t.ravenwood = ravenwoodTestSuite(ctx, files["ravenwood-tests"]) + ctx.Phony("ravenwood-tests", t.ravenwood) } func (t *testSuiteFiles) MakeVars(ctx MakeVarsContext) { ctx.DistForGoal("robolectric-tests", t.robolectric) + ctx.DistForGoal("ravenwood-tests", t.ravenwood) } func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) WritablePath { @@ -74,3 +78,23 @@ func robolectricTestSuite(ctx SingletonContext, files map[string]InstallPaths) W return outputFile } + +func ravenwoodTestSuite(ctx SingletonContext, files map[string]InstallPaths) WritablePath { + var installedPaths InstallPaths + for _, module := range SortedKeys(files) { + installedPaths = append(installedPaths, files[module]...) + } + testCasesDir := pathForInstall(ctx, ctx.Config().BuildOS, X86, "testcases") + + outputFile := PathForOutput(ctx, "packaging", "ravenwood-tests.zip") + rule := NewRuleBuilder(pctx, ctx) + rule.Command().BuiltTool("soong_zip"). + FlagWithOutput("-o ", outputFile). + FlagWithArg("-P ", "host/testcases"). + FlagWithArg("-C ", testCasesDir.String()). + FlagWithRspFileInputList("-r ", outputFile.ReplaceExtension(ctx, "rsp"), installedPaths.Paths()). + Flag("-sha256") + rule.Build("ravenwood_tests_zip", "ravenwood-tests.zip") + + return outputFile +} diff --git a/java/Android.bp b/java/Android.bp index 4450c4275..b8d26bf78 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -66,6 +66,7 @@ bootstrap_go_package { "plugin.go", "prebuilt_apis.go", "proto.go", + "ravenwood.go", "resourceshrinker.go", "robolectric.go", "rro.go", @@ -106,6 +107,7 @@ bootstrap_go_package { "plugin_test.go", "prebuilt_apis_test.go", "proto_test.go", + "ravenwood_test.go", "resourceshrinker_test.go", "rro_test.go", "sdk_test.go", diff --git a/java/ravenwood.go b/java/ravenwood.go new file mode 100644 index 000000000..a03d8fb17 --- /dev/null +++ b/java/ravenwood.go @@ -0,0 +1,183 @@ +// Copyright 2023 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package java + +import ( + "android/soong/android" + "android/soong/tradefed" + "github.com/google/blueprint/proptools" +) + +func init() { + RegisterRavenwoodBuildComponents(android.InitRegistrationContext) +} + +func RegisterRavenwoodBuildComponents(ctx android.RegistrationContext) { + ctx.RegisterModuleType("android_ravenwood_test", ravenwoodTestFactory) + ctx.RegisterModuleType("android_ravenwood_libgroup", ravenwoodLibgroupFactory) +} + +var ravenwoodTag = dependencyTag{name: "ravenwood"} + +const ravenwoodUtilsName = "ravenwood-utils" +const ravenwoodRuntimeName = "ravenwood-runtime" + +type ravenwoodTest struct { + Library + + testProperties testProperties + testConfig android.Path + + forceOSType android.OsType + forceArchType android.ArchType +} + +func ravenwoodTestFactory() android.Module { + module := &ravenwoodTest{} + + module.addHostAndDeviceProperties() + module.AddProperties(&module.testProperties) + + module.Module.dexpreopter.isTest = true + module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) + + module.testProperties.Test_suites = []string{"ravenwood-tests"} + module.testProperties.Test_options.Unit_test = proptools.BoolPtr(false) + + InitJavaModule(module, android.DeviceSupported) + android.InitDefaultableModule(module) + + return module +} + +func (r *ravenwoodTest) InstallInTestcases() bool { return true } +func (r *ravenwoodTest) InstallForceOS() (*android.OsType, *android.ArchType) { + return &r.forceOSType, &r.forceArchType +} +func (r *ravenwoodTest) TestSuites() []string { + return r.testProperties.Test_suites +} + +func (r *ravenwoodTest) DepsMutator(ctx android.BottomUpMutatorContext) { + r.Library.DepsMutator(ctx) + + // Generically depend on the runtime so that it's installed together with us + ctx.AddVariationDependencies(nil, ravenwoodTag, ravenwoodRuntimeName) + + // Directly depend on any utils so that we link against them + utils := ctx.AddVariationDependencies(nil, ravenwoodTag, ravenwoodUtilsName)[0] + if utils != nil { + for _, lib := range utils.(*ravenwoodLibgroup).ravenwoodLibgroupProperties.Libs { + ctx.AddVariationDependencies(nil, libTag, lib) + } + } +} + +func (r *ravenwoodTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { + r.forceOSType = ctx.Config().BuildOS + r.forceArchType = ctx.Config().BuildArch + + r.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{ + TestConfigProp: r.testProperties.Test_config, + TestConfigTemplateProp: r.testProperties.Test_config_template, + TestSuites: r.testProperties.Test_suites, + AutoGenConfig: r.testProperties.Auto_gen_config, + DeviceTemplate: "${RavenwoodTestConfigTemplate}", + HostTemplate: "${RavenwoodTestConfigTemplate}", + }) + + r.Library.GenerateAndroidBuildActions(ctx) + + // Start by depending on all files installed by dependancies + var installDeps android.Paths + for _, dep := range ctx.GetDirectDepsWithTag(ravenwoodTag) { + for _, installFile := range dep.FilesToInstall() { + installDeps = append(installDeps, installFile) + } + } + + // Also depend on our config + installPath := android.PathForModuleInstall(ctx, r.BaseModuleName()) + installConfig := ctx.InstallFile(installPath, ctx.ModuleName()+".config", r.testConfig) + installDeps = append(installDeps, installConfig) + + // Finally install our JAR with all dependencies + ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.outputFile, installDeps...) +} + +func (r *ravenwoodTest) AndroidMkEntries() []android.AndroidMkEntries { + entriesList := r.Library.AndroidMkEntries() + entries := &entriesList[0] + entries.ExtraEntries = append(entries.ExtraEntries, + func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { + entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) + entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", "ravenwood-tests") + if r.testConfig != nil { + entries.SetPath("LOCAL_FULL_TEST_CONFIG", r.testConfig) + } + }) + return entriesList +} + +type ravenwoodLibgroupProperties struct { + Libs []string +} + +type ravenwoodLibgroup struct { + android.ModuleBase + + ravenwoodLibgroupProperties ravenwoodLibgroupProperties + + forceOSType android.OsType + forceArchType android.ArchType +} + +func ravenwoodLibgroupFactory() android.Module { + module := &ravenwoodLibgroup{} + module.AddProperties(&module.ravenwoodLibgroupProperties) + + android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) + return module +} + +func (r *ravenwoodLibgroup) InstallInTestcases() bool { return true } +func (r *ravenwoodLibgroup) InstallForceOS() (*android.OsType, *android.ArchType) { + return &r.forceOSType, &r.forceArchType +} +func (r *ravenwoodLibgroup) TestSuites() []string { + return []string{"ravenwood-tests"} +} + +func (r *ravenwoodLibgroup) DepsMutator(ctx android.BottomUpMutatorContext) { + // Always depends on our underlying libs + for _, lib := range r.ravenwoodLibgroupProperties.Libs { + ctx.AddVariationDependencies(nil, ravenwoodTag, lib) + } +} + +func (r *ravenwoodLibgroup) GenerateAndroidBuildActions(ctx android.ModuleContext) { + r.forceOSType = ctx.Config().BuildOS + r.forceArchType = ctx.Config().BuildArch + + // Install our runtime into expected location for packaging + installPath := android.PathForModuleInstall(ctx, r.BaseModuleName()) + for _, lib := range r.ravenwoodLibgroupProperties.Libs { + libModule := ctx.GetDirectDepWithTag(lib, ravenwoodTag) + libJar := android.OutputFileForModule(ctx, libModule, "") + ctx.InstallFile(installPath, lib+".jar", libJar) + } + + // Normal build should perform install steps + ctx.Phony(r.BaseModuleName(), android.PathForPhony(ctx, r.BaseModuleName()+"-install")) +} diff --git a/java/ravenwood_test.go b/java/ravenwood_test.go new file mode 100644 index 000000000..4ae1d7cf5 --- /dev/null +++ b/java/ravenwood_test.go @@ -0,0 +1,113 @@ +// Copyright 2022 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package java + +import ( + "testing" + + "android/soong/android" +) + +var prepareRavenwoodRuntime = android.GroupFixturePreparers( + android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) { + RegisterRavenwoodBuildComponents(ctx) + }), + android.FixtureAddTextFile("ravenwood/Android.bp", ` + java_library_static { + name: "framework-minus-apex.ravenwood", + srcs: ["Framework.java"], + } + java_library_static { + name: "framework-services.ravenwood", + srcs: ["Services.java"], + } + java_library_static { + name: "framework-rules.ravenwood", + srcs: ["Rules.java"], + } + android_ravenwood_libgroup { + name: "ravenwood-runtime", + libs: [ + "framework-minus-apex.ravenwood", + "framework-services.ravenwood", + ], + } + android_ravenwood_libgroup { + name: "ravenwood-utils", + libs: [ + "framework-rules.ravenwood", + ], + } + `), +) + +var installPathPrefix = "out/soong/host/linux-x86/testcases" + +func TestRavenwoodRuntime(t *testing.T) { + ctx := android.GroupFixturePreparers( + PrepareForIntegrationTestWithJava, + prepareRavenwoodRuntime, + ).RunTest(t) + + // Verify that our runtime depends on underlying libs + CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-minus-apex.ravenwood") + CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-runtime", "android_common", "framework-services.ravenwood") + CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-utils", "android_common", "framework-rules.ravenwood") + + // Verify that we've emitted artifacts in expected location + runtime := ctx.ModuleForTests("ravenwood-runtime", "android_common") + runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-minus-apex.ravenwood.jar") + runtime.Output(installPathPrefix + "/ravenwood-runtime/framework-services.ravenwood.jar") + utils := ctx.ModuleForTests("ravenwood-utils", "android_common") + utils.Output(installPathPrefix + "/ravenwood-utils/framework-rules.ravenwood.jar") +} + +func TestRavenwoodTest(t *testing.T) { + ctx := android.GroupFixturePreparers( + PrepareForIntegrationTestWithJava, + prepareRavenwoodRuntime, + ).RunTestWithBp(t, ` + android_ravenwood_test { + name: "ravenwood-test", + srcs: ["Test.java"], + sdk_version: "test_current", + } + `) + + // Verify that our test depends on underlying libs + CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-buildtime") + CheckModuleHasDependency(t, ctx.TestContext, "ravenwood-test", "android_common", "ravenwood-utils") + + module := ctx.ModuleForTests("ravenwood-test", "android_common") + classpath := module.Rule("javac").Args["classpath"] + + // Verify that we're linking against test_current + android.AssertStringDoesContain(t, "classpath", classpath, "android_test_stubs_current.jar") + // Verify that we're linking against utils + android.AssertStringDoesContain(t, "classpath", classpath, "framework-rules.ravenwood.jar") + // Verify that we're *NOT* linking against runtime + android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-minus-apex.ravenwood.jar") + android.AssertStringDoesNotContain(t, "classpath", classpath, "framework-services.ravenwood.jar") + + // Verify that we've emitted test artifacts in expected location + outputJar := module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.jar") + module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.config") + + // Verify that we're going to install underlying libs + orderOnly := outputJar.OrderOnly.Strings() + android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-minus-apex.ravenwood.jar") + android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-runtime/framework-services.ravenwood.jar") + android.AssertStringListContains(t, "orderOnly", orderOnly, installPathPrefix+"/ravenwood-utils/framework-rules.ravenwood.jar") +} diff --git a/tradefed/config.go b/tradefed/config.go index 326a00666..b0150348b 100644 --- a/tradefed/config.go +++ b/tradefed/config.go @@ -33,6 +33,7 @@ func init() { pctx.SourcePathVariable("NativeTestConfigTemplate", "build/make/core/native_test_config_template.xml") pctx.SourcePathVariable("PythonBinaryHostMoblyTestConfigTemplate", "build/make/core/python_binary_host_mobly_test_config_template.xml") pctx.SourcePathVariable("PythonBinaryHostTestConfigTemplate", "build/make/core/python_binary_host_test_config_template.xml") + pctx.SourcePathVariable("RavenwoodTestConfigTemplate", "build/make/core/ravenwood_test_config_template.xml") pctx.SourcePathVariable("RustDeviceTestConfigTemplate", "build/make/core/rust_device_test_config_template.xml") pctx.SourcePathVariable("RustHostTestConfigTemplate", "build/make/core/rust_host_test_config_template.xml") pctx.SourcePathVariable("RustDeviceBenchmarkConfigTemplate", "build/make/core/rust_device_benchmark_config_template.xml") -- cgit v1.2.3-59-g8ed1b From a45bf7f254028b8c4d1bf1518493aefce8e9edb0 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Mon, 6 Nov 2023 13:56:38 -0700 Subject: Fix tests that are broken on darwin builds. Bug: 292141694 Test: m nothing --no-skip-soong-tests Change-Id: Ie9a2f8961a8c43bbe1388471fc0d7aadc1456c57 --- java/ravenwood_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'java') diff --git a/java/ravenwood_test.go b/java/ravenwood_test.go index 4ae1d7cf5..2443ea8e7 100644 --- a/java/ravenwood_test.go +++ b/java/ravenwood_test.go @@ -15,6 +15,7 @@ package java import ( + "runtime" "testing" "android/soong/android" @@ -56,6 +57,10 @@ var prepareRavenwoodRuntime = android.GroupFixturePreparers( var installPathPrefix = "out/soong/host/linux-x86/testcases" func TestRavenwoodRuntime(t *testing.T) { + if runtime.GOOS != "linux" { + t.Skip("requires linux") + } + ctx := android.GroupFixturePreparers( PrepareForIntegrationTestWithJava, prepareRavenwoodRuntime, @@ -75,6 +80,10 @@ func TestRavenwoodRuntime(t *testing.T) { } func TestRavenwoodTest(t *testing.T) { + if runtime.GOOS != "linux" { + t.Skip("requires linux") + } + ctx := android.GroupFixturePreparers( PrepareForIntegrationTestWithJava, prepareRavenwoodRuntime, -- cgit v1.2.3-59-g8ed1b From 856cedb2c0ba56e736dc993fb7e716a97471c052 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Thu, 2 Nov 2023 15:18:09 +0000 Subject: Add a new flag to stop disabling lint errors java_sdk_library has historically suppressed a few legitimate lint errors. Make it possible to remove these suppressions via a flag. Ignore-AOSP-First: in internal topic, will cp after Bug: 306806877 Test: checkapi Change-Id: I10577dacbd7ea8063c6e1e02f3b6c60a2bee5094 --- java/sdk_library.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'java') diff --git a/java/sdk_library.go b/java/sdk_library.go index 1de89727f..11fde8c6a 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -618,6 +618,10 @@ type sdkLibraryProperties struct { Api_lint struct { // Enable api linting. Enabled *bool + + // If API lint is enabled, this flag controls whether a set of legitimate lint errors + // are turned off. The default is true. + Legacy_errors_allowed *bool } // TODO: determines whether to create HTML doc or not @@ -1747,13 +1751,16 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC android.JoinWithPrefix(module.sdkLibraryProperties.Hidden_api_packages, " --hide-package ")) } droidstubsArgs = append(droidstubsArgs, module.sdkLibraryProperties.Droiddoc_options...) - disabledWarnings := []string{ - "BroadcastBehavior", - "DeprecationMismatch", - "HiddenSuperclass", - "MissingPermission", - "SdkConstant", - "Todo", + disabledWarnings := []string{"HiddenSuperclass"} + if proptools.BoolDefault(module.sdkLibraryProperties.Api_lint.Legacy_errors_allowed, true) { + disabledWarnings = append(disabledWarnings, + "BroadcastBehavior", + "DeprecationMismatch", + "HiddenSuperclass", + "MissingPermission", + "SdkConstant", + "Todo", + ) } droidstubsArgs = append(droidstubsArgs, android.JoinWithPrefix(disabledWarnings, "--hide ")) -- cgit v1.2.3-59-g8ed1b From 8b9661f3656a96716414ca6af95f1c7ad0a25dde Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Tue, 7 Nov 2023 10:11:18 +0000 Subject: Remove duplicated hidden warning HiddenSuperclass is already in disabledWarnings. Test: presubmit Change-Id: I0ddd145a7b39d2367b27164fa65266fc0042631c --- java/sdk_library.go | 1 - 1 file changed, 1 deletion(-) (limited to 'java') diff --git a/java/sdk_library.go b/java/sdk_library.go index 11fde8c6a..ea451743b 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -1756,7 +1756,6 @@ func (module *SdkLibrary) createStubsSourcesAndApi(mctx android.DefaultableHookC disabledWarnings = append(disabledWarnings, "BroadcastBehavior", "DeprecationMismatch", - "HiddenSuperclass", "MissingPermission", "SdkConstant", "Todo", -- cgit v1.2.3-59-g8ed1b From b3a9fcf6649697535ab6b49b7f0a620adda6c0c3 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Wed, 8 Nov 2023 13:21:04 +0000 Subject: Re-enable the bannedThrow check It's been disabled previously due to pre-existing failures. Baseline those and remove the disabling. Bug: 222738070 Test: m checkapi Ignore-AOSP-First: This error is not being re-enabled in AOSP yet Change-Id: Ia4f91f1470a5bce332df1896b81550276c4b174d --- java/config/droidstubs.go | 2 -- 1 file changed, 2 deletions(-) (limited to 'java') diff --git a/java/config/droidstubs.go b/java/config/droidstubs.go index b7aab5a98..1d7a2d22e 100644 --- a/java/config/droidstubs.go +++ b/java/config/droidstubs.go @@ -50,8 +50,6 @@ var ( "--hide HiddenTypedefConstant", "--hide SuperfluousPrefix", "--hide AnnotationExtraction", - // b/222738070 - "--hide BannedThrow", } MetalavaAnnotationsWarningsFlags = strings.Join(metalavaAnnotationsWarningsFlags, " ") -- cgit v1.2.3-59-g8ed1b From d972a088d934cb94b36ca59651fc6c42e5169b22 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Wed, 8 Nov 2023 18:23:38 +0000 Subject: Re-enable the InvalidNullabilityOverride check It's been disabled previously due to pre-existing failures. Baseline those and remove the disabling. Ignore-AOSP-First: This error is not being re-enabled in AOSP yet Bug: 222738070 Test: m checkapi Change-Id: I3382152186d7d8f63da7c1cc95d3ef962f422642 --- java/config/droidstubs.go | 1 - 1 file changed, 1 deletion(-) (limited to 'java') diff --git a/java/config/droidstubs.go b/java/config/droidstubs.go index 1d7a2d22e..45c6f0f31 100644 --- a/java/config/droidstubs.go +++ b/java/config/droidstubs.go @@ -23,7 +23,6 @@ var ( "--format=v2", "--repeat-errors-max 10", "--hide UnresolvedImport", - "--hide InvalidNullabilityOverride", // Force metalava to ignore classes on the classpath when an API file contains missing classes. // See b/285140653 for more information. -- cgit v1.2.3-59-g8ed1b From a6ae274e3b405e0d1a57aedb009cfe8cb51b86f2 Mon Sep 17 00:00:00 2001 From: Anton Hansson Date: Thu, 9 Nov 2023 19:26:25 +0000 Subject: Re-enable the AnnotationExtraction error This prevents errors in typedef definitions. Re-enable it. Ignore-AOSP-First: This error is not being re-enabled in AOSP yet Bug: 309971481 Test: m checkapi Change-Id: If9f0e580cda62d0021e82b1831746b3d15d1bfbd --- java/config/droidstubs.go | 1 - 1 file changed, 1 deletion(-) (limited to 'java') diff --git a/java/config/droidstubs.go b/java/config/droidstubs.go index 1d7a2d22e..8a526ff59 100644 --- a/java/config/droidstubs.go +++ b/java/config/droidstubs.go @@ -49,7 +49,6 @@ var ( // TODO(tnorbye): find owners to fix these warnings when annotation was enabled. "--hide HiddenTypedefConstant", "--hide SuperfluousPrefix", - "--hide AnnotationExtraction", } MetalavaAnnotationsWarningsFlags = strings.Join(metalavaAnnotationsWarningsFlags, " ") -- cgit v1.2.3-59-g8ed1b From 5fcd83edaa4290b6beb38d4baf7ffacb1c41f4fd Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 15 Nov 2023 12:29:33 -0800 Subject: Change deps of ctx.Install* from Paths to InstallPaths Installed files should only depend on other installed files, change the deps arguments of the ctx.Install* methods from Paths to InstallPaths. Bug: 311428265 Test: builds Ignore-AOSP-First: resolving conflict Change-Id: I1ebef60a943bdbe907744cc43aa985371ac56d32 --- android/module_context.go | 20 ++++++++++---------- apex/apex.go | 2 +- apex/builder.go | 2 +- apex/prebuilt.go | 2 +- java/app.go | 2 +- java/java.go | 4 ++-- java/ravenwood.go | 3 ++- java/robolectric.go | 2 +- java/tradefed.go | 4 ++-- 9 files changed, 21 insertions(+), 20 deletions(-) (limited to 'java') diff --git a/android/module_context.go b/android/module_context.go index 0b4d28c54..a0a410428 100644 --- a/android/module_context.go +++ b/android/module_context.go @@ -114,7 +114,7 @@ type ModuleContext interface { // installed file will be returned by PackagingSpecs() on this module or by // TransitivePackagingSpecs() on modules that depend on this module through dependency tags // for which IsInstallDepNeeded returns true. - InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath + InstallExecutable(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath // InstallFile creates a rule to copy srcPath to name in the installPath directory, // with the given additional dependencies. @@ -123,7 +123,7 @@ type ModuleContext interface { // installed file will be returned by PackagingSpecs() on this module or by // TransitivePackagingSpecs() on modules that depend on this module through dependency tags // for which IsInstallDepNeeded returns true. - InstallFile(installPath InstallPath, name string, srcPath Path, deps ...Path) InstallPath + InstallFile(installPath InstallPath, name string, srcPath Path, deps ...InstallPath) InstallPath // InstallFileWithExtraFilesZip creates a rule to copy srcPath to name in the installPath // directory, and also unzip a zip file containing extra files to install into the same @@ -133,7 +133,7 @@ type ModuleContext interface { // installed file will be returned by PackagingSpecs() on this module or by // TransitivePackagingSpecs() on modules that depend on this module through dependency tags // for which IsInstallDepNeeded returns true. - InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path, extraZip Path, deps ...Path) InstallPath + InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path, extraZip Path, deps ...InstallPath) InstallPath // InstallSymlink creates a rule to create a symlink from src srcPath to name in the installPath // directory. @@ -451,17 +451,17 @@ func (m *moduleContext) skipInstall() bool { } func (m *moduleContext) InstallFile(installPath InstallPath, name string, srcPath Path, - deps ...Path) InstallPath { + deps ...InstallPath) InstallPath { return m.installFile(installPath, name, srcPath, deps, false, nil) } func (m *moduleContext) InstallExecutable(installPath InstallPath, name string, srcPath Path, - deps ...Path) InstallPath { + deps ...InstallPath) InstallPath { return m.installFile(installPath, name, srcPath, deps, true, nil) } func (m *moduleContext) InstallFileWithExtraFilesZip(installPath InstallPath, name string, srcPath Path, - extraZip Path, deps ...Path) InstallPath { + extraZip Path, deps ...InstallPath) InstallPath { return m.installFile(installPath, name, srcPath, deps, false, &extraFilesZip{ zip: extraZip, dir: installPath, @@ -487,23 +487,23 @@ func (m *moduleContext) packageFile(fullInstallPath InstallPath, srcPath Path, e return spec } -func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []Path, +func (m *moduleContext) installFile(installPath InstallPath, name string, srcPath Path, deps []InstallPath, executable bool, extraZip *extraFilesZip) InstallPath { fullInstallPath := installPath.Join(m, name) m.module.base().hooks.runInstallHooks(m, srcPath, fullInstallPath, false) if !m.skipInstall() { - deps = append(deps, InstallPaths(m.module.base().installFilesDepSet.ToList()).Paths()...) + deps = append(deps, InstallPaths(m.module.base().installFilesDepSet.ToList())...) var implicitDeps, orderOnlyDeps Paths if m.Host() { // Installed host modules might be used during the build, depend directly on their // dependencies so their timestamp is updated whenever their dependency is updated - implicitDeps = deps + implicitDeps = InstallPaths(deps).Paths() } else { - orderOnlyDeps = deps + orderOnlyDeps = InstallPaths(deps).Paths() } if m.Config().KatiEnabled() { diff --git a/apex/apex.go b/apex/apex.go index 4c0230539..ecc794b5b 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -1890,7 +1890,7 @@ func (a *apexBundle) ProcessBazelQueryResponse(ctx android.ModuleContext) { installSuffix = imageCapexSuffix } a.installedFile = ctx.InstallFile(a.installDir, a.Name()+installSuffix, a.outputFile, - a.compatSymlinks.Paths()...) + a.compatSymlinks...) // filesInfo in mixed mode must retrieve all information about the apex's // contents completely from the Starlark providers. It should never rely on diff --git a/apex/builder.go b/apex/builder.go index ba4df5f6b..909a4792a 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -956,7 +956,7 @@ func (a *apexBundle) buildApex(ctx android.ModuleContext) { // Install to $OUT/soong/{target,host}/.../apex. a.installedFile = ctx.InstallFile(a.installDir, a.Name()+installSuffix, a.outputFile, - a.compatSymlinks.Paths()...) + a.compatSymlinks...) // installed-files.txt is dist'ed a.installedFilesFile = a.buildInstalledFilesFile(ctx, a.outputFile, imageDir) diff --git a/apex/prebuilt.go b/apex/prebuilt.go index 7a9d23e54..7d339d54e 100644 --- a/apex/prebuilt.go +++ b/apex/prebuilt.go @@ -794,7 +794,7 @@ func (p *Prebuilt) GenerateAndroidBuildActions(ctx android.ModuleContext) { } if p.installable() { - p.installedFile = ctx.InstallFile(p.installDir, p.installFilename, p.inputApex, p.compatSymlinks.Paths()...) + p.installedFile = ctx.InstallFile(p.installDir, p.installFilename, p.inputApex, p.compatSymlinks...) p.provenanceMetaDataFile = provenance.GenerateArtifactProvenanceMetaData(ctx, p.inputApex, p.installedFile) } } diff --git a/java/app.go b/java/app.go index 41848ce0b..883b950e8 100755 --- a/java/app.go +++ b/java/app.go @@ -858,7 +858,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { ctx.InstallFile(allowlistInstallPath, allowlistInstallFilename, a.privAppAllowlist.Path()) } - var extraInstalledPaths android.Paths + var extraInstalledPaths android.InstallPaths for _, extra := range a.extraOutputFiles { installed := ctx.InstallFile(a.installDir, extra.Base(), extra) extraInstalledPaths = append(extraInstalledPaths, installed) diff --git a/java/java.go b/java/java.go index 500ae37c7..bb9357cc7 100644 --- a/java/java.go +++ b/java/java.go @@ -641,7 +641,7 @@ type Library struct { exportedProguardFlagFiles android.Paths - InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths) + InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.InstallPaths) } var _ android.ApexModule = (*Library)(nil) @@ -722,7 +722,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { exclusivelyForApex := !apexInfo.IsForPlatform() if (Bool(j.properties.Installable) || ctx.Host()) && !exclusivelyForApex { - var extraInstallDeps android.Paths + var extraInstallDeps android.InstallPaths if j.InstallMixin != nil { extraInstallDeps = j.InstallMixin(ctx, j.outputFile) } diff --git a/java/ravenwood.go b/java/ravenwood.go index a03d8fb17..85f64a86c 100644 --- a/java/ravenwood.go +++ b/java/ravenwood.go @@ -16,6 +16,7 @@ package java import ( "android/soong/android" "android/soong/tradefed" + "github.com/google/blueprint/proptools" ) @@ -100,7 +101,7 @@ func (r *ravenwoodTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { r.Library.GenerateAndroidBuildActions(ctx) // Start by depending on all files installed by dependancies - var installDeps android.Paths + var installDeps android.InstallPaths for _, dep := range ctx.GetDirectDepsWithTag(ravenwoodTag) { for _, installFile := range dep.FilesToInstall() { installDeps = append(installDeps, installFile) diff --git a/java/robolectric.go b/java/robolectric.go index a8e6bfaff..a66b31007 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -226,7 +226,7 @@ func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) } installPath := android.PathForModuleInstall(ctx, r.BaseModuleName()) - var installDeps android.Paths + var installDeps android.InstallPaths if r.manifest != nil { r.data = append(r.data, r.manifest) diff --git a/java/tradefed.go b/java/tradefed.go index ebbdec13d..349b327e8 100644 --- a/java/tradefed.go +++ b/java/tradefed.go @@ -30,8 +30,8 @@ func tradefedJavaLibraryFactory() android.Module { return module } -func tradefedJavaLibraryInstall(ctx android.ModuleContext, path android.Path) android.Paths { +func tradefedJavaLibraryInstall(ctx android.ModuleContext, path android.Path) android.InstallPaths { installedPath := ctx.InstallFile(android.PathForModuleInstall(ctx, "tradefed"), ctx.ModuleName()+".jar", path) - return android.Paths{installedPath} + return android.InstallPaths{installedPath} } -- cgit v1.2.3-59-g8ed1b From 20c2010030612da735e0416c03a3ca884f1ef6ac Mon Sep 17 00:00:00 2001 From: Rico Wind Date: Thu, 23 Nov 2023 08:41:28 +0100 Subject: Reapply "Use R8 for resource shrinking" This reverts commit a9fd59a7f28df05f9d75bda7d661241e4d1a3f6a. We are moving the resource shinking pipeline into r8 (gennerally, not just for platform) This disables the usage of the resource shrinker cli from cmd-line tools There are no changes in this cl compared to the original land, the fix was done in R8 (to use the same compression for res folder entries as in the original) Bug: 308710394 Bug: 309078004 Test: Existing, validated that resource table on SystemUI was byte<>byte equal, validated uncompression Ignore-AOSP-First: Merge does not apply cleanly Change-Id: Ib8a6fb128084e994325b975c46a036cb41494654 --- java/Android.bp | 2 -- java/app.go | 24 +++++++++++++++----- java/app_builder.go | 8 +------ java/dex.go | 39 +++++++++++++++++++++---------- java/resourceshrinker.go | 45 ------------------------------------ java/resourceshrinker_test.go | 53 ------------------------------------------- 6 files changed, 46 insertions(+), 125 deletions(-) delete mode 100644 java/resourceshrinker.go delete mode 100644 java/resourceshrinker_test.go (limited to 'java') diff --git a/java/Android.bp b/java/Android.bp index fe9bac1e4..1dc560268 100644 --- a/java/Android.bp +++ b/java/Android.bp @@ -68,7 +68,6 @@ bootstrap_go_package { "prebuilt_apis.go", "proto.go", "ravenwood.go", - "resourceshrinker.go", "robolectric.go", "rro.go", "sdk.go", @@ -109,7 +108,6 @@ bootstrap_go_package { "prebuilt_apis_test.go", "proto_test.go", "ravenwood_test.go", - "resourceshrinker_test.go", "rro_test.go", "sdk_test.go", "sdk_library_test.go", diff --git a/java/app.go b/java/app.go index 6d7411d47..6ec6bb273 100755 --- a/java/app.go +++ b/java/app.go @@ -544,7 +544,7 @@ func (a *AndroidApp) installPath(ctx android.ModuleContext) android.InstallPath return android.PathForModuleInstall(ctx, installDir, a.installApkName+".apk") } -func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { +func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) (android.Path, android.Path) { a.dexpreopter.installPath = a.installPath(ctx) a.dexpreopter.isApp = true if a.dexProperties.Uncompress_dex == nil { @@ -557,7 +557,15 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { a.dexpreopter.manifestFile = a.mergedManifestFile a.dexpreopter.preventInstall = a.appProperties.PreventInstall + var packageResources = a.exportPackage + if ctx.ModuleName() != "framework-res" { + if Bool(a.dexProperties.Optimize.Shrink_resources) { + protoFile := android.PathForModuleOut(ctx, packageResources.Base()+".proto.apk") + aapt2Convert(ctx, protoFile, packageResources, "proto") + a.dexer.resourcesInput = android.OptionalPathForPath(protoFile) + } + var extraSrcJars android.Paths var extraClasspathJars android.Paths var extraCombinedJars android.Paths @@ -575,9 +583,14 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { } a.Module.compile(ctx, extraSrcJars, extraClasspathJars, extraCombinedJars) + if Bool(a.dexProperties.Optimize.Shrink_resources) { + binaryResources := android.PathForModuleOut(ctx, packageResources.Base()+".binary.out.apk") + aapt2Convert(ctx, binaryResources, a.dexer.resourcesOutput.Path(), "binary") + packageResources = binaryResources + } } - return a.dexJarFile.PathOrNil() + return a.dexJarFile.PathOrNil(), packageResources } func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, prebuiltJniPackages android.Paths, ctx android.ModuleContext) android.WritablePath { @@ -762,7 +775,6 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { // Process all building blocks, from AAPT to certificates. a.aaptBuildActions(ctx) - // The decision to enforce checks is made before adding implicit SDK libraries. a.usesLibrary.freezeEnforceUsesLibraries() @@ -788,7 +800,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.linter.resources = a.aapt.resourceFiles a.linter.buildModuleReportZip = ctx.Config().UnbundledBuildApps() - dexJarFile := a.dexBuildActions(ctx) + dexJarFile, packageResources := a.dexBuildActions(ctx) jniLibs, prebuiltJniPackages, certificates := collectAppDeps(ctx, a, a.shouldEmbedJnis(ctx), !Bool(a.appProperties.Jni_uses_platform_apis)) jniJarFile := a.jniBuildActions(jniLibs, prebuiltJniPackages, ctx) @@ -812,7 +824,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { } rotationMinSdkVersion := String(a.overridableAppProperties.RotationMinSdkVersion) - CreateAndSignAppPackage(ctx, packageFile, a.exportPackage, jniJarFile, dexJarFile, certificates, apkDeps, v4SignatureFile, lineageFile, rotationMinSdkVersion, Bool(a.dexProperties.Optimize.Shrink_resources)) + CreateAndSignAppPackage(ctx, packageFile, packageResources, jniJarFile, dexJarFile, certificates, apkDeps, v4SignatureFile, lineageFile, rotationMinSdkVersion) a.outputFile = packageFile if v4SigningRequested { a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile) @@ -841,7 +853,7 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { if v4SigningRequested { v4SignatureFile = android.PathForModuleOut(ctx, a.installApkName+"_"+split.suffix+".apk.idsig") } - CreateAndSignAppPackage(ctx, packageFile, split.path, nil, nil, certificates, apkDeps, v4SignatureFile, lineageFile, rotationMinSdkVersion, false) + CreateAndSignAppPackage(ctx, packageFile, split.path, nil, nil, certificates, apkDeps, v4SignatureFile, lineageFile, rotationMinSdkVersion) a.extraOutputFiles = append(a.extraOutputFiles, packageFile) if v4SigningRequested { a.extraOutputFiles = append(a.extraOutputFiles, v4SignatureFile) diff --git a/java/app_builder.go b/java/app_builder.go index d397ff7f5..943ce317b 100644 --- a/java/app_builder.go +++ b/java/app_builder.go @@ -52,7 +52,7 @@ var combineApk = pctx.AndroidStaticRule("combineApk", }) func CreateAndSignAppPackage(ctx android.ModuleContext, outputFile android.WritablePath, - packageFile, jniJarFile, dexJarFile android.Path, certificates []Certificate, deps android.Paths, v4SignatureFile android.WritablePath, lineageFile android.Path, rotationMinSdkVersion string, shrinkResources bool) { + packageFile, jniJarFile, dexJarFile android.Path, certificates []Certificate, deps android.Paths, v4SignatureFile android.WritablePath, lineageFile android.Path, rotationMinSdkVersion string) { unsignedApkName := strings.TrimSuffix(outputFile.Base(), ".apk") + "-unsigned.apk" unsignedApk := android.PathForModuleOut(ctx, unsignedApkName) @@ -71,12 +71,6 @@ func CreateAndSignAppPackage(ctx android.ModuleContext, outputFile android.Writa Output: unsignedApk, Implicits: deps, }) - - if shrinkResources { - shrunkenApk := android.PathForModuleOut(ctx, "resource-shrunken", unsignedApk.Base()) - ShrinkResources(ctx, unsignedApk, shrunkenApk) - unsignedApk = shrunkenApk - } SignAppPackage(ctx, outputFile, unsignedApk, certificates, v4SignatureFile, lineageFile, rotationMinSdkVersion) } diff --git a/java/dex.go b/java/dex.go index aa017834d..ee28643e9 100644 --- a/java/dex.go +++ b/java/dex.go @@ -95,6 +95,8 @@ type dexer struct { proguardDictionary android.OptionalPath proguardConfiguration android.OptionalPath proguardUsageZip android.OptionalPath + resourcesInput android.OptionalPath + resourcesOutput android.OptionalPath providesTransitiveHeaderJars } @@ -161,7 +163,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8", "$r8Template": &remoteexec.REParams{ Labels: map[string]string{"type": "compile", "compiler": "r8"}, Inputs: []string{"$implicits", "${config.R8Jar}"}, - OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}"}, + OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}", "${resourcesOutput}"}, ExecStrategy: "${config.RER8ExecStrategy}", ToolchainInputs: []string{"${config.JavaCmd}"}, Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, @@ -181,7 +183,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8", Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"}, }, }, []string{"outDir", "outDict", "outConfig", "outUsage", "outUsageZip", "outUsageDir", - "r8Flags", "zipFlags", "mergeZipsFlags"}, []string{"implicits"}) + "r8Flags", "zipFlags", "mergeZipsFlags", "resourcesOutput"}, []string{"implicits"}) func (d *dexer) dexCommonFlags(ctx android.ModuleContext, dexParams *compileDexParams) (flags []string, deps android.Paths) { @@ -350,6 +352,12 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Fl r8Flags = append(r8Flags, "-ignorewarnings") } + if d.resourcesInput.Valid() { + r8Flags = append(r8Flags, "--resource-input", d.resourcesInput.Path().String()) + r8Deps = append(r8Deps, d.resourcesInput.Path()) + r8Flags = append(r8Flags, "--resource-output", d.resourcesOutput.Path().String()) + } + return r8Flags, r8Deps } @@ -391,6 +399,8 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam android.ModuleNameWithPossibleOverride(ctx), "unused.txt") proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip") d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip) + resourcesOutput := android.PathForModuleOut(ctx, "package-res-shrunken.apk") + d.resourcesOutput = android.OptionalPathForPath(resourcesOutput) r8Flags, r8Deps := d.r8Flags(ctx, dexParams.flags) r8Deps = append(r8Deps, commonDeps...) rule := r8 @@ -409,17 +419,22 @@ func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParam rule = r8RE args["implicits"] = strings.Join(r8Deps.Strings(), ",") } + implicitOutputs := android.WritablePaths{ + proguardDictionary, + proguardUsageZip, + proguardConfiguration} + if d.resourcesInput.Valid() { + implicitOutputs = append(implicitOutputs, resourcesOutput) + args["resourcesOutput"] = resourcesOutput.String() + } ctx.Build(pctx, android.BuildParams{ - Rule: rule, - Description: "r8", - Output: javalibJar, - ImplicitOutputs: android.WritablePaths{ - proguardDictionary, - proguardUsageZip, - proguardConfiguration}, - Input: dexParams.classesJar, - Implicits: r8Deps, - Args: args, + Rule: rule, + Description: "r8", + Output: javalibJar, + ImplicitOutputs: implicitOutputs, + Input: dexParams.classesJar, + Implicits: r8Deps, + Args: args, }) } else { d8Flags, d8Deps := d8Flags(dexParams.flags) diff --git a/java/resourceshrinker.go b/java/resourceshrinker.go deleted file mode 100644 index af13aa3cb..000000000 --- a/java/resourceshrinker.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2022 Google Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package java - -import ( - "android/soong/android" - - "github.com/google/blueprint" -) - -var shrinkResources = pctx.AndroidStaticRule("shrinkResources", - blueprint.RuleParams{ - // Note that we suppress stdout to avoid successful log confirmations. - Command: `RESOURCESHRINKER_OPTS=-Dcom.android.tools.r8.dexContainerExperiment ` + - `${config.ResourceShrinkerCmd} --output $out --input $in --raw_resources $raw_resources >/dev/null`, - CommandDeps: []string{"${config.ResourceShrinkerCmd}"}, - }, "raw_resources") - -func ShrinkResources(ctx android.ModuleContext, apk android.Path, outputFile android.WritablePath) { - protoFile := android.PathForModuleOut(ctx, apk.Base()+".proto.apk") - aapt2Convert(ctx, protoFile, apk, "proto") - strictModeFile := android.PathForSource(ctx, "prebuilts/cmdline-tools/shrinker.xml") - protoOut := android.PathForModuleOut(ctx, apk.Base()+".proto.out.apk") - ctx.Build(pctx, android.BuildParams{ - Rule: shrinkResources, - Input: protoFile, - Output: protoOut, - Args: map[string]string{ - "raw_resources": strictModeFile.String(), - }, - }) - aapt2Convert(ctx, outputFile, protoOut, "binary") -} diff --git a/java/resourceshrinker_test.go b/java/resourceshrinker_test.go deleted file mode 100644 index 3bbf11670..000000000 --- a/java/resourceshrinker_test.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2022 Google Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package java - -import ( - "testing" - - "android/soong/android" -) - -func TestShrinkResourcesArgs(t *testing.T) { - result := android.GroupFixturePreparers( - PrepareForTestWithJavaDefaultModules, - ).RunTestWithBp(t, ` - android_app { - name: "app_shrink", - platform_apis: true, - optimize: { - shrink_resources: true, - } - } - - android_app { - name: "app_no_shrink", - platform_apis: true, - optimize: { - shrink_resources: false, - } - } - `) - - appShrink := result.ModuleForTests("app_shrink", "android_common") - appShrinkResources := appShrink.Rule("shrinkResources") - android.AssertStringDoesContain(t, "expected shrinker.xml in app_shrink resource shrinker flags", - appShrinkResources.Args["raw_resources"], "shrinker.xml") - - appNoShrink := result.ModuleForTests("app_no_shrink", "android_common") - if appNoShrink.MaybeRule("shrinkResources").Rule != nil { - t.Errorf("unexpected shrinkResources rule for app_no_shrink") - } -} -- cgit v1.2.3-59-g8ed1b From 7a19abf260a9790fd107e3fb1e7a28495f21db78 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 30 Nov 2023 09:29:50 -0700 Subject: Include Ravenwood tests in `general-tests`. EngProd has indicated that we need to be included in that suite to support TEST_MAPPING files in their infrastructure. Bug: 308854804 Test: TH Change-Id: I763b033f0f5f275091db45ab62df6af48dcddc66 --- java/ravenwood.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'java') diff --git a/java/ravenwood.go b/java/ravenwood.go index 85f64a86c..e36200307 100644 --- a/java/ravenwood.go +++ b/java/ravenwood.go @@ -53,7 +53,10 @@ func ravenwoodTestFactory() android.Module { module.Module.dexpreopter.isTest = true module.Module.linter.properties.Lint.Test = proptools.BoolPtr(true) - module.testProperties.Test_suites = []string{"ravenwood-tests"} + module.testProperties.Test_suites = []string{ + "general-tests", + "ravenwood-tests", + } module.testProperties.Test_options.Unit_test = proptools.BoolPtr(false) InitJavaModule(module, android.DeviceSupported) @@ -123,7 +126,8 @@ func (r *ravenwoodTest) AndroidMkEntries() []android.AndroidMkEntries { entries.ExtraEntries = append(entries.ExtraEntries, func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { entries.SetBool("LOCAL_UNINSTALLABLE_MODULE", true) - entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", "ravenwood-tests") + entries.AddStrings("LOCAL_COMPATIBILITY_SUITE", + "general-tests", "ravenwood-tests") if r.testConfig != nil { entries.SetPath("LOCAL_FULL_TEST_CONFIG", r.testConfig) } @@ -157,7 +161,10 @@ func (r *ravenwoodLibgroup) InstallForceOS() (*android.OsType, *android.ArchType return &r.forceOSType, &r.forceArchType } func (r *ravenwoodLibgroup) TestSuites() []string { - return []string{"ravenwood-tests"} + return []string{ + "general-tests", + "ravenwood-tests", + } } func (r *ravenwoodLibgroup) DepsMutator(ctx android.BottomUpMutatorContext) { -- cgit v1.2.3-59-g8ed1b