diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/aar.go | 20 | ||||
-rwxr-xr-x | java/app.go | 6 | ||||
-rw-r--r-- | java/app_import.go | 4 | ||||
-rw-r--r-- | java/base.go | 2 | ||||
-rw-r--r-- | java/bootclasspath_fragment.go | 2 | ||||
-rw-r--r-- | java/bootclasspath_fragment_test.go | 4 | ||||
-rw-r--r-- | java/dexpreopt.go | 67 | ||||
-rw-r--r-- | java/hiddenapi_modular.go | 188 | ||||
-rw-r--r-- | java/java.go | 22 | ||||
-rw-r--r-- | java/sdk_library.go | 7 |
10 files changed, 161 insertions, 161 deletions
diff --git a/java/aar.go b/java/aar.go index b162ef639..f61fc8374 100644 --- a/java/aar.go +++ b/java/aar.go @@ -159,8 +159,8 @@ func propagateRROEnforcementMutator(ctx android.TopDownMutatorContext) { } } -func (a *aapt) useResourceProcessorBusyBox() bool { - return BoolDefault(a.aaptProperties.Use_resource_processor, false) +func (a *aapt) useResourceProcessorBusyBox(ctx android.BaseModuleContext) bool { + return BoolDefault(a.aaptProperties.Use_resource_processor, ctx.Config().UseResourceProcessorByDefault()) } func (a *aapt) filterProduct() string { @@ -414,7 +414,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio linkFlags = append(linkFlags, "--static-lib") } - if a.isLibrary && a.useResourceProcessorBusyBox() { + if a.isLibrary && a.useResourceProcessorBusyBox(ctx) { // 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. @@ -453,7 +453,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio // of transitiveStaticLibs. transitiveStaticLibs := android.ReversePaths(staticDeps.resPackages()) - if a.isLibrary && a.useResourceProcessorBusyBox() { + if a.isLibrary && a.useResourceProcessorBusyBox(ctx) { // 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 @@ -515,7 +515,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio }) } - if !a.useResourceProcessorBusyBox() { + if !a.useResourceProcessorBusyBox(ctx) { // the subdir "android" is required to be filtered by package names srcJar = android.PathForModuleGen(ctx, "android", "R.srcjar") } @@ -542,7 +542,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio a.assetPackage = android.OptionalPathForPath(assets) } - if a.useResourceProcessorBusyBox() { + if a.useResourceProcessorBusyBox(ctx) { rJar := android.PathForModuleOut(ctx, "busybox/R.jar") resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary, a.aaptProperties.Aaptflags) aapt2ExtractExtraPackages(ctx, extraPackages, rJar) @@ -577,7 +577,7 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio rJar: a.rJar, assets: a.assetPackage, - usedResourceProcessor: a.useResourceProcessorBusyBox(), + usedResourceProcessor: a.useResourceProcessorBusyBox(ctx), }). Transitive(staticResourcesNodesDepSet).Build() a.rroDirsDepSet = android.NewDepSetBuilder[rroDir](android.TOPOLOGICAL). @@ -823,7 +823,7 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) ctx.CheckbuildFile(a.aapt.proguardOptionsFile) ctx.CheckbuildFile(a.aapt.exportPackage) - if a.useResourceProcessorBusyBox() { + if a.useResourceProcessorBusyBox(ctx) { ctx.CheckbuildFile(a.aapt.rJar) } else { ctx.CheckbuildFile(a.aapt.aaptSrcJar) @@ -849,7 +849,7 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) var extraSrcJars android.Paths var extraCombinedJars android.Paths var extraClasspathJars android.Paths - if a.useResourceProcessorBusyBox() { + if a.useResourceProcessorBusyBox(ctx) { // 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. @@ -889,7 +889,7 @@ func (a *AndroidLibrary) IDEInfo(dpInfo *android.IdeInfo) { } func (a *aapt) IDEInfo(dpInfo *android.IdeInfo) { - if a.useResourceProcessorBusyBox() { + if a.rJar != nil { dpInfo.Jars = append(dpInfo.Jars, a.rJar.String()) } } diff --git a/java/app.go b/java/app.go index cb05807b8..0c56d81fc 100755 --- a/java/app.go +++ b/java/app.go @@ -431,7 +431,7 @@ func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool { return false } - return shouldUncompressDex(ctx, &a.dexpreopter) + return shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &a.dexpreopter) } func (a *AndroidApp) shouldEmbedJnis(ctx android.BaseModuleContext) bool { @@ -588,7 +588,7 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) (android.Path, a var extraSrcJars android.Paths var extraClasspathJars android.Paths var extraCombinedJars android.Paths - if a.useResourceProcessorBusyBox() { + if a.useResourceProcessorBusyBox(ctx) { // 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. @@ -1108,7 +1108,7 @@ func (a *AndroidApp) Privileged() bool { return Bool(a.appProperties.Privileged) } -func (a *AndroidApp) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { +func (a *AndroidApp) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { return ctx.Device() && ctx.DeviceConfig().NativeCoverageEnabled() } diff --git a/java/app_import.go b/java/app_import.go index 5f20fdd05..12ead0aa2 100644 --- a/java/app_import.go +++ b/java/app_import.go @@ -246,7 +246,7 @@ func (a *AndroidAppImport) shouldUncompressDex(ctx android.ModuleContext) bool { return ctx.Config().UncompressPrivAppDex() } - return shouldUncompressDex(ctx, &a.dexpreopter) + return shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &a.dexpreopter) } func (a *AndroidAppImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -324,7 +324,7 @@ func (a *AndroidAppImport) generateAndroidBuildActions(ctx android.ModuleContext a.usesLibrary.verifyUsesLibrariesAPK(ctx, srcApk) } - a.dexpreopter.dexpreopt(ctx, jnisUncompressed) + a.dexpreopter.dexpreopt(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), jnisUncompressed) if a.dexpreopter.uncompressedDex { dexUncompressed := android.PathForModuleOut(ctx, "dex-uncompressed", ctx.ModuleName()+".apk") ctx.Build(pctx, android.BuildParams{ diff --git a/java/base.go b/java/base.go index 1ac3d30a6..e52ceddf7 100644 --- a/java/base.go +++ b/java/base.go @@ -1626,7 +1626,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath j.dexJarFile = makeDexJarPathFromPath(dexOutputFile) // Dexpreopting - j.dexpreopt(ctx, dexOutputFile) + j.dexpreopt(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), dexOutputFile) outputFile = dexOutputFile } else { diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index c89c64358..2c13d99e9 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -949,7 +949,7 @@ func (b *bootclasspathFragmentSdkMemberProperties) AddToPropertySet(ctx android. builder.CopyToSnapshot(p, dest) dests = append(dests, dest) } - hiddenAPISet.AddProperty(category.PropertyName, dests) + hiddenAPISet.AddProperty(category.PropertyName(), dests) } } } diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index 95cd4a922..8bc0a7ef6 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -467,10 +467,10 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { android.AssertArrayString(t, "single packages", []string{"newlibrary.mine"}, info.SinglePackages) for _, c := range HiddenAPIFlagFileCategories { expectedMaxTargetQPaths := []string(nil) - if c.PropertyName == "max_target_q" { + if c.PropertyName() == "max_target_q" { expectedMaxTargetQPaths = []string{"my-new-max-target-q.txt"} } - android.AssertPathsRelativeToTopEquals(t, c.PropertyName, expectedMaxTargetQPaths, info.FlagFilesByCategory[c]) + android.AssertPathsRelativeToTopEquals(t, c.PropertyName(), expectedMaxTargetQPaths, info.FlagFilesByCategory[c]) } // Make sure that the signature-patterns.csv is passed all the appropriate package properties diff --git a/java/dexpreopt.go b/java/dexpreopt.go index bd3cce412..4c0a0a155 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -29,7 +29,7 @@ type DexpreopterInterface interface { IsInstallable() bool // True if dexpreopt is disabled for the java module. - dexpreoptDisabled(ctx android.BaseModuleContext) bool + dexpreoptDisabled(ctx android.BaseModuleContext, libraryName string) bool // If the java module is to be installed into an APEX, this list contains information about the // dexpreopt outputs to be installed on devices. Note that these dexpreopt outputs are installed @@ -182,15 +182,9 @@ func forPrebuiltApex(ctx android.BaseModuleContext) bool { return apexInfo.ForPrebuiltApex } -func moduleName(ctx android.BaseModuleContext) string { - // Remove the "prebuilt_" prefix if the module is from a prebuilt because the prefix is not - // expected by dexpreopter. - return android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()) -} - // Returns whether dexpreopt is applicable to the module. // When it returns true, neither profile nor dexpreopt artifacts will be generated. -func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { +func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext, libName string) bool { if !ctx.Device() { return true } @@ -213,11 +207,20 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { return true } + if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex { + // dexpreopt rules for system server jars can be generated in the ModuleCtx of prebuilt apexes + return false + } + global := dexpreopt.GetGlobalConfig(ctx) - isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx)) - if isApexVariant(ctx) { - // Don't preopt APEX variant module unless the module is an APEX system server jar. + // Use the libName argument to determine if the library being dexpreopt'd is a system server jar + // ctx.ModuleName() is not safe. In case of prebuilt apexes, the dexpreopt rules of system server jars + // are created in the ctx object of the top-level prebuilt apex. + isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(libName) + + if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex || isApexVariant(ctx) { + // dexpreopt rules for system server jars can be generated in the ModuleCtx of prebuilt apexes if !isApexSystemServerJar { return true } @@ -234,14 +237,20 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { } func dexpreoptToolDepsMutator(ctx android.BottomUpMutatorContext) { - if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx) || !dexpreopt.IsDex2oatNeeded(ctx) { + if _, isApex := android.ModuleProvider(ctx, android.ApexBundleInfoProvider); isApex && dexpreopt.IsDex2oatNeeded(ctx) { + // prebuilt apexes can genererate rules to dexpreopt deapexed jars + // Add a dex2oat dep aggressively on _every_ apex module + dexpreopt.RegisterToolDeps(ctx) + return + } + if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName())) || !dexpreopt.IsDex2oatNeeded(ctx) { return } dexpreopt.RegisterToolDeps(ctx) } -func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, installPath android.InstallPath) bool { - return dexpreopt.OdexOnSystemOtherByName(moduleName(ctx), android.InstallPathToOnDevicePath(ctx, installPath), dexpreopt.GetGlobalConfig(ctx)) +func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, libName string, installPath android.InstallPath) bool { + return dexpreopt.OdexOnSystemOtherByName(libName, android.InstallPathToOnDevicePath(ctx, installPath), dexpreopt.GetGlobalConfig(ctx)) } // Returns the install path of the dex jar of a module. @@ -252,13 +261,13 @@ func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, installPath a // This function is on a best-effort basis. It cannot handle the case where an APEX jar is not a // system server jar, which is fine because we currently only preopt system server jars for APEXes. func (d *dexpreopter) getInstallPath( - ctx android.ModuleContext, defaultInstallPath android.InstallPath) android.InstallPath { + ctx android.ModuleContext, libName string, defaultInstallPath android.InstallPath) android.InstallPath { global := dexpreopt.GetGlobalConfig(ctx) - if global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx)) { - dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, moduleName(ctx)) + if global.AllApexSystemServerJars(ctx).ContainsJar(libName) { + dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, libName) return android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexLocation, "/")) } - if !d.dexpreoptDisabled(ctx) && isApexVariant(ctx) && + if !d.dexpreoptDisabled(ctx, libName) && isApexVariant(ctx) && filepath.Base(defaultInstallPath.PartitionDir()) != "apex" { ctx.ModuleErrorf("unable to get the install path of the dex jar for dexpreopt") } @@ -273,10 +282,10 @@ func (d *Dexpreopter) DexpreoptPrebuiltApexSystemServerJars(ctx android.ModuleCo d.installPath = android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexpreopt.GetSystemServerDexLocation(ctx, dc, libraryName), "/")) // generate the rules for creating the .odex and .vdex files for this system server jar dexJarFile := di.PrebuiltExportPath(ApexRootRelativePathToJavaLib(libraryName)) - d.dexpreopt(ctx, dexJarFile) + d.dexpreopt(ctx, libraryName, dexJarFile) } -func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.WritablePath) { +func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, libName string, dexJarFile android.WritablePath) { global := dexpreopt.GetGlobalConfig(ctx) // TODO(b/148690468): The check on d.installPath is to bail out in cases where @@ -289,7 +298,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath) - providesUsesLib := moduleName(ctx) + providesUsesLib := libName if ulib, ok := ctx.Module().(ProvidesUsesLib); ok { name := ulib.ProvidesUsesLib() if name != nil { @@ -299,11 +308,11 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr // If it is test, make config files regardless of its dexpreopt setting. // The config files are required for apps defined in make which depend on the lib. - if d.isTest && d.dexpreoptDisabled(ctx) { + if d.isTest && d.dexpreoptDisabled(ctx, libName) { return } - isSystemServerJar := global.AllSystemServerJars(ctx).ContainsJar(moduleName(ctx)) + isSystemServerJar := global.AllSystemServerJars(ctx).ContainsJar(libName) bootImage := defaultBootImageConfig(ctx) // When `global.PreoptWithUpdatableBcp` is true, `bcpForDexpreopt` below includes the mainline @@ -322,7 +331,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr targets = append(targets, target) } } - if isSystemServerJar && moduleName(ctx) != "com.android.location.provider" { + if isSystemServerJar && libName != "com.android.location.provider" { // If the module is a system server jar, only preopt for the primary arch because the jar can // only be loaded by system server. "com.android.location.provider" is a special case because // it's also used by apps as a shared library. @@ -358,7 +367,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr profileIsTextListing = true } else if global.ProfileDir != "" { profileClassListing = android.ExistentPathForSource(ctx, - global.ProfileDir, moduleName(ctx)+".prof") + global.ProfileDir, libName+".prof") } } @@ -370,9 +379,9 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr // Full dexpreopt config, used to create dexpreopt build rules. dexpreoptConfig := &dexpreopt.ModuleConfig{ - Name: moduleName(ctx), + Name: libName, DexLocation: dexLocation, - BuildPath: android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, moduleName(ctx)+".jar").OutputPath, + BuildPath: android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, libName+".jar").OutputPath, DexPath: dexJarFile, ManifestPath: android.OptionalPathForPath(d.manifestFile), UncompressedDex: d.uncompressedDex, @@ -405,7 +414,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr d.configPath = android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, "dexpreopt.config") dexpreopt.WriteModuleConfig(ctx, dexpreoptConfig, d.configPath) - if d.dexpreoptDisabled(ctx) { + if d.dexpreoptDisabled(ctx, libName) { return } @@ -476,7 +485,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Wr // The installs will be handled by Make as sub-modules of the java library. d.builtInstalledForApex = append(d.builtInstalledForApex, dexpreopterInstall{ name: arch + "-" + installBase, - moduleName: dexJarStem, + moduleName: libName, outputPathOnHost: install.From, installDirOnDevice: installPath, installFileOnDevice: installBase, diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index 3c7cf3ab6..e4beb5e55 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -435,122 +435,118 @@ type HiddenAPIFlagFileProperties struct { } } -type hiddenAPIFlagFileCategory struct { - // PropertyName is the name of the property for this category. - PropertyName string +type hiddenAPIFlagFileCategory int - // propertyValueReader retrieves the value of the property for this category from the set of - // properties. - propertyValueReader func(properties *HiddenAPIFlagFileProperties) []string +const ( + // The flag file category for removed members of the API. + // + // This is extracted from HiddenAPIFlagFileCategories as it is needed to add the dex signatures + // list of removed API members that are generated automatically from the removed.txt files provided + // by API stubs. + hiddenAPIFlagFileCategoryRemoved hiddenAPIFlagFileCategory = iota + hiddenAPIFlagFileCategoryUnsupported + hiddenAPIFlagFileCategoryMaxTargetRLowPriority + hiddenAPIFlagFileCategoryMaxTargetQ + hiddenAPIFlagFileCategoryMaxTargetP + hiddenAPIFlagFileCategoryMaxTargetOLowPriority + hiddenAPIFlagFileCategoryBlocked + hiddenAPIFlagFileCategoryUnsupportedPackages +) - // commandMutator adds the appropriate command line options for this category to the supplied - // command - commandMutator func(command *android.RuleBuilderCommand, path android.Path) +func (c hiddenAPIFlagFileCategory) PropertyName() string { + switch c { + case hiddenAPIFlagFileCategoryRemoved: + return "removed" + case hiddenAPIFlagFileCategoryUnsupported: + return "unsupported" + case hiddenAPIFlagFileCategoryMaxTargetRLowPriority: + return "max_target_r_low_priority" + case hiddenAPIFlagFileCategoryMaxTargetQ: + return "max_target_q" + case hiddenAPIFlagFileCategoryMaxTargetP: + return "max_target_p" + case hiddenAPIFlagFileCategoryMaxTargetOLowPriority: + return "max_target_o_low_priority" + case hiddenAPIFlagFileCategoryBlocked: + return "blocked" + case hiddenAPIFlagFileCategoryUnsupportedPackages: + return "unsupported_packages" + default: + panic(fmt.Sprintf("Unknown hidden api flag file category type: %d", c)) + } } -// The flag file category for removed members of the API. -// -// This is extracted from HiddenAPIFlagFileCategories as it is needed to add the dex signatures -// list of removed API members that are generated automatically from the removed.txt files provided -// by API stubs. -var hiddenAPIRemovedFlagFileCategory = &hiddenAPIFlagFileCategory{ - // See HiddenAPIFlagFileProperties.Removed - PropertyName: "removed", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { +// propertyValueReader retrieves the value of the property for this category from the set of properties. +func (c hiddenAPIFlagFileCategory) propertyValueReader(properties *HiddenAPIFlagFileProperties) []string { + switch c { + case hiddenAPIFlagFileCategoryRemoved: return properties.Hidden_api.Removed - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--unsupported ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed") - }, + case hiddenAPIFlagFileCategoryUnsupported: + return properties.Hidden_api.Unsupported + case hiddenAPIFlagFileCategoryMaxTargetRLowPriority: + return properties.Hidden_api.Max_target_r_low_priority + case hiddenAPIFlagFileCategoryMaxTargetQ: + return properties.Hidden_api.Max_target_q + case hiddenAPIFlagFileCategoryMaxTargetP: + return properties.Hidden_api.Max_target_p + case hiddenAPIFlagFileCategoryMaxTargetOLowPriority: + return properties.Hidden_api.Max_target_o_low_priority + case hiddenAPIFlagFileCategoryBlocked: + return properties.Hidden_api.Blocked + case hiddenAPIFlagFileCategoryUnsupportedPackages: + return properties.Hidden_api.Unsupported_packages + default: + panic(fmt.Sprintf("Unknown hidden api flag file category type: %d", c)) + } } -type hiddenAPIFlagFileCategories []*hiddenAPIFlagFileCategory - -func (c hiddenAPIFlagFileCategories) byProperty(name string) *hiddenAPIFlagFileCategory { - for _, category := range c { - if category.PropertyName == name { - return category - } +// commandMutator adds the appropriate command line options for this category to the supplied command +func (c hiddenAPIFlagFileCategory) commandMutator(command *android.RuleBuilderCommand, path android.Path) { + switch c { + case hiddenAPIFlagFileCategoryRemoved: + command.FlagWithInput("--unsupported ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "removed") + case hiddenAPIFlagFileCategoryUnsupported: + command.FlagWithInput("--unsupported ", path) + case hiddenAPIFlagFileCategoryMaxTargetRLowPriority: + command.FlagWithInput("--max-target-r ", path).FlagWithArg("--tag ", "lo-prio") + case hiddenAPIFlagFileCategoryMaxTargetQ: + command.FlagWithInput("--max-target-q ", path) + case hiddenAPIFlagFileCategoryMaxTargetP: + command.FlagWithInput("--max-target-p ", path) + case hiddenAPIFlagFileCategoryMaxTargetOLowPriority: + command.FlagWithInput("--max-target-o ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio") + case hiddenAPIFlagFileCategoryBlocked: + command.FlagWithInput("--blocked ", path) + case hiddenAPIFlagFileCategoryUnsupportedPackages: + command.FlagWithInput("--unsupported ", path).Flag("--packages ") + default: + panic(fmt.Sprintf("Unknown hidden api flag file category type: %d", c)) } - panic(fmt.Errorf("no category exists with property name %q in %v", name, c)) } +type hiddenAPIFlagFileCategories []hiddenAPIFlagFileCategory + var HiddenAPIFlagFileCategories = hiddenAPIFlagFileCategories{ // See HiddenAPIFlagFileProperties.Unsupported - { - PropertyName: "unsupported", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Unsupported - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--unsupported ", path) - }, - }, - hiddenAPIRemovedFlagFileCategory, + hiddenAPIFlagFileCategoryUnsupported, + // See HiddenAPIFlagFileProperties.Removed + hiddenAPIFlagFileCategoryRemoved, // See HiddenAPIFlagFileProperties.Max_target_r_low_priority - { - PropertyName: "max_target_r_low_priority", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Max_target_r_low_priority - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--max-target-r ", path).FlagWithArg("--tag ", "lo-prio") - }, - }, + hiddenAPIFlagFileCategoryMaxTargetRLowPriority, // See HiddenAPIFlagFileProperties.Max_target_q - { - PropertyName: "max_target_q", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Max_target_q - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--max-target-q ", path) - }, - }, + hiddenAPIFlagFileCategoryMaxTargetQ, // See HiddenAPIFlagFileProperties.Max_target_p - { - PropertyName: "max_target_p", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Max_target_p - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--max-target-p ", path) - }, - }, + hiddenAPIFlagFileCategoryMaxTargetP, // See HiddenAPIFlagFileProperties.Max_target_o_low_priority - { - PropertyName: "max_target_o_low_priority", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Max_target_o_low_priority - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--max-target-o ", path).Flag("--ignore-conflicts ").FlagWithArg("--tag ", "lo-prio") - }, - }, + hiddenAPIFlagFileCategoryMaxTargetOLowPriority, // See HiddenAPIFlagFileProperties.Blocked - { - PropertyName: "blocked", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Blocked - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--blocked ", path) - }, - }, + hiddenAPIFlagFileCategoryBlocked, // See HiddenAPIFlagFileProperties.Unsupported_packages - { - PropertyName: "unsupported_packages", - propertyValueReader: func(properties *HiddenAPIFlagFileProperties) []string { - return properties.Hidden_api.Unsupported_packages - }, - commandMutator: func(command *android.RuleBuilderCommand, path android.Path) { - command.FlagWithInput("--unsupported ", path).Flag("--packages ") - }, - }, + hiddenAPIFlagFileCategoryUnsupportedPackages, } // FlagFilesByCategory maps a hiddenAPIFlagFileCategory to the paths to the files in that category. -type FlagFilesByCategory map[*hiddenAPIFlagFileCategory]android.Paths +type FlagFilesByCategory map[hiddenAPIFlagFileCategory]android.Paths // append the supplied flags files to the corresponding category in this map. func (s FlagFilesByCategory) append(other FlagFilesByCategory) { @@ -1014,7 +1010,7 @@ func buildRuleToGenerateHiddenApiFlags(ctx android.BuilderContext, name, desc st // If available then pass the automatically generated file containing dex signatures of removed // API members to the rule so they can be marked as removed. if generatedRemovedDexSignatures.Valid() { - hiddenAPIRemovedFlagFileCategory.commandMutator(command, generatedRemovedDexSignatures.Path()) + hiddenAPIFlagFileCategoryRemoved.commandMutator(command, generatedRemovedDexSignatures.Path()) } commitChangeForRestat(rule, tempPath, outputPath) diff --git a/java/java.go b/java/java.go index d18d915cc..d536ca11b 100644 --- a/java/java.go +++ b/java/java.go @@ -653,7 +653,7 @@ func (j *Library) PermittedPackagesForUpdatableBootJars() []string { return j.properties.Permitted_packages } -func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bool { +func shouldUncompressDex(ctx android.ModuleContext, libName string, dexpreopter *dexpreopter) bool { // Store uncompressed (and aligned) any dex files from jars in APEXes. if apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider); !apexInfo.IsForPlatform() { return true @@ -665,7 +665,7 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo } // Store uncompressed dex files that are preopted on /system. - if !dexpreopter.dexpreoptDisabled(ctx) && (ctx.Host() || !dexpreopter.odexOnSystemOther(ctx, dexpreopter.installPath)) { + if !dexpreopter.dexpreoptDisabled(ctx, libName) && (ctx.Host() || !dexpreopter.odexOnSystemOther(ctx, libName, dexpreopter.installPath)) { return true } if ctx.Config().UncompressPrivAppDex() && @@ -680,7 +680,7 @@ func shouldUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter) bo func setUncompressDex(ctx android.ModuleContext, dexpreopter *dexpreopter, dexer *dexer) { if dexer.dexProperties.Uncompress_dex == nil { // If the value was not force-set by the user, use reasonable default based on the module. - dexer.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, dexpreopter)) + dexer.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), dexpreopter)) } } @@ -712,7 +712,7 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.checkHeadersOnly(ctx) if ctx.Device() { j.dexpreopter.installPath = j.dexpreopter.getInstallPath( - ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) + ctx, j.Name(), android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary setUncompressDex(ctx, &j.dexpreopter, &j.dexer) j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex @@ -1084,7 +1084,7 @@ func (j *JavaTestImport) InstallInTestcases() bool { return true } -func (j *TestHost) IsNativeCoverageNeeded(ctx android.BaseModuleContext) bool { +func (j *TestHost) IsNativeCoverageNeeded(ctx android.IncomingTransitionContext) bool { return ctx.DeviceConfig().NativeCoverageEnabled() } @@ -2274,7 +2274,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { installPath := android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, ApexRootRelativePathToJavaLib(j.BaseModuleName())) j.dexJarInstallFile = installPath - j.dexpreopter.installPath = j.dexpreopter.getInstallPath(ctx, installPath) + j.dexpreopter.installPath = j.dexpreopter.getInstallPath(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), installPath) setUncompressDex(ctx, &j.dexpreopter, &j.dexer) j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex @@ -2282,8 +2282,6 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.dexpreopter.inputProfilePathOnHost = profilePath } - j.dexpreopt(ctx, dexOutputPath) - // Initialize the hiddenapi structure. j.initHiddenAPI(ctx, dexJarFile, outputFile, j.dexProperties.Uncompress_dex) } else { @@ -2304,7 +2302,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Dex compilation j.dexpreopter.installPath = j.dexpreopter.getInstallPath( - ctx, android.PathForModuleInstall(ctx, "framework", jarName)) + ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), android.PathForModuleInstall(ctx, "framework", jarName)) setUncompressDex(ctx, &j.dexpreopter, &j.dexer) j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex @@ -2592,8 +2590,8 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { } j.dexpreopter.installPath = j.dexpreopter.getInstallPath( - ctx, android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) - j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &j.dexpreopter) + ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")) + j.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &j.dexpreopter) inputJar := ctx.ExpandSource(j.properties.Jars[0], "jars") dexOutputFile := android.PathForModuleOut(ctx, ctx.ModuleName()+".jar") @@ -2632,7 +2630,7 @@ func (j *DexImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.dexJarFile = makeDexJarPathFromPath(dexOutputFile) - j.dexpreopt(ctx, dexOutputFile) + j.dexpreopt(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), dexOutputFile) if apexInfo.IsForPlatform() { ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), diff --git a/java/sdk_library.go b/java/sdk_library.go index 5ee713c15..2bf66449d 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -2879,16 +2879,13 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo module.installFile = installPath module.initHiddenAPI(ctx, dexJarFile, module.findScopePaths(apiScopePublic).stubsImplPath[0], nil) - module.dexpreopter.installPath = module.dexpreopter.getInstallPath(ctx, installPath) + module.dexpreopter.installPath = module.dexpreopter.getInstallPath(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), installPath) module.dexpreopter.isSDKLibrary = true - module.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, &module.dexpreopter) + module.dexpreopter.uncompressedDex = shouldUncompressDex(ctx, android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()), &module.dexpreopter) if profilePath := di.PrebuiltExportPath(dexJarFileApexRootRelative + ".prof"); profilePath != nil { module.dexpreopter.inputProfilePathOnHost = profilePath } - - // Dexpreopting. - module.dexpreopt(ctx, dexOutputPath) } else { // This should never happen as a variant for a prebuilt_apex is only created if the // prebuilt_apex has been configured to export the java library dex file. |