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.
|
|
|
|
|
|
|
|
package java
|
|
|
|
|
|
|
|
import (
|
2021-09-09 10:09:41 +02:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/dexpreopt"
|
|
|
|
)
|
|
|
|
|
2021-09-09 10:09:41 +02:00
|
|
|
type DexpreopterInterface interface {
|
2020-01-31 18:10:36 +01:00
|
|
|
IsInstallable() bool // Structs that embed dexpreopter must implement this.
|
|
|
|
dexpreoptDisabled(ctx android.BaseModuleContext) bool
|
2021-09-09 10:09:41 +02:00
|
|
|
DexpreoptBuiltInstalledForApex() []dexpreopterInstall
|
|
|
|
AndroidMkEntriesForApex() []android.AndroidMkEntries
|
2023-02-07 18:19:19 +01:00
|
|
|
ProfilePathOnHost() android.Path
|
2021-09-09 10:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type dexpreopterInstall struct {
|
|
|
|
// A unique name to distinguish an output from others for the same java library module. Usually in
|
|
|
|
// the form of `<arch>-<encoded-path>.odex/vdex/art`.
|
|
|
|
name string
|
|
|
|
|
|
|
|
// The name of the input java module.
|
|
|
|
moduleName string
|
|
|
|
|
|
|
|
// The path to the dexpreopt output on host.
|
|
|
|
outputPathOnHost android.Path
|
|
|
|
|
|
|
|
// The directory on the device for the output to install to.
|
|
|
|
installDirOnDevice android.InstallPath
|
|
|
|
|
|
|
|
// The basename (the last segment of the path) for the output to install as.
|
|
|
|
installFileOnDevice string
|
|
|
|
}
|
|
|
|
|
|
|
|
// The full module name of the output in the makefile.
|
|
|
|
func (install *dexpreopterInstall) FullModuleName() string {
|
|
|
|
return install.moduleName + install.SubModuleName()
|
|
|
|
}
|
|
|
|
|
|
|
|
// The sub-module name of the output in the makefile (the name excluding the java module name).
|
|
|
|
func (install *dexpreopterInstall) SubModuleName() string {
|
|
|
|
return "-dexpreopt-" + install.name
|
2020-01-31 18:10:36 +01:00
|
|
|
}
|
|
|
|
|
2022-01-12 18:56:19 +01:00
|
|
|
// Returns Make entries for installing the file.
|
|
|
|
//
|
|
|
|
// This function uses a value receiver rather than a pointer receiver to ensure that the object is
|
|
|
|
// safe to use in `android.AndroidMkExtraEntriesFunc`.
|
|
|
|
func (install dexpreopterInstall) ToMakeEntries() android.AndroidMkEntries {
|
|
|
|
return android.AndroidMkEntries{
|
|
|
|
Class: "ETC",
|
|
|
|
SubName: install.SubModuleName(),
|
|
|
|
OutputFile: android.OptionalPathForPath(install.outputPathOnHost),
|
|
|
|
ExtraEntries: []android.AndroidMkExtraEntriesFunc{
|
|
|
|
func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) {
|
|
|
|
entries.SetString("LOCAL_MODULE_PATH", install.installDirOnDevice.String())
|
|
|
|
entries.SetString("LOCAL_INSTALLED_MODULE_STEM", install.installFileOnDevice)
|
|
|
|
entries.SetString("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", "false")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
type dexpreopter struct {
|
2023-02-08 17:09:24 +01:00
|
|
|
dexpreoptProperties DexpreoptProperties
|
|
|
|
importDexpreoptProperties ImportDexpreoptProperties
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-10-02 07:05:35 +02:00
|
|
|
installPath android.InstallPath
|
2019-04-15 18:48:31 +02:00
|
|
|
uncompressedDex bool
|
|
|
|
isSDKLibrary bool
|
2021-01-14 18:52:43 +01:00
|
|
|
isApp bool
|
2019-04-15 18:48:31 +02:00
|
|
|
isTest bool
|
|
|
|
isPresignedPrebuilt bool
|
2021-11-11 01:42:38 +01:00
|
|
|
preventInstall bool
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2020-11-03 16:15:46 +01:00
|
|
|
manifestFile android.Path
|
Add non-fatal mode for verify_uses_libraries check.
The new mode is enabled with environment variable
RELAX_USES_LIBRARY_CHECK. If the variable is set to true, then a
verify_uses_libraries check failure does not fail the build, instead it
sets a special compiler filter "extract" for dexpreopt, which means that
the DEX file will be extracted, but it won't be compiled to native code.
Class loader context will be set to empty in this case (not &, as it is
going to be deprecated soon).
If the variable RELAX_USES_LIBRARY_CHECK is unset or set to something
other than "true", then the old behaviour of the verify_uses_libraries
check is preserved.
The intended use case for this flag is to have a smoother migration path
for the Java modules that need to add <uses-library> information in
the build files. The flag allows to quickly silence build errors. This
flag should be used with caution and only as a temporary measure, as it
masks real errors and affects performance.
verify_uses_libraries check is reworked so that it writes the error
message to a status file (which is used instead of the former timestamp
file). Currently the stored error message is not used, but it may be
used later to produce a warning. Dexpreopt command checks if the status
file exists and is nonempty; if that is the case, then compiler filter
is set to "extract".
Bug: 132357300
Test: Manually add some mismatch between the libraries in the Android.bp
and Android.mk files for dexpreopted apps, build with
RELAX_USES_LIBRARY_CHECK=true and obsserve that the build doesn't
fail and they are compiled with compiler-filter "extract".
Unset RELAX_USES_LIBRARY_CHECK and observe that the build fails.
Change-Id: Ibb5d993a25b1df1d2e70b7d5aafc6997f9d64e67
2021-02-17 17:23:28 +01:00
|
|
|
statusFile android.WritablePath
|
2020-11-03 16:15:46 +01:00
|
|
|
enforceUsesLibs bool
|
|
|
|
classLoaderContexts dexpreopt.ClassLoaderContextMap
|
2019-05-16 21:28:22 +02:00
|
|
|
|
2021-09-09 10:09:41 +02:00
|
|
|
// See the `dexpreopt` function for details.
|
|
|
|
builtInstalled string
|
|
|
|
builtInstalledForApex []dexpreopterInstall
|
2021-01-14 18:52:43 +01:00
|
|
|
|
2021-04-07 17:00:19 +02:00
|
|
|
// The config is used for two purposes:
|
|
|
|
// - Passing dexpreopt information about libraries from Soong to Make. This is needed when
|
|
|
|
// a <uses-library> is defined in Android.bp, but used in Android.mk (see dex_preopt_config_merger.py).
|
|
|
|
// Note that dexpreopt.config might be needed even if dexpreopt is disabled for the library itself.
|
|
|
|
// - Dexpreopt post-processing (using dexpreopt artifacts from a prebuilt system image to incrementally
|
|
|
|
// dexpreopt another partition).
|
2021-01-14 18:52:43 +01:00
|
|
|
configPath android.WritablePath
|
2023-02-07 18:19:19 +01:00
|
|
|
|
|
|
|
// The path to the profile on host.
|
|
|
|
profilePathOnHost android.Path
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type DexpreoptProperties struct {
|
|
|
|
Dex_preopt struct {
|
2019-10-18 15:51:38 +02:00
|
|
|
// If false, prevent dexpreopting. Defaults to true.
|
2018-11-12 19:13:39 +01:00
|
|
|
Enabled *bool
|
|
|
|
|
|
|
|
// If true, generate an app image (.art file) for this module.
|
|
|
|
App_image *bool
|
|
|
|
|
|
|
|
// If true, use a checked-in profile to guide optimization. Defaults to false unless
|
|
|
|
// a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR
|
|
|
|
// that matches the name of this module, in which case it is defaulted to true.
|
|
|
|
Profile_guided *bool
|
|
|
|
|
|
|
|
// If set, provides the path to profile relative to the Android.bp file. If not set,
|
|
|
|
// defaults to searching for a file that matches the name of this module in the default
|
|
|
|
// profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found.
|
2019-04-26 19:52:32 +02:00
|
|
|
Profile *string `android:"path"`
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
2023-02-08 17:09:24 +01:00
|
|
|
|
|
|
|
Dex_preopt_result struct {
|
|
|
|
// True if profile-guided optimization is actually enabled.
|
|
|
|
Profile_guided bool
|
|
|
|
} `blueprint:"mutated"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ImportDexpreoptProperties struct {
|
|
|
|
Dex_preopt struct {
|
|
|
|
// If true, use the profile in the prebuilt APEX to guide optimization. Defaults to false.
|
|
|
|
Profile_guided *bool
|
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2020-04-24 13:15:20 +02:00
|
|
|
func init() {
|
|
|
|
dexpreopt.DexpreoptRunningInSoong = true
|
|
|
|
}
|
|
|
|
|
2021-09-09 10:09:41 +02:00
|
|
|
func isApexVariant(ctx android.BaseModuleContext) bool {
|
|
|
|
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
|
|
|
return !apexInfo.IsForPlatform()
|
|
|
|
}
|
|
|
|
|
2021-12-20 16:08:57 +01:00
|
|
|
func forPrebuiltApex(ctx android.BaseModuleContext) bool {
|
|
|
|
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
|
|
|
return apexInfo.ForPrebuiltApex
|
|
|
|
}
|
|
|
|
|
2021-09-09 10:09:41 +02:00
|
|
|
func moduleName(ctx android.BaseModuleContext) string {
|
|
|
|
// Remove the "prebuilt_" prefix if the module is from a prebuilt because the prefix is not
|
|
|
|
// expected by dexpreopter.
|
|
|
|
return android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName())
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:10:36 +01:00
|
|
|
func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool {
|
2021-12-01 19:34:14 +01:00
|
|
|
if !ctx.Device() {
|
|
|
|
return true
|
|
|
|
}
|
2019-02-15 19:39:37 +01:00
|
|
|
|
2021-12-01 19:34:14 +01:00
|
|
|
if d.isTest {
|
2019-02-11 23:21:24 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-12-01 19:34:14 +01:00
|
|
|
if !BoolDefault(d.dexpreoptProperties.Dex_preopt.Enabled, true) {
|
2018-11-12 19:13:39 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-12-20 16:08:57 +01:00
|
|
|
// If the module is from a prebuilt APEX, it shouldn't be installable, but it can still be
|
|
|
|
// dexpreopted.
|
|
|
|
if !ctx.Module().(DexpreopterInterface).IsInstallable() && !forPrebuiltApex(ctx) {
|
2018-11-12 19:13:39 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-12-01 19:34:14 +01:00
|
|
|
if !android.IsModulePreferred(ctx.Module()) {
|
2018-11-12 19:13:39 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-12-01 19:34:14 +01:00
|
|
|
global := dexpreopt.GetGlobalConfig(ctx)
|
|
|
|
|
|
|
|
if global.DisablePreopt {
|
2020-01-31 18:10:36 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-12-01 19:34:14 +01:00
|
|
|
if inList(moduleName(ctx), global.DisablePreoptModules) {
|
2019-01-06 07:13:05 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-12-14 19:54:06 +01:00
|
|
|
isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx))
|
2021-09-09 10:09:41 +02:00
|
|
|
if isApexVariant(ctx) {
|
2023-02-07 18:19:19 +01:00
|
|
|
// Don't preopt APEX variant module unless the module is an APEX system server jar.
|
|
|
|
if !isApexSystemServerJar {
|
2021-09-09 10:09:41 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Don't preopt the platform variant of an APEX system server jar to avoid conflicts.
|
2021-12-14 19:54:06 +01:00
|
|
|
if isApexSystemServerJar {
|
2021-09-09 10:09:41 +02:00
|
|
|
return true
|
|
|
|
}
|
2020-01-09 12:00:27 +01:00
|
|
|
}
|
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
// TODO: contains no java code
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-01-31 18:10:36 +01:00
|
|
|
func dexpreoptToolDepsMutator(ctx android.BottomUpMutatorContext) {
|
2021-09-09 10:09:41 +02:00
|
|
|
if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx) {
|
2020-01-31 18:10:36 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
dexpreopt.RegisterToolDeps(ctx)
|
|
|
|
}
|
|
|
|
|
2021-09-09 10:09:41 +02:00
|
|
|
func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, installPath android.InstallPath) bool {
|
|
|
|
return dexpreopt.OdexOnSystemOtherByName(moduleName(ctx), android.InstallPathToOnDevicePath(ctx, installPath), dexpreopt.GetGlobalConfig(ctx))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the install path of the dex jar of a module.
|
|
|
|
//
|
|
|
|
// Do not rely on `ApexInfo.ApexVariationName` because it can be something like "apex1000", rather
|
|
|
|
// than the `name` in the path `/apex/<name>` as suggested in its comment.
|
|
|
|
//
|
|
|
|
// This function is on a best-effort basis. It cannot handle the case where an APEX jar is not a
|
|
|
|
// system server jar, which is fine because we currently only preopt system server jars for APEXes.
|
|
|
|
func (d *dexpreopter) getInstallPath(
|
|
|
|
ctx android.ModuleContext, defaultInstallPath android.InstallPath) android.InstallPath {
|
|
|
|
global := dexpreopt.GetGlobalConfig(ctx)
|
2021-12-14 19:54:06 +01:00
|
|
|
if global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx)) {
|
|
|
|
dexLocation := dexpreopt.GetSystemServerDexLocation(ctx, global, moduleName(ctx))
|
2021-09-09 10:09:41 +02:00
|
|
|
return android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexLocation, "/"))
|
|
|
|
}
|
|
|
|
if !d.dexpreoptDisabled(ctx) && isApexVariant(ctx) &&
|
|
|
|
filepath.Base(defaultInstallPath.PartitionDir()) != "apex" {
|
|
|
|
ctx.ModuleErrorf("unable to get the install path of the dex jar for dexpreopt")
|
|
|
|
}
|
|
|
|
return defaultInstallPath
|
2019-02-12 14:12:16 +01:00
|
|
|
}
|
|
|
|
|
2021-02-02 14:38:13 +01:00
|
|
|
func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.WritablePath) {
|
2021-09-09 10:09:41 +02:00
|
|
|
global := dexpreopt.GetGlobalConfig(ctx)
|
|
|
|
|
2020-01-31 18:10:36 +01:00
|
|
|
// TODO(b/148690468): The check on d.installPath is to bail out in cases where
|
|
|
|
// the dexpreopter struct hasn't been fully initialized before we're called,
|
|
|
|
// e.g. in aar.go. This keeps the behaviour that dexpreopting is effectively
|
|
|
|
// disabled, even if installable is true.
|
2021-01-14 18:52:43 +01:00
|
|
|
if d.installPath.Base() == "." {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath)
|
|
|
|
|
2021-09-09 10:09:41 +02:00
|
|
|
providesUsesLib := moduleName(ctx)
|
2021-01-14 18:52:43 +01:00
|
|
|
if ulib, ok := ctx.Module().(ProvidesUsesLib); ok {
|
|
|
|
name := ulib.ProvidesUsesLib()
|
|
|
|
if name != nil {
|
|
|
|
providesUsesLib = *name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-08 04:35:00 +02:00
|
|
|
// If it is test, make config files regardless of its dexpreopt setting.
|
2021-04-07 17:00:19 +02:00
|
|
|
// The config files are required for apps defined in make which depend on the lib.
|
2021-06-08 04:35:00 +02:00
|
|
|
if d.isTest && d.dexpreoptDisabled(ctx) {
|
2020-12-17 18:43:28 +01:00
|
|
|
return
|
2019-02-12 14:12:16 +01:00
|
|
|
}
|
|
|
|
|
2021-12-14 19:54:06 +01:00
|
|
|
isSystemServerJar := global.AllSystemServerJars(ctx).ContainsJar(moduleName(ctx))
|
2021-03-22 17:02:28 +01:00
|
|
|
|
2019-02-16 08:06:46 +01:00
|
|
|
bootImage := defaultBootImageConfig(ctx)
|
2021-09-11 05:44:06 +02:00
|
|
|
dexFiles, dexLocations := bcpForDexpreopt(ctx, global.PreoptWithUpdatableBcp)
|
2021-03-22 17:02:28 +01:00
|
|
|
|
2020-02-18 21:43:06 +01:00
|
|
|
targets := ctx.MultiTargets()
|
|
|
|
if len(targets) == 0 {
|
2018-11-12 19:13:39 +01:00
|
|
|
// assume this is a java library, dexpreopt for all arches for now
|
|
|
|
for _, target := range ctx.Config().Targets[android.Android] {
|
2019-03-26 12:39:31 +01:00
|
|
|
if target.NativeBridge == android.NativeBridgeDisabled {
|
2020-02-18 21:43:06 +01:00
|
|
|
targets = append(targets, target)
|
2019-03-26 12:39:31 +01:00
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
2022-11-28 16:38:23 +01:00
|
|
|
if isSystemServerJar && moduleName(ctx) != "com.android.location.provider" {
|
|
|
|
// If the module is a system server jar, only preopt for the primary arch because the jar can
|
|
|
|
// only be loaded by system server. "com.android.location.provider" is a special case because
|
|
|
|
// it's also used by apps as a shared library.
|
2020-02-18 21:43:06 +01:00
|
|
|
targets = targets[:1]
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 21:43:06 +01:00
|
|
|
var archs []android.ArchType
|
2019-02-15 19:39:37 +01:00
|
|
|
var images android.Paths
|
2019-11-08 11:54:21 +01:00
|
|
|
var imagesDeps []android.OutputPaths
|
2020-02-18 21:43:06 +01:00
|
|
|
for _, target := range targets {
|
|
|
|
archs = append(archs, target.Arch.ArchType)
|
|
|
|
variant := bootImage.getVariant(target)
|
2021-05-07 11:53:21 +02:00
|
|
|
images = append(images, variant.imagePathOnHost)
|
2020-02-18 21:43:06 +01:00
|
|
|
imagesDeps = append(imagesDeps, variant.imagesDeps)
|
2019-02-09 06:37:00 +01:00
|
|
|
}
|
2020-03-30 18:24:13 +02:00
|
|
|
// The image locations for all Android variants are identical.
|
2021-04-27 16:56:44 +02:00
|
|
|
hostImageLocations, deviceImageLocations := bootImage.getAnyAndroidVariant().imageLocations()
|
2019-02-09 06:37:00 +01:00
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
var profileClassListing android.OptionalPath
|
2019-07-24 14:19:29 +02:00
|
|
|
var profileBootListing android.OptionalPath
|
2018-11-12 19:13:39 +01:00
|
|
|
profileIsTextListing := false
|
|
|
|
if BoolDefault(d.dexpreoptProperties.Dex_preopt.Profile_guided, true) {
|
|
|
|
// If dex_preopt.profile_guided is not set, default it based on the existence of the
|
|
|
|
// dexprepot.profile option or the profile class listing.
|
|
|
|
if String(d.dexpreoptProperties.Dex_preopt.Profile) != "" {
|
|
|
|
profileClassListing = android.OptionalPathForPath(
|
|
|
|
android.PathForModuleSrc(ctx, String(d.dexpreoptProperties.Dex_preopt.Profile)))
|
2019-07-24 14:19:29 +02:00
|
|
|
profileBootListing = android.ExistentPathForSource(ctx,
|
|
|
|
ctx.ModuleDir(), String(d.dexpreoptProperties.Dex_preopt.Profile)+"-boot")
|
2018-11-12 19:13:39 +01:00
|
|
|
profileIsTextListing = true
|
2020-06-25 01:33:31 +02:00
|
|
|
} else if global.ProfileDir != "" {
|
2018-11-12 19:13:39 +01:00
|
|
|
profileClassListing = android.ExistentPathForSource(ctx,
|
2021-09-09 10:09:41 +02:00
|
|
|
global.ProfileDir, moduleName(ctx)+".prof")
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-08 17:09:24 +01:00
|
|
|
d.dexpreoptProperties.Dex_preopt_result.Profile_guided = profileClassListing.Valid()
|
|
|
|
|
2021-01-14 18:52:43 +01:00
|
|
|
// Full dexpreopt config, used to create dexpreopt build rules.
|
2020-01-31 18:44:54 +01:00
|
|
|
dexpreoptConfig := &dexpreopt.ModuleConfig{
|
2021-09-09 10:09:41 +02:00
|
|
|
Name: moduleName(ctx),
|
2019-01-29 22:00:33 +01:00
|
|
|
DexLocation: dexLocation,
|
2021-09-09 10:09:41 +02:00
|
|
|
BuildPath: android.PathForModuleOut(ctx, "dexpreopt", moduleName(ctx)+".jar").OutputPath,
|
2019-02-15 19:39:37 +01:00
|
|
|
DexPath: dexJarFile,
|
2021-04-15 02:12:49 +02:00
|
|
|
ManifestPath: android.OptionalPathForPath(d.manifestFile),
|
2019-01-29 22:00:33 +01:00
|
|
|
UncompressedDex: d.uncompressedDex,
|
|
|
|
HasApkLibraries: false,
|
|
|
|
PreoptFlags: nil,
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-02-15 19:39:37 +01:00
|
|
|
ProfileClassListing: profileClassListing,
|
2018-11-12 19:13:39 +01:00
|
|
|
ProfileIsTextListing: profileIsTextListing,
|
2019-07-24 14:19:29 +02:00
|
|
|
ProfileBootListing: profileBootListing,
|
2018-11-12 19:13:39 +01:00
|
|
|
|
Add non-fatal mode for verify_uses_libraries check.
The new mode is enabled with environment variable
RELAX_USES_LIBRARY_CHECK. If the variable is set to true, then a
verify_uses_libraries check failure does not fail the build, instead it
sets a special compiler filter "extract" for dexpreopt, which means that
the DEX file will be extracted, but it won't be compiled to native code.
Class loader context will be set to empty in this case (not &, as it is
going to be deprecated soon).
If the variable RELAX_USES_LIBRARY_CHECK is unset or set to something
other than "true", then the old behaviour of the verify_uses_libraries
check is preserved.
The intended use case for this flag is to have a smoother migration path
for the Java modules that need to add <uses-library> information in
the build files. The flag allows to quickly silence build errors. This
flag should be used with caution and only as a temporary measure, as it
masks real errors and affects performance.
verify_uses_libraries check is reworked so that it writes the error
message to a status file (which is used instead of the former timestamp
file). Currently the stored error message is not used, but it may be
used later to produce a warning. Dexpreopt command checks if the status
file exists and is nonempty; if that is the case, then compiler filter
is set to "extract".
Bug: 132357300
Test: Manually add some mismatch between the libraries in the Android.bp
and Android.mk files for dexpreopted apps, build with
RELAX_USES_LIBRARY_CHECK=true and obsserve that the build doesn't
fail and they are compiled with compiler-filter "extract".
Unset RELAX_USES_LIBRARY_CHECK and observe that the build fails.
Change-Id: Ibb5d993a25b1df1d2e70b7d5aafc6997f9d64e67
2021-02-17 17:23:28 +01:00
|
|
|
EnforceUsesLibrariesStatusFile: dexpreopt.UsesLibrariesStatusFile(ctx),
|
|
|
|
EnforceUsesLibraries: d.enforceUsesLibs,
|
|
|
|
ProvidesUsesLibrary: providesUsesLib,
|
|
|
|
ClassLoaderContexts: d.classLoaderContexts,
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2021-04-27 16:56:44 +02:00
|
|
|
Archs: archs,
|
|
|
|
DexPreoptImagesDeps: imagesDeps,
|
|
|
|
DexPreoptImageLocationsOnHost: hostImageLocations,
|
|
|
|
DexPreoptImageLocationsOnDevice: deviceImageLocations,
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2021-03-22 17:02:28 +01:00
|
|
|
PreoptBootClassPathDexFiles: dexFiles.Paths(),
|
2020-02-06 16:14:29 +01:00
|
|
|
PreoptBootClassPathDexLocations: dexLocations,
|
2019-02-11 23:21:24 +01:00
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
PreoptExtractedApk: false,
|
|
|
|
|
|
|
|
NoCreateAppImage: !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true),
|
|
|
|
ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false),
|
|
|
|
|
2019-04-15 18:48:31 +02:00
|
|
|
PresignedPrebuilt: d.isPresignedPrebuilt,
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2021-04-07 17:00:19 +02:00
|
|
|
d.configPath = android.PathForModuleOut(ctx, "dexpreopt", "dexpreopt.config")
|
|
|
|
dexpreopt.WriteModuleConfig(ctx, dexpreoptConfig, d.configPath)
|
|
|
|
|
|
|
|
if d.dexpreoptDisabled(ctx) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
|
|
|
|
|
2020-01-10 21:32:59 +01:00
|
|
|
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, globalSoong, global, dexpreoptConfig)
|
2018-11-12 19:13:39 +01:00
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())
|
2020-12-17 18:43:28 +01:00
|
|
|
return
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
|
2020-11-17 02:32:30 +01:00
|
|
|
dexpreoptRule.Build("dexpreopt", "dexpreopt")
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2021-12-14 19:54:06 +01:00
|
|
|
isApexSystemServerJar := global.AllApexSystemServerJars(ctx).ContainsJar(moduleName(ctx))
|
|
|
|
|
2021-11-03 22:08:20 +01:00
|
|
|
for _, install := range dexpreoptRule.Installs() {
|
|
|
|
// Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT.
|
|
|
|
installDir := strings.TrimPrefix(filepath.Dir(install.To), "/")
|
|
|
|
installBase := filepath.Base(install.To)
|
|
|
|
arch := filepath.Base(installDir)
|
|
|
|
installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir)
|
2023-02-07 18:19:19 +01:00
|
|
|
isProfile := strings.HasSuffix(installBase, ".prof")
|
|
|
|
|
|
|
|
if isProfile {
|
|
|
|
d.profilePathOnHost = install.From
|
|
|
|
}
|
2021-11-03 22:08:20 +01:00
|
|
|
|
2021-12-14 19:54:06 +01:00
|
|
|
if isApexSystemServerJar {
|
2023-02-07 18:19:19 +01:00
|
|
|
// Profiles are handled separately because they are installed into the APEX.
|
|
|
|
if !isProfile {
|
|
|
|
// APEX variants of java libraries are hidden from Make, so their dexpreopt
|
|
|
|
// outputs need special handling. Currently, for APEX variants of java
|
|
|
|
// libraries, only those in the system server classpath are handled here.
|
|
|
|
// Preopting of boot classpath jars in the ART APEX are handled in
|
|
|
|
// java/dexpreopt_bootjars.go, and other APEX jars are not preopted.
|
|
|
|
// The installs will be handled by Make as sub-modules of the java library.
|
|
|
|
d.builtInstalledForApex = append(d.builtInstalledForApex, dexpreopterInstall{
|
|
|
|
name: arch + "-" + installBase,
|
|
|
|
moduleName: moduleName(ctx),
|
|
|
|
outputPathOnHost: install.From,
|
|
|
|
installDirOnDevice: installPath,
|
|
|
|
installFileOnDevice: installBase,
|
|
|
|
})
|
|
|
|
}
|
2021-11-11 01:42:38 +01:00
|
|
|
} else if !d.preventInstall {
|
2021-11-03 22:08:20 +01:00
|
|
|
ctx.InstallFile(installPath, installBase, install.From)
|
2021-09-09 10:09:41 +02:00
|
|
|
}
|
2021-11-03 22:08:20 +01:00
|
|
|
}
|
|
|
|
|
2021-12-14 19:54:06 +01:00
|
|
|
if !isApexSystemServerJar {
|
2021-09-09 10:09:41 +02:00
|
|
|
d.builtInstalled = dexpreoptRule.Installs().String()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dexpreopter) DexpreoptBuiltInstalledForApex() []dexpreopterInstall {
|
|
|
|
return d.builtInstalledForApex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dexpreopter) AndroidMkEntriesForApex() []android.AndroidMkEntries {
|
|
|
|
var entries []android.AndroidMkEntries
|
|
|
|
for _, install := range d.builtInstalledForApex {
|
2022-01-12 18:56:19 +01:00
|
|
|
entries = append(entries, install.ToMakeEntries())
|
2021-09-09 10:09:41 +02:00
|
|
|
}
|
|
|
|
return entries
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
2023-02-07 18:19:19 +01:00
|
|
|
|
|
|
|
func (d *dexpreopter) ProfilePathOnHost() android.Path {
|
|
|
|
return d.profilePathOnHost
|
|
|
|
}
|