2019-02-16 15:06:46 +08: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 (
|
2020-02-17 22:55:06 +08:00
|
|
|
"fmt"
|
2019-02-16 15:06:46 +08:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2019-05-10 12:50:00 +08:00
|
|
|
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/dexpreopt"
|
2019-02-16 15:06:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// systemServerClasspath returns the on-device locations of the modules in the system server classpath. It is computed
|
|
|
|
// once the first time it is called for any ctx.Config(), and returns the same slice for all future calls with the same
|
|
|
|
// ctx.Config().
|
2019-12-03 23:39:23 +08:00
|
|
|
func systemServerClasspath(ctx android.MakeVarsContext) []string {
|
2019-02-16 15:06:46 +08:00
|
|
|
return ctx.Config().OnceStringSlice(systemServerClasspathKey, func() []string {
|
2020-01-21 02:12:23 +08:00
|
|
|
global := dexpreopt.GetGlobalConfig(ctx)
|
2019-02-16 15:06:46 +08:00
|
|
|
var systemServerClasspathLocations []string
|
2020-03-11 19:59:34 +08:00
|
|
|
nonUpdatable := dexpreopt.NonUpdatableSystemServerJars(ctx, global)
|
|
|
|
// 1) Non-updatable jars.
|
|
|
|
for _, m := range nonUpdatable {
|
2019-02-16 15:06:46 +08:00
|
|
|
systemServerClasspathLocations = append(systemServerClasspathLocations,
|
|
|
|
filepath.Join("/system/framework", m+".jar"))
|
|
|
|
}
|
2020-02-17 22:55:06 +08:00
|
|
|
// 2) The jars that are from an updatable apex.
|
2020-07-01 21:31:13 +08:00
|
|
|
systemServerClasspathLocations = append(systemServerClasspathLocations,
|
|
|
|
global.UpdatableSystemServerJars.DevicePaths(ctx.Config(), android.Android)...)
|
|
|
|
if len(systemServerClasspathLocations) != len(global.SystemServerJars)+global.UpdatableSystemServerJars.Len() {
|
2020-02-17 22:55:06 +08:00
|
|
|
panic(fmt.Errorf("Wrong number of system server jars, got %d, expected %d",
|
|
|
|
len(systemServerClasspathLocations),
|
2020-07-01 21:31:13 +08:00
|
|
|
len(global.SystemServerJars)+global.UpdatableSystemServerJars.Len()))
|
2020-02-17 22:55:06 +08:00
|
|
|
}
|
2019-02-16 15:06:46 +08:00
|
|
|
return systemServerClasspathLocations
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var systemServerClasspathKey = android.NewOnceKey("systemServerClasspath")
|
|
|
|
|
2019-05-09 06:18:22 +08: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-18 05:45:31 +08:00
|
|
|
for _, target := range ctx.Config().Targets[android.Android] {
|
2019-05-09 06:18:22 +08:00
|
|
|
if target.NativeBridge == android.NativeBridgeDisabled {
|
|
|
|
targets = append(targets, target)
|
|
|
|
}
|
|
|
|
}
|
2020-02-14 00:00:45 +08:00
|
|
|
// We may also need the images on host in order to run host-based tests.
|
|
|
|
for _, target := range ctx.Config().Targets[android.BuildOs] {
|
|
|
|
targets = append(targets, target)
|
|
|
|
}
|
2019-05-09 06:18:22 +08:00
|
|
|
|
|
|
|
return targets
|
|
|
|
}
|
|
|
|
|
2019-11-08 18:54:21 +08:00
|
|
|
var (
|
2020-02-10 23:29:28 +08:00
|
|
|
bootImageConfigKey = android.NewOnceKey("bootImageConfig")
|
|
|
|
artBootImageName = "art"
|
|
|
|
frameworkBootImageName = "boot"
|
2019-11-08 18:54:21 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Construct the global boot image configs.
|
|
|
|
func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
|
|
|
|
return ctx.Config().Once(bootImageConfigKey, func() interface{} {
|
2019-11-08 18:51:01 +08:00
|
|
|
|
2020-01-21 02:12:23 +08:00
|
|
|
global := dexpreopt.GetGlobalConfig(ctx)
|
2019-11-08 18:54:21 +08:00
|
|
|
targets := dexpreoptTargets(ctx)
|
|
|
|
deviceDir := android.PathForOutput(ctx, ctx.Config().DeviceName())
|
2019-02-22 23:34:40 +08:00
|
|
|
|
2020-10-24 01:26:03 +08:00
|
|
|
artModules := global.ArtApexJars
|
|
|
|
frameworkModules := global.BootJars.RemoveList(artModules)
|
2019-02-22 23:34:40 +08:00
|
|
|
|
2020-10-15 06:29:49 +08:00
|
|
|
artSubdir := "apex/art_boot_images/javalib"
|
2019-11-08 18:54:21 +08:00
|
|
|
frameworkSubdir := "system/framework"
|
2019-02-22 23:34:40 +08:00
|
|
|
|
2019-11-08 18:54:21 +08:00
|
|
|
// ART config for the primary boot image in the ART apex.
|
|
|
|
// It includes the Core Libraries.
|
|
|
|
artCfg := bootImageConfig{
|
2020-03-31 00:24:13 +08:00
|
|
|
name: artBootImageName,
|
|
|
|
stem: "boot",
|
|
|
|
installSubdir: artSubdir,
|
|
|
|
modules: artModules,
|
2019-04-30 16:43:22 +08:00
|
|
|
}
|
|
|
|
|
2019-11-08 18:54:21 +08:00
|
|
|
// Framework config for the boot image extension.
|
2019-12-19 01:32:33 +08:00
|
|
|
// It includes framework libraries and depends on the ART config.
|
2019-11-08 18:54:21 +08:00
|
|
|
frameworkCfg := bootImageConfig{
|
2020-03-31 00:24:13 +08:00
|
|
|
extends: &artCfg,
|
|
|
|
name: frameworkBootImageName,
|
|
|
|
stem: "boot",
|
|
|
|
installSubdir: frameworkSubdir,
|
|
|
|
modules: frameworkModules,
|
2019-02-22 23:34:40 +08:00
|
|
|
}
|
|
|
|
|
2019-11-08 18:54:21 +08:00
|
|
|
configs := map[string]*bootImageConfig{
|
2020-02-10 23:29:28 +08:00
|
|
|
artBootImageName: &artCfg,
|
|
|
|
frameworkBootImageName: &frameworkCfg,
|
2019-10-23 22:56:32 +08:00
|
|
|
}
|
2019-02-22 23:34:40 +08:00
|
|
|
|
2019-11-08 18:54:21 +08:00
|
|
|
// common to all configs
|
|
|
|
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-12 01:06:15 +08:00
|
|
|
imageName := c.firstModuleNameOrStem(ctx) + ".art"
|
2019-06-14 05:44:53 +08:00
|
|
|
|
2019-11-08 18:54:21 +08: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 21:31:13 +08:00
|
|
|
c.dexPaths = c.modules.BuildPaths(ctx, inputDir)
|
2019-11-08 18:54:21 +08:00
|
|
|
c.dexPathsDeps = c.dexPaths
|
|
|
|
|
2020-02-19 04:43:06 +08:00
|
|
|
// Create target-specific variants.
|
2019-11-08 18:54:21 +08:00
|
|
|
for _, target := range targets {
|
|
|
|
arch := target.Arch.ArchType
|
2020-02-14 00:00:45 +08:00
|
|
|
imageDir := c.dir.Join(ctx, target.Os.String(), c.installSubdir, arch.String())
|
2020-02-19 04:43:06 +08:00
|
|
|
variant := &bootImageVariant{
|
|
|
|
bootImageConfig: c,
|
|
|
|
target: target,
|
|
|
|
images: imageDir.Join(ctx, imageName),
|
|
|
|
imagesDeps: c.moduleFiles(ctx, imageDir, ".art", ".oat", ".vdex"),
|
2020-07-01 21:31:13 +08:00
|
|
|
dexLocations: c.modules.DevicePaths(ctx.Config(), target.Os),
|
2020-03-31 00:24:13 +08:00
|
|
|
}
|
|
|
|
variant.dexLocationsDeps = variant.dexLocations
|
2020-02-19 04:43:06 +08:00
|
|
|
c.variants = append(c.variants, variant)
|
2019-06-14 05:44:53 +08:00
|
|
|
}
|
2019-12-05 05:16:01 +08:00
|
|
|
|
|
|
|
c.zip = c.dir.Join(ctx, c.name+".zip")
|
2019-06-14 05:44:53 +08:00
|
|
|
}
|
|
|
|
|
2019-12-19 01:32:33 +08:00
|
|
|
// specific to the framework config
|
|
|
|
frameworkCfg.dexPathsDeps = append(artCfg.dexPathsDeps, frameworkCfg.dexPathsDeps...)
|
2020-02-19 04:43:06 +08:00
|
|
|
for i := range targets {
|
|
|
|
frameworkCfg.variants[i].primaryImages = artCfg.variants[i].images
|
2020-03-31 00:24:13 +08:00
|
|
|
frameworkCfg.variants[i].dexLocationsDeps = append(artCfg.variants[i].dexLocations, frameworkCfg.variants[i].dexLocationsDeps...)
|
2020-02-19 04:43:06 +08:00
|
|
|
}
|
2019-12-19 01:32:33 +08:00
|
|
|
|
2019-11-08 18:54:21 +08:00
|
|
|
return configs
|
|
|
|
}).(map[string]*bootImageConfig)
|
2019-02-22 23:34:40 +08:00
|
|
|
}
|
|
|
|
|
2020-02-19 04:43:06 +08:00
|
|
|
func artBootImageConfig(ctx android.PathContext) *bootImageConfig {
|
|
|
|
return genBootImageConfigs(ctx)[artBootImageName]
|
2019-11-08 18:54:21 +08:00
|
|
|
}
|
2019-02-22 23:34:40 +08:00
|
|
|
|
2020-02-19 04:43:06 +08:00
|
|
|
func defaultBootImageConfig(ctx android.PathContext) *bootImageConfig {
|
|
|
|
return genBootImageConfigs(ctx)[frameworkBootImageName]
|
2019-10-23 22:56:32 +08:00
|
|
|
}
|
|
|
|
|
2019-02-16 15:06:46 +08:00
|
|
|
func defaultBootclasspath(ctx android.PathContext) []string {
|
|
|
|
return ctx.Config().OnceStringSlice(defaultBootclasspathKey, func() []string {
|
2020-01-21 02:12:23 +08:00
|
|
|
global := dexpreopt.GetGlobalConfig(ctx)
|
2019-02-16 15:06:46 +08:00
|
|
|
image := defaultBootImageConfig(ctx)
|
2019-11-08 18:54:21 +08:00
|
|
|
|
2020-07-01 21:31:13 +08:00
|
|
|
updatableBootclasspath := global.UpdatableBootJars.DevicePaths(ctx.Config(), android.Android)
|
2019-11-08 18:54:21 +08:00
|
|
|
|
2020-03-31 00:24:13 +08:00
|
|
|
bootclasspath := append(copyOf(image.getAnyAndroidVariant().dexLocationsDeps), updatableBootclasspath...)
|
2019-02-16 15:06:46 +08:00
|
|
|
return bootclasspath
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var defaultBootclasspathKey = android.NewOnceKey("defaultBootclasspath")
|
|
|
|
|
|
|
|
var copyOf = android.CopyOf
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
android.RegisterMakeVarsProvider(pctx, dexpreoptConfigMakevars)
|
|
|
|
}
|
|
|
|
|
|
|
|
func dexpreoptConfigMakevars(ctx android.MakeVarsContext) {
|
|
|
|
ctx.Strict("PRODUCT_BOOTCLASSPATH", strings.Join(defaultBootclasspath(ctx), ":"))
|
2020-03-31 00:24:13 +08:00
|
|
|
ctx.Strict("PRODUCT_DEX2OAT_BOOTCLASSPATH", strings.Join(defaultBootImageConfig(ctx).getAnyAndroidVariant().dexLocationsDeps, ":"))
|
2019-02-16 15:06:46 +08:00
|
|
|
ctx.Strict("PRODUCT_SYSTEM_SERVER_CLASSPATH", strings.Join(systemServerClasspath(ctx), ":"))
|
2019-02-21 02:40:13 +08:00
|
|
|
|
2020-07-01 21:31:13 +08:00
|
|
|
ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules.CopyOfApexJarPairs(), ":"))
|
2019-02-16 15:06:46 +08:00
|
|
|
}
|