Allow an sdk member type not to provide a bp property
Bug: 181569894 Test: m nothing Change-Id: I7e98f14cb377683457fba32fd05d6c614f78ffeb
This commit is contained in:
parent
0d4ed0ac56
commit
1308205638
|
@ -380,6 +380,10 @@ type SdkMemberType interface {
|
||||||
// The name of the member type property on an sdk module.
|
// The name of the member type property on an sdk module.
|
||||||
SdkPropertyName() string
|
SdkPropertyName() string
|
||||||
|
|
||||||
|
// RequiresBpProperty returns true if this member type requires its property to be usable within
|
||||||
|
// an Android.bp file.
|
||||||
|
RequiresBpProperty() bool
|
||||||
|
|
||||||
// True if the member type supports the sdk/sdk_snapshot, false otherwise.
|
// True if the member type supports the sdk/sdk_snapshot, false otherwise.
|
||||||
UsableWithSdkAndSdkSnapshot() bool
|
UsableWithSdkAndSdkSnapshot() bool
|
||||||
|
|
||||||
|
@ -452,7 +456,12 @@ type SdkMemberType interface {
|
||||||
|
|
||||||
// Base type for SdkMemberType implementations.
|
// Base type for SdkMemberType implementations.
|
||||||
type SdkMemberTypeBase struct {
|
type SdkMemberTypeBase struct {
|
||||||
PropertyName string
|
PropertyName string
|
||||||
|
|
||||||
|
// When set to true BpPropertyNotRequired indicates that the member type does not require the
|
||||||
|
// property to be specifiable in an Android.bp file.
|
||||||
|
BpPropertyNotRequired bool
|
||||||
|
|
||||||
SupportsSdk bool
|
SupportsSdk bool
|
||||||
HostOsDependent bool
|
HostOsDependent bool
|
||||||
|
|
||||||
|
@ -466,6 +475,10 @@ func (b *SdkMemberTypeBase) SdkPropertyName() string {
|
||||||
return b.PropertyName
|
return b.PropertyName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *SdkMemberTypeBase) RequiresBpProperty() bool {
|
||||||
|
return !b.BpPropertyNotRequired
|
||||||
|
}
|
||||||
|
|
||||||
func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool {
|
func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool {
|
||||||
return b.SupportsSdk
|
return b.SupportsSdk
|
||||||
}
|
}
|
||||||
|
|
44
sdk/sdk.go
44
sdk/sdk.go
|
@ -169,23 +169,27 @@ func createDynamicSdkMemberTypes(sdkMemberTypes []android.SdkMemberType) *dynami
|
||||||
var fields []reflect.StructField
|
var fields []reflect.StructField
|
||||||
|
|
||||||
// Iterate over the member types creating StructField and sdkMemberListProperty objects.
|
// Iterate over the member types creating StructField and sdkMemberListProperty objects.
|
||||||
for f, memberType := range sdkMemberTypes {
|
nextFieldIndex := 0
|
||||||
|
for _, memberType := range sdkMemberTypes {
|
||||||
|
|
||||||
p := memberType.SdkPropertyName()
|
p := memberType.SdkPropertyName()
|
||||||
|
|
||||||
// Create a dynamic exported field for the member type's property.
|
var getter func(properties interface{}) []string
|
||||||
fields = append(fields, reflect.StructField{
|
var setter func(properties interface{}, list []string)
|
||||||
Name: proptools.FieldNameForProperty(p),
|
if memberType.RequiresBpProperty() {
|
||||||
Type: reflect.TypeOf([]string{}),
|
// Create a dynamic exported field for the member type's property.
|
||||||
Tag: `android:"arch_variant"`,
|
fields = append(fields, reflect.StructField{
|
||||||
})
|
Name: proptools.FieldNameForProperty(p),
|
||||||
|
Type: reflect.TypeOf([]string{}),
|
||||||
|
Tag: `android:"arch_variant"`,
|
||||||
|
})
|
||||||
|
|
||||||
// Copy the field index for use in the getter func as using the loop variable directly will
|
// Copy the field index for use in the getter func as using the loop variable directly will
|
||||||
// cause all funcs to use the last value.
|
// cause all funcs to use the last value.
|
||||||
fieldIndex := f
|
fieldIndex := nextFieldIndex
|
||||||
|
nextFieldIndex += 1
|
||||||
|
|
||||||
// Create an sdkMemberListProperty for the member type.
|
getter = func(properties interface{}) []string {
|
||||||
memberListProperty := &sdkMemberListProperty{
|
|
||||||
getter: func(properties interface{}) []string {
|
|
||||||
// The properties is expected to be of the following form (where
|
// The properties is expected to be of the following form (where
|
||||||
// <Module_types> is the name of an SdkMemberType.SdkPropertyName().
|
// <Module_types> is the name of an SdkMemberType.SdkPropertyName().
|
||||||
// properties *struct {<Module_types> []string, ....}
|
// properties *struct {<Module_types> []string, ....}
|
||||||
|
@ -195,9 +199,9 @@ func createDynamicSdkMemberTypes(sdkMemberTypes []android.SdkMemberType) *dynami
|
||||||
//
|
//
|
||||||
list := reflect.ValueOf(properties).Elem().Field(fieldIndex).Interface().([]string)
|
list := reflect.ValueOf(properties).Elem().Field(fieldIndex).Interface().([]string)
|
||||||
return list
|
return list
|
||||||
},
|
}
|
||||||
|
|
||||||
setter: func(properties interface{}, list []string) {
|
setter = func(properties interface{}, list []string) {
|
||||||
// The properties is expected to be of the following form (where
|
// The properties is expected to be of the following form (where
|
||||||
// <Module_types> is the name of an SdkMemberType.SdkPropertyName().
|
// <Module_types> is the name of an SdkMemberType.SdkPropertyName().
|
||||||
// properties *struct {<Module_types> []string, ....}
|
// properties *struct {<Module_types> []string, ....}
|
||||||
|
@ -206,8 +210,13 @@ func createDynamicSdkMemberTypes(sdkMemberTypes []android.SdkMemberType) *dynami
|
||||||
// *properties.<Module_types> = list
|
// *properties.<Module_types> = list
|
||||||
//
|
//
|
||||||
reflect.ValueOf(properties).Elem().Field(fieldIndex).Set(reflect.ValueOf(list))
|
reflect.ValueOf(properties).Elem().Field(fieldIndex).Set(reflect.ValueOf(list))
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create an sdkMemberListProperty for the member type.
|
||||||
|
memberListProperty := &sdkMemberListProperty{
|
||||||
|
getter: getter,
|
||||||
|
setter: setter,
|
||||||
memberType: memberType,
|
memberType: memberType,
|
||||||
|
|
||||||
// Dependencies added directly from member properties are always exported.
|
// Dependencies added directly from member properties are always exported.
|
||||||
|
@ -402,6 +411,9 @@ func memberMutator(mctx android.BottomUpMutatorContext) {
|
||||||
// Add dependencies from enabled and non CommonOS variants to the sdk member variants.
|
// Add dependencies from enabled and non CommonOS variants to the sdk member variants.
|
||||||
if s.Enabled() && !s.IsCommonOSVariant() {
|
if s.Enabled() && !s.IsCommonOSVariant() {
|
||||||
for _, memberListProperty := range s.memberListProperties() {
|
for _, memberListProperty := range s.memberListProperties() {
|
||||||
|
if memberListProperty.getter == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
|
names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
|
||||||
if len(names) > 0 {
|
if len(names) > 0 {
|
||||||
tag := memberListProperty.dependencyTag
|
tag := memberListProperty.dependencyTag
|
||||||
|
|
|
@ -513,15 +513,19 @@ func (s *sdk) collateSnapshotModuleInfo(ctx android.BaseModuleContext, sdkVarian
|
||||||
}
|
}
|
||||||
|
|
||||||
combined := sdkVariantToCombinedProperties[memberVariantDep.sdkVariant]
|
combined := sdkVariantToCombinedProperties[memberVariantDep.sdkVariant]
|
||||||
memberTypeProperty := s.memberListProperty(memberVariantDep.memberType)
|
memberListProperty := s.memberListProperty(memberVariantDep.memberType)
|
||||||
memberName := ctx.OtherModuleName(memberVariantDep.variant)
|
memberName := ctx.OtherModuleName(memberVariantDep.variant)
|
||||||
|
|
||||||
|
if memberListProperty.getter == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Append the member to the appropriate list, if it is not already present in the list.
|
// Append the member to the appropriate list, if it is not already present in the list.
|
||||||
memberList := memberTypeProperty.getter(combined.dynamicProperties)
|
memberList := memberListProperty.getter(combined.dynamicProperties)
|
||||||
if !android.InList(memberName, memberList) {
|
if !android.InList(memberName, memberList) {
|
||||||
memberList = append(memberList, memberName)
|
memberList = append(memberList, memberName)
|
||||||
}
|
}
|
||||||
memberTypeProperty.setter(combined.dynamicProperties, memberList)
|
memberListProperty.setter(combined.dynamicProperties, memberList)
|
||||||
}
|
}
|
||||||
|
|
||||||
return list
|
return list
|
||||||
|
@ -573,6 +577,9 @@ func (s *sdk) addSnapshotPropertiesToPropertySet(builder *snapshotBuilder, prope
|
||||||
|
|
||||||
dynamicMemberTypeListProperties := combined.dynamicProperties
|
dynamicMemberTypeListProperties := combined.dynamicProperties
|
||||||
for _, memberListProperty := range s.memberListProperties() {
|
for _, memberListProperty := range s.memberListProperties() {
|
||||||
|
if memberListProperty.getter == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
names := memberListProperty.getter(dynamicMemberTypeListProperties)
|
names := memberListProperty.getter(dynamicMemberTypeListProperties)
|
||||||
if len(names) > 0 {
|
if len(names) > 0 {
|
||||||
propertySet.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names, false))
|
propertySet.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names, false))
|
||||||
|
|
Loading…
Reference in New Issue