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
diff --git a/android/configured_jars.go b/android/configured_jars.go
index 53fef05..1281bae 100644
--- a/android/configured_jars.go
+++ b/android/configured_jars.go
@@ -311,4 +311,9 @@
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")
diff --git a/java/bootclasspath.go b/java/bootclasspath.go
index f4cef7f..29eed79 100644
--- a/java/bootclasspath.go
+++ b/java/bootclasspath.go
@@ -77,7 +77,7 @@
// 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},
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go
index 9057a1c..794bc4a 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -505,8 +505,7 @@
// 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)
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go
index 9100e87..d9c474d 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -105,8 +105,7 @@
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 @@
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 @@
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"
}
diff --git a/java/hiddenapi_singleton.go b/java/hiddenapi_singleton.go
index d4ee4fc..714634f 100644
--- a/java/hiddenapi_singleton.go
+++ b/java/hiddenapi_singleton.go
@@ -166,7 +166,7 @@
// 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