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/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{},