diff options
author | Colin Cross <ccross@android.com> | 2017-06-30 22:54:46 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-06-30 22:54:46 +0000 |
commit | c59a0042a1610bccaec991fd2558555ccf610751 (patch) | |
tree | 98c5328938a0649a118a5ca24cd90953434da1fa /android | |
parent | 73de19749274f4644c2a29620bdd655ab78ca1a3 (diff) | |
parent | 36242850fdad11b4e6fbe061ef30f62e7e8c08d8 (diff) | |
download | build_soong-c59a0042a1610bccaec991fd2558555ccf610751.tar.gz build_soong-c59a0042a1610bccaec991fd2558555ccf610751.tar.bz2 build_soong-c59a0042a1610bccaec991fd2558555ccf610751.zip |
Refactor factories
am: 36242850fd
Change-Id: Ied58f93022523557a5d28edbcd79a76b8e2fb875
Diffstat (limited to 'android')
-rw-r--r-- | android/arch.go | 15 | ||||
-rw-r--r-- | android/defaults.go | 22 | ||||
-rw-r--r-- | android/module.go | 39 | ||||
-rw-r--r-- | android/prebuilt_test.go | 16 | ||||
-rw-r--r-- | android/register.go | 15 |
5 files changed, 59 insertions, 48 deletions
diff --git a/android/arch.go b/android/arch.go index effd5a6b..67ce30eb 100644 --- a/android/arch.go +++ b/android/arch.go @@ -20,7 +20,6 @@ import ( "runtime" "strings" - "github.com/google/blueprint" "github.com/google/blueprint/proptools" ) @@ -491,13 +490,11 @@ func createArchType(props reflect.Type) reflect.Type { var archPropTypeMap OncePer -func InitArchModule(m Module, - propertyStructs ...interface{}) (blueprint.Module, []interface{}) { +func InitArchModule(m Module) { base := m.base() - base.generalProperties = append(base.generalProperties, - propertyStructs...) + base.generalProperties = m.GetProperties() for _, properties := range base.generalProperties { propertiesValue := reflect.ValueOf(properties) @@ -524,17 +521,13 @@ func InitArchModule(m Module, } } - var allProperties []interface{} - allProperties = append(allProperties, base.generalProperties...) for _, asp := range base.archProperties { if asp != nil { - allProperties = append(allProperties, asp) + m.AddProperties(asp) } } - base.customizableProperties = allProperties - - return m, allProperties + base.customizableProperties = m.GetProperties() } var variantReplacer = strings.NewReplacer("-", "_", ".", "_") diff --git a/android/defaults.go b/android/defaults.go index df1409e8..0776405f 100644 --- a/android/defaults.go +++ b/android/defaults.go @@ -50,14 +50,11 @@ type Defaultable interface { var _ Defaultable = (*DefaultableModule)(nil) -func InitDefaultableModule(module Module, d Defaultable, - props ...interface{}) (blueprint.Module, []interface{}) { +func InitDefaultableModule(module Module, d Defaultable) { - d.setProperties(props) + d.setProperties(module.GetProperties()) - props = append(props, d.defaults()) - - return module, props + module.AddProperties(d.defaults()) } type DefaultsModule struct { @@ -79,21 +76,18 @@ func (d *DefaultsModule) properties() []interface{} { return d.defaultableProperties } -func InitDefaultsModule(module Module, d Defaults, props ...interface{}) (blueprint.Module, []interface{}) { - props = append(props, +func InitDefaultsModule(module Module, d Defaults) { + module.AddProperties( &hostAndDeviceProperties{}, &commonProperties{}, &variableProperties{}) - _, props = InitArchModule(module, props...) - - _, props = InitDefaultableModule(module, d, props...) + InitArchModule(module) + InitDefaultableModule(module, d) - props = append(props, &module.base().nameProperties) + module.AddProperties(&module.base().nameProperties) module.base().module = module - - return module, props } var _ Defaults = (*DefaultsModule)(nil) diff --git a/android/module.go b/android/module.go index 8f8f34b3..18810fb8 100644 --- a/android/module.go +++ b/android/module.go @@ -108,6 +108,9 @@ type Module interface { InstallInData() bool InstallInSanitizerDir() bool SkipInstall() + + AddProperties(props ...interface{}) + GetProperties() []interface{} } type nameProperties struct { @@ -194,24 +197,18 @@ const ( NeitherHostNorDeviceSupported ) -func InitAndroidModule(m Module, - propertyStructs ...interface{}) (blueprint.Module, []interface{}) { - +func InitAndroidModule(m Module) { base := m.base() base.module = m - propertyStructs = append(propertyStructs, + m.AddProperties( &base.nameProperties, &base.commonProperties, &base.variableProperties) - - return m, propertyStructs } -func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib, - propertyStructs ...interface{}) (blueprint.Module, []interface{}) { - - _, propertyStructs = InitAndroidModule(m, propertyStructs...) +func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib Multilib) { + InitAndroidModule(m) base := m.base() base.commonProperties.HostOrDeviceSupported = hod @@ -225,10 +222,10 @@ func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib base.hostAndDeviceProperties.Device_supported = boolPtr(true) fallthrough case HostAndDeviceDefault: - propertyStructs = append(propertyStructs, &base.hostAndDeviceProperties) + m.AddProperties(&base.hostAndDeviceProperties) } - return InitArchModule(m, propertyStructs...) + InitArchModule(m) } // A ModuleBase object contains the properties that are common to all Android @@ -250,7 +247,6 @@ func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib // // import ( // "android/soong/android" -// "github.com/google/blueprint" // ) // // type myModule struct { @@ -260,9 +256,11 @@ func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib // } // } // -// func NewMyModule() (blueprint.Module, []interface{}) { +// func NewMyModule() android.Module) { // m := &myModule{} -// return android.InitAndroidModule(m, &m.properties) +// m.AddProperties(&m.properties) +// android.InitAndroidModule(m) +// return m // } // // func (m *myModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -274,6 +272,7 @@ func InitAndroidArchModule(m Module, hod HostOrDeviceSupported, defaultMultilib type ModuleBase struct { // Putting the curiously recurring thing pointing to the thing that contains // the thing pattern to good use. + // TODO: remove this module Module nameProperties nameProperties @@ -295,6 +294,16 @@ type ModuleBase struct { blueprintDir string hooks hooks + + registerProps []interface{} +} + +func (a *ModuleBase) AddProperties(props ...interface{}) { + a.registerProps = append(a.registerProps, props...) +} + +func (a *ModuleBase) GetProperties() []interface{} { + return a.registerProps } // Name returns the name of the module. It may be overridden by individual module types, for diff --git a/android/prebuilt_test.go b/android/prebuilt_test.go index d09518b4..5fa20326 100644 --- a/android/prebuilt_test.go +++ b/android/prebuilt_test.go @@ -123,8 +123,8 @@ func TestPrebuilts(t *testing.T) { for _, test := range prebuiltsTests { t.Run(test.name, func(t *testing.T) { ctx := NewContext() - ctx.RegisterModuleType("prebuilt", newPrebuiltModule) - ctx.RegisterModuleType("source", newSourceModule) + ctx.RegisterModuleType("prebuilt", ModuleFactoryAdaptor(newPrebuiltModule)) + ctx.RegisterModuleType("source", ModuleFactoryAdaptor(newSourceModule)) ctx.MockFileSystem(map[string][]byte{ "Blueprints": []byte(` source { @@ -183,9 +183,11 @@ type prebuiltModule struct { prebuilt Prebuilt } -func newPrebuiltModule() (blueprint.Module, []interface{}) { +func newPrebuiltModule() Module { m := &prebuiltModule{} - return InitAndroidModule(m, &m.prebuilt.Properties) + m.AddProperties(&m.prebuilt.Properties) + InitAndroidModule(m) + return m } func (p *prebuiltModule) Name() string { @@ -210,9 +212,11 @@ type sourceModule struct { dependsOnSourceModule, dependsOnPrebuiltModule bool } -func newSourceModule() (blueprint.Module, []interface{}) { +func newSourceModule() Module { m := &sourceModule{} - return InitAndroidModule(m, &m.properties) + m.AddProperties(&m.properties) + InitAndroidModule(m) + return m } func (s *sourceModule) DepsMutator(ctx BottomUpMutatorContext) { diff --git a/android/register.go b/android/register.go index 93966646..76a1cc9f 100644 --- a/android/register.go +++ b/android/register.go @@ -41,8 +41,19 @@ type mutator struct { var mutators []*mutator -func RegisterModuleType(name string, factory blueprint.ModuleFactory) { - moduleTypes = append(moduleTypes, moduleType{name, factory}) +type ModuleFactory func() Module + +// ModuleFactoryAdapter Wraps a ModuleFactory into a blueprint.ModuleFactory by converting an Module +// into a blueprint.Module and a list of property structs +func ModuleFactoryAdaptor(factory ModuleFactory) blueprint.ModuleFactory { + return func() (blueprint.Module, []interface{}) { + module := factory() + return module, module.GetProperties() + } +} + +func RegisterModuleType(name string, factory ModuleFactory) { + moduleTypes = append(moduleTypes, moduleType{name, ModuleFactoryAdaptor(factory)}) } func RegisterSingletonType(name string, factory blueprint.SingletonFactory) { |