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
|
|
|
)
|
|
|
|
|
|
|
|
// dexpreoptGlobalConfig returns the global dexpreopt.config. It is loaded once the first time it is called for any
|
|
|
|
// ctx.Config(), and returns the same data for all future calls with the same ctx.Config(). A value can be inserted
|
|
|
|
// for tests using setDexpreoptTestGlobalConfig.
|
|
|
|
func dexpreoptGlobalConfig(ctx android.PathContext) dexpreopt.GlobalConfig {
|
2019-05-10 06:50:00 +02:00
|
|
|
return dexpreoptGlobalConfigRaw(ctx).global
|
|
|
|
}
|
|
|
|
|
|
|
|
type globalConfigAndRaw struct {
|
|
|
|
global dexpreopt.GlobalConfig
|
|
|
|
data []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func dexpreoptGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
|
2019-02-16 08:06:46 +01:00
|
|
|
return ctx.Config().Once(dexpreoptGlobalConfigKey, func() interface{} {
|
|
|
|
if f := ctx.Config().DexpreoptGlobalConfig(); f != "" {
|
|
|
|
ctx.AddNinjaFileDeps(f)
|
2019-05-10 06:50:00 +02:00
|
|
|
globalConfig, data, err := dexpreopt.LoadGlobalConfig(ctx, f)
|
2019-02-16 08:06:46 +01:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-05-10 06:50:00 +02:00
|
|
|
return globalConfigAndRaw{globalConfig, data}
|
2019-02-16 08:06:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// No global config filename set, see if there is a test config set
|
|
|
|
return ctx.Config().Once(dexpreoptTestGlobalConfigKey, func() interface{} {
|
|
|
|
// Nope, return a config with preopting disabled
|
2019-05-10 06:50:00 +02:00
|
|
|
return globalConfigAndRaw{dexpreopt.GlobalConfig{
|
2019-06-26 19:01:36 +02:00
|
|
|
DisablePreopt: true,
|
|
|
|
DisableGenerateProfile: true,
|
2019-05-10 06:50:00 +02:00
|
|
|
}, nil}
|
2019-02-16 08:06:46 +01:00
|
|
|
})
|
2019-05-10 06:50:00 +02:00
|
|
|
}).(globalConfigAndRaw)
|
2019-02-16 08:06:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// setDexpreoptTestGlobalConfig sets a GlobalConfig that future calls to dexpreoptGlobalConfig will return. It must
|
|
|
|
// be called before the first call to dexpreoptGlobalConfig for the config.
|
|
|
|
func setDexpreoptTestGlobalConfig(config android.Config, globalConfig dexpreopt.GlobalConfig) {
|
2019-05-10 06:50:00 +02:00
|
|
|
config.Once(dexpreoptTestGlobalConfigKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} })
|
2019-02-16 08:06:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var dexpreoptGlobalConfigKey = android.NewOnceKey("DexpreoptGlobalConfig")
|
|
|
|
var dexpreoptTestGlobalConfigKey = android.NewOnceKey("TestDexpreoptGlobalConfig")
|
|
|
|
|
|
|
|
// 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().
|
|
|
|
func systemServerClasspath(ctx android.PathContext) []string {
|
|
|
|
return ctx.Config().OnceStringSlice(systemServerClasspathKey, func() []string {
|
|
|
|
global := dexpreoptGlobalConfig(ctx)
|
|
|
|
|
|
|
|
var systemServerClasspathLocations []string
|
|
|
|
for _, m := range global.SystemServerJars {
|
|
|
|
systemServerClasspathLocations = append(systemServerClasspathLocations,
|
|
|
|
filepath.Join("/system/framework", m+".jar"))
|
|
|
|
}
|
2019-11-21 21:36:53 +01:00
|
|
|
for _, m := range global.UpdatableSystemServerJars {
|
|
|
|
systemServerClasspathLocations = append(systemServerClasspathLocations,
|
2019-11-27 18:37:46 +01:00
|
|
|
dexpreopt.GetJarLocationFromApexJarPair(m))
|
2019-11-21 21:36:53 +01:00
|
|
|
}
|
2019-02-16 08:06:46 +01:00
|
|
|
return systemServerClasspathLocations
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var systemServerClasspathKey = android.NewOnceKey("systemServerClasspath")
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return targets
|
|
|
|
}
|
|
|
|
|
2019-10-29 03:23:10 +01:00
|
|
|
func stemOf(moduleName string) string {
|
|
|
|
// b/139391334: the stem of framework-minus-apex is framework
|
|
|
|
// This is hard coded here until we find a good way to query the stem
|
|
|
|
// of a module before any other mutators are run
|
|
|
|
if moduleName == "framework-minus-apex" {
|
|
|
|
return "framework"
|
|
|
|
}
|
|
|
|
return moduleName
|
|
|
|
}
|
|
|
|
|
2019-11-27 18:37:46 +01:00
|
|
|
func getJarsFromApexJarPairs(apexJarPairs []string) []string {
|
|
|
|
modules := make([]string, len(apexJarPairs))
|
|
|
|
for i, p := range apexJarPairs {
|
|
|
|
_, jar := dexpreopt.SplitApexJarPair(p)
|
|
|
|
modules[i] = jar
|
|
|
|
}
|
|
|
|
return modules
|
|
|
|
}
|
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
var (
|
|
|
|
bootImageConfigKey = android.NewOnceKey("bootImageConfig")
|
|
|
|
artBootImageName = "art"
|
|
|
|
frameworkBootImageName = "boot"
|
|
|
|
apexBootImageName = "apex"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Construct the global boot image configs.
|
|
|
|
func genBootImageConfigs(ctx android.PathContext) map[string]*bootImageConfig {
|
|
|
|
return ctx.Config().Once(bootImageConfigKey, func() interface{} {
|
2019-11-08 11:51:01 +01:00
|
|
|
|
2019-02-22 16:34:40 +01:00
|
|
|
global := dexpreoptGlobalConfig(ctx)
|
2019-11-08 11:54:21 +01:00
|
|
|
targets := dexpreoptTargets(ctx)
|
|
|
|
deviceDir := android.PathForOutput(ctx, ctx.Config().DeviceName())
|
2019-02-22 16:34:40 +01:00
|
|
|
|
2019-07-05 23:38:25 +02:00
|
|
|
artModules := global.ArtApexJars
|
2019-11-08 11:54:21 +01:00
|
|
|
// In coverage builds ART boot class path jars are instrumented and have additional dependencies.
|
|
|
|
if ctx.Config().IsEnvTrue("EMMA_INSTRUMENT_FRAMEWORK") {
|
|
|
|
artModules = append(artModules, "jacocoagent")
|
|
|
|
}
|
|
|
|
frameworkModules := android.RemoveListFromList(global.BootJars,
|
|
|
|
concat(artModules, getJarsFromApexJarPairs(global.UpdatableBootJars)))
|
2019-02-22 16:34:40 +01:00
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
artSubdir := "apex/com.android.art/javalib"
|
|
|
|
frameworkSubdir := "system/framework"
|
2019-02-22 16:34:40 +01:00
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
var artLocations, frameworkLocations []string
|
2019-07-05 23:38:25 +02:00
|
|
|
for _, m := range artModules {
|
2019-11-08 11:54:21 +01:00
|
|
|
artLocations = append(artLocations, filepath.Join("/"+artSubdir, stemOf(m)+".jar"))
|
|
|
|
}
|
|
|
|
for _, m := range frameworkModules {
|
|
|
|
frameworkLocations = append(frameworkLocations, filepath.Join("/"+frameworkSubdir, stemOf(m)+".jar"))
|
2019-02-22 16:34:40 +01:00
|
|
|
}
|
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
// ART config for the primary boot image in the ART apex.
|
|
|
|
// It includes the Core Libraries.
|
|
|
|
artCfg := bootImageConfig{
|
|
|
|
extension: false,
|
|
|
|
name: artBootImageName,
|
|
|
|
stem: "boot",
|
|
|
|
installSubdir: artSubdir,
|
|
|
|
modules: artModules,
|
|
|
|
dexLocations: artLocations,
|
|
|
|
dexLocationsDeps: artLocations,
|
2019-04-30 10:43:22 +02:00
|
|
|
}
|
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
// Framework config for the boot image extension.
|
|
|
|
// It includes framework libraries and depends on the ART config.
|
|
|
|
frameworkCfg := bootImageConfig{
|
|
|
|
extension: true,
|
|
|
|
name: frameworkBootImageName,
|
|
|
|
stem: "boot",
|
|
|
|
installSubdir: frameworkSubdir,
|
|
|
|
modules: frameworkModules,
|
|
|
|
dexLocations: frameworkLocations,
|
|
|
|
dexLocationsDeps: append(artLocations, frameworkLocations...),
|
2019-02-22 16:34:40 +01:00
|
|
|
}
|
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
// Apex config for the boot image used in the JIT-zygote experiment.
|
|
|
|
// It includes both the Core libraries and framework.
|
|
|
|
apexCfg := bootImageConfig{
|
|
|
|
extension: false,
|
|
|
|
name: apexBootImageName,
|
|
|
|
stem: "apex",
|
|
|
|
installSubdir: frameworkSubdir,
|
|
|
|
modules: concat(artModules, frameworkModules),
|
|
|
|
dexLocations: concat(artLocations, frameworkLocations),
|
|
|
|
dexLocationsDeps: concat(artLocations, frameworkLocations),
|
|
|
|
}
|
2019-10-23 16:56:32 +02:00
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
configs := map[string]*bootImageConfig{
|
|
|
|
artBootImageName: &artCfg,
|
|
|
|
frameworkBootImageName: &frameworkCfg,
|
|
|
|
apexBootImageName: &apexCfg,
|
2019-10-23 16:56:32 +02:00
|
|
|
}
|
2019-02-22 16:34:40 +01:00
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
// common to all configs
|
|
|
|
for _, c := range configs {
|
|
|
|
c.targets = targets
|
2019-05-09 00:18:22 +02:00
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
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
|
|
|
|
imageName := c.firstModuleNameOrStem() + ".art"
|
2019-06-13 23:44:53 +02:00
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
c.imageLocations = []string{c.dir.Join(ctx, c.installSubdir, imageName).String()}
|
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")
|
|
|
|
for _, m := range c.modules {
|
|
|
|
c.dexPaths = append(c.dexPaths, inputDir.Join(ctx, stemOf(m)+".jar"))
|
|
|
|
}
|
|
|
|
c.dexPathsDeps = c.dexPaths
|
|
|
|
|
|
|
|
c.images = make(map[android.ArchType]android.OutputPath)
|
|
|
|
c.imagesDeps = make(map[android.ArchType]android.OutputPaths)
|
|
|
|
|
|
|
|
for _, target := range targets {
|
|
|
|
arch := target.Arch.ArchType
|
|
|
|
imageDir := c.dir.Join(ctx, c.installSubdir, arch.String())
|
|
|
|
c.images[arch] = imageDir.Join(ctx, imageName)
|
|
|
|
c.imagesDeps[arch] = c.moduleFiles(ctx, imageDir, ".art", ".oat", ".vdex")
|
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
|
|
|
}
|
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
// specific to the framework config
|
|
|
|
frameworkCfg.dexPathsDeps = append(artCfg.dexPathsDeps, frameworkCfg.dexPathsDeps...)
|
|
|
|
frameworkCfg.imageLocations = append(artCfg.imageLocations, frameworkCfg.imageLocations...)
|
|
|
|
|
|
|
|
return configs
|
|
|
|
}).(map[string]*bootImageConfig)
|
2019-02-22 16:34:40 +01:00
|
|
|
}
|
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
func artBootImageConfig(ctx android.PathContext) bootImageConfig {
|
|
|
|
return *genBootImageConfigs(ctx)[artBootImageName]
|
|
|
|
}
|
2019-02-22 16:34:40 +01:00
|
|
|
|
2019-10-23 16:56:32 +02:00
|
|
|
func defaultBootImageConfig(ctx android.PathContext) bootImageConfig {
|
2019-11-08 11:54:21 +01:00
|
|
|
return *genBootImageConfigs(ctx)[frameworkBootImageName]
|
2019-10-23 16:56:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func apexBootImageConfig(ctx android.PathContext) bootImageConfig {
|
2019-11-08 11:54:21 +01:00
|
|
|
return *genBootImageConfigs(ctx)[apexBootImageName]
|
2019-10-23 16:56:32 +02:00
|
|
|
}
|
|
|
|
|
2019-02-16 08:06:46 +01:00
|
|
|
func defaultBootclasspath(ctx android.PathContext) []string {
|
|
|
|
return ctx.Config().OnceStringSlice(defaultBootclasspathKey, func() []string {
|
|
|
|
global := dexpreoptGlobalConfig(ctx)
|
|
|
|
image := defaultBootImageConfig(ctx)
|
2019-11-08 11:54:21 +01:00
|
|
|
|
2019-11-27 18:37:46 +01:00
|
|
|
updatableBootclasspath := make([]string, len(global.UpdatableBootJars))
|
|
|
|
for i, p := range global.UpdatableBootJars {
|
|
|
|
updatableBootclasspath[i] = dexpreopt.GetJarLocationFromApexJarPair(p)
|
|
|
|
}
|
2019-11-08 11:54:21 +01:00
|
|
|
|
|
|
|
bootclasspath := append(copyOf(image.dexLocationsDeps), updatableBootclasspath...)
|
2019-02-16 08:06:46 +01: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), ":"))
|
2019-11-08 11:54:21 +01:00
|
|
|
ctx.Strict("PRODUCT_DEX2OAT_BOOTCLASSPATH", strings.Join(defaultBootImageConfig(ctx).dexLocationsDeps, ":"))
|
2019-02-16 08:06:46 +01:00
|
|
|
ctx.Strict("PRODUCT_SYSTEM_SERVER_CLASSPATH", strings.Join(systemServerClasspath(ctx), ":"))
|
2019-02-20 19:40:13 +01:00
|
|
|
|
|
|
|
ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules, ":"))
|
2019-02-16 08:06:46 +01:00
|
|
|
}
|