Dexpreopt soong modules inside soong

Port the dexpreopt logic from Make to the dexpreopt package in Soong,
and use it to dexpreopt Soong modules.  The same package is also
compiled into the dexpreopt_gen binary to generate dexpreopt scripts
for Make modules.

Bug: 119412419
Bug: 120273280
Test: no differences to dexpreopt outputs on aosp_sailfish system/,
      only expected changes to dexpreopt outputs on system_other
      (.vdex files for privileged Soong modules no longer incorrectly
      contain .dex contents).
Change-Id: Ib67e2febf9ed921f06e8a86b9ec945c80dff35eb
This commit is contained in:
Colin Cross
2018-11-12 10:13:39 -08:00
parent 9d824cc850
commit 29ff88741e
20 changed files with 1690 additions and 118 deletions

View File

@@ -357,6 +357,7 @@ func AndroidLibraryFactory() android.Module {
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
&module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.aaptProperties,
&module.androidLibraryProperties)

View File

@@ -25,7 +25,7 @@ import (
func (library *Library) AndroidMk() android.AndroidMkData {
return android.AndroidMkData{
Class: "JAVA_LIBRARIES",
OutputFile: android.OptionalPathForPath(library.implementationAndResourcesJar),
OutputFile: android.OptionalPathForPath(library.outputFile),
Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk",
Extra: []android.AndroidMkExtraFunc{
func(w io.Writer, outputFile android.Path) {
@@ -42,21 +42,12 @@ func (library *Library) AndroidMk() android.AndroidMkData {
}
if library.dexJarFile != nil {
fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
if library.deviceProperties.Dex_preopt.Enabled != nil {
fmt.Fprintln(w, "LOCAL_DEX_PREOPT :=", *library.deviceProperties.Dex_preopt.Enabled)
}
if library.deviceProperties.Dex_preopt.App_image != nil {
fmt.Fprintln(w, "LOCAL_DEX_PREOPT_APP_IMAGE :=", *library.deviceProperties.Dex_preopt.App_image)
}
if library.deviceProperties.Dex_preopt.Profile_guided != nil {
fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE :=", *library.deviceProperties.Dex_preopt.Profile_guided)
}
if library.deviceProperties.Dex_preopt.Profile != nil {
fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE := true")
fmt.Fprintln(w, "LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(LOCAL_PATH)/"+*library.deviceProperties.Dex_preopt.Profile)
}
}
if len(library.dexpreopter.builtInstalled) > 0 {
fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", strings.Join(library.dexpreopter.builtInstalled, " "))
}
fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.sdkVersion())
fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
if library.jacocoReportClassesFile != nil {
@@ -84,7 +75,6 @@ func (library *Library) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex")
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES")
fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationAndResourcesJar.String())
if library.installFile == nil {
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
}
@@ -92,6 +82,7 @@ func (library *Library) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String())
}
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String())
fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String())
fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " "))
fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk")
}
@@ -128,6 +119,7 @@ func (prebuilt *Import) AndroidMk() android.AndroidMkData {
func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable))
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String())
fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.combinedClasspathFile.String())
fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion())
},
},
@@ -142,8 +134,8 @@ func (prebuilt *AARImport) AndroidMk() android.AndroidMkData {
Extra: []android.AndroidMkExtraFunc{
func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String())
fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.classpathFile.String())
fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String())
fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String())
fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String())
@@ -164,6 +156,7 @@ func (binary *Binary) AndroidMk() android.AndroidMkData {
Extra: []android.AndroidMkExtraFunc{
func(w io.Writer, outputFile android.Path) {
fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", binary.headerJarFile.String())
fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", binary.implementationAndResourcesJar.String())
},
},
Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) {
@@ -250,6 +243,9 @@ func (app *AndroidApp) AndroidMk() android.AndroidMkData {
for _, jniLib := range app.installJniLibs {
fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), "+=", jniLib.name)
}
if len(app.dexpreopter.builtInstalled) > 0 {
fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", strings.Join(app.dexpreopter.builtInstalled, " "))
}
},
},
}
@@ -313,7 +309,6 @@ func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
})
return data

View File

@@ -17,6 +17,7 @@ package java
// This file contains the module types for compiling Android apps.
import (
"path/filepath"
"strings"
"github.com/google/blueprint"
@@ -69,7 +70,6 @@ type appProperties struct {
AllowDexPreopt bool `blueprint:"mutated"`
EmbedJNI bool `blueprint:"mutated"`
StripDex bool `blueprint:"mutated"`
}
type AndroidApp struct {
@@ -143,42 +143,16 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.generateAndroidBuildActions(ctx)
}
// Returns whether this module should have the dex file stored uncompressed in the APK, or stripped completely. If
// stripped, the code will still be present on the device in the dexpreopted files.
// This is only necessary for APKs, and not jars, because APKs are signed and the dex file should not be uncompressed
// or removed after the signature has been generated. For jars, which are not signed, the dex file is uncompressed
// or removed at installation time in Make.
func (a *AndroidApp) uncompressOrStripDex(ctx android.ModuleContext) (uncompress, strip bool) {
// Returns whether this module should have the dex file stored uncompressed in the APK.
func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool {
if ctx.Config().UnbundledBuild() {
return false, false
return false
}
strip = ctx.Config().DefaultStripDex()
// TODO(ccross): don't strip dex installed on partitions that may be updated separately (like vendor)
// TODO(ccross): don't strip dex on modules with LOCAL_APK_LIBRARIES equivalent
// Uncompress dex in APKs of privileged apps, and modules used by privileged apps.
if ctx.Config().UncompressPrivAppDex() &&
return ctx.Config().UncompressPrivAppDex() &&
(Bool(a.appProperties.Privileged) ||
inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) {
uncompress = true
// If the dex files is store uncompressed, don't strip it, we will reuse the uncompressed dex from the APK
// instead of copying it into the odex file.
strip = false
}
// If dexpreopt is disabled, don't strip the dex file
if !a.appProperties.AllowDexPreopt ||
!BoolDefault(a.deviceProperties.Dex_preopt.Enabled, true) ||
ctx.Config().DisableDexPreopt(ctx.ModuleName()) {
strip = false
}
// TODO(ccross): strip dexpropted modules that are not propted to system_other
strip = false
return uncompress, strip
inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules()))
}
func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
@@ -228,16 +202,25 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
a.deviceProperties.UncompressDex, a.appProperties.StripDex = a.uncompressOrStripDex(ctx)
a.deviceProperties.UncompressDex = a.shouldUncompressDex(ctx)
var installDir string
if ctx.ModuleName() == "framework-res" {
// framework-res.apk is installed as system/framework/framework-res.apk
installDir = "framework"
} else if Bool(a.appProperties.Privileged) {
installDir = filepath.Join("priv-app", ctx.ModuleName())
} else {
installDir = filepath.Join("app", ctx.ModuleName())
}
a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, ctx.ModuleName()+".apk")
a.dexpreopter.isPrivApp = Bool(a.appProperties.Privileged)
if ctx.ModuleName() != "framework-res" {
a.Module.compile(ctx, a.aaptSrcJar)
}
dexJarFile := a.dexJarFile
if a.appProperties.StripDex {
dexJarFile = nil
}
dexJarFile := a.maybeStrippedDexJarFile
var certificates []Certificate
@@ -287,9 +270,9 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) {
// framework-res.apk is installed as system/framework/framework-res.apk
ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".apk", a.outputFile)
} else if Bool(a.appProperties.Privileged) {
ctx.InstallFile(android.PathForModuleInstall(ctx, "priv-app"), ctx.ModuleName()+".apk", a.outputFile)
ctx.InstallFile(android.PathForModuleInstall(ctx, "priv-app", ctx.ModuleName()), ctx.ModuleName()+".apk", a.outputFile)
} else {
ctx.InstallFile(android.PathForModuleInstall(ctx, "app"), ctx.ModuleName()+".apk", a.outputFile)
ctx.InstallFile(android.PathForModuleInstall(ctx, "app", ctx.ModuleName()), ctx.ModuleName()+".apk", a.outputFile)
}
}
@@ -342,6 +325,7 @@ func AndroidAppFactory() android.Module {
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
&module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.aaptProperties,
&module.appProperties)
@@ -404,6 +388,7 @@ func AndroidTestFactory() android.Module {
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
&module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.aaptProperties,
&module.appProperties,
@@ -439,6 +424,7 @@ func AndroidTestHelperAppFactory() android.Module {
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
&module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.aaptProperties,
&module.appProperties,

View File

@@ -138,6 +138,17 @@ var (
CommandDeps: []string{"${config.JavaCmd}", "${config.JetifierJar}"},
},
)
zipalign = pctx.AndroidStaticRule("zipalign",
blueprint.RuleParams{
Command: "if ! ${config.ZipAlign} -c 4 $in > /dev/null; then " +
"${config.ZipAlign} -f 4 $in $out; " +
"else " +
"cp -f $in $out; " +
"fi",
CommandDeps: []string{"${config.ZipAlign}"},
},
)
)
func init() {
@@ -410,6 +421,15 @@ func GenerateMainClassManifest(ctx android.ModuleContext, outputFile android.Wri
})
}
func TransformZipAlign(ctx android.ModuleContext, outputFile android.WritablePath, inputFile android.Path) {
ctx.Build(pctx, android.BuildParams{
Rule: zipalign,
Description: "align",
Input: inputFile,
Output: outputFile,
})
}
type classpath []android.Path
func (x *classpath) FormJavaClassPath(optName string) string {

View File

@@ -126,6 +126,7 @@ func init() {
pctx.HostJavaToolVariable("JetifierJar", "jetifier.jar")
pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper")
pctx.HostBinToolVariable("DexpreoptGen", "dexpreopt_gen")
pctx.VariableFunc("JavacWrapper", func(ctx android.PackageVarContext) string {
if override := ctx.Config().Getenv("JAVAC_WRAPPER"); override != "" {
@@ -152,4 +153,6 @@ func init() {
pctx.SourcePathsVariable("ManifestMergerJars", " ", ManifestMergerClasspath...)
pctx.SourcePathsVariable("ManifestMergerClasspath", ":", ManifestMergerClasspath...)
pctx.HostBinToolVariable("ZipAlign", "zipalign")
}

View File

@@ -65,6 +65,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("JMOD", "${JmodCmd}")
ctx.Strict("SOONG_JAVAC_WRAPPER", "${SoongJavacWrapper}")
ctx.Strict("DEXPREOPT_GEN", "${DexpreoptGen}")
ctx.Strict("ZIPSYNC", "${ZipSyncCmd}")
ctx.Strict("JACOCO_CLI_JAR", "${JacocoCLIJar}")

246
java/dexpreopt.go Normal file
View File

@@ -0,0 +1,246 @@
// 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 (
"path/filepath"
"strings"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
"android/soong/android"
"android/soong/dexpreopt"
)
type dexpreopter struct {
dexpreoptProperties DexpreoptProperties
installPath android.OutputPath
isPrivApp bool
isSDKLibrary bool
builtInstalled []string
}
type DexpreoptProperties struct {
Dex_preopt struct {
// If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
// true.
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.
Profile *string
}
}
func (d *dexpreopter) dexpreoptDisabled(ctx android.ModuleContext) bool {
if ctx.Config().DisableDexPreopt(ctx.ModuleName()) {
return true
}
if ctx.Config().UnbundledBuild() {
return true
}
if !BoolDefault(d.dexpreoptProperties.Dex_preopt.Enabled, true) {
return true
}
// TODO: contains no java code
// TODO: is test
return false
}
func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.ModuleOutPath) android.ModuleOutPath {
if d.dexpreoptDisabled(ctx) {
return dexJarFile
}
globalConfig := ctx.Config().Once("DexpreoptGlobalConfig", func() interface{} {
if f := ctx.Config().DexpreoptGlobalConfig(); f != "" {
ctx.AddNinjaFileDeps(f)
globalConfig, err := dexpreopt.LoadGlobalConfig(f)
if err != nil {
panic(err)
}
return globalConfig
}
return dexpreopt.GlobalConfig{}
}).(dexpreopt.GlobalConfig)
var archs []string
for _, a := range ctx.MultiTargets() {
archs = append(archs, a.Arch.ArchType.String())
}
if len(archs) == 0 {
// assume this is a java library, dexpreopt for all arches for now
for _, target := range ctx.Config().Targets[android.Android] {
archs = append(archs, target.Arch.ArchType.String())
}
if inList(ctx.ModuleName(), globalConfig.SystemServerJars) && !d.isSDKLibrary {
// If the module is not an SDK library and it's a system server jar, only preopt the primary arch.
archs = archs[:1]
}
}
if ctx.Config().SecondArchIsTranslated() {
// Only preopt primary arch for translated arch since there is only an image there.
archs = archs[:1]
}
dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath)
strippedDexJarFile := android.PathForModuleOut(ctx, "dexpreopt", dexJarFile.Base())
deps := android.Paths{dexJarFile}
var profileClassListing android.OptionalPath
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)))
profileIsTextListing = true
} else {
profileClassListing = android.ExistentPathForSource(ctx,
ctx.Config().DexPreoptProfileDir(), ctx.ModuleName()+".prof")
}
}
if profileClassListing.Valid() {
deps = append(deps, profileClassListing.Path())
}
uncompressedDex := false
if ctx.Config().UncompressPrivAppDex() &&
(d.isPrivApp || inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) {
uncompressedDex = true
}
dexpreoptConfig := dexpreopt.ModuleConfig{
Name: ctx.ModuleName(),
DexLocation: dexLocation,
BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").String(),
DexPath: dexJarFile.String(),
PreferIntegrity: false,
UncompressedDex: uncompressedDex,
HasApkLibraries: false,
PreoptFlags: nil,
ProfileClassListing: profileClassListing.String(),
ProfileIsTextListing: profileIsTextListing,
EnforceUsesLibraries: false,
OptionalUsesLibraries: nil,
UsesLibraries: nil,
LibraryPaths: nil,
Archs: archs,
DexPreoptImageLocation: "",
PreoptExtractedApk: false,
NoCreateAppImage: !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true),
ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false),
StripInputPath: dexJarFile.String(),
StripOutputPath: strippedDexJarFile.String(),
}
dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(globalConfig, dexpreoptConfig)
if err != nil {
ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())
return dexJarFile
}
var inputs android.Paths
for _, input := range dexpreoptRule.Inputs() {
if input == "" {
// Tests sometimes have empty configuration values that lead to empty inputs
continue
}
rel, isRel := android.MaybeRel(ctx, android.PathForModuleOut(ctx).String(), input)
if isRel {
inputs = append(inputs, android.PathForModuleOut(ctx, rel))
} else {
// TODO: use PathForOutput once boot image is moved to where PathForOutput can find it.
inputs = append(inputs, &bootImagePath{input})
}
}
var outputs android.WritablePaths
for _, output := range dexpreoptRule.Outputs() {
rel := android.Rel(ctx, android.PathForModuleOut(ctx).String(), output)
outputs = append(outputs, android.PathForModuleOut(ctx, rel))
}
for _, install := range dexpreoptRule.Installs() {
d.builtInstalled = append(d.builtInstalled, install.From+":"+install.To)
}
if len(dexpreoptRule.Commands()) > 0 {
ctx.Build(pctx, android.BuildParams{
Rule: ctx.Rule(pctx, "dexpreopt", blueprint.RuleParams{
Command: strings.Join(proptools.NinjaEscape(dexpreoptRule.Commands()), " && "),
CommandDeps: dexpreoptRule.Tools(),
}),
Implicits: inputs,
Outputs: outputs,
Description: "dexpreopt",
})
}
stripRule, err := dexpreopt.GenerateStripRule(globalConfig, dexpreoptConfig)
if err != nil {
ctx.ModuleErrorf("error generating dexpreopt strip rule: %s", err.Error())
return dexJarFile
}
ctx.Build(pctx, android.BuildParams{
Rule: ctx.Rule(pctx, "dexpreopt_strip", blueprint.RuleParams{
Command: strings.Join(proptools.NinjaEscape(stripRule.Commands()), " && "),
CommandDeps: stripRule.Tools(),
}),
Input: dexJarFile,
Output: strippedDexJarFile,
Description: "dexpreopt strip",
})
return strippedDexJarFile
}
type bootImagePath struct {
path string
}
var _ android.Path = (*bootImagePath)(nil)
func (p *bootImagePath) String() string { return p.path }
func (p *bootImagePath) Ext() string { return filepath.Ext(p.path) }
func (p *bootImagePath) Base() string { return filepath.Base(p.path) }
func (p *bootImagePath) Rel() string { return p.path }

View File

@@ -217,25 +217,6 @@ type CompilerDeviceProperties struct {
// If set to true, compile dex regardless of installable. Defaults to false.
Compile_dex *bool
Dex_preopt struct {
// If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to
// true.
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.
Profile *string
}
Optimize struct {
// If false, disable all optimization. Defaults to true for android_app and android_test
// modules, false for java_library and java_test modules.
@@ -266,6 +247,7 @@ type CompilerDeviceProperties struct {
System_modules *string
UncompressDex bool `blueprint:"mutated"`
IsSDKLibrary bool `blueprint:"mutated"`
}
// Module contains the properties and members used by all java module types
@@ -295,6 +277,9 @@ type Module struct {
// output file containing classes.dex and resources
dexJarFile android.Path
// output file that contains classes.dex if it should be in the output file
maybeStrippedDexJarFile android.Path
// output file containing uninstrumented classes that will be instrumented by jacoco
jacocoReportClassesFile android.Path
@@ -327,6 +312,8 @@ type Module struct {
// list of source files, collected from compiledJavaSrcs and compiledSrcJars
// filter out Exclude_srcs, will be used by android.IDEInfo struct
expandIDEInfoCompiledSrcs []string
dexpreopter
}
func (j *Module) Srcs() android.Paths {
@@ -1332,7 +1319,15 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
j.dexJarFile = dexOutputFile
dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
j.maybeStrippedDexJarFile = dexOutputFile
outputFile = dexOutputFile
if ctx.Failed() {
return
}
} else {
outputFile = implementationAndResourcesJar
}
@@ -1486,9 +1481,17 @@ type Library struct {
}
func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar")
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
j.compile(ctx)
if Bool(j.properties.Installable) || ctx.Host() {
if j.deviceProperties.UncompressDex {
alignedOutputFile := android.PathForModuleOut(ctx, "aligned", ctx.ModuleName()+".jar")
TransformZipAlign(ctx, alignedOutputFile, j.outputFile)
j.outputFile = alignedOutputFile
}
j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"),
ctx.ModuleName()+".jar", j.outputFile)
}
@@ -1504,6 +1507,7 @@ func LibraryFactory() android.Module {
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
&module.Module.dexpreoptProperties,
&module.Module.protoProperties)
InitJavaModule(module, android.HostAndDeviceSupported)
@@ -1574,6 +1578,7 @@ func TestFactory() android.Module {
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
&module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.testProperties)
@@ -1670,6 +1675,7 @@ func BinaryFactory() android.Module {
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
&module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.binaryProperties)
@@ -1889,6 +1895,7 @@ func DefaultsFactory(props ...interface{}) android.Module {
module.AddProperties(
&CompilerProperties{},
&CompilerDeviceProperties{},
&DexpreoptProperties{},
&android.ProtoProperties{},
&aaptProperties{},
&androidLibraryProperties{},

View File

@@ -141,8 +141,9 @@ type sdkLibrary struct {
android.ModuleBase
android.DefaultableModuleBase
properties sdkLibraryProperties
deviceProperties CompilerDeviceProperties
properties sdkLibraryProperties
deviceProperties CompilerDeviceProperties
dexpreoptProperties DexpreoptProperties
publicApiStubsPath android.Paths
systemApiStubsPath android.Paths
@@ -564,6 +565,7 @@ func (module *sdkLibrary) createImplLibrary(mctx android.TopDownMutatorContext)
Errorprone struct {
Javacflags []string
}
IsSDKLibrary bool
}{}
props.Name = proptools.StringPtr(module.implName())
@@ -574,6 +576,7 @@ func (module *sdkLibrary) createImplLibrary(mctx android.TopDownMutatorContext)
// XML file is installed along with the impl lib
props.Required = []string{module.xmlFileName()}
props.Errorprone.Javacflags = module.properties.Errorprone.Javacflags
props.IsSDKLibrary = true
if module.SocSpecific() {
props.Soc_specific = proptools.BoolPtr(true)
@@ -583,7 +586,10 @@ func (module *sdkLibrary) createImplLibrary(mctx android.TopDownMutatorContext)
props.Product_specific = proptools.BoolPtr(true)
}
mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), &props, &module.deviceProperties)
mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory),
&props,
&module.deviceProperties,
&module.dexpreoptProperties)
}
// Creates the xml file that publicizes the runtime library
@@ -716,6 +722,7 @@ func sdkLibraryFactory() android.Module {
module := &sdkLibrary{}
module.AddProperties(&module.properties)
module.AddProperties(&module.deviceProperties)
module.AddProperties(&module.dexpreoptProperties)
InitJavaModule(module, android.DeviceSupported)
return module
}