Add support for defaults modules
Add a cc_defaults module, which will prepend any matching properties to modules that reference it with a "defaults" property. Change-Id: I5908dd98d204f71b29ad95a4ab85403aa1621ca2
This commit is contained in:
@@ -91,6 +91,7 @@ bootstrap_go_package {
|
|||||||
srcs: [
|
srcs: [
|
||||||
"common/arch.go",
|
"common/arch.go",
|
||||||
"common/config.go",
|
"common/config.go",
|
||||||
|
"common/defaults.go",
|
||||||
"common/defs.go",
|
"common/defs.go",
|
||||||
"common/env.go",
|
"common/env.go",
|
||||||
"common/glob.go",
|
"common/glob.go",
|
||||||
|
51
cc/cc.go
51
cc/cc.go
@@ -41,6 +41,7 @@ func init() {
|
|||||||
soong.RegisterModuleType("cc_binary", CCBinaryFactory)
|
soong.RegisterModuleType("cc_binary", CCBinaryFactory)
|
||||||
soong.RegisterModuleType("cc_test", CCTestFactory)
|
soong.RegisterModuleType("cc_test", CCTestFactory)
|
||||||
soong.RegisterModuleType("cc_benchmark", CCBenchmarkFactory)
|
soong.RegisterModuleType("cc_benchmark", CCBenchmarkFactory)
|
||||||
|
soong.RegisterModuleType("cc_defaults", CCDefaultsFactory)
|
||||||
|
|
||||||
soong.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
|
soong.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
|
||||||
soong.RegisterModuleType("ndk_prebuilt_library", NdkPrebuiltLibraryFactory)
|
soong.RegisterModuleType("ndk_prebuilt_library", NdkPrebuiltLibraryFactory)
|
||||||
@@ -320,23 +321,26 @@ type CCBaseProperties struct {
|
|||||||
Relative_install_path string
|
Relative_install_path string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CCUnusedProperties struct {
|
||||||
|
Native_coverage *bool
|
||||||
|
Required []string
|
||||||
|
Sanitize []string `android:"arch_variant"`
|
||||||
|
Sanitize_recover []string
|
||||||
|
Strip string
|
||||||
|
Tags []string
|
||||||
|
}
|
||||||
|
|
||||||
// CCBase contains the properties and members used by all C/C++ module types, and implements
|
// CCBase contains the properties and members used by all C/C++ module types, and implements
|
||||||
// the blueprint.Module interface. It expects to be embedded into an outer specialization struct,
|
// the blueprint.Module interface. It expects to be embedded into an outer specialization struct,
|
||||||
// and uses a ccModuleType interface to that struct to create the build steps.
|
// and uses a ccModuleType interface to that struct to create the build steps.
|
||||||
type CCBase struct {
|
type CCBase struct {
|
||||||
common.AndroidModuleBase
|
common.AndroidModuleBase
|
||||||
|
common.DefaultableModule
|
||||||
module CCModuleType
|
module CCModuleType
|
||||||
|
|
||||||
Properties CCBaseProperties
|
Properties CCBaseProperties
|
||||||
|
|
||||||
unused struct {
|
unused CCUnusedProperties
|
||||||
Native_coverage *bool
|
|
||||||
Required []string
|
|
||||||
Sanitize []string `android:"arch_variant"`
|
|
||||||
Sanitize_recover []string
|
|
||||||
Strip string
|
|
||||||
Tags []string
|
|
||||||
}
|
|
||||||
|
|
||||||
installPath string
|
installPath string
|
||||||
|
|
||||||
@@ -350,7 +354,9 @@ func newCCBase(base *CCBase, module CCModuleType, hod common.HostOrDeviceSupport
|
|||||||
|
|
||||||
props = append(props, &base.Properties, &base.unused)
|
props = append(props, &base.Properties, &base.unused)
|
||||||
|
|
||||||
return common.InitAndroidArchModule(module, hod, multilib, props...)
|
_, props = common.InitAndroidArchModule(module, hod, multilib, props...)
|
||||||
|
|
||||||
|
return common.InitDefaultableModule(module, base, props...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *CCBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
func (c *CCBase) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
||||||
@@ -1685,6 +1691,33 @@ func CCBenchmarkHostFactory() (blueprint.Module, []interface{}) {
|
|||||||
return NewCCBinary(&module.CCBinary, module, common.HostSupported)
|
return NewCCBinary(&module.CCBinary, module, common.HostSupported)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Defaults
|
||||||
|
//
|
||||||
|
type CCDefaults struct {
|
||||||
|
common.AndroidModuleBase
|
||||||
|
common.DefaultsModule
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*CCDefaults) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func CCDefaultsFactory() (blueprint.Module, []interface{}) {
|
||||||
|
module := &CCDefaults{}
|
||||||
|
|
||||||
|
propertyStructs := []interface{}{
|
||||||
|
&CCBaseProperties{},
|
||||||
|
&CCLibraryProperties{},
|
||||||
|
&CCBinaryProperties{},
|
||||||
|
&CCUnusedProperties{},
|
||||||
|
}
|
||||||
|
|
||||||
|
_, propertyStructs = common.InitAndroidArchModule(module, common.HostOrDeviceSupported(0),
|
||||||
|
common.Multilib(""), propertyStructs...)
|
||||||
|
|
||||||
|
return common.InitDefaultsModule(module, module, propertyStructs...)
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Device libraries shipped with gcc
|
// Device libraries shipped with gcc
|
||||||
//
|
//
|
||||||
|
@@ -25,6 +25,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
RegisterBottomUpMutator("defaults_deps", defaultsDepsMutator)
|
||||||
|
RegisterTopDownMutator("defaults", defaultsMutator)
|
||||||
|
|
||||||
RegisterBottomUpMutator("host_or_device", HostOrDeviceMutator)
|
RegisterBottomUpMutator("host_or_device", HostOrDeviceMutator)
|
||||||
RegisterBottomUpMutator("arch", ArchMutator)
|
RegisterBottomUpMutator("arch", ArchMutator)
|
||||||
}
|
}
|
||||||
@@ -383,13 +386,11 @@ func ArchMutator(mctx AndroidBottomUpMutatorContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitArchModule(m AndroidModule, defaultMultilib Multilib,
|
func InitArchModule(m AndroidModule,
|
||||||
propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
|
propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
|
||||||
|
|
||||||
base := m.base()
|
base := m.base()
|
||||||
|
|
||||||
base.commonProperties.Compile_multilib = string(defaultMultilib)
|
|
||||||
|
|
||||||
base.generalProperties = append(base.generalProperties,
|
base.generalProperties = append(base.generalProperties,
|
||||||
propertyStructs...)
|
propertyStructs...)
|
||||||
|
|
||||||
|
127
common/defaults.go
Normal file
127
common/defaults.go
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
// Copyright 2015 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/google/blueprint"
|
||||||
|
"github.com/google/blueprint/proptools"
|
||||||
|
)
|
||||||
|
|
||||||
|
type defaultsProperties struct {
|
||||||
|
Defaults []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type DefaultableModule struct {
|
||||||
|
defaultsProperties defaultsProperties
|
||||||
|
defaultableProperties []interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DefaultableModule) defaults() *defaultsProperties {
|
||||||
|
return &d.defaultsProperties
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DefaultableModule) setProperties(props []interface{}) {
|
||||||
|
d.defaultableProperties = props
|
||||||
|
}
|
||||||
|
|
||||||
|
type Defaultable interface {
|
||||||
|
defaults() *defaultsProperties
|
||||||
|
setProperties([]interface{})
|
||||||
|
applyDefaults(AndroidTopDownMutatorContext, Defaults)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Defaultable = (*DefaultableModule)(nil)
|
||||||
|
|
||||||
|
func InitDefaultableModule(module AndroidModule, d Defaultable,
|
||||||
|
props ...interface{}) (blueprint.Module, []interface{}) {
|
||||||
|
|
||||||
|
d.setProperties(props)
|
||||||
|
|
||||||
|
props = append(props, d.defaults())
|
||||||
|
|
||||||
|
return module, props
|
||||||
|
}
|
||||||
|
|
||||||
|
type DefaultsModule struct {
|
||||||
|
defaultProperties []interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Defaults interface {
|
||||||
|
isDefaults() bool
|
||||||
|
setProperties([]interface{})
|
||||||
|
properties() []interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DefaultsModule) isDefaults() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DefaultsModule) properties() []interface{} {
|
||||||
|
return d.defaultProperties
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DefaultsModule) setProperties(props []interface{}) {
|
||||||
|
d.defaultProperties = props
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitDefaultsModule(module AndroidModule, d Defaults, props ...interface{}) (blueprint.Module, []interface{}) {
|
||||||
|
d.setProperties(props)
|
||||||
|
|
||||||
|
return module, props
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Defaults = (*DefaultsModule)(nil)
|
||||||
|
|
||||||
|
func (defaultable *DefaultableModule) applyDefaults(ctx AndroidTopDownMutatorContext,
|
||||||
|
defaults Defaults) {
|
||||||
|
|
||||||
|
for _, prop := range defaultable.defaultableProperties {
|
||||||
|
for _, def := range defaults.properties() {
|
||||||
|
if proptools.TypeEqual(prop, def) {
|
||||||
|
err := proptools.PrependProperties(prop, def, nil)
|
||||||
|
if err != nil {
|
||||||
|
if propertyErr, ok := err.(*proptools.ExtendPropertyError); ok {
|
||||||
|
ctx.PropertyErrorf(propertyErr.Property, "%s", propertyErr.Err.Error())
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultsDepsMutator(ctx AndroidBottomUpMutatorContext) {
|
||||||
|
if defaultable, ok := ctx.Module().(Defaultable); ok {
|
||||||
|
ctx.AddDependency(ctx.Module(), defaultable.defaults().Defaults...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultsMutator(ctx AndroidTopDownMutatorContext) {
|
||||||
|
if defaultable, ok := ctx.Module().(Defaultable); ok {
|
||||||
|
for _, defaultsDep := range defaultable.defaults().Defaults {
|
||||||
|
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
||||||
|
if ctx.OtherModuleName(m) == defaultsDep {
|
||||||
|
if defaultsModule, ok := m.(Defaults); ok {
|
||||||
|
defaultable.applyDefaults(ctx, defaultsModule)
|
||||||
|
} else {
|
||||||
|
ctx.PropertyErrorf("defaults", "module %s is not an defaults module",
|
||||||
|
ctx.OtherModuleName(m))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -127,6 +127,7 @@ func InitAndroidArchModule(m AndroidModule, hod HostOrDeviceSupported, defaultMu
|
|||||||
|
|
||||||
base := m.base()
|
base := m.base()
|
||||||
base.commonProperties.HostOrDeviceSupported = hod
|
base.commonProperties.HostOrDeviceSupported = hod
|
||||||
|
base.commonProperties.Compile_multilib = string(defaultMultilib)
|
||||||
|
|
||||||
if hod == HostAndDeviceSupported {
|
if hod == HostAndDeviceSupported {
|
||||||
// Default to module to device supported, host not supported, can override in module
|
// Default to module to device supported, host not supported, can override in module
|
||||||
@@ -135,7 +136,7 @@ func InitAndroidArchModule(m AndroidModule, hod HostOrDeviceSupported, defaultMu
|
|||||||
propertyStructs = append(propertyStructs, &base.hostAndDeviceProperties)
|
propertyStructs = append(propertyStructs, &base.hostAndDeviceProperties)
|
||||||
}
|
}
|
||||||
|
|
||||||
return InitArchModule(m, defaultMultilib, propertyStructs...)
|
return InitArchModule(m, propertyStructs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A AndroidModuleBase object contains the properties that are common to all Android
|
// A AndroidModuleBase object contains the properties that are common to all Android
|
||||||
|
Reference in New Issue
Block a user