Removes usages of SdkMemberTrait/TypeRegistry outside android/sdk.go

In preparation for a refactoring that will dedup the registry code.

Bug: 195754365
Test: m nothing
Change-Id: I93e8485d588f5b4d6b5e2967da5dbef7b6c831ad
This commit is contained in:
Paul Duffin 2021-09-22 11:49:47 +01:00
parent 93b750e2a0
commit 30c830b82a
4 changed files with 45 additions and 35 deletions

View file

@ -538,12 +538,20 @@ func (r *SdkMemberTraitsRegistry) UniqueOnceKey() OnceKey {
return NewCustomOnceKey(r)
}
var RegisteredSdkMemberTraits = &SdkMemberTraitsRegistry{}
var registeredSdkMemberTraits = &SdkMemberTraitsRegistry{}
// RegisteredSdkMemberTraits returns a OnceKey and a sorted list of registered traits.
//
// The key uniquely identifies the array of traits and can be used with OncePer.Once() to cache
// information derived from the array of traits.
func RegisteredSdkMemberTraits() (OnceKey, []SdkMemberTrait) {
return registeredSdkMemberTraits.UniqueOnceKey(), registeredSdkMemberTraits.RegisteredTraits()
}
// RegisterSdkMemberTrait registers an SdkMemberTrait object to allow them to be used in the
// module_exports, module_exports_snapshot, sdk and sdk_snapshot module types.
func RegisterSdkMemberTrait(trait SdkMemberTrait) {
RegisteredSdkMemberTraits = RegisteredSdkMemberTraits.copyAndAppend(trait)
registeredSdkMemberTraits = registeredSdkMemberTraits.copyAndAppend(trait)
}
// SdkMember is an individual member of the SDK.
@ -813,22 +821,43 @@ func (r *SdkMemberTypesRegistry) UniqueOnceKey() OnceKey {
return NewCustomOnceKey(r)
}
// ModuleExportsMemberTypes is the set of registered SdkMemberTypes for module_exports modules.
var ModuleExportsMemberTypes = &SdkMemberTypesRegistry{}
// registeredModuleExportsMemberTypes is the set of registered SdkMemberTypes for module_exports
// modules.
var registeredModuleExportsMemberTypes = &SdkMemberTypesRegistry{}
// SdkMemberTypes is the set of registered SdkMemberTypes for sdk modules.
var SdkMemberTypes = &SdkMemberTypesRegistry{}
// registeredSdkMemberTypes is the set of registered SdkMemberTypes for sdk modules.
var registeredSdkMemberTypes = &SdkMemberTypesRegistry{}
// RegisteredSdkMemberTypes returns a OnceKey and a sorted list of registered types.
//
// If moduleExports is true then the slice of types includes all registered types that can be used
// with the module_exports and module_exports_snapshot module types. Otherwise, the slice of types
// only includes those registered types that can be used with the sdk and sdk_snapshot module
// types.
//
// The key uniquely identifies the array of types and can be used with OncePer.Once() to cache
// information derived from the array of types.
func RegisteredSdkMemberTypes(moduleExports bool) (OnceKey, []SdkMemberType) {
var registry *SdkMemberTypesRegistry
if moduleExports {
registry = registeredModuleExportsMemberTypes
} else {
registry = registeredSdkMemberTypes
}
return registry.UniqueOnceKey(), registry.RegisteredTypes()
}
// RegisterSdkMemberType registers an SdkMemberType object to allow them to be used in the
// module_exports, module_exports_snapshot and (depending on the value returned from
// SdkMemberType.UsableWithSdkAndSdkSnapshot) the sdk and sdk_snapshot module types.
func RegisterSdkMemberType(memberType SdkMemberType) {
// All member types are usable with module_exports.
ModuleExportsMemberTypes = ModuleExportsMemberTypes.copyAndAppend(memberType)
registeredModuleExportsMemberTypes = registeredModuleExportsMemberTypes.copyAndAppend(memberType)
// Only those that explicitly indicate it are usable with sdk.
if memberType.UsableWithSdkAndSdkSnapshot() {
SdkMemberTypes = SdkMemberTypes.copyAndAppend(memberType)
registeredSdkMemberTypes = registeredSdkMemberTypes.copyAndAppend(memberType)
}
}

View file

@ -32,7 +32,7 @@ type sdkMemberTraitListProperty struct {
}
// Cache of dynamically generated dynamicSdkMemberTraits objects. The key is the pointer
// to a slice of SdkMemberTrait instances held in android.RegisteredSdkMemberTraits.
// to a slice of SdkMemberTrait instances returned by android.RegisteredSdkMemberTraits().
var dynamicSdkMemberTraitsMap android.OncePer
// A dynamically generated set of member list properties and associated structure type.
@ -41,7 +41,7 @@ var dynamicSdkMemberTraitsMap android.OncePer
type dynamicSdkMemberTraits struct {
// The dynamically generated structure type.
//
// Contains one []string exported field for each android.RegisteredSdkMemberTraits. The name of
// Contains one []string exported field for each SdkMemberTrait returned by android.RegisteredSdkMemberTraits(). The name of
// the field is the exported form of the value returned by SdkMemberTrait.SdkPropertyName().
propertiesStructType reflect.Type
@ -53,14 +53,7 @@ func (d *dynamicSdkMemberTraits) createMemberTraitListProperties() interface{} {
return reflect.New(d.propertiesStructType).Interface()
}
func getDynamicSdkMemberTraits(registry *android.SdkMemberTraitsRegistry) *dynamicSdkMemberTraits {
// Get a key that uniquely identifies the registry contents.
key := registry.UniqueOnceKey()
// Get the registered traits.
registeredTraits := registry.RegisteredTraits()
func getDynamicSdkMemberTraits(key android.OnceKey, registeredTraits []android.SdkMemberTrait) *dynamicSdkMemberTraits {
// Get the cached value, creating new instance if necessary.
return dynamicSdkMemberTraitsMap.Once(key, func() interface{} {
return createDynamicSdkMemberTraits(registeredTraits)

View file

@ -64,14 +64,7 @@ func (d *dynamicSdkMemberTypes) createMemberTypeListProperties() interface{} {
return reflect.New(d.propertiesStructType).Interface()
}
func getDynamicSdkMemberTypes(registry *android.SdkMemberTypesRegistry) *dynamicSdkMemberTypes {
// Get a key that uniquely identifies the registry contents.
key := registry.UniqueOnceKey()
// Get the registered types.
registeredTypes := registry.RegisteredTypes()
func getDynamicSdkMemberTypes(key android.OnceKey, registeredTypes []android.SdkMemberType) *dynamicSdkMemberTypes {
// Get the cached value, creating new instance if necessary.
return dynamicSdkMemberTypesMap.Once(key, func() interface{} {
return createDynamicSdkMemberTypes(registeredTypes)

View file

@ -111,19 +111,14 @@ func newSdkModule(moduleExports bool) *sdk {
s := &sdk{}
s.properties.Module_exports = moduleExports
// Get the dynamic sdk member type data for the currently registered sdk member types.
var typeRegistry *android.SdkMemberTypesRegistry
if moduleExports {
typeRegistry = android.ModuleExportsMemberTypes
} else {
typeRegistry = android.SdkMemberTypes
}
s.dynamicSdkMemberTypes = getDynamicSdkMemberTypes(typeRegistry)
sdkMemberTypeKey, sdkMemberTypes := android.RegisteredSdkMemberTypes(moduleExports)
s.dynamicSdkMemberTypes = getDynamicSdkMemberTypes(sdkMemberTypeKey, sdkMemberTypes)
// Create an instance of the dynamically created struct that contains all the
// properties for the member type specific list properties.
s.dynamicMemberTypeListProperties = s.dynamicSdkMemberTypes.createMemberTypeListProperties()
traitRegistry := android.RegisteredSdkMemberTraits
s.dynamicSdkMemberTraits = getDynamicSdkMemberTraits(traitRegistry)
sdkMemberTraitsKey, sdkMemberTraits := android.RegisteredSdkMemberTraits()
s.dynamicSdkMemberTraits = getDynamicSdkMemberTraits(sdkMemberTraitsKey, sdkMemberTraits)
// Create an instance of the dynamically created struct that contains all the properties for the
// member trait specific list properties.
s.dynamicMemberTraitListProperties = s.dynamicSdkMemberTraits.createMemberTraitListProperties()