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.
This relands Ib67e2febf9ed921f06e8a86b9ec945c80dff35eb and
I462182638bd57b1367b5bfb0718e975c11ae66f7, along with multiple fixes
to depsfile generation in dexpreopt_gen that caused .odex files for
modules in defined make to be missing dependencies on boot.art, and
a fix to not dexpreopt and strip tests.
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).
Test: OUT_DIR=$PWD/out m
Test: NINJA_ARGS="-t deps out/target/product/sailfish/obj/APPS/Contacts_intermediates/dexpreopt.zip" m
Change-Id: I6bb2c971cee65d2338839753aa0d84939f335b1b
diff --git a/java/aar.go b/java/aar.go
index 99e9136..89517fe 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -357,6 +357,7 @@
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
+ &module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.aaptProperties,
&module.androidLibraryProperties)
diff --git a/java/androidmk.go b/java/androidmk.go
index 0700b58..70d0f7f 100644
--- a/java/androidmk.go
+++ b/java/androidmk.go
@@ -25,7 +25,7 @@
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 @@
}
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 @@
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 @@
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(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 @@
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 @@
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 @@
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 @@
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
diff --git a/java/app.go b/java/app.go
index 392ad3f..a037ef3 100644
--- a/java/app.go
+++ b/java/app.go
@@ -17,6 +17,7 @@
// This file contains the module types for compiling Android apps.
import (
+ "path/filepath"
"strings"
"github.com/google/blueprint"
@@ -67,9 +68,7 @@
// list of native libraries that will be provided in or alongside the resulting jar
Jni_libs []string `android:"arch_variant"`
- AllowDexPreopt bool `blueprint:"mutated"`
- EmbedJNI bool `blueprint:"mutated"`
- StripDex bool `blueprint:"mutated"`
+ EmbedJNI bool `blueprint:"mutated"`
}
type AndroidApp struct {
@@ -143,42 +142,16 @@
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 +201,25 @@
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 +269,9 @@
// 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)
}
}
@@ -337,11 +319,11 @@
module.Module.properties.Instrument = true
module.Module.properties.Installable = proptools.BoolPtr(true)
- module.appProperties.AllowDexPreopt = true
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
+ &module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.aaptProperties,
&module.appProperties)
@@ -399,11 +381,12 @@
module.Module.properties.Instrument = true
module.Module.properties.Installable = proptools.BoolPtr(true)
module.appProperties.EmbedJNI = true
- module.appProperties.AllowDexPreopt = false
+ module.Module.dexpreopter.isTest = true
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
+ &module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.aaptProperties,
&module.appProperties,
@@ -434,11 +417,12 @@
module.Module.properties.Installable = proptools.BoolPtr(true)
module.appProperties.EmbedJNI = true
- module.appProperties.AllowDexPreopt = false
+ module.Module.dexpreopter.isTest = true
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
+ &module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.aaptProperties,
&module.appProperties,
diff --git a/java/builder.go b/java/builder.go
index cefb916..8615664 100644
--- a/java/builder.go
+++ b/java/builder.go
@@ -138,6 +138,17 @@
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 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 {
diff --git a/java/config/config.go b/java/config/config.go
index d2a8c46..da4eed7 100644
--- a/java/config/config.go
+++ b/java/config/config.go
@@ -126,6 +126,7 @@
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 @@
pctx.SourcePathsVariable("ManifestMergerJars", " ", ManifestMergerClasspath...)
pctx.SourcePathsVariable("ManifestMergerClasspath", ":", ManifestMergerClasspath...)
+
+ pctx.HostBinToolVariable("ZipAlign", "zipalign")
}
diff --git a/java/config/makevars.go b/java/config/makevars.go
index 275f496..01adaa7 100644
--- a/java/config/makevars.go
+++ b/java/config/makevars.go
@@ -65,6 +65,7 @@
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}")
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
new file mode 100644
index 0000000..ae8d369
--- /dev/null
+++ b/java/dexpreopt.go
@@ -0,0 +1,250 @@
+// 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
+ isTest 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 d.isTest {
+ return true
+ }
+
+ if !BoolDefault(d.dexpreoptProperties.Dex_preopt.Enabled, true) {
+ return true
+ }
+
+ // TODO: contains no java code
+
+ 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 }
diff --git a/java/java.go b/java/java.go
index 5ed99f7..aea1ef9 100644
--- a/java/java.go
+++ b/java/java.go
@@ -217,25 +217,6 @@
// 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 @@
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 @@
// 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 @@
// 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 @@
j.dexJarFile = dexOutputFile
+ dexOutputFile = j.dexpreopt(ctx, dexOutputFile)
+
+ j.maybeStrippedDexJarFile = dexOutputFile
+
outputFile = dexOutputFile
+
+ if ctx.Failed() {
+ return
+ }
} else {
outputFile = implementationAndResourcesJar
}
@@ -1486,9 +1481,17 @@
}
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 @@
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
+ &module.Module.dexpreoptProperties,
&module.Module.protoProperties)
InitJavaModule(module, android.HostAndDeviceSupported)
@@ -1574,6 +1578,7 @@
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
+ &module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.testProperties)
@@ -1670,6 +1675,7 @@
module.AddProperties(
&module.Module.properties,
&module.Module.deviceProperties,
+ &module.Module.dexpreoptProperties,
&module.Module.protoProperties,
&module.binaryProperties)
@@ -1889,6 +1895,7 @@
module.AddProperties(
&CompilerProperties{},
&CompilerDeviceProperties{},
+ &DexpreoptProperties{},
&android.ProtoProperties{},
&aaptProperties{},
&androidLibraryProperties{},
diff --git a/java/sdk_library.go b/java/sdk_library.go
index fdbf19d..877abe4 100644
--- a/java/sdk_library.go
+++ b/java/sdk_library.go
@@ -141,8 +141,9 @@
android.ModuleBase
android.DefaultableModuleBase
- properties sdkLibraryProperties
- deviceProperties CompilerDeviceProperties
+ properties sdkLibraryProperties
+ deviceProperties CompilerDeviceProperties
+ dexpreoptProperties DexpreoptProperties
publicApiStubsPath android.Paths
systemApiStubsPath android.Paths
@@ -564,6 +565,7 @@
Errorprone struct {
Javacflags []string
}
+ IsSDKLibrary bool
}{}
props.Name = proptools.StringPtr(module.implName())
@@ -574,6 +576,7 @@
// 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 @@
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 @@
module := &sdkLibrary{}
module.AddProperties(&module.properties)
module.AddProperties(&module.deviceProperties)
+ module.AddProperties(&module.dexpreoptProperties)
InitJavaModule(module, android.DeviceSupported)
return module
}