Merge "Use the correct mainline BCP jars for app dexpreopt." into main

This commit is contained in:
Jiakai Zhang 2023-11-08 10:56:58 +00:00 committed by Gerrit Code Review
commit 04445d5443
3 changed files with 7 additions and 55 deletions

View file

@ -5459,7 +5459,7 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
checkBootDexJarPath := func(t *testing.T, ctx *android.TestContext, stem string, bootDexJarPath string) {
t.Helper()
s := ctx.ModuleForTests("platform-bootclasspath", "android_common")
s := ctx.ModuleForTests("dex_bootjars", "android_common")
foundLibfooJar := false
base := stem + ".jar"
for _, output := range s.AllOutputs() {
@ -5909,8 +5909,8 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
`
ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment)
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/libbar/android_common_myapex/hiddenapi/libbar.jar")
checkBootDexJarPath(t, ctx, "libfoo", "out/soong/.intermediates/my-bootclasspath-fragment/android_common_myapex/hiddenapi-modular/encoded/libfoo.jar")
checkBootDexJarPath(t, ctx, "libbar", "out/soong/.intermediates/my-bootclasspath-fragment/android_common_myapex/hiddenapi-modular/encoded/libbar.jar")
// Verify the correct module jars contribute to the hiddenapi index file.
checkHiddenAPIIndexFromClassesInputs(t, ctx, ``)

View file

@ -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
}

View file

@ -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)
}