diff --git a/android/sdk.go b/android/sdk.go index 2e057d9b7..048a36cd0 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -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 } diff --git a/sdk/sdk.go b/sdk/sdk.go index 624c0fa9b..b1c8aebf9 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -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 // is the name of an SdkMemberType.SdkPropertyName(). // properties *struct { []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 // is the name of an SdkMemberType.SdkPropertyName(). // properties *struct { []string, ....} @@ -206,8 +210,13 @@ func createDynamicSdkMemberTypes(sdkMemberTypes []android.SdkMemberType) *dynami // *properties. = 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 diff --git a/sdk/update.go b/sdk/update.go index 40dba1937..141762c6f 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -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))