Merge "Fix handling optimize.enabled from java_defaults"
am: 36ab727c82
Change-Id: I23a8d2e2dadf413597d59be9d43667bb7bd05193
This commit is contained in:
commit
2f65feddde
4 changed files with 43 additions and 5 deletions
|
@ -438,7 +438,7 @@ func (a *AndroidApp) getCertString(ctx android.BaseContext) string {
|
||||||
func AndroidAppFactory() android.Module {
|
func AndroidAppFactory() android.Module {
|
||||||
module := &AndroidApp{}
|
module := &AndroidApp{}
|
||||||
|
|
||||||
module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
|
module.Module.deviceProperties.Optimize.EnabledByDefault = true
|
||||||
module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true)
|
module.Module.deviceProperties.Optimize.Shrink = proptools.BoolPtr(true)
|
||||||
|
|
||||||
module.Module.properties.Instrument = true
|
module.Module.properties.Instrument = true
|
||||||
|
@ -508,7 +508,7 @@ func (a *AndroidTest) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||||
func AndroidTestFactory() android.Module {
|
func AndroidTestFactory() android.Module {
|
||||||
module := &AndroidTest{}
|
module := &AndroidTest{}
|
||||||
|
|
||||||
module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
|
module.Module.deviceProperties.Optimize.EnabledByDefault = true
|
||||||
|
|
||||||
module.Module.properties.Instrument = true
|
module.Module.properties.Instrument = true
|
||||||
module.Module.properties.Installable = proptools.BoolPtr(true)
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
||||||
|
@ -550,7 +550,7 @@ type AndroidTestHelperApp struct {
|
||||||
func AndroidTestHelperAppFactory() android.Module {
|
func AndroidTestHelperAppFactory() android.Module {
|
||||||
module := &AndroidTestHelperApp{}
|
module := &AndroidTestHelperApp{}
|
||||||
|
|
||||||
module.Module.deviceProperties.Optimize.Enabled = proptools.BoolPtr(true)
|
module.Module.deviceProperties.Optimize.EnabledByDefault = true
|
||||||
|
|
||||||
module.Module.properties.Installable = proptools.BoolPtr(true)
|
module.Module.properties.Installable = proptools.BoolPtr(true)
|
||||||
module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
|
module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true)
|
||||||
|
|
|
@ -171,7 +171,7 @@ func (j *Module) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8F
|
||||||
func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
|
func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
|
||||||
classesJar android.Path, jarName string) android.ModuleOutPath {
|
classesJar android.Path, jarName string) android.ModuleOutPath {
|
||||||
|
|
||||||
useR8 := Bool(j.deviceProperties.Optimize.Enabled)
|
useR8 := j.deviceProperties.EffectiveOptimizeEnabled()
|
||||||
|
|
||||||
// Compile classes.jar into classes.dex and then javalib.jar
|
// Compile classes.jar into classes.dex and then javalib.jar
|
||||||
javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
|
javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
|
||||||
|
|
|
@ -228,6 +228,8 @@ type CompilerDeviceProperties struct {
|
||||||
// If false, disable all optimization. Defaults to true for android_app and android_test
|
// If false, disable all optimization. Defaults to true for android_app and android_test
|
||||||
// modules, false for java_library and java_test modules.
|
// modules, false for java_library and java_test modules.
|
||||||
Enabled *bool
|
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,
|
// If true, optimize for size by removing unused code. Defaults to true for apps,
|
||||||
// false for libraries and tests.
|
// false for libraries and tests.
|
||||||
|
@ -257,6 +259,10 @@ type CompilerDeviceProperties struct {
|
||||||
IsSDKLibrary bool `blueprint:"mutated"`
|
IsSDKLibrary bool `blueprint:"mutated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (me *CompilerDeviceProperties) EffectiveOptimizeEnabled() bool {
|
||||||
|
return BoolDefault(me.Optimize.Enabled, me.Optimize.EnabledByDefault)
|
||||||
|
}
|
||||||
|
|
||||||
// Module contains the properties and members used by all java module types
|
// Module contains the properties and members used by all java module types
|
||||||
type Module struct {
|
type Module struct {
|
||||||
android.ModuleBase
|
android.ModuleBase
|
||||||
|
@ -460,7 +466,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
||||||
} else if sdkDep.useModule {
|
} else if sdkDep.useModule {
|
||||||
ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
|
ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules)
|
||||||
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
|
ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...)
|
||||||
if Bool(j.deviceProperties.Optimize.Enabled) {
|
if j.deviceProperties.EffectiveOptimizeEnabled() {
|
||||||
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
|
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultBootclasspathLibraries...)
|
||||||
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
|
ctx.AddVariationDependencies(nil, proguardRaiseTag, config.DefaultLibraries...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -377,6 +377,7 @@ func TestDefaults(t *testing.T) {
|
||||||
srcs: ["a.java"],
|
srcs: ["a.java"],
|
||||||
libs: ["bar"],
|
libs: ["bar"],
|
||||||
static_libs: ["baz"],
|
static_libs: ["baz"],
|
||||||
|
optimize: {enabled: false},
|
||||||
}
|
}
|
||||||
|
|
||||||
java_library {
|
java_library {
|
||||||
|
@ -393,6 +394,22 @@ func TestDefaults(t *testing.T) {
|
||||||
name: "baz",
|
name: "baz",
|
||||||
srcs: ["c.java"],
|
srcs: ["c.java"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
android_test {
|
||||||
|
name: "atestOptimize",
|
||||||
|
defaults: ["defaults"],
|
||||||
|
optimize: {enabled: true},
|
||||||
|
}
|
||||||
|
|
||||||
|
android_test {
|
||||||
|
name: "atestNoOptimize",
|
||||||
|
defaults: ["defaults"],
|
||||||
|
}
|
||||||
|
|
||||||
|
android_test {
|
||||||
|
name: "atestDefault",
|
||||||
|
srcs: ["a.java"],
|
||||||
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
||||||
|
@ -411,6 +428,21 @@ func TestDefaults(t *testing.T) {
|
||||||
if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
|
if len(combineJar.Inputs) != 2 || combineJar.Inputs[1].String() != baz {
|
||||||
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
|
t.Errorf("foo combineJar inputs %v does not contain %q", combineJar.Inputs, baz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atestOptimize := ctx.ModuleForTests("atestOptimize", "android_common").MaybeRule("r8")
|
||||||
|
if atestOptimize.Output == nil {
|
||||||
|
t.Errorf("atestOptimize should optimize APK")
|
||||||
|
}
|
||||||
|
|
||||||
|
atestNoOptimize := ctx.ModuleForTests("atestNoOptimize", "android_common").MaybeRule("d8")
|
||||||
|
if atestNoOptimize.Output == nil {
|
||||||
|
t.Errorf("atestNoOptimize should not optimize APK")
|
||||||
|
}
|
||||||
|
|
||||||
|
atestDefault := ctx.ModuleForTests("atestDefault", "android_common").MaybeRule("r8")
|
||||||
|
if atestDefault.Output == nil {
|
||||||
|
t.Errorf("atestDefault should optimize APK")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResources(t *testing.T) {
|
func TestResources(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue