2019-02-16 08:06:46 +01:00
|
|
|
// Copyright 2019 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 (
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2019-05-10 06:50:00 +02:00
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/dexpreopt"
|
2019-02-16 08:06:46 +01:00
|
|
|
)
|
|
|
|
|
2019-05-09 00:18:22 +02:00
|
|
|
// dexpreoptTargets returns the list of targets that are relevant to dexpreopting, which excludes architectures
|
|
|
|
// supported through native bridge.
|
|
|
|
func dexpreoptTargets(ctx android.PathContext) []android.Target {
|
|
|
|
var targets []android.Target
|
2019-09-17 23:45:31 +02:00
|
|
|
for _, target := range ctx.Config().Targets[android.Android] {
|
2019-05-09 00:18:22 +02:00
|
|
|
if target.NativeBridge == android.NativeBridgeDisabled {
|
|
|
|
targets = append(targets, target)
|
|
|
|
}
|
|
|
|
}
|
2020-02-13 17:00:45 +01:00
|
|
|
// We may also need the images on host in order to run host-based tests.
|
2021-07-20 18:47:41 +02:00
|
|
|
for _, target := range ctx.Config().Targets[ctx.Config().BuildOS] {
|
2020-02-13 17:00:45 +01:00
|
|
|
targets = append(targets, target)
|
|
|
|
}
|
2019-05-09 00:18:22 +02:00
|
|
|
|
|
|
|
return targets
|
|
|
|
}
|
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
var (
|
2023-07-13 12:03:38 +02:00
|
|
|
bootImageConfigKey = android.NewOnceKey("bootImageConfig")
|
|
|
|
bootImageConfigRawKey = android.NewOnceKey("bootImageConfigRaw")
|
|
|
|
frameworkBootImageName = "boot"
|
|
|
|
mainlineBootImageName = "mainline"
|
|
|
|
bootImageStem = "boot"
|
|
|
|
profileInstallPathInApex = "etc/boot-image.prof"
|
2019-11-08 11:54:21 +01:00
|
|
|
)
|
|
|
|
|
2023-07-13 12:03:38 +02:00
|
|
|
// getImageNames returns an ordered list of image names. The order doesn't matter but needs to be
|
|
|
|
// deterministic. The names listed here must match the map keys returned by genBootImageConfigs.
|
|
|
|
func getImageNames() []string {
|
|
|
|
return []string{"art", "boot", "mainline"}
|
|
|
|
}
|
|
|
|
|
2022-01-12 18:56:19 +01:00
|
|
|
func genBootImageConfigRaw(ctx android.PathContext) map[string]*bootImageConfig {
|
|
|
|
return ctx.Config().Once(bootImageConfigRawKey, func() interface{} {
|
2020-01-20 19:12:23 +01:00
|
|
|
global := dexpreopt.GetGlobalConfig(ctx)
|
2019-02-22 16:34:40 +01:00
|
|
|
|
2023-07-12 17:51:57 +02:00
|
|
|
artBootImageName := "art" // Keep this local to avoid accidental references.
|
2023-07-13 12:03:38 +02:00
|
|
|
frameworkModules := global.BootJars // This includes `global.ArtApexJars`.
|
2023-03-06 20:16:48 +01:00
|
|
|
mainlineBcpModules := global.ApexBootJars
|
|
|
|
frameworkSubdir := "system/framework"
|
2019-02-22 16:34:40 +01:00
|
|
|
|
2023-07-13 12:03:38 +02:00
|
|
|
profileImports := []string{"com.android.art"}
|
|
|
|
|
|
|
|
// ART boot image for testing only. Do not rely on it to make any build-time decision.
|
2019-11-08 11:54:21 +01:00
|
|
|
artCfg := bootImageConfig{
|
2023-07-13 12:03:38 +02:00
|
|
|
name: artBootImageName,
|
|
|
|
enabledIfExists: "art-bootclasspath-fragment",
|
|
|
|
stem: bootImageStem,
|
|
|
|
installDir: "apex/art_boot_images/javalib",
|
2023-07-12 17:51:57 +02:00
|
|
|
modules: global.TestOnlyArtBootImageJars,
|
2023-07-13 12:03:38 +02:00
|
|
|
preloadedClassesFile: "art/build/boot/preloaded-classes",
|
|
|
|
compilerFilter: "speed-profile",
|
|
|
|
singleImage: false,
|
|
|
|
profileImports: profileImports,
|
2019-04-30 10:43:22 +02:00
|
|
|
}
|
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
// Framework config for the boot image extension.
|
2019-12-18 18:32:33 +01:00
|
|
|
// It includes framework libraries and depends on the ART config.
|
2019-11-08 11:54:21 +01:00
|
|
|
frameworkCfg := bootImageConfig{
|
2022-03-14 16:31:47 +01:00
|
|
|
name: frameworkBootImageName,
|
2023-07-13 12:03:38 +02:00
|
|
|
enabledIfExists: "platform-bootclasspath",
|
2023-03-06 20:16:48 +01:00
|
|
|
stem: bootImageStem,
|
2023-05-10 18:04:53 +02:00
|
|
|
installDir: frameworkSubdir,
|
2022-03-14 16:31:47 +01:00
|
|
|
modules: frameworkModules,
|
|
|
|
preloadedClassesFile: "frameworks/base/config/preloaded-classes",
|
2023-02-23 18:50:46 +01:00
|
|
|
compilerFilter: "speed-profile",
|
2023-03-06 20:16:48 +01:00
|
|
|
singleImage: false,
|
2023-07-13 12:03:38 +02:00
|
|
|
profileImports: profileImports,
|
2023-03-06 20:16:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
mainlineCfg := bootImageConfig{
|
2023-07-13 12:03:38 +02:00
|
|
|
extends: &frameworkCfg,
|
|
|
|
name: mainlineBootImageName,
|
|
|
|
enabledIfExists: "platform-bootclasspath",
|
|
|
|
stem: bootImageStem,
|
|
|
|
installDir: frameworkSubdir,
|
|
|
|
modules: mainlineBcpModules,
|
|
|
|
compilerFilter: "verify",
|
|
|
|
singleImage: true,
|
2019-02-22 16:34:40 +01:00
|
|
|
}
|
|
|
|
|
2022-01-12 18:56:19 +01:00
|
|
|
return map[string]*bootImageConfig{
|
2020-02-10 16:29:28 +01:00
|
|
|
artBootImageName: &artCfg,
|
|
|
|
frameworkBootImageName: &frameworkCfg,
|
2023-03-06 20:16:48 +01:00
|
|
|
mainlineBootImageName: &mainlineCfg,
|
2019-10-23 16:56:32 +02:00
|
|
|
}
|
2022-01-12 18:56:19 +01:00
|
|
|
}).(map[string]*bootImageConfig)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct the global boot image configs.
|
|
|
|
func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
|
|
|
|
return ctx.Config().Once(bootImageConfigKey, func() interface{} {
|
|
|
|
targets := dexpreoptTargets(ctx)
|
2023-07-11 16:03:13 +02:00
|
|
|
deviceDir := android.PathForOutput(ctx, getDexpreoptDirName(ctx))
|
2022-01-12 18:56:19 +01:00
|
|
|
|
|
|
|
configs := genBootImageConfigRaw(ctx)
|
2019-02-22 16:34:40 +01:00
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
for _, c := range configs {
|
|
|
|
c.dir = deviceDir.Join(ctx, "dex_"+c.name+"jars")
|
|
|
|
c.symbolsDir = deviceDir.Join(ctx, "dex_"+c.name+"jars_unstripped")
|
|
|
|
|
|
|
|
// expands to <stem>.art for primary image and <stem>-<1st module>.art for extension
|
2020-05-11 19:06:15 +02:00
|
|
|
imageName := c.firstModuleNameOrStem(ctx) + ".art"
|
2019-06-13 23:44:53 +02:00
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
// The path to bootclasspath dex files needs to be known at module
|
|
|
|
// GenerateAndroidBuildAction time, before the bootclasspath modules have been compiled.
|
|
|
|
// Set up known paths for them, the singleton rules will copy them there.
|
|
|
|
// TODO(b/143682396): use module dependencies instead
|
|
|
|
inputDir := deviceDir.Join(ctx, "dex_"+c.name+"jars_input")
|
2020-07-01 15:31:13 +02:00
|
|
|
c.dexPaths = c.modules.BuildPaths(ctx, inputDir)
|
2021-06-02 18:24:22 +02:00
|
|
|
c.dexPathsByModule = c.modules.BuildPathsByModule(ctx, inputDir)
|
2019-11-08 11:54:21 +01:00
|
|
|
c.dexPathsDeps = c.dexPaths
|
|
|
|
|
2020-02-18 21:43:06 +01:00
|
|
|
// Create target-specific variants.
|
2019-11-08 11:54:21 +01:00
|
|
|
for _, target := range targets {
|
|
|
|
arch := target.Arch.ArchType
|
2023-05-10 18:04:53 +02:00
|
|
|
imageDir := c.dir.Join(ctx, target.Os.String(), c.installDir, arch.String())
|
2020-02-18 21:43:06 +01:00
|
|
|
variant := &bootImageVariant{
|
2021-04-27 16:56:44 +02:00
|
|
|
bootImageConfig: c,
|
|
|
|
target: target,
|
|
|
|
imagePathOnHost: imageDir.Join(ctx, imageName),
|
2023-05-10 18:04:53 +02:00
|
|
|
imagePathOnDevice: filepath.Join("/", c.installDir, arch.String(), imageName),
|
2021-04-27 16:56:44 +02:00
|
|
|
imagesDeps: c.moduleFiles(ctx, imageDir, ".art", ".oat", ".vdex"),
|
|
|
|
dexLocations: c.modules.DevicePaths(ctx.Config(), target.Os),
|
2020-03-30 18:24:13 +02:00
|
|
|
}
|
|
|
|
variant.dexLocationsDeps = variant.dexLocations
|
2020-02-18 21:43:06 +01:00
|
|
|
c.variants = append(c.variants, variant)
|
2019-06-13 23:44:53 +02:00
|
|
|
}
|
2019-12-04 22:16:01 +01:00
|
|
|
|
|
|
|
c.zip = c.dir.Join(ctx, c.name+".zip")
|
2019-06-13 23:44:53 +02:00
|
|
|
}
|
|
|
|
|
2023-02-23 18:37:16 +01:00
|
|
|
visited := make(map[string]bool)
|
|
|
|
for _, c := range configs {
|
|
|
|
calculateDepsRecursive(c, targets, visited)
|
2020-02-18 21:43:06 +01:00
|
|
|
}
|
2019-12-18 18:32:33 +01:00
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
return configs
|
|
|
|
}).(map[string]*bootImageConfig)
|
2019-02-22 16:34:40 +01:00
|
|
|
}
|
|
|
|
|
2023-02-23 18:37:16 +01:00
|
|
|
// calculateDepsRecursive calculates the dependencies of the given boot image config and all its
|
|
|
|
// ancestors, if they are not visited.
|
|
|
|
// The boot images are supposed to form a tree, where the root is the primary boot image. We do not
|
|
|
|
// expect loops (e.g., A extends B, B extends C, C extends A), and we let them crash soong with a
|
|
|
|
// stack overflow.
|
|
|
|
// Note that a boot image config only has a pointer to the parent, not to children. Therefore, we
|
|
|
|
// first go up through the parent chain, and then go back down to visit every code along the path.
|
|
|
|
// `visited` is a map where a key is a boot image name and the value indicates whether the boot
|
|
|
|
// image config is visited. The boot image names are guaranteed to be unique because they come from
|
|
|
|
// `genBootImageConfigRaw` above, which also returns a map and would fail in the first place if the
|
|
|
|
// names were not unique.
|
|
|
|
func calculateDepsRecursive(c *bootImageConfig, targets []android.Target, visited map[string]bool) {
|
|
|
|
if c.extends == nil || visited[c.name] {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if c.extends.extends != nil {
|
|
|
|
calculateDepsRecursive(c.extends, targets, visited)
|
|
|
|
}
|
|
|
|
visited[c.name] = true
|
|
|
|
c.dexPathsDeps = android.Concat(c.extends.dexPathsDeps, c.dexPathsDeps)
|
|
|
|
for i := range targets {
|
|
|
|
c.variants[i].baseImages = android.Concat(c.extends.variants[i].baseImages, android.OutputPaths{c.extends.variants[i].imagePathOnHost})
|
|
|
|
c.variants[i].baseImagesDeps = android.Concat(c.extends.variants[i].baseImagesDeps, c.extends.variants[i].imagesDeps.Paths())
|
|
|
|
c.variants[i].dexLocationsDeps = android.Concat(c.extends.variants[i].dexLocationsDeps, c.variants[i].dexLocationsDeps)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 21:43:06 +01:00
|
|
|
func defaultBootImageConfig(ctx android.PathContext) *bootImageConfig {
|
|
|
|
return genBootImageConfigs(ctx)[frameworkBootImageName]
|
2019-10-23 16:56:32 +02:00
|
|
|
}
|
|
|
|
|
2023-03-06 20:16:48 +01:00
|
|
|
func mainlineBootImageConfig(ctx android.PathContext) *bootImageConfig {
|
|
|
|
return genBootImageConfigs(ctx)[mainlineBootImageName]
|
|
|
|
}
|
|
|
|
|
2023-07-13 12:03:38 +02:00
|
|
|
// isProfileProviderApex returns true if this apex provides a boot image profile.
|
|
|
|
func isProfileProviderApex(ctx android.PathContext, apexName string) bool {
|
|
|
|
for _, config := range genBootImageConfigs(ctx) {
|
|
|
|
for _, profileImport := range config.profileImports {
|
|
|
|
if profileImport == apexName {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-07-21 15:23:52 +02:00
|
|
|
// Apex boot config allows to access build/install paths of apex boot jars without going
|
2021-03-22 17:02:28 +01:00
|
|
|
// through the usual trouble of registering dependencies on those modules and extracting build paths
|
|
|
|
// from those dependencies.
|
2021-07-21 15:23:52 +02:00
|
|
|
type apexBootConfig struct {
|
|
|
|
// A list of apex boot jars.
|
2021-03-22 17:02:28 +01:00
|
|
|
modules android.ConfiguredJarList
|
|
|
|
|
2021-07-21 15:23:52 +02:00
|
|
|
// A list of predefined build paths to apex boot jars. They are configured very early,
|
2021-03-22 17:02:28 +01:00
|
|
|
// 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
|
|
|
|
|
2021-06-02 18:24:22 +02:00
|
|
|
// Map from module name (without prebuilt_ prefix) to the predefined build path.
|
|
|
|
dexPathsByModule map[string]android.WritablePath
|
|
|
|
|
2021-03-22 17:02:28 +01:00
|
|
|
// A list of dex locations (a.k.a. on-device paths) to the boot jars.
|
|
|
|
dexLocations []string
|
|
|
|
}
|
|
|
|
|
2021-07-21 15:23:52 +02:00
|
|
|
var updatableBootConfigKey = android.NewOnceKey("apexBootConfig")
|
2021-03-22 17:02:28 +01:00
|
|
|
|
2021-07-21 15:23:52 +02:00
|
|
|
// Returns apex boot config.
|
|
|
|
func GetApexBootConfig(ctx android.PathContext) apexBootConfig {
|
2021-03-22 17:02:28 +01:00
|
|
|
return ctx.Config().Once(updatableBootConfigKey, func() interface{} {
|
2021-07-21 15:23:52 +02:00
|
|
|
apexBootJars := dexpreopt.GetGlobalConfig(ctx).ApexBootJars
|
2023-07-11 16:03:13 +02:00
|
|
|
dir := android.PathForOutput(ctx, getDexpreoptDirName(ctx), "apex_bootjars")
|
2021-07-21 15:23:52 +02:00
|
|
|
dexPaths := apexBootJars.BuildPaths(ctx, dir)
|
|
|
|
dexPathsByModuleName := apexBootJars.BuildPathsByModule(ctx, dir)
|
2021-03-22 17:02:28 +01:00
|
|
|
|
2021-07-21 15:23:52 +02:00
|
|
|
dexLocations := apexBootJars.DevicePaths(ctx.Config(), android.Android)
|
2021-03-22 17:02:28 +01:00
|
|
|
|
2021-07-21 15:23:52 +02:00
|
|
|
return apexBootConfig{apexBootJars, dexPaths, dexPathsByModuleName, dexLocations}
|
|
|
|
}).(apexBootConfig)
|
2021-03-22 17:02:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
dexPaths := bootImage.dexPathsDeps
|
|
|
|
// The dex locations for all Android variants are identical.
|
|
|
|
dexLocations := bootImage.getAnyAndroidVariant().dexLocationsDeps
|
|
|
|
|
|
|
|
if withUpdatable {
|
2021-07-21 15:23:52 +02:00
|
|
|
// 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...)
|
2021-03-22 17:02:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return dexPaths, dexLocations
|
|
|
|
}
|
|
|
|
|
2019-02-16 08:06:46 +01:00
|
|
|
var defaultBootclasspathKey = android.NewOnceKey("defaultBootclasspath")
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
android.RegisterMakeVarsProvider(pctx, dexpreoptConfigMakevars)
|
|
|
|
}
|
|
|
|
|
|
|
|
func dexpreoptConfigMakevars(ctx android.MakeVarsContext) {
|
2020-07-01 15:31:13 +02:00
|
|
|
ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules.CopyOfApexJarPairs(), ":"))
|
2019-02-16 08:06:46 +01:00
|
|
|
}
|
2023-04-19 16:25:41 +02:00
|
|
|
|
2023-07-11 16:03:13 +02:00
|
|
|
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"
|
2023-04-19 16:25:41 +02:00
|
|
|
}
|