Allow an sdk member type not to provide a bp property

Bug: 181569894
Test: m nothing
Change-Id: I7e98f14cb377683457fba32fd05d6c614f78ffeb
This commit is contained in:
Paul Duffin 2021-05-11 00:31:38 +01:00
parent 0d4ed0ac56
commit 1308205638
3 changed files with 52 additions and 20 deletions

View File

@ -380,6 +380,10 @@ type SdkMemberType interface {
// The name of the member type property on an sdk module.
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.
UsableWithSdkAndSdkSnapshot() bool
@ -452,7 +456,12 @@ type SdkMemberType interface {
// Base type for SdkMemberType implementations.
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
HostOsDependent bool
@ -466,6 +475,10 @@ func (b *SdkMemberTypeBase) SdkPropertyName() string {
return b.PropertyName
}
func (b *SdkMemberTypeBase) RequiresBpProperty() bool {
return !b.BpPropertyNotRequired
}
func (b *SdkMemberTypeBase) UsableWithSdkAndSdkSnapshot() bool {
return b.SupportsSdk
}

View File

@ -169,23 +169,27 @@ func createDynamicSdkMemberTypes(sdkMemberTypes []android.SdkMemberType) *dynami
var fields []reflect.StructField
// Iterate over the member types creating StructField and sdkMemberListProperty objects.
for f, memberType := range sdkMemberTypes {
nextFieldIndex := 0
for _, memberType := range sdkMemberTypes {
p := memberType.SdkPropertyName()
// Create a dynamic exported field for the member type's property.
fields = append(fields, reflect.StructField{
Name: proptools.FieldNameForProperty(p),
Type: reflect.TypeOf([]string{}),
Tag: `android:"arch_variant"`,
})
var getter func(properties interface{}) []string
var setter func(properties interface{}, list []string)
if memberType.RequiresBpProperty() {
// Create a dynamic exported field for the member type's property.
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
// cause all funcs to use the last value.
fieldIndex := f
// 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.
fieldIndex := nextFieldIndex
nextFieldIndex += 1
// Create an sdkMemberListProperty for the member type.
memberListProperty := &sdkMemberListProperty{
getter: func(properties interface{}) []string {
getter = func(properties interface{}) []string {
// The properties is expected to be of the following form (where
// <Module_types> is the name of an SdkMemberType.SdkPropertyName().
// properties *struct {<Module_types> []string, ....}
@ -195,9 +199,9 @@ func createDynamicSdkMemberTypes(sdkMemberTypes []android.SdkMemberType) *dynami
//
list := reflect.ValueOf(properties).Elem().Field(fieldIndex).Interface().([]string)
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
// <Module_types> is the name of an SdkMemberType.SdkPropertyName().
// properties *struct {<Module_types> []string, ....}
@ -206,8 +210,13 @@ func createDynamicSdkMemberTypes(sdkMemberTypes []android.SdkMemberType) *dynami
// *properties.<Module_types> = 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,
// 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.
if s.Enabled() && !s.IsCommonOSVariant() {
for _, memberListProperty := range s.memberListProperties() {
if memberListProperty.getter == nil {
continue
}
names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
if len(names) > 0 {
tag := memberListProperty.dependencyTag

View File

@ -513,15 +513,19 @@ func (s *sdk) collateSnapshotModuleInfo(ctx android.BaseModuleContext, sdkVarian
}
combined := sdkVariantToCombinedProperties[memberVariantDep.sdkVariant]
memberTypeProperty := s.memberListProperty(memberVariantDep.memberType)
memberListProperty := s.memberListProperty(memberVariantDep.memberType)
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.
memberList := memberTypeProperty.getter(combined.dynamicProperties)
memberList := memberListProperty.getter(combined.dynamicProperties)
if !android.InList(memberName, memberList) {
memberList = append(memberList, memberName)
}
memberTypeProperty.setter(combined.dynamicProperties, memberList)
memberListProperty.setter(combined.dynamicProperties, memberList)
}
return list
@ -573,6 +577,9 @@ func (s *sdk) addSnapshotPropertiesToPropertySet(builder *snapshotBuilder, prope
dynamicMemberTypeListProperties := combined.dynamicProperties
for _, memberListProperty := range s.memberListProperties() {
if memberListProperty.getter == nil {
continue
}
names := memberListProperty.getter(dynamicMemberTypeListProperties)
if len(names) > 0 {
propertySet.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names, false))