Move configuration checks from getBootImageJar
The getBootImageJar function will be removed once the boot image
creation has been moved to the platform_bootclasspath and
bootclasspath_fragment module types. However, the consistency checks
that it performs are still useful so this change moves them out
first.
The ART boot image related checks are now performed in the
bootclasspath_fragment module type. A previous change accidentally
disabled the checks when the contents property was not empty which has
been fixed. Also, the error messages have been tweaked to make it clear
that the art-bootclasspath-fragment is now the source of truth as to
its contents not the configuration.
The framework boot image related checks are now performed in the
platform_bootclasspath module type.
Initially, this change included an extra check to make sure that
UpdatableBootJars comes from updatable APEXes but that broke because
framework-wifi and framework-tethering are not currently marked as
updatable in AOSP.
Bug: 177892522
Test: m nothing
Change-Id: I80fb600fa2c7cec4566b3461c6a33c4c6f0743f4
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index d7525ec..8fe362a 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -145,11 +145,6 @@
ctx.ModuleErrorf(`neither of the "image_name" and "contents" properties have been supplied, please supply exactly one`)
}
- if len(contents) != 0 {
- // Nothing to do.
- return
- }
-
imageName := proptools.String(m.properties.Image_name)
if imageName == "art" {
// TODO(b/177892522): Prebuilts (versioned or not) should not use the image_name property.
@@ -181,7 +176,7 @@
continue
}
if !m.AvailableFor(apex) {
- ctx.ModuleErrorf("incompatible with ArtApexJars which expects this to be in apex %q but this is only in apexes %q",
+ ctx.ModuleErrorf("ArtApexJars configuration incompatible with this module, ArtApexJars expects this to be in apex %q but this is only in apexes %q",
apex, m.ApexAvailable())
continue
}
@@ -193,6 +188,11 @@
}
}
+ if len(contents) != 0 {
+ // Nothing to do.
+ return
+ }
+
// Store the jars in the Contents property so that they can be used to add dependencies.
m.properties.Contents = modules.CopyOfJars()
}
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go
index 8c6c9e3..617bbc0 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -460,8 +460,7 @@
// be needed there too.
//
// TODO(b/177892522): Avoid having to perform this type of check or if necessary dedup it.
-func getBootJar(ctx android.SingletonContext, bootjars android.ConfiguredJarList,
- module android.Module, fromWhere string) (int, android.Path, *android.ApexInfo) {
+func getBootJar(ctx android.SingletonContext, bootjars android.ConfiguredJarList, module android.Module, fromWhere string) (int, android.Path) {
name := ctx.ModuleName(module)
@@ -471,7 +470,7 @@
// Ignore any module that is not listed in the boot image configuration.
index := bootjars.IndexOfJar(name)
if index == -1 {
- return -1, nil, nil
+ return -1, nil
}
// It is an error if a module configured in the boot image does not support accessing the dex jar.
@@ -479,13 +478,13 @@
jar, hasJar := module.(interface{ DexJarBuildPath() android.Path })
if !hasJar {
ctx.Errorf("module %q %sdoes not support accessing dex jar", module, fromWhere)
- return -1, nil, nil
+ return -1, nil
}
// It is also an error if the module is not an ApexModule.
if _, ok := module.(android.ApexModule); !ok {
ctx.Errorf("module %q %sdoes not support being added to an apex", module, fromWhere)
- return -1, nil, nil
+ return -1, nil
}
apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
@@ -495,62 +494,24 @@
if requiredApex == "platform" || requiredApex == "system_ext" {
if len(apexInfo.InApexes) != 0 {
// A platform variant is required but this is for an apex so ignore it.
- return -1, nil, nil
+ return -1, nil
}
} else if !apexInfo.InApexByBaseName(requiredApex) {
// An apex variant for a specific apex is required but this is the wrong apex.
- return -1, nil, nil
+ return -1, nil
}
- return index, jar.DexJarBuildPath(), &apexInfo
+ return index, jar.DexJarBuildPath()
}
// Inspect this module to see if it contains a bootclasspath dex jar from a given boot image.
func getBootImageJar(ctx android.SingletonContext, image *bootImageConfig, module android.Module) (int, android.Path) {
fromImage := fmt.Sprintf("configured in boot image %q ", image.name)
- index, jarPath, apexInfo := getBootJar(ctx, image.modules, module, fromImage)
+ index, jarPath := getBootJar(ctx, image.modules, module, fromImage)
if index == -1 {
return -1, nil
}
- name := ctx.ModuleName(module)
-
- // Check that this module satisfies any boot image specific constraints.
- fromUpdatableApex := apexInfo.Updatable
-
- switch image.name {
- case artBootImageName:
- inArtApex := false
- for _, n := range artApexNames {
- if apexInfo.InApexByBaseName(n) {
- inArtApex = true
- break
- }
- }
- if inArtApex {
- // ok: found the jar in the ART apex
- } else if name == "jacocoagent" && ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
- // exception (skip and continue): Jacoco platform variant for a coverage build
- return -1, nil
- } else if fromUpdatableApex {
- // error: this jar is part of an updatable apex other than ART
- ctx.Errorf("module %q from updatable apexes %q is not allowed in the ART boot image", name, apexInfo.InApexes)
- } else {
- // error: this jar is part of the platform or a non-updatable apex
- ctx.Errorf("module %q is not allowed in the ART boot image", name)
- }
-
- case frameworkBootImageName:
- if !fromUpdatableApex {
- // ok: this jar is part of the platform or a non-updatable apex
- } else {
- // error: this jar is part of an updatable apex
- ctx.Errorf("module %q from updatable apexes %q is not allowed in the framework boot image", name, apexInfo.InApexes)
- }
- default:
- panic("unknown boot image: " + image.name)
- }
-
return index, jarPath
}
@@ -645,7 +606,7 @@
func copyUpdatableBootJars(ctx android.SingletonContext) {
config := GetUpdatableBootConfig(ctx)
getBootJarFunc := func(module android.Module) (int, android.Path) {
- index, jar, _ := getBootJar(ctx, config.modules, module, "configured in updatable boot jars ")
+ index, jar := getBootJar(ctx, config.modules, module, "configured in updatable boot jars ")
return index, jar
}
findAndCopyBootJars(ctx, config.modules, config.dexPaths, getBootJarFunc)
diff --git a/java/platform_bootclasspath.go b/java/platform_bootclasspath.go
index 9f16294..f88823f 100644
--- a/java/platform_bootclasspath.go
+++ b/java/platform_bootclasspath.go
@@ -184,6 +184,11 @@
// Gather all the fragments dependencies.
b.fragments = gatherApexModulePairDepsWithTag(ctx, bootclasspathFragmentDepTag)
+ // Check the configuration of the boot modules.
+ // ART modules are checked by the art-bootclasspath-fragment.
+ b.checkNonUpdatableModules(ctx, nonUpdatableModules)
+ b.checkUpdatableModules(ctx, updatableModules)
+
b.generateHiddenAPIBuildActions(ctx, b.configuredModules, b.fragments)
// Nothing to do if skipping the dexpreopt of boot image jars.
@@ -194,6 +199,42 @@
b.generateBootImageBuildActions(ctx, updatableModules)
}
+// checkNonUpdatableModules ensures that the non-updatable modules supplied are not part of an
+// updatable module.
+func (b *platformBootclasspathModule) checkNonUpdatableModules(ctx android.ModuleContext, modules []android.Module) {
+ for _, m := range modules {
+ apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo)
+ fromUpdatableApex := apexInfo.Updatable
+ if fromUpdatableApex {
+ // error: this jar is part of an updatable apex
+ ctx.ModuleErrorf("module %q from updatable apexes %q is not allowed in the framework boot image", ctx.OtherModuleName(m), apexInfo.InApexes)
+ } else {
+ // ok: this jar is part of the platform or a non-updatable apex
+ }
+ }
+}
+
+// checkUpdatableModules ensures that the updatable modules supplied are not from the platform.
+func (b *platformBootclasspathModule) checkUpdatableModules(ctx android.ModuleContext, modules []android.Module) {
+ for _, m := range modules {
+ apexInfo := ctx.OtherModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo)
+ fromUpdatableApex := apexInfo.Updatable
+ if fromUpdatableApex {
+ // ok: this jar is part of an updatable apex
+ } else {
+ name := ctx.OtherModuleName(m)
+ if apexInfo.IsForPlatform() {
+ // error: this jar is part of the platform
+ ctx.ModuleErrorf("module %q from platform is not allowed in the updatable boot jars list", name)
+ } else {
+ // TODO(b/177892522): Treat this as an error.
+ // Cannot do that at the moment because framework-wifi and framework-tethering are in the
+ // PRODUCT_UPDATABLE_BOOT_JARS but not marked as updatable in AOSP.
+ }
+ }
+ }
+}
+
func (b *platformBootclasspathModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
return defaultBootImageConfig(ctx)
}