2018-11-12 19:13:39 +01:00
|
|
|
// Copyright 2018 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.
|
|
|
|
|
|
|
|
// The dexpreopt package converts a global dexpreopt config and a module dexpreopt config into rules to perform
|
2019-10-18 15:51:38 +02:00
|
|
|
// dexpreopting.
|
2018-11-12 19:13:39 +01:00
|
|
|
//
|
|
|
|
// It is used in two places; in the dexpeopt_gen binary for modules defined in Make, and directly linked into Soong.
|
|
|
|
//
|
|
|
|
// For Make modules it is built into the dexpreopt_gen binary, which is executed as a Make rule using global config and
|
|
|
|
// module config specified in JSON files. The binary writes out two shell scripts, only updating them if they have
|
|
|
|
// changed. One script takes an APK or JAR as an input and produces a zip file containing any outputs of preopting,
|
|
|
|
// in the location they should be on the device. The Make build rules will unzip the zip file into $(PRODUCT_OUT) when
|
|
|
|
// installing the APK, which will install the preopt outputs into $(PRODUCT_OUT)/system or $(PRODUCT_OUT)/system_other
|
2019-10-18 15:51:38 +02:00
|
|
|
// as necessary. The zip file may be empty if preopting was disabled for any reason.
|
2018-11-12 19:13:39 +01:00
|
|
|
//
|
|
|
|
// The intermediate shell scripts allow changes to this package or to the global config to regenerate the shell scripts
|
|
|
|
// but only require re-executing preopting if the script has changed.
|
|
|
|
//
|
|
|
|
// For Soong modules this package is linked directly into Soong and run from the java package. It generates the same
|
|
|
|
// commands as for make, using athe same global config JSON file used by make, but using a module config structure
|
|
|
|
// provided by Soong. The generated commands are then converted into Soong rule and written directly to the ninja file,
|
|
|
|
// with no extra shell scripts involved.
|
|
|
|
package dexpreopt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2019-02-15 19:39:37 +01:00
|
|
|
"runtime"
|
2018-11-12 19:13:39 +01:00
|
|
|
"strings"
|
|
|
|
|
2019-01-31 02:32:39 +01:00
|
|
|
"android/soong/android"
|
|
|
|
|
2019-12-03 16:39:23 +01:00
|
|
|
"github.com/google/blueprint"
|
2018-11-12 19:13:39 +01:00
|
|
|
"github.com/google/blueprint/pathtools"
|
|
|
|
)
|
|
|
|
|
|
|
|
const SystemPartition = "/system/"
|
|
|
|
const SystemOtherPartition = "/system_other/"
|
|
|
|
|
2019-12-03 16:39:23 +01:00
|
|
|
type dependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
var SystemServerDepTag = dependencyTag{name: "system-server-dep"}
|
|
|
|
var SystemServerForcedDepTag = dependencyTag{name: "system-server-forced-dep"}
|
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
// GenerateDexpreoptRule generates a set of commands that will preopt a module based on a GlobalConfig and a
|
|
|
|
// ModuleConfig. The produced files and their install locations will be available through rule.Installs().
|
2020-01-31 18:44:54 +01:00
|
|
|
func GenerateDexpreoptRule(ctx android.PathContext, globalSoong *GlobalSoongConfig,
|
|
|
|
global *GlobalConfig, module *ModuleConfig) (rule *android.RuleBuilder, err error) {
|
2019-02-15 19:39:37 +01:00
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
2019-02-15 19:39:37 +01:00
|
|
|
if _, ok := r.(runtime.Error); ok {
|
|
|
|
panic(r)
|
|
|
|
} else if e, ok := r.(error); ok {
|
2018-11-12 19:13:39 +01:00
|
|
|
err = e
|
|
|
|
rule = nil
|
|
|
|
} else {
|
|
|
|
panic(r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2019-02-02 01:42:32 +01:00
|
|
|
rule = android.NewRuleBuilder()
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-02-15 19:39:37 +01:00
|
|
|
generateProfile := module.ProfileClassListing.Valid() && !global.DisableGenerateProfile
|
2019-07-24 14:19:29 +02:00
|
|
|
generateBootProfile := module.ProfileBootListing.Valid() && !global.DisableGenerateProfile
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-02-15 19:39:37 +01:00
|
|
|
var profile android.WritablePath
|
2018-11-12 19:13:39 +01:00
|
|
|
if generateProfile {
|
2020-01-10 21:32:59 +01:00
|
|
|
profile = profileCommand(ctx, globalSoong, global, module, rule)
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
2019-07-24 14:19:29 +02:00
|
|
|
if generateBootProfile {
|
2020-01-10 21:32:59 +01:00
|
|
|
bootProfileCommand(ctx, globalSoong, global, module, rule)
|
2019-07-24 14:19:29 +02:00
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-12-03 16:39:23 +01:00
|
|
|
if !dexpreoptDisabled(ctx, global, module) {
|
2019-01-09 02:38:37 +01:00
|
|
|
// Don't preopt individual boot jars, they will be preopted together.
|
|
|
|
if !contains(global.BootJars, module.Name) {
|
|
|
|
appImage := (generateProfile || module.ForceCreateAppImage || global.DefaultAppImages) &&
|
|
|
|
!module.NoCreateAppImage
|
|
|
|
|
|
|
|
generateDM := shouldGenerateDM(module, global)
|
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
for archIdx, _ := range module.Archs {
|
2020-01-10 21:32:59 +01:00
|
|
|
dexpreoptCommand(ctx, globalSoong, global, module, rule, archIdx, profile, appImage, generateDM)
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rule, nil
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func dexpreoptDisabled(ctx android.PathContext, global *GlobalConfig, module *ModuleConfig) bool {
|
2019-01-09 02:38:37 +01:00
|
|
|
if contains(global.DisablePreoptModules, module.Name) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-11-27 13:26:49 +01:00
|
|
|
// Don't preopt system server jars that are updatable.
|
|
|
|
for _, p := range global.UpdatableSystemServerJars {
|
2020-02-10 16:29:28 +01:00
|
|
|
if _, jar := android.SplitApexJarPair(p); jar == module.Name {
|
2019-11-27 13:26:49 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 16:39:23 +01:00
|
|
|
// Don't preopt system server jars that are not Soong modules.
|
|
|
|
if android.InList(module.Name, NonUpdatableSystemServerJars(ctx, global)) {
|
|
|
|
if _, ok := ctx.(android.ModuleContext); !ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-09 02:38:37 +01:00
|
|
|
// If OnlyPreoptBootImageAndSystemServer=true and module is not in boot class path skip
|
|
|
|
// Also preopt system server jars since selinux prevents system server from loading anything from
|
|
|
|
// /data. If we don't do this they will need to be extracted which is not favorable for RAM usage
|
|
|
|
// or performance. If PreoptExtractedApk is true, we ignore the only preopt boot image options.
|
|
|
|
if global.OnlyPreoptBootImageAndSystemServer && !contains(global.BootJars, module.Name) &&
|
|
|
|
!contains(global.SystemServerJars, module.Name) && !module.PreoptExtractedApk {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func profileCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig,
|
|
|
|
module *ModuleConfig, rule *android.RuleBuilder) android.WritablePath {
|
2019-02-15 19:39:37 +01:00
|
|
|
|
|
|
|
profilePath := module.BuildPath.InSameDir(ctx, "profile.prof")
|
2018-11-12 19:13:39 +01:00
|
|
|
profileInstalledPath := module.DexLocation + ".prof"
|
|
|
|
|
|
|
|
if !module.ProfileIsTextListing {
|
|
|
|
rule.Command().FlagWithOutput("touch ", profilePath)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := rule.Command().
|
|
|
|
Text(`ANDROID_LOG_TAGS="*:e"`).
|
2020-01-10 21:32:59 +01:00
|
|
|
Tool(globalSoong.Profman)
|
2018-11-12 19:13:39 +01:00
|
|
|
|
|
|
|
if module.ProfileIsTextListing {
|
|
|
|
// The profile is a test listing of classes (used for framework jars).
|
|
|
|
// We need to generate the actual binary profile before being able to compile.
|
2019-02-15 19:39:37 +01:00
|
|
|
cmd.FlagWithInput("--create-profile-from=", module.ProfileClassListing.Path())
|
2018-11-12 19:13:39 +01:00
|
|
|
} else {
|
|
|
|
// The profile is binary profile (used for apps). Run it through profman to
|
|
|
|
// ensure the profile keys match the apk.
|
|
|
|
cmd.
|
|
|
|
Flag("--copy-and-update-profile-key").
|
2019-02-15 19:39:37 +01:00
|
|
|
FlagWithInput("--profile-file=", module.ProfileClassListing.Path())
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.
|
|
|
|
FlagWithInput("--apk=", module.DexPath).
|
|
|
|
Flag("--dex-location="+module.DexLocation).
|
|
|
|
FlagWithOutput("--reference-profile-file=", profilePath)
|
|
|
|
|
|
|
|
if !module.ProfileIsTextListing {
|
|
|
|
cmd.Text(fmt.Sprintf(`|| echo "Profile out of date for %s"`, module.DexPath))
|
|
|
|
}
|
|
|
|
rule.Install(profilePath, profileInstalledPath)
|
|
|
|
|
|
|
|
return profilePath
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func bootProfileCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig,
|
|
|
|
module *ModuleConfig, rule *android.RuleBuilder) android.WritablePath {
|
2019-07-24 14:19:29 +02:00
|
|
|
|
|
|
|
profilePath := module.BuildPath.InSameDir(ctx, "profile.bprof")
|
|
|
|
profileInstalledPath := module.DexLocation + ".bprof"
|
|
|
|
|
|
|
|
if !module.ProfileIsTextListing {
|
|
|
|
rule.Command().FlagWithOutput("touch ", profilePath)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := rule.Command().
|
|
|
|
Text(`ANDROID_LOG_TAGS="*:e"`).
|
2020-01-10 21:32:59 +01:00
|
|
|
Tool(globalSoong.Profman)
|
2019-07-24 14:19:29 +02:00
|
|
|
|
|
|
|
// The profile is a test listing of methods.
|
|
|
|
// We need to generate the actual binary profile.
|
|
|
|
cmd.FlagWithInput("--create-profile-from=", module.ProfileBootListing.Path())
|
|
|
|
|
|
|
|
cmd.
|
|
|
|
Flag("--generate-boot-profile").
|
|
|
|
FlagWithInput("--apk=", module.DexPath).
|
|
|
|
Flag("--dex-location="+module.DexLocation).
|
|
|
|
FlagWithOutput("--reference-profile-file=", profilePath)
|
|
|
|
|
|
|
|
if !module.ProfileIsTextListing {
|
|
|
|
cmd.Text(fmt.Sprintf(`|| echo "Profile out of date for %s"`, module.DexPath))
|
|
|
|
}
|
|
|
|
rule.Install(profilePath, profileInstalledPath)
|
|
|
|
|
|
|
|
return profilePath
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func dexpreoptCommand(ctx android.PathContext, globalSoong *GlobalSoongConfig, global *GlobalConfig,
|
|
|
|
module *ModuleConfig, rule *android.RuleBuilder, archIdx int, profile android.WritablePath,
|
2020-01-10 21:32:59 +01:00
|
|
|
appImage bool, generateDM bool) {
|
2019-11-08 11:54:21 +01:00
|
|
|
|
|
|
|
arch := module.Archs[archIdx]
|
2018-11-12 19:13:39 +01:00
|
|
|
|
|
|
|
// HACK: make soname in Soong-generated .odex files match Make.
|
|
|
|
base := filepath.Base(module.DexLocation)
|
|
|
|
if filepath.Ext(base) == ".jar" {
|
|
|
|
base = "javalib.jar"
|
|
|
|
} else if filepath.Ext(base) == ".apk" {
|
|
|
|
base = "package.apk"
|
|
|
|
}
|
|
|
|
|
|
|
|
toOdexPath := func(path string) string {
|
|
|
|
return filepath.Join(
|
|
|
|
filepath.Dir(path),
|
|
|
|
"oat",
|
2019-02-12 00:11:14 +01:00
|
|
|
arch.String(),
|
2018-11-12 19:13:39 +01:00
|
|
|
pathtools.ReplaceExtension(filepath.Base(path), "odex"))
|
|
|
|
}
|
|
|
|
|
2019-02-15 19:39:37 +01:00
|
|
|
odexPath := module.BuildPath.InSameDir(ctx, "oat", arch.String(), pathtools.ReplaceExtension(base, "odex"))
|
2018-11-12 19:13:39 +01:00
|
|
|
odexInstallPath := toOdexPath(module.DexLocation)
|
|
|
|
if odexOnSystemOther(module, global) {
|
2019-10-03 15:18:45 +02:00
|
|
|
odexInstallPath = filepath.Join(SystemOtherPartition, odexInstallPath)
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2019-02-15 19:39:37 +01:00
|
|
|
vdexPath := odexPath.ReplaceExtension(ctx, "vdex")
|
2018-11-12 19:13:39 +01:00
|
|
|
vdexInstallPath := pathtools.ReplaceExtension(odexInstallPath, "vdex")
|
|
|
|
|
2019-02-15 19:39:37 +01:00
|
|
|
invocationPath := odexPath.ReplaceExtension(ctx, "invocation")
|
2018-12-19 00:16:26 +01:00
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
// The class loader context using paths in the build
|
2019-02-15 19:39:37 +01:00
|
|
|
var classLoaderContextHost android.Paths
|
2018-11-12 19:13:39 +01:00
|
|
|
|
|
|
|
// The class loader context using paths as they will be on the device
|
|
|
|
var classLoaderContextTarget []string
|
|
|
|
|
|
|
|
// Extra paths that will be appended to the class loader if the APK manifest has targetSdkVersion < 28
|
2019-02-15 19:39:37 +01:00
|
|
|
var conditionalClassLoaderContextHost28 android.Paths
|
2018-12-18 15:15:12 +01:00
|
|
|
var conditionalClassLoaderContextTarget28 []string
|
|
|
|
|
|
|
|
// Extra paths that will be appended to the class loader if the APK manifest has targetSdkVersion < 29
|
2019-02-15 19:39:37 +01:00
|
|
|
var conditionalClassLoaderContextHost29 android.Paths
|
2018-12-18 15:15:12 +01:00
|
|
|
var conditionalClassLoaderContextTarget29 []string
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-12-03 16:39:23 +01:00
|
|
|
var classLoaderContextHostString, classLoaderContextDeviceString string
|
|
|
|
var classLoaderDeps android.Paths
|
2019-02-15 19:39:37 +01:00
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
if module.EnforceUsesLibraries {
|
2019-05-16 21:28:22 +02:00
|
|
|
usesLibs := append(copyOf(module.UsesLibraries), module.PresentOptionalUsesLibraries...)
|
2018-11-12 19:13:39 +01:00
|
|
|
|
|
|
|
// Create class loader context for dex2oat from uses libraries and filtered optional libraries
|
2019-05-16 21:28:22 +02:00
|
|
|
for _, l := range usesLibs {
|
2018-11-12 19:13:39 +01:00
|
|
|
|
|
|
|
classLoaderContextHost = append(classLoaderContextHost,
|
|
|
|
pathForLibrary(module, l))
|
|
|
|
classLoaderContextTarget = append(classLoaderContextTarget,
|
|
|
|
filepath.Join("/system/framework", l+".jar"))
|
|
|
|
}
|
|
|
|
|
|
|
|
const httpLegacy = "org.apache.http.legacy"
|
|
|
|
const httpLegacyImpl = "org.apache.http.legacy.impl"
|
|
|
|
|
2019-05-22 19:21:09 +02:00
|
|
|
// org.apache.http.legacy contains classes that were in the default classpath until API 28. If the
|
|
|
|
// targetSdkVersion in the manifest or APK is < 28, and the module does not explicitly depend on
|
|
|
|
// org.apache.http.legacy, then implicitly add the classes to the classpath for dexpreopt. One the
|
|
|
|
// device the classes will be in a file called org.apache.http.legacy.impl.jar.
|
2019-05-16 21:28:22 +02:00
|
|
|
module.LibraryPaths[httpLegacyImpl] = module.LibraryPaths[httpLegacy]
|
|
|
|
|
|
|
|
if !contains(module.UsesLibraries, httpLegacy) && !contains(module.PresentOptionalUsesLibraries, httpLegacy) {
|
2018-12-18 15:15:12 +01:00
|
|
|
conditionalClassLoaderContextHost28 = append(conditionalClassLoaderContextHost28,
|
2018-11-12 19:13:39 +01:00
|
|
|
pathForLibrary(module, httpLegacyImpl))
|
2018-12-18 15:15:12 +01:00
|
|
|
conditionalClassLoaderContextTarget28 = append(conditionalClassLoaderContextTarget28,
|
2018-11-12 19:13:39 +01:00
|
|
|
filepath.Join("/system/framework", httpLegacyImpl+".jar"))
|
|
|
|
}
|
2018-12-18 15:15:12 +01:00
|
|
|
|
|
|
|
const hidlBase = "android.hidl.base-V1.0-java"
|
|
|
|
const hidlManager = "android.hidl.manager-V1.0-java"
|
|
|
|
|
2019-05-22 19:21:09 +02:00
|
|
|
// android.hidl.base-V1.0-java and android.hidl.manager-V1.0 contain classes that were in the default
|
|
|
|
// classpath until API 29. If the targetSdkVersion in the manifest or APK is < 29 then implicitly add
|
|
|
|
// the classes to the classpath for dexpreopt.
|
2018-12-18 15:15:12 +01:00
|
|
|
conditionalClassLoaderContextHost29 = append(conditionalClassLoaderContextHost29,
|
2018-12-19 00:16:26 +01:00
|
|
|
pathForLibrary(module, hidlManager))
|
2018-12-18 15:15:12 +01:00
|
|
|
conditionalClassLoaderContextTarget29 = append(conditionalClassLoaderContextTarget29,
|
|
|
|
filepath.Join("/system/framework", hidlManager+".jar"))
|
|
|
|
conditionalClassLoaderContextHost29 = append(conditionalClassLoaderContextHost29,
|
2018-12-19 00:16:26 +01:00
|
|
|
pathForLibrary(module, hidlBase))
|
2018-12-18 15:15:12 +01:00
|
|
|
conditionalClassLoaderContextTarget29 = append(conditionalClassLoaderContextTarget29,
|
|
|
|
filepath.Join("/system/framework", hidlBase+".jar"))
|
2019-02-15 19:39:37 +01:00
|
|
|
|
|
|
|
classLoaderContextHostString = strings.Join(classLoaderContextHost.Strings(), ":")
|
2019-12-03 16:39:23 +01:00
|
|
|
} else if android.InList(module.Name, NonUpdatableSystemServerJars(ctx, global)) {
|
|
|
|
// We expect that all dexpreopted system server jars are Soong modules.
|
|
|
|
mctx, isModule := ctx.(android.ModuleContext)
|
|
|
|
if !isModule {
|
|
|
|
panic("Cannot dexpreopt system server jar that is not a soong module.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// System server jars should be dexpreopted together: class loader context of each jar
|
|
|
|
// should include preceding jars (which can be found as dependencies of the current jar
|
|
|
|
// with a special tag).
|
|
|
|
var jarsOnHost android.Paths
|
|
|
|
var jarsOnDevice []string
|
|
|
|
mctx.VisitDirectDepsWithTag(SystemServerDepTag, func(dep android.Module) {
|
|
|
|
depName := mctx.OtherModuleName(dep)
|
|
|
|
if jar, ok := dep.(interface{ DexJar() android.Path }); ok {
|
|
|
|
jarsOnHost = append(jarsOnHost, jar.DexJar())
|
|
|
|
jarsOnDevice = append(jarsOnDevice, "/system/framework/"+depName+".jar")
|
|
|
|
} else {
|
|
|
|
mctx.ModuleErrorf("module \"%s\" is not a jar", depName)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
classLoaderContextHostString = strings.Join(jarsOnHost.Strings(), ":")
|
|
|
|
classLoaderContextDeviceString = strings.Join(jarsOnDevice, ":")
|
|
|
|
classLoaderDeps = jarsOnHost
|
2018-11-12 19:13:39 +01:00
|
|
|
} else {
|
|
|
|
// Pass special class loader context to skip the classpath and collision check.
|
|
|
|
// This will get removed once LOCAL_USES_LIBRARIES is enforced.
|
|
|
|
// Right now LOCAL_USES_LIBRARIES is opt in, for the case where it's not specified we still default
|
|
|
|
// to the &.
|
2019-02-15 19:39:37 +01:00
|
|
|
classLoaderContextHostString = `\&`
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2019-02-15 19:39:37 +01:00
|
|
|
rule.Command().FlagWithArg("mkdir -p ", filepath.Dir(odexPath.String()))
|
2018-11-12 19:13:39 +01:00
|
|
|
rule.Command().FlagWithOutput("rm -f ", odexPath)
|
|
|
|
// Set values in the environment of the rule. These may be modified by construct_context.sh.
|
2019-12-03 16:39:23 +01:00
|
|
|
if classLoaderContextHostString == `\&` {
|
|
|
|
rule.Command().Text(`class_loader_context_arg=--class-loader-context=\&`)
|
|
|
|
rule.Command().Text(`stored_class_loader_context_arg=""`)
|
|
|
|
} else {
|
|
|
|
rule.Command().Text("class_loader_context_arg=--class-loader-context=PCL[" + classLoaderContextHostString + "]")
|
|
|
|
rule.Command().Text("stored_class_loader_context_arg=--stored-class-loader-context=PCL[" + classLoaderContextDeviceString + "]")
|
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
|
|
|
|
if module.EnforceUsesLibraries {
|
2019-05-22 19:21:09 +02:00
|
|
|
if module.ManifestPath != nil {
|
|
|
|
rule.Command().Text(`target_sdk_version="$(`).
|
2020-01-10 21:32:59 +01:00
|
|
|
Tool(globalSoong.ManifestCheck).
|
2019-05-22 19:21:09 +02:00
|
|
|
Flag("--extract-target-sdk-version").
|
|
|
|
Input(module.ManifestPath).
|
|
|
|
Text(`)"`)
|
|
|
|
} else {
|
|
|
|
// No manifest to extract targetSdkVersion from, hope that DexJar is an APK
|
|
|
|
rule.Command().Text(`target_sdk_version="$(`).
|
2020-01-10 21:32:59 +01:00
|
|
|
Tool(globalSoong.Aapt).
|
2019-05-22 19:21:09 +02:00
|
|
|
Flag("dump badging").
|
|
|
|
Input(module.DexPath).
|
|
|
|
Text(`| grep "targetSdkVersion" | sed -n "s/targetSdkVersion:'\(.*\)'/\1/p"`).
|
|
|
|
Text(`)"`)
|
|
|
|
}
|
2019-02-15 19:39:37 +01:00
|
|
|
rule.Command().Textf(`dex_preopt_host_libraries="%s"`,
|
|
|
|
strings.Join(classLoaderContextHost.Strings(), " ")).
|
|
|
|
Implicits(classLoaderContextHost)
|
|
|
|
rule.Command().Textf(`dex_preopt_target_libraries="%s"`,
|
|
|
|
strings.Join(classLoaderContextTarget, " "))
|
|
|
|
rule.Command().Textf(`conditional_host_libs_28="%s"`,
|
|
|
|
strings.Join(conditionalClassLoaderContextHost28.Strings(), " ")).
|
|
|
|
Implicits(conditionalClassLoaderContextHost28)
|
|
|
|
rule.Command().Textf(`conditional_target_libs_28="%s"`,
|
|
|
|
strings.Join(conditionalClassLoaderContextTarget28, " "))
|
|
|
|
rule.Command().Textf(`conditional_host_libs_29="%s"`,
|
|
|
|
strings.Join(conditionalClassLoaderContextHost29.Strings(), " ")).
|
|
|
|
Implicits(conditionalClassLoaderContextHost29)
|
|
|
|
rule.Command().Textf(`conditional_target_libs_29="%s"`,
|
|
|
|
strings.Join(conditionalClassLoaderContextTarget29, " "))
|
2020-01-10 21:32:59 +01:00
|
|
|
rule.Command().Text("source").Tool(globalSoong.ConstructContext).Input(module.DexPath)
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2019-03-05 15:07:07 +01:00
|
|
|
// Devices that do not have a product partition use a symlink from /product to /system/product.
|
|
|
|
// Because on-device dexopt will see dex locations starting with /product, we change the paths
|
|
|
|
// to mimic this behavior.
|
|
|
|
dexLocationArg := module.DexLocation
|
|
|
|
if strings.HasPrefix(dexLocationArg, "/system/product/") {
|
|
|
|
dexLocationArg = strings.TrimPrefix(dexLocationArg, "/system")
|
|
|
|
}
|
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
cmd := rule.Command().
|
|
|
|
Text(`ANDROID_LOG_TAGS="*:e"`).
|
2020-01-10 21:32:59 +01:00
|
|
|
Tool(globalSoong.Dex2oat).
|
2018-11-12 19:13:39 +01:00
|
|
|
Flag("--avoid-storing-invocation").
|
2018-12-19 00:16:26 +01:00
|
|
|
FlagWithOutput("--write-invocation-to=", invocationPath).ImplicitOutput(invocationPath).
|
2018-11-12 19:13:39 +01:00
|
|
|
Flag("--runtime-arg").FlagWithArg("-Xms", global.Dex2oatXms).
|
|
|
|
Flag("--runtime-arg").FlagWithArg("-Xmx", global.Dex2oatXmx).
|
2019-02-11 23:21:24 +01:00
|
|
|
Flag("--runtime-arg").FlagWithInputList("-Xbootclasspath:", module.PreoptBootClassPathDexFiles, ":").
|
|
|
|
Flag("--runtime-arg").FlagWithList("-Xbootclasspath-locations:", module.PreoptBootClassPathDexLocations, ":").
|
2018-11-12 19:13:39 +01:00
|
|
|
Flag("${class_loader_context_arg}").
|
2019-12-03 16:39:23 +01:00
|
|
|
Flag("${stored_class_loader_context_arg}").Implicits(classLoaderDeps).
|
2020-01-03 18:33:17 +01:00
|
|
|
FlagWithArg("--boot-image=", strings.Join(module.DexPreoptImageLocations, ":")).Implicits(module.DexPreoptImagesDeps[archIdx].Paths()).
|
2018-11-12 19:13:39 +01:00
|
|
|
FlagWithInput("--dex-file=", module.DexPath).
|
2019-03-05 15:07:07 +01:00
|
|
|
FlagWithArg("--dex-location=", dexLocationArg).
|
2018-11-12 19:13:39 +01:00
|
|
|
FlagWithOutput("--oat-file=", odexPath).ImplicitOutput(vdexPath).
|
|
|
|
// Pass an empty directory, dex2oat shouldn't be reading arbitrary files
|
|
|
|
FlagWithArg("--android-root=", global.EmptyDirectory).
|
2019-02-12 00:11:14 +01:00
|
|
|
FlagWithArg("--instruction-set=", arch.String()).
|
2018-11-12 19:13:39 +01:00
|
|
|
FlagWithArg("--instruction-set-variant=", global.CpuVariant[arch]).
|
|
|
|
FlagWithArg("--instruction-set-features=", global.InstructionSetFeatures[arch]).
|
|
|
|
Flag("--no-generate-debug-info").
|
|
|
|
Flag("--generate-build-id").
|
|
|
|
Flag("--abort-on-hard-verifier-error").
|
|
|
|
Flag("--force-determinism").
|
|
|
|
FlagWithArg("--no-inline-from=", "core-oj.jar")
|
|
|
|
|
|
|
|
var preoptFlags []string
|
|
|
|
if len(module.PreoptFlags) > 0 {
|
|
|
|
preoptFlags = module.PreoptFlags
|
|
|
|
} else if len(global.PreoptFlags) > 0 {
|
|
|
|
preoptFlags = global.PreoptFlags
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(preoptFlags) > 0 {
|
|
|
|
cmd.Text(strings.Join(preoptFlags, " "))
|
|
|
|
}
|
|
|
|
|
|
|
|
if module.UncompressedDex {
|
|
|
|
cmd.FlagWithArg("--copy-dex-files=", "false")
|
|
|
|
}
|
|
|
|
|
2020-02-11 16:54:35 +01:00
|
|
|
if !android.PrefixInList(preoptFlags, "--compiler-filter=") {
|
2018-11-12 19:13:39 +01:00
|
|
|
var compilerFilter string
|
|
|
|
if contains(global.SystemServerJars, module.Name) {
|
|
|
|
// Jars of system server, use the product option if it is set, speed otherwise.
|
|
|
|
if global.SystemServerCompilerFilter != "" {
|
|
|
|
compilerFilter = global.SystemServerCompilerFilter
|
|
|
|
} else {
|
|
|
|
compilerFilter = "speed"
|
|
|
|
}
|
|
|
|
} else if contains(global.SpeedApps, module.Name) || contains(global.SystemServerApps, module.Name) {
|
|
|
|
// Apps loaded into system server, and apps the product default to being compiled with the
|
|
|
|
// 'speed' compiler filter.
|
|
|
|
compilerFilter = "speed"
|
2019-02-15 19:39:37 +01:00
|
|
|
} else if profile != nil {
|
2018-11-12 19:13:39 +01:00
|
|
|
// For non system server jars, use speed-profile when we have a profile.
|
|
|
|
compilerFilter = "speed-profile"
|
|
|
|
} else if global.DefaultCompilerFilter != "" {
|
|
|
|
compilerFilter = global.DefaultCompilerFilter
|
|
|
|
} else {
|
|
|
|
compilerFilter = "quicken"
|
|
|
|
}
|
|
|
|
cmd.FlagWithArg("--compiler-filter=", compilerFilter)
|
|
|
|
}
|
|
|
|
|
|
|
|
if generateDM {
|
|
|
|
cmd.FlagWithArg("--copy-dex-files=", "false")
|
2019-02-15 19:39:37 +01:00
|
|
|
dmPath := module.BuildPath.InSameDir(ctx, "generated.dm")
|
2018-11-12 19:13:39 +01:00
|
|
|
dmInstalledPath := pathtools.ReplaceExtension(module.DexLocation, "dm")
|
2019-02-15 19:39:37 +01:00
|
|
|
tmpPath := module.BuildPath.InSameDir(ctx, "primary.vdex")
|
2018-11-12 19:13:39 +01:00
|
|
|
rule.Command().Text("cp -f").Input(vdexPath).Output(tmpPath)
|
2020-01-10 21:32:59 +01:00
|
|
|
rule.Command().Tool(globalSoong.SoongZip).
|
2018-11-12 19:13:39 +01:00
|
|
|
FlagWithArg("-L", "9").
|
|
|
|
FlagWithOutput("-o", dmPath).
|
|
|
|
Flag("-j").
|
|
|
|
Input(tmpPath)
|
|
|
|
rule.Install(dmPath, dmInstalledPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
// By default, emit debug info.
|
|
|
|
debugInfo := true
|
|
|
|
if global.NoDebugInfo {
|
|
|
|
// If the global setting suppresses mini-debug-info, disable it.
|
|
|
|
debugInfo = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// PRODUCT_SYSTEM_SERVER_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO.
|
|
|
|
// PRODUCT_OTHER_JAVA_DEBUG_INFO overrides WITH_DEXPREOPT_DEBUG_INFO.
|
|
|
|
if contains(global.SystemServerJars, module.Name) {
|
|
|
|
if global.AlwaysSystemServerDebugInfo {
|
|
|
|
debugInfo = true
|
|
|
|
} else if global.NeverSystemServerDebugInfo {
|
|
|
|
debugInfo = false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if global.AlwaysOtherDebugInfo {
|
|
|
|
debugInfo = true
|
|
|
|
} else if global.NeverOtherDebugInfo {
|
|
|
|
debugInfo = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Never enable on eng.
|
|
|
|
if global.IsEng {
|
|
|
|
debugInfo = false
|
|
|
|
}
|
|
|
|
|
|
|
|
if debugInfo {
|
|
|
|
cmd.Flag("--generate-mini-debug-info")
|
|
|
|
} else {
|
|
|
|
cmd.Flag("--no-generate-mini-debug-info")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the compiler reason to 'prebuilt' to identify the oat files produced
|
|
|
|
// during the build, as opposed to compiled on the device.
|
|
|
|
cmd.FlagWithArg("--compilation-reason=", "prebuilt")
|
|
|
|
|
|
|
|
if appImage {
|
2019-02-15 19:39:37 +01:00
|
|
|
appImagePath := odexPath.ReplaceExtension(ctx, "art")
|
2018-11-12 19:13:39 +01:00
|
|
|
appImageInstallPath := pathtools.ReplaceExtension(odexInstallPath, "art")
|
|
|
|
cmd.FlagWithOutput("--app-image-file=", appImagePath).
|
|
|
|
FlagWithArg("--image-format=", "lz4")
|
2019-04-29 18:33:50 +02:00
|
|
|
if !global.DontResolveStartupStrings {
|
|
|
|
cmd.FlagWithArg("--resolve-startup-const-strings=", "true")
|
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
rule.Install(appImagePath, appImageInstallPath)
|
|
|
|
}
|
|
|
|
|
2019-02-15 19:39:37 +01:00
|
|
|
if profile != nil {
|
|
|
|
cmd.FlagWithInput("--profile-file=", profile)
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rule.Install(odexPath, odexInstallPath)
|
|
|
|
rule.Install(vdexPath, vdexInstallPath)
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func shouldGenerateDM(module *ModuleConfig, global *GlobalConfig) bool {
|
2018-11-12 19:13:39 +01:00
|
|
|
// Generating DM files only makes sense for verify, avoid doing for non verify compiler filter APKs.
|
|
|
|
// No reason to use a dm file if the dex is already uncompressed.
|
|
|
|
return global.GenerateDMFiles && !module.UncompressedDex &&
|
|
|
|
contains(module.PreoptFlags, "--compiler-filter=verify")
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func OdexOnSystemOtherByName(name string, dexLocation string, global *GlobalConfig) bool {
|
2018-11-12 19:13:39 +01:00
|
|
|
if !global.HasSystemOther {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if global.SanitizeLite {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-12 14:12:16 +01:00
|
|
|
if contains(global.SpeedApps, name) || contains(global.SystemServerApps, name) {
|
2018-11-12 19:13:39 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range global.PatternsOnSystemOther {
|
2019-10-14 17:53:02 +02:00
|
|
|
if makefileMatch(filepath.Join(SystemPartition, f), dexLocation) {
|
2018-11-12 19:13:39 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func odexOnSystemOther(module *ModuleConfig, global *GlobalConfig) bool {
|
2019-02-12 14:12:16 +01:00
|
|
|
return OdexOnSystemOtherByName(module.Name, module.DexLocation, global)
|
|
|
|
}
|
|
|
|
|
2019-02-09 06:37:00 +01:00
|
|
|
// PathToLocation converts .../system/framework/arm64/boot.art to .../system/framework/boot.art
|
2019-02-15 19:39:37 +01:00
|
|
|
func PathToLocation(path android.Path, arch android.ArchType) string {
|
|
|
|
pathArch := filepath.Base(filepath.Dir(path.String()))
|
2019-02-12 00:11:14 +01:00
|
|
|
if pathArch != arch.String() {
|
|
|
|
panic(fmt.Errorf("last directory in %q must be %q", path, arch.String()))
|
2019-02-09 06:37:00 +01:00
|
|
|
}
|
2019-02-15 19:39:37 +01:00
|
|
|
return filepath.Join(filepath.Dir(filepath.Dir(path.String())), filepath.Base(path.String()))
|
2019-02-09 06:37:00 +01:00
|
|
|
}
|
|
|
|
|
2020-01-31 18:44:54 +01:00
|
|
|
func pathForLibrary(module *ModuleConfig, lib string) android.Path {
|
2019-02-15 19:39:37 +01:00
|
|
|
path, ok := module.LibraryPaths[lib]
|
|
|
|
if !ok {
|
2018-11-12 19:13:39 +01:00
|
|
|
panic(fmt.Errorf("unknown library path for %q", lib))
|
|
|
|
}
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
|
|
|
func makefileMatch(pattern, s string) bool {
|
|
|
|
percent := strings.IndexByte(pattern, '%')
|
|
|
|
switch percent {
|
|
|
|
case -1:
|
|
|
|
return pattern == s
|
|
|
|
case len(pattern) - 1:
|
|
|
|
return strings.HasPrefix(s, pattern[:len(pattern)-1])
|
|
|
|
default:
|
|
|
|
panic(fmt.Errorf("unsupported makefile pattern %q", pattern))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 18:37:46 +01:00
|
|
|
// Expected format for apexJarValue = <apex name>:<jar name>
|
2019-11-08 11:54:21 +01:00
|
|
|
func GetJarLocationFromApexJarPair(apexJarValue string) string {
|
2020-02-10 16:29:28 +01:00
|
|
|
apex, jar := android.SplitApexJarPair(apexJarValue)
|
2019-11-08 11:54:21 +01:00
|
|
|
return filepath.Join("/apex", apex, "javalib", jar+".jar")
|
2019-11-27 18:37:46 +01:00
|
|
|
}
|
|
|
|
|
2019-12-03 16:39:23 +01:00
|
|
|
func GetJarsFromApexJarPairs(apexJarPairs []string) []string {
|
|
|
|
modules := make([]string, len(apexJarPairs))
|
|
|
|
for i, p := range apexJarPairs {
|
|
|
|
_, jar := android.SplitApexJarPair(p)
|
|
|
|
modules[i] = jar
|
|
|
|
}
|
|
|
|
return modules
|
|
|
|
}
|
|
|
|
|
|
|
|
var nonUpdatableSystemServerJarsKey = android.NewOnceKey("nonUpdatableSystemServerJars")
|
|
|
|
|
|
|
|
// TODO: eliminate the superficial global config parameter by moving global config definition
|
|
|
|
// from java subpackage to dexpreopt.
|
2020-01-31 18:44:54 +01:00
|
|
|
func NonUpdatableSystemServerJars(ctx android.PathContext, global *GlobalConfig) []string {
|
2019-12-03 16:39:23 +01:00
|
|
|
return ctx.Config().Once(nonUpdatableSystemServerJarsKey, func() interface{} {
|
|
|
|
return android.RemoveListFromList(global.SystemServerJars,
|
|
|
|
GetJarsFromApexJarPairs(global.UpdatableSystemServerJars))
|
|
|
|
}).([]string)
|
|
|
|
}
|
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
func contains(l []string, s string) bool {
|
|
|
|
for _, e := range l {
|
|
|
|
if e == s {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-16 08:03:34 +01:00
|
|
|
var copyOf = android.CopyOf
|