summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rwxr-xr-xjava/app.go2
-rw-r--r--java/bootclasspath_fragment.go2
-rw-r--r--java/config/droidstubs.go4
-rw-r--r--java/dexpreopt_bootjars.go3
-rw-r--r--java/dexpreopt_check.go2
-rw-r--r--java/dexpreopt_config.go47
-rw-r--r--java/platform_bootclasspath.go9
-rw-r--r--java/sdk_library_test.go131
8 files changed, 140 insertions, 60 deletions
diff --git a/java/app.go b/java/app.go
index 7c2cc3720..41848ce0b 100755
--- a/java/app.go
+++ b/java/app.go
@@ -1586,7 +1586,7 @@ func (u *usesLibrary) verifyUsesLibraries(ctx android.ModuleContext, inputFile a
// non-linux build platforms where dexpreopt is generally disabled (the check may fail due to
// various unrelated reasons, such as a failure to get manifest from an APK).
global := dexpreopt.GetGlobalConfig(ctx)
- if global.DisablePreopt || global.OnlyPreoptBootImageAndSystemServer {
+ if global.DisablePreopt || global.OnlyPreoptArtBootImage {
return inputFile
}
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index 2433530c9..ea3fc9dbb 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -584,7 +584,7 @@ func (b *BootclasspathFragmentModule) configuredJars(ctx android.ModuleContext)
// So ignore it even if it is not in PRODUCT_APEX_BOOT_JARS.
// TODO(b/202896428): Add better way to handle this.
_, unknown = android.RemoveFromList("android.car-module", unknown)
- if len(unknown) > 0 {
+ if isActiveModule(ctx.Module()) && len(unknown) > 0 {
ctx.ModuleErrorf("%s in contents must also be declared in PRODUCT_APEX_BOOT_JARS", unknown)
}
}
diff --git a/java/config/droidstubs.go b/java/config/droidstubs.go
index 59cee1d61..b7aab5a98 100644
--- a/java/config/droidstubs.go
+++ b/java/config/droidstubs.go
@@ -24,8 +24,6 @@ var (
"--repeat-errors-max 10",
"--hide UnresolvedImport",
"--hide InvalidNullabilityOverride",
- // b/223382732
- "--hide ChangedDefault",
// Force metalava to ignore classes on the classpath when an API file contains missing classes.
// See b/285140653 for more information.
@@ -54,8 +52,6 @@ var (
"--hide AnnotationExtraction",
// b/222738070
"--hide BannedThrow",
- // b/223382732
- "--hide ChangedDefault",
}
MetalavaAnnotationsWarningsFlags = strings.Join(metalavaAnnotationsWarningsFlags, " ")
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go
index c0f73afc5..5fb36df6d 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -610,7 +610,8 @@ func generateBootImage(ctx android.ModuleContext, imageConfig *bootImageConfig)
profile := bootImageProfileRule(ctx, imageConfig)
// If dexpreopt of boot image jars should be skipped, stop after generating a profile.
- if SkipDexpreoptBootJars(ctx) {
+ global := dexpreopt.GetGlobalConfig(ctx)
+ if SkipDexpreoptBootJars(ctx) || (global.OnlyPreoptArtBootImage && imageConfig.name != "art") {
return
}
diff --git a/java/dexpreopt_check.go b/java/dexpreopt_check.go
index 7499481de..33be60352 100644
--- a/java/dexpreopt_check.go
+++ b/java/dexpreopt_check.go
@@ -68,7 +68,7 @@ func (m *dexpreoptSystemserverCheck) GenerateAndroidBuildActions(ctx android.Mod
// The check should be skipped on unbundled builds because system server jars are not preopted on
// unbundled builds since the artifacts are installed into the system image, not the APEXes.
- if global.DisablePreopt || len(targets) == 0 || ctx.Config().UnbundledBuild() {
+ if global.DisablePreopt || global.OnlyPreoptArtBootImage || len(targets) == 0 || ctx.Config().UnbundledBuild() {
return
}
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go
index 29551efcc..2bd696c3d 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -210,57 +210,18 @@ func isProfileProviderApex(ctx android.PathContext, apexName string) bool {
return false
}
-// Apex boot config allows to access build/install paths of apex boot jars without going
-// through the usual trouble of registering dependencies on those modules and extracting build paths
-// from those dependencies.
-type apexBootConfig struct {
- // A list of apex boot jars.
- modules android.ConfiguredJarList
-
- // A list of predefined build paths to apex boot jars. They are configured very early,
- // before the modules for these jars are processed and the actual paths are generated, and
- // later on a singleton adds commands to copy actual jars to the predefined paths.
- dexPaths android.WritablePaths
-
- // Map from module name (without prebuilt_ prefix) to the predefined build path.
- dexPathsByModule map[string]android.WritablePath
-
- // A list of dex locations (a.k.a. on-device paths) to the boot jars.
- dexLocations []string
-}
-
-var updatableBootConfigKey = android.NewOnceKey("apexBootConfig")
-
-// Returns apex boot config.
-func GetApexBootConfig(ctx android.PathContext) apexBootConfig {
- return ctx.Config().Once(updatableBootConfigKey, func() interface{} {
- apexBootJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars
- dir := android.PathForOutput(ctx, getDexpreoptDirName(ctx), "apex_bootjars")
- dexPaths := apexBootJars.BuildPaths(ctx, dir)
- dexPathsByModuleName := apexBootJars.BuildPathsByModule(ctx, dir)
-
- dexLocations := apexBootJars.DevicePaths(ctx.Config(), android.Android)
-
- return apexBootConfig{apexBootJars, dexPaths, dexPathsByModuleName, dexLocations}
- }).(apexBootConfig)
-}
-
// Returns a list of paths and a list of locations for the boot jars used in dexpreopt (to be
// passed in -Xbootclasspath and -Xbootclasspath-locations arguments for dex2oat).
func bcpForDexpreopt(ctx android.PathContext, withUpdatable bool) (android.WritablePaths, []string) {
- // Non-updatable boot jars (they are used both in the boot image and in dexpreopt).
bootImage := defaultBootImageConfig(ctx)
+ if withUpdatable {
+ bootImage = mainlineBootImageConfig(ctx)
+ }
+
dexPaths := bootImage.dexPathsDeps
// The dex locations for all Android variants are identical.
dexLocations := bootImage.getAnyAndroidVariant().dexLocationsDeps
- if withUpdatable {
- // Apex boot jars (they are used only in dexpreopt, but not in the boot image).
- apexBootConfig := GetApexBootConfig(ctx)
- dexPaths = append(dexPaths, apexBootConfig.dexPaths...)
- dexLocations = append(dexLocations, apexBootConfig.dexLocations...)
- }
-
return dexPaths, dexLocations
}
diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go
index 02a2298cd..0d52614ea 100644
--- a/java/platform_bootclasspath.go
+++ b/java/platform_bootclasspath.go
@@ -202,8 +202,6 @@ func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.Mo
bootDexJarByModule := b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments)
buildRuleForBootJarsPackageCheck(ctx, bootDexJarByModule)
-
- b.copyApexBootJarsForAppsDexpreopt(ctx, apexModules)
}
// Generate classpaths.proto config
@@ -415,10 +413,3 @@ func (b *platformBootclasspathModule) generateHiddenApiMakeVars(ctx android.Make
// INTERNAL_PLATFORM_HIDDENAPI_FLAGS is used by Make rules in art/ and cts/.
ctx.Strict("INTERNAL_PLATFORM_HIDDENAPI_FLAGS", b.hiddenAPIFlagsCSV.String())
}
-
-// Copy apex module dex jars to their predefined locations. They will be used for dexpreopt for apps.
-func (b *platformBootclasspathModule) copyApexBootJarsForAppsDexpreopt(ctx android.ModuleContext, apexModules []android.Module) {
- config := GetApexBootConfig(ctx)
- apexBootDexJarsByModule := extractEncodedDexJarsFromModules(ctx, apexModules)
- copyBootJarsToPredefinedLocations(ctx, apexBootDexJarsByModule, config.dexPathsByModule)
-}
diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go
index 21f0bab37..82f8a4d50 100644
--- a/java/sdk_library_test.go
+++ b/java/sdk_library_test.go
@@ -1068,6 +1068,137 @@ func TestJavaSdkLibraryImport_Preferred(t *testing.T) {
})
}
+// If a module is listed in `mainline_module_contributions, it should be used
+// It will supersede any other source vs prebuilt selection mechanism like `prefer` attribute
+func TestSdkLibraryImport_MetadataModuleSupersedesPreferred(t *testing.T) {
+ bp := `
+ apex_contributions {
+ name: "my_mainline_module_contributions",
+ api_domain: "my_mainline_module",
+ contents: [
+ // legacy mechanism prefers the prebuilt
+ // mainline_module_contributions supersedes this since source is listed explicitly
+ "sdklib.prebuilt_preferred_using_legacy_flags",
+
+ // legacy mechanism prefers the source
+ // mainline_module_contributions supersedes this since prebuilt is listed explicitly
+ "prebuilt_sdklib.source_preferred_using_legacy_flags",
+ ],
+ }
+ all_apex_contributions {
+ name: "all_apex_contributions",
+ }
+ java_sdk_library {
+ name: "sdklib.prebuilt_preferred_using_legacy_flags",
+ srcs: ["a.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ public: {
+ enabled: true,
+ },
+ system: {
+ enabled: true,
+ }
+ }
+ java_sdk_library_import {
+ name: "sdklib.prebuilt_preferred_using_legacy_flags",
+ prefer: true, // prebuilt is preferred using legacy mechanism
+ public: {
+ jars: ["a.jar"],
+ stub_srcs: ["a.java"],
+ current_api: "current.txt",
+ removed_api: "removed.txt",
+ annotations: "annotations.zip",
+ },
+ system: {
+ jars: ["a.jar"],
+ stub_srcs: ["a.java"],
+ current_api: "current.txt",
+ removed_api: "removed.txt",
+ annotations: "annotations.zip",
+ },
+ }
+ java_sdk_library {
+ name: "sdklib.source_preferred_using_legacy_flags",
+ srcs: ["a.java"],
+ sdk_version: "none",
+ system_modules: "none",
+ public: {
+ enabled: true,
+ },
+ system: {
+ enabled: true,
+ }
+ }
+ java_sdk_library_import {
+ name: "sdklib.source_preferred_using_legacy_flags",
+ prefer: false, // source is preferred using legacy mechanism
+ public: {
+ jars: ["a.jar"],
+ stub_srcs: ["a.java"],
+ current_api: "current.txt",
+ removed_api: "removed.txt",
+ annotations: "annotations.zip",
+ },
+ system: {
+ jars: ["a.jar"],
+ stub_srcs: ["a.java"],
+ current_api: "current.txt",
+ removed_api: "removed.txt",
+ annotations: "annotations.zip",
+ },
+ }
+
+ // rdeps
+ java_library {
+ name: "public",
+ srcs: ["a.java"],
+ libs: [
+ // this should get source since source is listed in my_mainline_module_contributions
+ "sdklib.prebuilt_preferred_using_legacy_flags.stubs",
+ "sdklib.prebuilt_preferred_using_legacy_flags.stubs.system",
+
+ // this should get prebuilt since source is listed in my_mainline_module_contributions
+ "sdklib.source_preferred_using_legacy_flags.stubs",
+ "sdklib.source_preferred_using_legacy_flags.stubs.system",
+
+ ],
+ }
+ `
+ result := android.GroupFixturePreparers(
+ prepareForJavaTest,
+ PrepareForTestWithJavaSdkLibraryFiles,
+ FixtureWithLastReleaseApis("sdklib.source_preferred_using_legacy_flags", "sdklib.prebuilt_preferred_using_legacy_flags"),
+ android.FixtureRegisterWithContext(func(ctx android.RegistrationContext) {
+ android.RegisterApexContributionsBuildComponents(ctx)
+ }),
+ android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
+ variables.BuildFlags = map[string]string{
+ "RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "my_mainline_module_contributions",
+ }
+ }),
+ ).RunTestWithBp(t, bp)
+
+ // Make sure that rdeps get the correct source vs prebuilt based on mainline_module_contributions
+ public := result.ModuleForTests("public", "android_common")
+ rule := public.Output("javac/public.jar")
+ inputs := rule.Implicits.Strings()
+ expectedInputs := []string{
+ // source
+ "out/soong/.intermediates/sdklib.prebuilt_preferred_using_legacy_flags.stubs/android_common/turbine-combined/sdklib.prebuilt_preferred_using_legacy_flags.stubs.jar",
+ "out/soong/.intermediates/sdklib.prebuilt_preferred_using_legacy_flags.stubs.system/android_common/turbine-combined/sdklib.prebuilt_preferred_using_legacy_flags.stubs.system.jar",
+
+ // prebuilt
+ "out/soong/.intermediates/prebuilt_sdklib.source_preferred_using_legacy_flags.stubs/android_common/combined/sdklib.source_preferred_using_legacy_flags.stubs.jar",
+ "out/soong/.intermediates/prebuilt_sdklib.source_preferred_using_legacy_flags.stubs.system/android_common/combined/sdklib.source_preferred_using_legacy_flags.stubs.system.jar",
+ }
+ for _, expected := range expectedInputs {
+ if !android.InList(expected, inputs) {
+ t.Errorf("expected %q to contain %q", inputs, expected)
+ }
+ }
+}
+
func TestJavaSdkLibraryEnforce(t *testing.T) {
partitionToBpOption := func(partition string) string {
switch partition {