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 (
|
|
|
|
"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
|
|
|
)
|
|
|
|
|
|
|
|
// 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 12:50:00 +08:00
|
|
|
return dexpreoptGlobalConfigRaw(ctx).global
|
|
|
|
}
|
|
|
|
|
|
|
|
type globalConfigAndRaw struct {
|
|
|
|
global dexpreopt.GlobalConfig
|
|
|
|
data []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func dexpreoptGlobalConfigRaw(ctx android.PathContext) globalConfigAndRaw {
|
2019-02-16 15:06:46 +08:00
|
|
|
return ctx.Config().Once(dexpreoptGlobalConfigKey, func() interface{} {
|
|
|
|
if f := ctx.Config().DexpreoptGlobalConfig(); f != "" {
|
|
|
|
ctx.AddNinjaFileDeps(f)
|
2019-05-10 12:50:00 +08:00
|
|
|
globalConfig, data, err := dexpreopt.LoadGlobalConfig(ctx, f)
|
2019-02-16 15:06:46 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-05-10 12:50:00 +08:00
|
|
|
return globalConfigAndRaw{globalConfig, data}
|
2019-02-16 15:06:46 +08: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 12:50:00 +08:00
|
|
|
return globalConfigAndRaw{dexpreopt.GlobalConfig{
|
2019-06-27 01:01:36 +08:00
|
|
|
DisablePreopt: true,
|
|
|
|
DisableGenerateProfile: true,
|
2019-05-10 12:50:00 +08:00
|
|
|
}, nil}
|
2019-02-16 15:06:46 +08:00
|
|
|
})
|
2019-05-10 12:50:00 +08:00
|
|
|
}).(globalConfigAndRaw)
|
2019-02-16 15:06:46 +08: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 12:50:00 +08:00
|
|
|
config.Once(dexpreoptTestGlobalConfigKey, func() interface{} { return globalConfigAndRaw{globalConfig, nil} })
|
2019-02-16 15:06:46 +08: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-22 04:36:53 +08:00
|
|
|
for _, m := range global.UpdatableSystemServerJars {
|
2019-11-27 20:26:49 +08:00
|
|
|
apex, jar := dexpreopt.SplitApexJarPair(m)
|
2019-11-22 04:36:53 +08:00
|
|
|
systemServerClasspathLocations = append(systemServerClasspathLocations,
|
2019-11-27 20:26:49 +08:00
|
|
|
filepath.Join("/apex", apex, "javalib", jar+".jar"))
|
2019-11-22 04:36:53 +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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return targets
|
|
|
|
}
|
|
|
|
|
2019-10-29 10:23:10 +08: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-08 18:51:01 +08:00
|
|
|
// Construct a variant of the global config for dexpreopted bootclasspath jars. The variants differ
|
|
|
|
// in the list of input jars (libcore, framework, or both), in the naming scheme for the dexpreopt
|
|
|
|
// files (ART recognizes "apex" names as special), and whether to include a zip archive.
|
|
|
|
//
|
|
|
|
// 'name' is a string unique for each profile (used in directory names and ninja rule names)
|
|
|
|
// 'stem' is the basename of the image: the resulting filenames are <stem>[-<jar>].{art,oat,vdex}.
|
|
|
|
func getBootImageConfig(ctx android.PathContext, key android.OnceKey, name string, stem string,
|
|
|
|
needZip bool, artApexJarsOnly bool) bootImageConfig {
|
|
|
|
|
2019-10-23 22:56:32 +08:00
|
|
|
return ctx.Config().Once(key, func() interface{} {
|
2019-02-22 23:34:40 +08:00
|
|
|
global := dexpreoptGlobalConfig(ctx)
|
|
|
|
|
2019-07-06 05:38:25 +08:00
|
|
|
artModules := global.ArtApexJars
|
2019-11-08 18:51:01 +08:00
|
|
|
imageModules := artModules
|
2019-02-22 23:34:40 +08:00
|
|
|
|
2019-04-30 16:43:22 +08:00
|
|
|
var bootLocations []string
|
2019-02-22 23:34:40 +08:00
|
|
|
|
2019-07-06 05:38:25 +08:00
|
|
|
for _, m := range artModules {
|
2019-04-30 16:43:22 +08:00
|
|
|
bootLocations = append(bootLocations,
|
2019-10-29 10:23:10 +08:00
|
|
|
filepath.Join("/apex/com.android.art/javalib", stemOf(m)+".jar"))
|
2019-02-22 23:34:40 +08:00
|
|
|
}
|
|
|
|
|
2019-11-08 18:51:01 +08:00
|
|
|
if !artApexJarsOnly {
|
|
|
|
nonFrameworkModules := concat(artModules, global.ProductUpdatableBootModules)
|
|
|
|
frameworkModules := android.RemoveListFromList(global.BootJars, nonFrameworkModules)
|
|
|
|
imageModules = concat(imageModules, frameworkModules)
|
|
|
|
|
|
|
|
for _, m := range frameworkModules {
|
|
|
|
bootLocations = append(bootLocations,
|
|
|
|
filepath.Join("/system/framework", stemOf(m)+".jar"))
|
|
|
|
}
|
2019-04-30 16:43:22 +08:00
|
|
|
}
|
|
|
|
|
2019-02-22 23:34:40 +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.
|
2019-10-29 10:23:10 +08:00
|
|
|
// TODO(b/143682396): use module dependencies instead
|
2019-04-30 16:43:22 +08:00
|
|
|
var bootDexPaths android.WritablePaths
|
|
|
|
for _, m := range imageModules {
|
|
|
|
bootDexPaths = append(bootDexPaths,
|
2019-10-30 19:26:52 +08:00
|
|
|
android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_"+name+"jars_input", m+".jar"))
|
2019-02-22 23:34:40 +08:00
|
|
|
}
|
|
|
|
|
2019-10-30 19:26:52 +08:00
|
|
|
dir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_"+name+"jars")
|
|
|
|
symbolsDir := android.PathForOutput(ctx, ctx.Config().DeviceName(), "dex_"+name+"jars_unstripped")
|
2019-10-23 22:56:32 +08:00
|
|
|
|
|
|
|
var zip android.WritablePath
|
|
|
|
if needZip {
|
2019-11-08 18:51:01 +08:00
|
|
|
zip = dir.Join(ctx, stem+".zip")
|
2019-10-23 22:56:32 +08:00
|
|
|
}
|
2019-02-22 23:34:40 +08:00
|
|
|
|
2019-05-09 06:18:22 +08:00
|
|
|
targets := dexpreoptTargets(ctx)
|
|
|
|
|
2019-06-14 05:44:53 +08:00
|
|
|
imageConfig := bootImageConfig{
|
2019-10-23 22:56:32 +08:00
|
|
|
name: name,
|
2019-11-08 18:51:01 +08:00
|
|
|
stem: stem,
|
2019-04-30 16:43:22 +08:00
|
|
|
modules: imageModules,
|
|
|
|
dexLocations: bootLocations,
|
|
|
|
dexPaths: bootDexPaths,
|
2019-02-22 23:34:40 +08:00
|
|
|
dir: dir,
|
|
|
|
symbolsDir: symbolsDir,
|
2019-05-09 06:18:22 +08:00
|
|
|
targets: targets,
|
2019-06-14 05:44:53 +08:00
|
|
|
images: make(map[android.ArchType]android.OutputPath),
|
|
|
|
imagesDeps: make(map[android.ArchType]android.Paths),
|
2019-10-23 22:56:32 +08:00
|
|
|
zip: zip,
|
2019-02-22 23:34:40 +08:00
|
|
|
}
|
2019-06-14 05:44:53 +08:00
|
|
|
|
|
|
|
for _, target := range targets {
|
|
|
|
imageDir := dir.Join(ctx, "system/framework", target.Arch.ArchType.String())
|
2019-11-08 18:51:01 +08:00
|
|
|
imageConfig.images[target.Arch.ArchType] = imageDir.Join(ctx, stem+".art")
|
2019-06-14 05:44:53 +08:00
|
|
|
|
|
|
|
imagesDeps := make([]android.Path, 0, len(imageConfig.modules)*3)
|
|
|
|
for _, dep := range imageConfig.moduleFiles(ctx, imageDir, ".art", ".oat", ".vdex") {
|
|
|
|
imagesDeps = append(imagesDeps, dep)
|
|
|
|
}
|
|
|
|
imageConfig.imagesDeps[target.Arch.ArchType] = imagesDeps
|
|
|
|
}
|
|
|
|
|
|
|
|
return imageConfig
|
2019-02-22 23:34:40 +08:00
|
|
|
}).(bootImageConfig)
|
|
|
|
}
|
|
|
|
|
2019-11-08 18:51:01 +08:00
|
|
|
// Default config is the one that goes in the system image. It includes both libcore and framework.
|
2019-10-23 22:56:32 +08:00
|
|
|
var defaultBootImageConfigKey = android.NewOnceKey("defaultBootImageConfig")
|
2019-02-22 23:34:40 +08:00
|
|
|
|
2019-10-23 22:56:32 +08:00
|
|
|
func defaultBootImageConfig(ctx android.PathContext) bootImageConfig {
|
2019-11-08 18:51:01 +08:00
|
|
|
return getBootImageConfig(ctx, defaultBootImageConfigKey, "boot", "boot", true, false)
|
2019-10-23 22:56:32 +08:00
|
|
|
}
|
|
|
|
|
2019-11-08 18:51:01 +08:00
|
|
|
// Apex config is used for the JIT-zygote experiment. It includes both libcore and framework, but AOT-compiles only libcore.
|
|
|
|
var apexBootImageConfigKey = android.NewOnceKey("apexBootImageConfig")
|
|
|
|
|
2019-10-23 22:56:32 +08:00
|
|
|
func apexBootImageConfig(ctx android.PathContext) bootImageConfig {
|
2019-11-08 18:51:01 +08:00
|
|
|
return getBootImageConfig(ctx, apexBootImageConfigKey, "apex", "apex", false, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ART config is the one used for the ART apex. It includes only libcore.
|
|
|
|
var artBootImageConfigKey = android.NewOnceKey("artBootImageConfig")
|
|
|
|
|
|
|
|
func artBootImageConfig(ctx android.PathContext) bootImageConfig {
|
|
|
|
return getBootImageConfig(ctx, artBootImageConfigKey, "art", "boot", false, true)
|
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 {
|
|
|
|
global := dexpreoptGlobalConfig(ctx)
|
|
|
|
image := defaultBootImageConfig(ctx)
|
|
|
|
bootclasspath := append(copyOf(image.dexLocations), global.ProductUpdatableBootLocations...)
|
|
|
|
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-02-23 00:57:42 +08:00
|
|
|
ctx.Strict("PRODUCT_DEX2OAT_BOOTCLASSPATH", strings.Join(defaultBootImageConfig(ctx).dexLocations, ":"))
|
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
|
|
|
|
|
|
|
ctx.Strict("DEXPREOPT_BOOT_JARS_MODULES", strings.Join(defaultBootImageConfig(ctx).modules, ":"))
|
2019-02-16 15:06:46 +08:00
|
|
|
}
|