From a8afdcb3072096d5c76243bf342a98be5f8b9e89 Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Thu, 29 Feb 2024 06:40:16 +0000 Subject: [PATCH 1/2] Disable source javalib dexpreopt when using prebuilt apex The apex_contributions in next builds use prebuilt apexes with source java_sdk_library for javac. The dexpreopt rules of the source java_sdk_library are disabled via RELEASE_DEFAULT_MODULE_BUILD_FROM_SOURCE coupled with some complicated special-casing in android/prebuilt.go This special-casing breaks if we want to use prebuilts of some modules, and sources of other modules. To enable per mainline module toggelability, explicitly disable dexpreopt of source variant of java_sdk_library if we use prebuilt of the containing apex. Test: In internal, updated trunk_staging.scl's RELEASE_APEX_CONTRIBUTIONS_ADSERVICES to use prebuilt followed by m nothing Change-Id: I32daefbd38338b396d6f07b899826b2869d8f8e1 --- java/dexpreopt.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/java/dexpreopt.go b/java/dexpreopt.go index 1cfa64245..38ed856ee 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -187,6 +187,33 @@ func forPrebuiltApex(ctx android.BaseModuleContext) bool { return apexInfo.ForPrebuiltApex } +// For apex variant of modules, this returns true on the source variant if the prebuilt apex +// has been selected using apex_contributions. +// The prebuilt apex will be responsible for generating the dexpreopt rules of the deapexed java lib. +func disableSourceApexVariant(ctx android.BaseModuleContext) bool { + if !isApexVariant(ctx) { + return false // platform variant + } + apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider) + psi := android.PrebuiltSelectionInfoMap{} + ctx.VisitDirectDepsWithTag(android.PrebuiltDepTag, func(am android.Module) { + psi, _ = android.OtherModuleProvider(ctx, am, android.PrebuiltSelectionInfoProvider) + }) + // Find the apex variant for this module + _, apexVariantsWithoutTestApexes, _ := android.ListSetDifference(apexInfo.InApexVariants, apexInfo.TestApexes) + disableSource := false + // find the selected apexes + for _, apexVariant := range apexVariantsWithoutTestApexes { + for _, selected := range psi.GetSelectedModulesForApiDomain(apexVariant) { + // If the apex_contribution for this api domain contains a prebuilt apex, disable the source variant + if strings.HasPrefix(selected, "prebuilt_com.google.android") { + disableSource = true + } + } + } + return disableSource +} + // 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, libName string) bool { @@ -216,6 +243,10 @@ func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext, libName s return true } + if disableSourceApexVariant(ctx) { + 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 From 614a6f2b41af284e6238ff8005ffc39c9049128e Mon Sep 17 00:00:00 2001 From: Spandan Das Date: Thu, 29 Feb 2024 19:54:28 +0000 Subject: [PATCH 2/2] Use BaseModuleName for LOCAL_MODULE This CL uses OverrideName to ensure that the LOCAL_MODULE does not contain any version information. Test: Created CaptiveLoginPortalGoogle.v2, and checked that its LOCAL_MODULE is CaptiveLoginPortalGoogle Change-Id: I177441bcd55ca538759b69aafb73d0a8b7261179 --- java/androidmk.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/java/androidmk.go b/java/androidmk.go index b7df9bf9e..498962f88 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -691,9 +691,10 @@ func (a *AndroidAppImport) AndroidMkEntries() []android.AndroidMkEntries { return nil } return []android.AndroidMkEntries{android.AndroidMkEntries{ - Class: "APPS", - OutputFile: android.OptionalPathForPath(a.outputFile), - Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk", + Class: "APPS", + OutputFile: android.OptionalPathForPath(a.outputFile), + OverrideName: a.BaseModuleName(), // TODO (spandandas): Add a test + Include: "$(BUILD_SYSTEM)/soong_app_prebuilt.mk", ExtraEntries: []android.AndroidMkExtraEntriesFunc{ func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { entries.SetBoolIfTrue("LOCAL_PRIVILEGED_MODULE", a.Privileged())