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 (
|
|
|
|
"android/soong/android"
|
|
|
|
"android/soong/dexpreopt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type dexpreopter struct {
|
|
|
|
dexpreoptProperties DexpreoptProperties
|
|
|
|
|
2019-10-02 07:05:35 +02:00
|
|
|
installPath android.InstallPath
|
2019-04-15 18:48:31 +02:00
|
|
|
uncompressedDex bool
|
|
|
|
isSDKLibrary bool
|
|
|
|
isTest bool
|
|
|
|
isInstallable bool
|
|
|
|
isPresignedPrebuilt bool
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-05-16 21:28:22 +02:00
|
|
|
manifestFile android.Path
|
|
|
|
usesLibs []string
|
|
|
|
optionalUsesLibs []string
|
|
|
|
enforceUsesLibs bool
|
|
|
|
libraryPaths map[string]android.Path
|
|
|
|
|
2019-02-11 23:11:09 +01:00
|
|
|
builtInstalled string
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dexpreopter) dexpreoptDisabled(ctx android.ModuleContext) bool {
|
2020-01-25 02:44:30 +01:00
|
|
|
global := dexpreoptGlobalConfig(ctx)
|
2019-02-15 19:39:37 +01:00
|
|
|
|
|
|
|
if global.DisablePreopt {
|
2019-02-11 23:21:24 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-02-15 19:39:37 +01:00
|
|
|
if inList(ctx.ModuleName(), global.DisablePreoptModules) {
|
2018-11-12 19:13:39 +01:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Config().UnbundledBuild() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if d.isTest {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
if !BoolDefault(d.dexpreoptProperties.Dex_preopt.Enabled, true) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2019-01-06 07:13:05 +01:00
|
|
|
if !d.isInstallable {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-01-09 12:00:27 +01:00
|
|
|
// Don't preopt APEX variant module
|
|
|
|
if am, ok := ctx.Module().(android.ApexModule); ok && !am.IsForPlatform() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
// TODO: contains no java code
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-10-02 07:05:35 +02:00
|
|
|
func odexOnSystemOther(ctx android.ModuleContext, installPath android.InstallPath) bool {
|
2020-01-25 02:44:30 +01:00
|
|
|
return dexpreopt.OdexOnSystemOtherByName(ctx.ModuleName(), android.InstallPathToOnDevicePath(ctx, installPath), dexpreoptGlobalConfig(ctx))
|
2019-02-12 14:12:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.ModuleOutPath) android.ModuleOutPath {
|
|
|
|
if d.dexpreoptDisabled(ctx) {
|
|
|
|
return dexJarFile
|
|
|
|
}
|
|
|
|
|
2020-01-10 21:32:59 +01:00
|
|
|
globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
|
2020-01-25 02:44:30 +01:00
|
|
|
global := dexpreoptGlobalConfig(ctx)
|
2019-02-16 08:06:46 +01:00
|
|
|
bootImage := defaultBootImageConfig(ctx)
|
2019-12-19 17:40:09 +01:00
|
|
|
if global.UseApexImage {
|
2019-12-09 16:40:17 +01:00
|
|
|
bootImage = frameworkJZBootImageConfig(ctx)
|
2019-12-19 17:40:09 +01:00
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-02-12 00:11:14 +01:00
|
|
|
var archs []android.ArchType
|
2018-11-12 19:13:39 +01:00
|
|
|
for _, a := range ctx.MultiTargets() {
|
2019-02-12 00:11:14 +01:00
|
|
|
archs = append(archs, a.Arch.ArchType)
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
if len(archs) == 0 {
|
|
|
|
// 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 {
|
|
|
|
archs = append(archs, target.Arch.ArchType)
|
|
|
|
}
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
2019-02-16 08:06:46 +01:00
|
|
|
if inList(ctx.ModuleName(), global.SystemServerJars) && !d.isSDKLibrary {
|
2018-11-12 19:13:39 +01:00
|
|
|
// If the module is not an SDK library and it's a system server jar, only preopt the primary arch.
|
|
|
|
archs = archs[:1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-15 19:39:37 +01:00
|
|
|
var images android.Paths
|
2019-11-08 11:54:21 +01:00
|
|
|
var imagesDeps []android.OutputPaths
|
2019-02-09 06:37:00 +01:00
|
|
|
for _, arch := range archs {
|
2019-02-16 08:06:46 +01:00
|
|
|
images = append(images, bootImage.images[arch])
|
2019-06-13 23:44:53 +02:00
|
|
|
imagesDeps = append(imagesDeps, bootImage.imagesDeps[arch])
|
2019-02-09 06:37:00 +01:00
|
|
|
}
|
|
|
|
|
2018-11-12 19:13:39 +01:00
|
|
|
dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath)
|
|
|
|
|
|
|
|
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
|
|
|
|
} else {
|
|
|
|
profileClassListing = android.ExistentPathForSource(ctx,
|
2019-02-16 08:06:46 +01:00
|
|
|
global.ProfileDir, ctx.ModuleName()+".prof")
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dexpreoptConfig := dexpreopt.ModuleConfig{
|
2019-01-29 22:00:33 +01:00
|
|
|
Name: ctx.ModuleName(),
|
|
|
|
DexLocation: dexLocation,
|
2019-02-15 19:39:37 +01:00
|
|
|
BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").OutputPath,
|
|
|
|
DexPath: dexJarFile,
|
2019-05-16 21:28:22 +02:00
|
|
|
ManifestPath: 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
|
|
|
|
2019-05-16 21:28:22 +02:00
|
|
|
EnforceUsesLibraries: d.enforceUsesLibs,
|
|
|
|
PresentOptionalUsesLibraries: d.optionalUsesLibs,
|
|
|
|
UsesLibraries: d.usesLibs,
|
|
|
|
LibraryPaths: d.libraryPaths,
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-11-08 11:54:21 +01:00
|
|
|
Archs: archs,
|
|
|
|
DexPreoptImages: images,
|
|
|
|
DexPreoptImagesDeps: imagesDeps,
|
|
|
|
DexPreoptImageLocations: bootImage.imageLocations,
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-12-09 16:40:17 +01:00
|
|
|
PreoptBootClassPathDexFiles: bootImage.dexPathsDeps.Paths(),
|
|
|
|
PreoptBootClassPathDexLocations: bootImage.dexLocationsDeps,
|
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
|
|
|
}
|
|
|
|
|
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())
|
|
|
|
return dexJarFile
|
|
|
|
}
|
|
|
|
|
2019-01-31 02:32:39 +01:00
|
|
|
dexpreoptRule.Build(pctx, ctx, "dexpreopt", "dexpreopt")
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-02-11 23:11:09 +01:00
|
|
|
d.builtInstalled = dexpreoptRule.Installs().String()
|
2018-11-12 19:13:39 +01:00
|
|
|
|
2019-10-18 15:51:38 +02:00
|
|
|
return dexJarFile
|
2018-11-12 19:13:39 +01:00
|
|
|
}
|