Merge changes Ic2daab29,I884ddd09
* changes:
Skip creating variants for disabled OSes
Use bitfield for HostOrDeviceSupported
diff --git a/android/arch.go b/android/arch.go
index 98ff07a..a5d416c 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -757,7 +757,7 @@
for _, os := range OsTypeList {
for _, t := range mctx.Config().Targets[os] {
- if base.supportsTarget(t, mctx.Config()) {
+ if base.supportsTarget(t) && base.osEnabled(os) {
moduleOSList = append(moduleOSList, os)
break
}
@@ -1183,6 +1183,16 @@
}
base.archProperties = append(base.archProperties, archProperties)
m.AddProperties(archProperties...)
+
+ // Special case the enabled property so the osMutator can skip creating variants that
+ // are disabled.
+ if properties == &base.enabledProperties {
+ if len(archProperties) != 1 {
+ panic(fmt.Errorf("expected a single arch-specific enabledProperties type, found %d",
+ len(archProperties)))
+ }
+ base.archEnabledProperties = archProperties[0].(*archPropRoot)
+ }
}
base.customizableProperties = m.GetProperties()
diff --git a/android/defaults.go b/android/defaults.go
index eb013d7..be5359f 100644
--- a/android/defaults.go
+++ b/android/defaults.go
@@ -174,20 +174,22 @@
func InitDefaultsModule(module DefaultsModule) {
commonProperties := &commonProperties{}
+ enabledProperties := &enabledProperties{}
module.AddProperties(
&hostAndDeviceProperties{},
+ enabledProperties,
commonProperties,
&ApexProperties{},
&distProperties{})
+ base := module.base()
initAndroidModuleBase(module)
initProductVariableModule(module)
InitArchModule(module)
InitDefaultableModule(module)
// Add properties that will not have defaults applied to them.
- base := module.base()
defaultsVisibility := &DefaultsVisibilityProperties{}
module.AddProperties(&base.nameProperties, defaultsVisibility)
diff --git a/android/module.go b/android/module.go
index 3cef3f5..27c145c 100644
--- a/android/module.go
+++ b/android/module.go
@@ -19,6 +19,7 @@
"os"
"path"
"path/filepath"
+ "reflect"
"regexp"
"strings"
"text/scanner"
@@ -513,7 +514,7 @@
Name *string
}
-type commonProperties struct {
+type enabledProperties struct {
// emit build rules for this module
//
// Disabling a module should only be done for those modules that cannot be built
@@ -522,7 +523,9 @@
// disabled as that will prevent them from being built by the checkbuild target
// and so prevent early detection of changes that have broken those modules.
Enabled *bool `android:"arch_variant"`
+}
+type commonProperties struct {
// Controls the visibility of this module to other modules. Allowable values are one or more of
// these formats:
//
@@ -766,27 +769,32 @@
type HostOrDeviceSupported int
const (
- _ HostOrDeviceSupported = iota
+ hostSupported = 1 << iota
+ hostCrossSupported
+ deviceSupported
+ hostDefault
+ deviceDefault
// Host and HostCross are built by default. Device is not supported.
- HostSupported
+ HostSupported = hostSupported | hostCrossSupported | hostDefault
// Host is built by default. HostCross and Device are not supported.
- HostSupportedNoCross
+ HostSupportedNoCross = hostSupported | hostDefault
// Device is built by default. Host and HostCross are not supported.
- DeviceSupported
+ DeviceSupported = deviceSupported | deviceDefault
// Device is built by default. Host and HostCross are supported.
- HostAndDeviceSupported
+ HostAndDeviceSupported = hostSupported | hostCrossSupported | deviceSupported | deviceDefault
// Host, HostCross, and Device are built by default.
- HostAndDeviceDefault
+ HostAndDeviceDefault = hostSupported | hostCrossSupported | hostDefault |
+ deviceSupported | deviceDefault
// Nothing is supported. This is not exposed to the user, but used to mark a
// host only module as unsupported when the module type is not supported on
// the host OS. E.g. benchmarks are supported on Linux but not Darwin.
- NeitherHostNorDeviceSupported
+ NeitherHostNorDeviceSupported = 0
)
type moduleKind int
@@ -826,6 +834,7 @@
m.AddProperties(
&base.nameProperties,
+ &base.enabledProperties,
&base.commonProperties,
&base.distProperties)
@@ -848,8 +857,7 @@
base.commonProperties.ArchSpecific = true
base.commonProperties.UseTargetVariants = true
- switch hod {
- case HostAndDeviceSupported, HostAndDeviceDefault:
+ if hod&hostSupported != 0 && hod&deviceSupported != 0 {
m.AddProperties(&base.hostAndDeviceProperties)
}
@@ -925,6 +933,11 @@
archProperties [][]interface{}
customizableProperties []interface{}
+ // The enabled property is special-cased so that the osMutator can skip creating variants
+ // that are disabled.
+ enabledProperties enabledProperties
+ archEnabledProperties *archPropRoot
+
// Information about all the properties on the module that contains visibility rules that need
// checking.
visibilityPropertyInfo []visibilityProperty
@@ -1100,43 +1113,81 @@
return m.commonProperties.CommonOSVariant
}
-func (m *ModuleBase) supportsTarget(target Target, config Config) bool {
- switch m.commonProperties.HostOrDeviceSupported {
- case HostSupported:
- return target.Os.Class == Host
- case HostSupportedNoCross:
- return target.Os.Class == Host && !target.HostCross
- case DeviceSupported:
- return target.Os.Class == Device
- case HostAndDeviceSupported, HostAndDeviceDefault:
- supported := false
- if Bool(m.hostAndDeviceProperties.Host_supported) ||
- (m.commonProperties.HostOrDeviceSupported == HostAndDeviceDefault &&
- m.hostAndDeviceProperties.Host_supported == nil) {
- supported = supported || target.Os.Class == Host
+// supportsTarget returns true if the given Target is supported by the current module.
+func (m *ModuleBase) supportsTarget(target Target) bool {
+ switch target.Os.Class {
+ case Host:
+ if target.HostCross {
+ return m.HostCrossSupported()
+ } else {
+ return m.HostSupported()
}
- if m.hostAndDeviceProperties.Device_supported == nil ||
- *m.hostAndDeviceProperties.Device_supported {
- supported = supported || target.Os.Class == Device
- }
- return supported
+ case Device:
+ return m.DeviceSupported()
default:
return false
}
}
-func (m *ModuleBase) DeviceSupported() bool {
- return m.commonProperties.HostOrDeviceSupported == DeviceSupported ||
- m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
- (m.hostAndDeviceProperties.Device_supported == nil ||
- *m.hostAndDeviceProperties.Device_supported)
+// osEnabled returns true if the given OS is enabled for the current module.
+func (m *ModuleBase) osEnabled(os OsType) bool {
+ targetStruct := reflect.ValueOf(m.archEnabledProperties.Target)
+
+ if targetStruct.Kind() != reflect.Ptr || targetStruct.Type().Elem().Kind() != reflect.Struct {
+ panic(fmt.Errorf("expected a pointer to a struct, found %s", targetStruct.Type()))
+ }
+
+ if targetStruct.IsNil() {
+ return !os.DefaultDisabled
+ }
+
+ osStruct := targetStruct.Elem().FieldByName(os.Field)
+
+ if targetStruct.Kind() != reflect.Ptr || targetStruct.Type().Elem().Kind() != reflect.Struct {
+ panic(fmt.Errorf("expected a pointer to a struct, found %s", targetStruct.Type()))
+ }
+
+ if osStruct.IsNil() {
+ return !os.DefaultDisabled
+ }
+
+ enabledField := osStruct.Elem().FieldByName("Enabled")
+
+ return proptools.BoolDefault(enabledField.Interface().(*bool), !os.DefaultDisabled)
}
+// DeviceSupported returns true if the current module is supported and enabled for device targets,
+// i.e. the factory method set the HostOrDeviceSupported value to include device support and
+// the device support is enabled by default or enabled by the device_supported property.
+func (m *ModuleBase) DeviceSupported() bool {
+ hod := m.commonProperties.HostOrDeviceSupported
+ // deviceEnabled is true if the device_supported property is true or the HostOrDeviceSupported
+ // value has the deviceDefault bit set.
+ deviceEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Device_supported, hod&deviceDefault != 0)
+ return hod&deviceSupported != 0 && deviceEnabled
+}
+
+// HostSupported returns true if the current module is supported and enabled for host targets,
+// i.e. the factory method set the HostOrDeviceSupported value to include host support and
+// the host support is enabled by default or enabled by the host_supported property.
func (m *ModuleBase) HostSupported() bool {
- return m.commonProperties.HostOrDeviceSupported == HostSupported ||
- m.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
- (m.hostAndDeviceProperties.Host_supported != nil &&
- *m.hostAndDeviceProperties.Host_supported)
+ hod := m.commonProperties.HostOrDeviceSupported
+ // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
+ // value has the hostDefault bit set.
+ hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
+ return hod&hostSupported != 0 && hostEnabled
+}
+
+// HostCrossSupported returns true if the current module is supported and enabled for host cross
+// targets, i.e. the factory method set the HostOrDeviceSupported value to include host cross
+// support and the host cross support is enabled by default or enabled by the
+// host_supported property.
+func (m *ModuleBase) HostCrossSupported() bool {
+ hod := m.commonProperties.HostOrDeviceSupported
+ // hostEnabled is true if the host_supported property is true or the HostOrDeviceSupported
+ // value has the hostDefault bit set.
+ hostEnabled := proptools.BoolDefault(m.hostAndDeviceProperties.Host_supported, hod&hostDefault != 0)
+ return hod&hostCrossSupported != 0 && hostEnabled
}
func (m *ModuleBase) Platform() bool {
@@ -1204,10 +1255,7 @@
if m.commonProperties.ForcedDisabled {
return false
}
- if m.commonProperties.Enabled == nil {
- return !m.Os().DefaultDisabled
- }
- return *m.commonProperties.Enabled
+ return proptools.BoolDefault(m.enabledProperties.Enabled, !m.Os().DefaultDisabled)
}
func (m *ModuleBase) Disable() {
diff --git a/android/path_properties.go b/android/path_properties.go
index 6b1cdb3..ee84c67 100644
--- a/android/path_properties.go
+++ b/android/path_properties.go
@@ -29,7 +29,7 @@
// property that is tagged with android:"path".
func pathDepsMutator(ctx BottomUpMutatorContext) {
m := ctx.Module().(Module)
- if m == nil {
+ if m == nil || !m.Enabled() {
return
}
diff --git a/genrule/genrule.go b/genrule/genrule.go
index f85146c..aea8d01 100644
--- a/genrule/genrule.go
+++ b/genrule/genrule.go
@@ -182,6 +182,9 @@
func toolDepsMutator(ctx android.BottomUpMutatorContext) {
if g, ok := ctx.Module().(*Module); ok {
+ if !g.Enabled() {
+ return
+ }
for _, tool := range g.properties.Tools {
tag := hostToolDependencyTag{label: tool}
if m := android.SrcIsModule(tool); m != "" {