Merge "Refactor java compileDex" am: 9eb51fc9d4
am: 46971c5469
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1360617 Change-Id: I574bbe46916d6e268956732f37022ba5f464fcaa
This commit is contained in:
84
java/java.go
84
java/java.go
@@ -264,9 +264,6 @@ type CompilerProperties struct {
|
||||
}
|
||||
|
||||
type CompilerDeviceProperties struct {
|
||||
// list of module-specific flags that will be used for dex compiles
|
||||
Dxflags []string `android:"arch_variant"`
|
||||
|
||||
// if not blank, set to the version of the sdk to compile against.
|
||||
// Defaults to compiling against the current platform.
|
||||
Sdk_version *string
|
||||
@@ -312,37 +309,6 @@ type CompilerDeviceProperties struct {
|
||||
}
|
||||
}
|
||||
|
||||
// If set to true, compile dex regardless of installable. Defaults to false.
|
||||
Compile_dex *bool
|
||||
|
||||
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.
|
||||
Enabled *bool
|
||||
// True if the module containing this has it set by default.
|
||||
EnabledByDefault bool `blueprint:"mutated"`
|
||||
|
||||
// If true, optimize for size by removing unused code. Defaults to true for apps,
|
||||
// false for libraries and tests.
|
||||
Shrink *bool
|
||||
|
||||
// If true, optimize bytecode. Defaults to false.
|
||||
Optimize *bool
|
||||
|
||||
// If true, obfuscate bytecode. Defaults to false.
|
||||
Obfuscate *bool
|
||||
|
||||
// If true, do not use the flag files generated by aapt that automatically keep
|
||||
// classes referenced by the app manifest. Defaults to false.
|
||||
No_aapt_flags *bool
|
||||
|
||||
// Flags to pass to proguard.
|
||||
Proguard_flags []string
|
||||
|
||||
// Specifies the locations of files containing proguard flags.
|
||||
Proguard_flags_files []string `android:"path"`
|
||||
}
|
||||
|
||||
// When targeting 1.9 and above, override the modules to use with --system,
|
||||
// otherwise provides defaults libraries to add to the bootclasspath.
|
||||
System_modules *string
|
||||
@@ -356,12 +322,6 @@ type CompilerDeviceProperties struct {
|
||||
// set the name of the output
|
||||
Stem *string
|
||||
|
||||
// Keep the data uncompressed. We always need uncompressed dex for execution,
|
||||
// so this might actually save space by avoiding storing the same data twice.
|
||||
// This defaults to reasonable value based on module and should not be set.
|
||||
// It exists only to support ART tests.
|
||||
Uncompress_dex *bool
|
||||
|
||||
IsSDKLibrary bool `blueprint:"mutated"`
|
||||
|
||||
// If true, generate the signature file of APK Signing Scheme V4, along side the signed APK file.
|
||||
@@ -369,10 +329,6 @@ type CompilerDeviceProperties struct {
|
||||
V4_signature *bool
|
||||
}
|
||||
|
||||
func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
|
||||
return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault)
|
||||
}
|
||||
|
||||
// Functionality common to Module and Import
|
||||
//
|
||||
// It is embedded in Module so its functionality can be used by methods in Module
|
||||
@@ -441,9 +397,6 @@ type Module struct {
|
||||
// output file containing uninstrumented classes that will be instrumented by jacoco
|
||||
jacocoReportClassesFile android.Path
|
||||
|
||||
// output file containing mapping of obfuscated names
|
||||
proguardDictionary android.Path
|
||||
|
||||
// output file of the module, which may be a classes jar or a dex jar
|
||||
outputFile android.Path
|
||||
extraOutputFiles android.Paths
|
||||
@@ -459,9 +412,6 @@ type Module struct {
|
||||
compiledJavaSrcs android.Paths
|
||||
compiledSrcJars android.Paths
|
||||
|
||||
// list of extra progurad flag files
|
||||
extraProguardFlagFiles android.Paths
|
||||
|
||||
// manifest file to use instead of properties.Manifest
|
||||
overrideManifest android.OptionalPath
|
||||
|
||||
@@ -488,6 +438,7 @@ type Module struct {
|
||||
extraResources android.Paths
|
||||
|
||||
hiddenAPI
|
||||
dexer
|
||||
dexpreopter
|
||||
linter
|
||||
|
||||
@@ -511,6 +462,7 @@ func (j *Module) addHostAndDeviceProperties() {
|
||||
j.addHostProperties()
|
||||
j.AddProperties(
|
||||
&j.deviceProperties,
|
||||
&j.dexer.dexProperties,
|
||||
&j.dexpreoptProperties,
|
||||
&j.linter.properties,
|
||||
)
|
||||
@@ -523,7 +475,10 @@ func (j *Module) OutputFiles(tag string) (android.Paths, error) {
|
||||
case ".jar":
|
||||
return android.Paths{j.implementationAndResourcesJar}, nil
|
||||
case ".proguard_map":
|
||||
return android.Paths{j.proguardDictionary}, nil
|
||||
if j.dexer.proguardDictionary.Valid() {
|
||||
return android.Paths{j.dexer.proguardDictionary.Path()}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("%q was requested, but no output file was found.", tag)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported module reference tag %q", tag)
|
||||
}
|
||||
@@ -732,10 +687,10 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
||||
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...)
|
||||
ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...)
|
||||
ctx.AddVariationDependencies(nil, libTag, sdkDep.classpath...)
|
||||
if j.deviceProperties.EffectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
|
||||
if j.effectiveOptimizeEnabled() && sdkDep.hasStandardLibs() {
|
||||
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.LegacyCorePlatformBootclasspathLibraries...)
|
||||
}
|
||||
if j.deviceProperties.EffectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() {
|
||||
if j.effectiveOptimizeEnabled() && sdkDep.hasFrameworkLibs() {
|
||||
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.FrameworkLibraries...)
|
||||
}
|
||||
}
|
||||
@@ -1651,8 +1606,8 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
||||
|
||||
// Enable dex compilation for the APEX variants, unless it is disabled explicitly
|
||||
if android.DirectlyInAnyApex(ctx, ctx.ModuleName()) && !j.IsForPlatform() {
|
||||
if j.deviceProperties.Compile_dex == nil {
|
||||
j.deviceProperties.Compile_dex = proptools.BoolPtr(true)
|
||||
if j.dexProperties.Compile_dex == nil {
|
||||
j.dexProperties.Compile_dex = proptools.BoolPtr(true)
|
||||
}
|
||||
if j.deviceProperties.Hostdex == nil {
|
||||
j.deviceProperties.Hostdex = proptools.BoolPtr(true)
|
||||
@@ -1660,10 +1615,14 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
||||
}
|
||||
|
||||
if ctx.Device() && j.hasCode(ctx) &&
|
||||
(Bool(j.properties.Installable) || Bool(j.deviceProperties.Compile_dex)) {
|
||||
(Bool(j.properties.Installable) || Bool(j.dexProperties.Compile_dex)) {
|
||||
if j.shouldInstrumentStatic(ctx) {
|
||||
j.dexer.extraProguardFlagFiles = append(j.dexer.extraProguardFlagFiles,
|
||||
android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
|
||||
}
|
||||
// Dex compilation
|
||||
var dexOutputFile android.ModuleOutPath
|
||||
dexOutputFile = j.compileDex(ctx, flags, outputFile, jarName)
|
||||
dexOutputFile = j.dexer.compileDex(ctx, flags, j.minSdkVersion(), outputFile, jarName)
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
@@ -1673,7 +1632,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
||||
|
||||
// Hidden API CSV generation and dex encoding
|
||||
dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, configurationName, primary, dexOutputFile, j.implementationJarFile,
|
||||
proptools.Bool(j.deviceProperties.Uncompress_dex))
|
||||
proptools.Bool(j.dexProperties.Uncompress_dex))
|
||||
|
||||
// merge dex jar with resources if necessary
|
||||
if j.resourceJar != nil {
|
||||
@@ -1681,7 +1640,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
||||
combinedJar := android.PathForModuleOut(ctx, "dex-withres", jarName)
|
||||
TransformJarsToJar(ctx, combinedJar, "for dex resources", jars, android.OptionalPath{},
|
||||
false, nil, nil)
|
||||
if *j.deviceProperties.Uncompress_dex {
|
||||
if *j.dexProperties.Uncompress_dex {
|
||||
combinedAlignedJar := android.PathForModuleOut(ctx, "dex-withres-aligned", jarName)
|
||||
TransformZipAlign(ctx, combinedAlignedJar, combinedJar)
|
||||
dexOutputFile = combinedAlignedJar
|
||||
@@ -2012,11 +1971,11 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
j.checkSdkVersions(ctx)
|
||||
j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", j.Stem()+".jar")
|
||||
j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary
|
||||
if j.deviceProperties.Uncompress_dex == nil {
|
||||
if j.dexProperties.Uncompress_dex == nil {
|
||||
// If the value was not force-set by the user, use reasonable default based on the module.
|
||||
j.deviceProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
|
||||
j.dexProperties.Uncompress_dex = proptools.BoolPtr(shouldUncompressDex(ctx, &j.dexpreopter))
|
||||
}
|
||||
j.dexpreopter.uncompressedDex = *j.deviceProperties.Uncompress_dex
|
||||
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
|
||||
j.compile(ctx, nil)
|
||||
|
||||
// Collect the module directory for IDE info in java/jdeps.go.
|
||||
@@ -2974,6 +2933,7 @@ func DefaultsFactory() android.Module {
|
||||
module.AddProperties(
|
||||
&CompilerProperties{},
|
||||
&CompilerDeviceProperties{},
|
||||
&DexProperties{},
|
||||
&DexpreoptProperties{},
|
||||
&android.ProtoProperties{},
|
||||
&aaptProperties{},
|
||||
|
Reference in New Issue
Block a user