59b9f14173
Consider this case: apex { name: "com.android.foo", native_libs: ["foo"], } override_apex { name: "com.mycompany.android.foo", base: "com.android.foo", } cc_library { name: "foo", } There are two APEXes defined: "com.android.foo" and "com.mycompany.android.foo" which is a copy of "com.android.foo" with some properties overridden (e.g. signing keys). The module "foo" is mutated into two variants by the apex mutator: the platform variant and the apex variant. The former has the variation name "" and the later has "apex<min_api_ver>" which usually is "apex10000". Internally, the apex variant has an alias "com.android.foo". ApexInfo.InApexVariants() returns only "com.android.foo" when called for the module "foo". We can see that the information that "foo" is also part of "com.mycompany.android.foo" is completely lost. This is causing problem when we compare the apex membership by their "soong module name", not the "apex name". In the example above, the two modules have different soone module names, but have the same apex name: "com.android.foo". To fix that, this CL introduces a new field `InApexes` to the `ApexInfo` struct. It has the actual name of the APEXes that the module is part of. With the example above, `InApexes` is ["com.android.foo", "com.mycompany.android.foo"]. Cherry-picked from https://r.android.com/1710529. Bug: 180325915 Test: m nothing Test: m nothing on non-AOSP targets with ag/13740887 applied. Change-Id: I4e7a7ac5495d2e622ba92a4358ed967e066c6c2e Merged-In: I4e7a7ac5495d2e622ba92a4358ed967e066c6c2e
136 lines
5 KiB
Go
136 lines
5 KiB
Go
// Copyright 2020 Google Inc. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package java
|
|
|
|
import (
|
|
"android/soong/android"
|
|
)
|
|
|
|
func init() {
|
|
android.RegisterSingletonType("boot_jars", bootJarsSingletonFactory)
|
|
}
|
|
|
|
func bootJarsSingletonFactory() android.Singleton {
|
|
return &bootJarsSingleton{}
|
|
}
|
|
|
|
type bootJarsSingleton struct{}
|
|
|
|
func populateMapFromConfiguredJarList(ctx android.SingletonContext, moduleToApex map[string]string, list android.ConfiguredJarList, name string) bool {
|
|
for i := 0; i < list.Len(); i++ {
|
|
module := list.Jar(i)
|
|
// Ignore jacocoagent it is only added when instrumenting and so has no impact on
|
|
// app compatibility.
|
|
if module == "jacocoagent" {
|
|
continue
|
|
}
|
|
apex := list.Apex(i)
|
|
if existing, ok := moduleToApex[module]; ok {
|
|
ctx.Errorf("Configuration property %q is invalid as it contains multiple references to module (%s) in APEXes (%s and %s)",
|
|
module, existing, apex)
|
|
return false
|
|
}
|
|
|
|
moduleToApex[module] = apex
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// isActiveModule returns true if the given module should be considered for boot
|
|
// jars, i.e. if it's enabled and the preferred one in case of source and
|
|
// prebuilt alternatives.
|
|
func isActiveModule(module android.Module) bool {
|
|
if !module.Enabled() {
|
|
return false
|
|
}
|
|
return android.IsModulePreferred(module)
|
|
}
|
|
|
|
func (b *bootJarsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
|
config := ctx.Config()
|
|
if config.SkipBootJarsCheck() {
|
|
return
|
|
}
|
|
|
|
// Populate a map from module name to APEX from the boot jars. If there is a
|
|
// problem such as duplicate modules then fail and return immediately. Note
|
|
// that both module and APEX names are tracked by base names here, so we need
|
|
// to be careful to remove "prebuilt_" prefixes when comparing them with
|
|
// actual modules and APEX bundles.
|
|
moduleToApex := make(map[string]string)
|
|
if !populateMapFromConfiguredJarList(ctx, moduleToApex, config.NonUpdatableBootJars(), "BootJars") ||
|
|
!populateMapFromConfiguredJarList(ctx, moduleToApex, config.UpdatableBootJars(), "UpdatableBootJars") {
|
|
return
|
|
}
|
|
|
|
// Map from module name to the correct apex variant.
|
|
nameToApexVariant := make(map[string]android.Module)
|
|
|
|
// Scan all the modules looking for the module/apex variants corresponding to the
|
|
// boot jars.
|
|
ctx.VisitAllModules(func(module android.Module) {
|
|
if !isActiveModule(module) {
|
|
return
|
|
}
|
|
|
|
name := android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName(module))
|
|
if apex, ok := moduleToApex[name]; ok {
|
|
apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo)
|
|
if (apex == "platform" && apexInfo.IsForPlatform()) || apexInfo.InApexModule(apex) {
|
|
// The module name/apex variant should be unique in the system but double check
|
|
// just in case something has gone wrong.
|
|
if existing, ok := nameToApexVariant[name]; ok {
|
|
ctx.Errorf("found multiple variants matching %s:%s: %q and %q", apex, name, existing, module)
|
|
}
|
|
nameToApexVariant[name] = module
|
|
}
|
|
}
|
|
})
|
|
|
|
timestamp := android.PathForOutput(ctx, "boot-jars-package-check/stamp")
|
|
|
|
rule := android.NewRuleBuilder(pctx, ctx)
|
|
checkBootJars := rule.Command().BuiltTool("check_boot_jars").
|
|
Input(ctx.Config().HostToolPath(ctx, "dexdump")).
|
|
Input(android.PathForSource(ctx, "build/soong/scripts/check_boot_jars/package_allowed_list.txt"))
|
|
|
|
// If this is not an unbundled build and missing dependencies are not allowed
|
|
// then all the boot jars listed must have been found.
|
|
strict := !config.UnbundledBuild() && !config.AllowMissingDependencies()
|
|
|
|
// Iterate over the module names on the boot classpath in order
|
|
for _, name := range android.SortedStringKeys(moduleToApex) {
|
|
if apexVariant, ok := nameToApexVariant[name]; ok {
|
|
if dep, ok := apexVariant.(interface{ DexJarBuildPath() android.Path }); ok {
|
|
// Add the dex implementation jar for the module to be checked.
|
|
checkBootJars.Input(dep.DexJarBuildPath())
|
|
} else {
|
|
ctx.Errorf("module %q is of type %q which is not supported as a boot jar", name, ctx.ModuleType(apexVariant))
|
|
}
|
|
} else if strict {
|
|
ctx.Errorf("boot jars package check failed as it could not find module %q for apex %q", name, moduleToApex[name])
|
|
}
|
|
}
|
|
|
|
checkBootJars.Text("&& touch").Output(timestamp)
|
|
rule.Build("boot_jars_package_check", "check boot jar packages")
|
|
|
|
// The check-boot-jars phony target depends on the timestamp created if the check succeeds.
|
|
ctx.Phony("check-boot-jars", timestamp)
|
|
|
|
// The droidcore phony target depends on the check-boot-jars phony target
|
|
ctx.Phony("droidcore", android.PathForPhony(ctx, "check-boot-jars"))
|
|
}
|