From 48de9a4ef5441dc4013ed7a68218bc47f98483d4 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 2 Oct 2018 13:53:33 -0700 Subject: [PATCH 1/3] Make more java modules defaultable Make java_import, android_library and android_library_import modules defaultable, and add some missing property structs to java_defaults. Also use InitJavaModule everywhere. Test: m checkbuild Change-Id: I981875bbec5d1f87bae73f36a385e0b77c56c368 --- java/aar.go | 5 +++-- java/java.go | 14 ++++++++++---- java/sdk_library.go | 3 +-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/java/aar.go b/java/aar.go index 29f5597a9..35fb96f78 100644 --- a/java/aar.go +++ b/java/aar.go @@ -359,7 +359,7 @@ func AndroidLibraryFactory() android.Module { module.androidLibraryProperties.BuildAAR = true - android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) + InitJavaModule(module, android.DeviceSupported) return module } @@ -382,6 +382,7 @@ type AARImportProperties struct { type AARImport struct { android.ModuleBase + android.DefaultableModuleBase prebuilt android.Prebuilt properties AARImportProperties @@ -555,6 +556,6 @@ func AARImportFactory() android.Module { module.AddProperties(&module.properties) android.InitPrebuiltModule(module, &module.properties.Aars) - android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) + InitJavaModule(module, android.DeviceSupported) return module } diff --git a/java/java.go b/java/java.go index 8b354d91d..b4b8feb23 100644 --- a/java/java.go +++ b/java/java.go @@ -1493,7 +1493,6 @@ func TestFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) InitJavaModule(module, android.HostAndDeviceSupported) - android.InitDefaultableModule(module) return module } @@ -1508,7 +1507,6 @@ func TestHostFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) InitJavaModule(module, android.HostSupported) - android.InitDefaultableModule(module) return module } @@ -1624,6 +1622,7 @@ type ImportProperties struct { type Import struct { android.ModuleBase + android.DefaultableModuleBase prebuilt android.Prebuilt properties ImportProperties @@ -1752,7 +1751,7 @@ func ImportFactory() android.Module { module.AddProperties(&module.properties) android.InitPrebuiltModule(module, &module.properties.Jars) - android.InitAndroidArchModule(module, android.HostAndDeviceSupported, android.MultilibCommon) + InitJavaModule(module, android.HostAndDeviceSupported) return module } @@ -1762,7 +1761,7 @@ func ImportFactoryHost() android.Module { module.AddProperties(&module.properties) android.InitPrebuiltModule(module, &module.properties.Jars) - android.InitAndroidArchModule(module, android.HostSupported, android.MultilibCommon) + InitJavaModule(module, android.HostSupported) return module } @@ -1792,6 +1791,13 @@ func DefaultsFactory(props ...interface{}) android.Module { &CompilerProperties{}, &CompilerDeviceProperties{}, &android.ProtoProperties{}, + &aaptProperties{}, + &androidLibraryProperties{}, + &appProperties{}, + &appTestProperties{}, + &ImportProperties{}, + &AARImportProperties{}, + &sdkLibraryProperties{}, ) android.InitDefaultsModule(module) diff --git a/java/sdk_library.go b/java/sdk_library.go index 3e6908bde..a8c3b118a 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -691,7 +691,6 @@ func sdkLibraryFactory() android.Module { module := &sdkLibrary{} module.AddProperties(&module.properties) module.AddProperties(&module.deviceProperties) - android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) - android.InitDefaultableModule(module) + InitJavaModule(module, android.DeviceSupported) return module } From 5eca7cb229902f35e99aaa485813545493e64f35 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 2 Oct 2018 14:02:10 -0700 Subject: [PATCH 2/3] Clean up archMutator Use a variable for module.base() and separate the full list of targets for the class from the filtered list of targets for the module. Test: m checkbuild Change-Id: I32edd26bcbaff0baf433d0581f253b8a5c8b81f3 --- android/arch.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/android/arch.go b/android/arch.go index 57899cd53..6742b0aa1 100644 --- a/android/arch.go +++ b/android/arch.go @@ -295,32 +295,39 @@ func archMutator(mctx BottomUpMutatorContext) { return } - if !module.base().ArchSpecific() { + base := module.base() + + if !base.ArchSpecific() { return } - osClasses := module.base().OsClassSupported() + osClasses := base.OsClassSupported() var moduleTargets []Target primaryModules := make(map[int]bool) for _, class := range osClasses { - targets := mctx.Config().Targets[class] - if len(targets) == 0 { + classTargets := mctx.Config().Targets[class] + if len(classTargets) == 0 { continue } + // only the primary arch in the recovery partition + if module.InstallInRecovery() { + classTargets = []Target{mctx.Config().Targets[Device][0]} + } + var multilib string switch class { case Device: - multilib = String(module.base().commonProperties.Target.Android.Compile_multilib) + multilib = String(base.commonProperties.Target.Android.Compile_multilib) case Host, HostCross: - multilib = String(module.base().commonProperties.Target.Host.Compile_multilib) + multilib = String(base.commonProperties.Target.Host.Compile_multilib) } if multilib == "" { - multilib = String(module.base().commonProperties.Compile_multilib) + multilib = String(base.commonProperties.Compile_multilib) } if multilib == "" { - multilib = module.base().commonProperties.Default_multilib + multilib = base.commonProperties.Default_multilib } var prefer32 bool switch class { @@ -330,11 +337,7 @@ func archMutator(mctx BottomUpMutatorContext) { // Windows builds always prefer 32-bit prefer32 = true } - // only the primary arch in the recovery partition - if module.InstallInRecovery() { - targets = []Target{mctx.Config().Targets[Device][0]} - } - targets, err := decodeMultilib(multilib, targets, prefer32) + targets, err := decodeMultilib(multilib, classTargets, prefer32) if err != nil { mctx.ModuleErrorf("%s", err.Error()) } @@ -345,7 +348,7 @@ func archMutator(mctx BottomUpMutatorContext) { } if len(moduleTargets) == 0 { - module.base().commonProperties.Enabled = boolPtr(false) + base.commonProperties.Enabled = boolPtr(false) return } From a9d8bee9f33b1835e8f09d9c3bc451294aeaa555 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 2 Oct 2018 13:59:46 -0700 Subject: [PATCH 3/3] Make prefer32 a lambda prefer32 needs to be set differently for app and native modules. Make it use lambda provided by the module type instead of trying to make archMutator figure it out. Test: m checkbuild Change-Id: Ibf8af35fdd3e1721725539d1f5452f4439d2125c --- android/arch.go | 12 +++++------- android/module.go | 6 ++++++ cc/cc.go | 11 +++++++++++ java/app.go | 4 ++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/android/arch.go b/android/arch.go index 6742b0aa1..95f880353 100644 --- a/android/arch.go +++ b/android/arch.go @@ -329,14 +329,12 @@ func archMutator(mctx BottomUpMutatorContext) { if multilib == "" { multilib = base.commonProperties.Default_multilib } - var prefer32 bool - switch class { - case Device: - prefer32 = mctx.Config().DevicePrefer32BitExecutables() - case HostCross: - // Windows builds always prefer 32-bit - prefer32 = true + + prefer32 := false + if base.prefer32 != nil { + prefer32 = base.prefer32(mctx, base, class) } + targets, err := decodeMultilib(multilib, classTargets, prefer32) if err != nil { mctx.ModuleErrorf("%s", err.Error()) diff --git a/android/module.go b/android/module.go index 92b11ed0d..01766b447 100644 --- a/android/module.go +++ b/android/module.go @@ -442,6 +442,8 @@ type ModuleBase struct { // For tests buildParams []BuildParams + + prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool } func (a *ModuleBase) AddProperties(props ...interface{}) { @@ -456,6 +458,10 @@ func (a *ModuleBase) BuildParamsForTests() []BuildParams { return a.buildParams } +func (a *ModuleBase) Prefer32(prefer32 func(ctx BaseModuleContext, base *ModuleBase, class OsClass) bool) { + a.prefer32 = prefer32 +} + // Name returns the name of the module. It may be overridden by individual module types, for // example prebuilts will prepend prebuilt_ to the name. func (a *ModuleBase) Name() string { diff --git a/cc/cc.go b/cc/cc.go index d31a38adc..d04485d71 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -406,6 +406,17 @@ func (c *Module) Init() android.Module { c.AddProperties(feature.props()...) } + c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { + switch class { + case android.Device: + return ctx.Config().DevicePrefer32BitExecutables() + case android.HostCross: + // Windows builds always prefer 32-bit + return true + default: + return false + } + }) android.InitAndroidArchModule(c, c.hod, c.multilib) android.InitDefaultableModule(c) diff --git a/java/app.go b/java/app.go index f8bef1ce8..dc5296d17 100644 --- a/java/app.go +++ b/java/app.go @@ -208,6 +208,10 @@ func AndroidAppFactory() android.Module { &module.aaptProperties, &module.appProperties) + module.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool { + return class == android.Device && ctx.Config().DevicePrefer32BitApps() + }) + InitJavaModule(module, android.DeviceSupported) return module }