Extract duplicate code to common helper functions.

Also, fall back to using a default name for the dexpreopt directory if
we are not building for Android.

Bug: 290583827
Test: m nothing
Change-Id: I3fc6ff9142a2dcdf995796f75891b242fe2848d0
This commit is contained in:
Jiakai Zhang
2023-07-11 15:03:13 +01:00
parent da47d3c6f3
commit b1639db53f
5 changed files with 17 additions and 10 deletions

View File

@@ -311,4 +311,9 @@ func EmptyConfiguredJarList() ConfiguredJarList {
return ConfiguredJarList{}
}
// IsConfiguredJarForPlatform returns true if the given apex name is a special name for the platform.
func IsConfiguredJarForPlatform(apex string) bool {
return apex == "platform" || apex == "system_ext"
}
var earlyBootJarsKey = NewOnceKey("earlyBootJars")

View File

@@ -77,7 +77,7 @@ func addDependencyOntoApexVariants(ctx android.BottomUpMutatorContext, propertyN
// Use gatherApexModulePairDepsWithTag to retrieve the dependencies.
func addDependencyOntoApexModulePair(ctx android.BottomUpMutatorContext, apex string, name string, tag blueprint.DependencyTag) {
var variations []blueprint.Variation
if apex != "platform" && apex != "system_ext" {
if !android.IsConfiguredJarForPlatform(apex) {
// Pick the correct apex variant.
variations = []blueprint.Variation{
{Mutator: "apex", Variation: apex},

View File

@@ -505,8 +505,7 @@ func (d *dexpreoptBootJars) GenerateSingletonBuildActions(ctx android.SingletonC
// No module has enabled dexpreopting, so we assume there will be no boot image to make.
return
}
archType := ctx.Config().Targets[android.Android][0].Arch.ArchType
d.dexpreoptConfigForMake = android.PathForOutput(ctx, toDexpreoptDirName(archType), "dexpreopt.config")
d.dexpreoptConfigForMake = android.PathForOutput(ctx, getDexpreoptDirName(ctx), "dexpreopt.config")
writeGlobalConfigForMake(ctx, d.dexpreoptConfigForMake)
global := dexpreopt.GetGlobalConfig(ctx)

View File

@@ -105,8 +105,7 @@ func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig
func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
return ctx.Config().Once(bootImageConfigKey, func() interface{} {
targets := dexpreoptTargets(ctx)
archType := ctx.Config().Targets[android.Android][0].Arch.ArchType
deviceDir := android.PathForOutput(ctx, toDexpreoptDirName(archType))
deviceDir := android.PathForOutput(ctx, getDexpreoptDirName(ctx))
configs := genBootImageConfigRaw(ctx)
@@ -218,8 +217,7 @@ var updatableBootConfigKey = android.NewOnceKey("apexBootConfig")
func GetApexBootConfig(ctx android.PathContext) apexBootConfig {
return ctx.Config().Once(updatableBootConfigKey, func() interface{} {
apexBootJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars
archType := ctx.Config().Targets[android.Android][0].Arch.ArchType
dir := android.PathForOutput(ctx, toDexpreoptDirName(archType), "apex_bootjars")
dir := android.PathForOutput(ctx, getDexpreoptDirName(ctx), "apex_bootjars")
dexPaths := apexBootJars.BuildPaths(ctx, dir)
dexPathsByModuleName := apexBootJars.BuildPathsByModule(ctx, dir)
@@ -260,6 +258,11 @@ func dexpreoptConfigMakevars(ctx android.MakeVarsContext) {
ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules.CopyOfApexJarPairs(), ":"))
}
func toDexpreoptDirName(arch android.ArchType) string {
return "dexpreopt_" + arch.String()
func getDexpreoptDirName(ctx android.PathContext) string {
prefix := "dexpreopt_"
targets := ctx.Config().Targets[android.Android]
if len(targets) > 0 {
return prefix+targets[0].Arch.ArchType.String()
}
return prefix+"unknown_target"
}

View File

@@ -166,7 +166,7 @@ func isModuleInConfiguredList(ctx android.BaseModuleContext, module android.Modu
// Now match the apex part of the boot image configuration.
requiredApex := configuredBootJars.Apex(index)
if requiredApex == "platform" || requiredApex == "system_ext" {
if android.IsConfiguredJarForPlatform(requiredApex) {
if len(apexInfo.InApexVariants) != 0 {
// A platform variant is required but this is for an apex so ignore it.
return false