Revert "Remove non-generic provider APIs"

This reverts commit ad50aca6ab.

Reason for revert: Broke builds when combined with aosp/2876755

Change-Id: I3bfbcb05d8c695b9315b7e8e3f63c6bd5c9dbe36
This commit is contained in:
Colin Cross
2023-12-20 00:59:28 +00:00
committed by Gerrit Code Review
parent ad50aca6ab
commit 84b68c90ae
3 changed files with 50 additions and 15 deletions

View File

@@ -75,28 +75,34 @@ type BaseModuleContext interface {
// It is intended for use inside the visit functions of Visit* and WalkDeps. // It is intended for use inside the visit functions of Visit* and WalkDeps.
OtherModuleType(m blueprint.Module) string OtherModuleType(m blueprint.Module) string
// otherModuleProvider returns the value for a provider for the given module. If the value is // OtherModuleProvider returns the value for a provider for the given module. If the value is
// not set it returns nil and false. The value returned may be a deep copy of the value originally // not set it returns the zero value of the type of the provider, so the return value can always
// passed to SetProvider. // be type asserted to the type of the provider. The value returned may be a deep copy of the
// // value originally passed to SetProvider.
// This method shouldn't be used directly, prefer the type-safe android.OtherModuleProvider instead. OtherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) any
// OtherModuleHasProvider returns true if the provider for the given module has been set.
OtherModuleHasProvider(m blueprint.Module, provider blueprint.AnyProviderKey) bool
otherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) otherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) (any, bool)
// Provider returns the value for a provider for the current module. If the value is // Provider returns the value for a provider for the current module. If the value is
// not set it returns nil and false. It panics if called before the appropriate // not set it returns the zero value of the type of the provider, so the return value can always
// be type asserted to the type of the provider. It panics if called before the appropriate
// mutator or GenerateBuildActions pass for the provider. The value returned may be a deep // mutator or GenerateBuildActions pass for the provider. The value returned may be a deep
// copy of the value originally passed to SetProvider. // copy of the value originally passed to SetProvider.
// Provider(provider blueprint.AnyProviderKey) any
// This method shouldn't be used directly, prefer the type-safe android.ModuleProvider instead.
// HasProvider returns true if the provider for the current module has been set.
HasProvider(provider blueprint.AnyProviderKey) bool
provider(provider blueprint.AnyProviderKey) (any, bool) provider(provider blueprint.AnyProviderKey) (any, bool)
// setProvider sets the value for a provider for the current module. It panics if not called // SetProvider sets the value for a provider for the current module. It panics if not called
// during the appropriate mutator or GenerateBuildActions pass for the provider, if the value // during the appropriate mutator or GenerateBuildActions pass for the provider, if the value
// is not of the appropriate type, or if the value has already been set. The value should not // is not of the appropriate type, or if the value has already been set. The value should not
// be modified after being passed to SetProvider. // be modified after being passed to SetProvider.
// SetProvider(provider blueprint.AnyProviderKey, value interface{})
// This method shouldn't be used directly, prefer the type-safe android.SetProvider instead.
setProvider(provider blueprint.AnyProviderKey, value any)
GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
@@ -258,16 +264,35 @@ func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name strin
func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string { func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
return b.bp.OtherModuleType(m) return b.bp.OtherModuleType(m)
} }
func (b *baseModuleContext) OtherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) any {
value, _ := b.bp.OtherModuleProvider(m, provider)
return value
}
func (b *baseModuleContext) OtherModuleHasProvider(m blueprint.Module, provider blueprint.AnyProviderKey) bool {
_, ok := b.bp.OtherModuleProvider(m, provider)
return ok
}
func (b *baseModuleContext) otherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) { func (b *baseModuleContext) otherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) {
return b.bp.OtherModuleProvider(m, provider) return b.bp.OtherModuleProvider(m, provider)
} }
func (b *baseModuleContext) Provider(provider blueprint.AnyProviderKey) any {
value, _ := b.bp.Provider(provider)
return value
}
func (b *baseModuleContext) HasProvider(provider blueprint.AnyProviderKey) bool {
_, ok := b.bp.Provider(provider)
return ok
}
func (b *baseModuleContext) provider(provider blueprint.AnyProviderKey) (any, bool) { func (b *baseModuleContext) provider(provider blueprint.AnyProviderKey) (any, bool) {
return b.bp.Provider(provider) return b.bp.Provider(provider)
} }
func (b *baseModuleContext) setProvider(provider blueprint.AnyProviderKey, value any) { func (b *baseModuleContext) SetProvider(provider blueprint.AnyProviderKey, value any) {
b.bp.SetProvider(provider, value) b.bp.SetProvider(provider, value)
} }

View File

@@ -79,7 +79,7 @@ func SingletonModuleProvider[K any](ctx SingletonModuleProviderContext, module b
// SetProviderContext is a helper interface that is a subset of ModuleContext, BottomUpMutatorContext, or // SetProviderContext is a helper interface that is a subset of ModuleContext, BottomUpMutatorContext, or
// TopDownMutatorContext for use in SetProvider. // TopDownMutatorContext for use in SetProvider.
type SetProviderContext interface { type SetProviderContext interface {
setProvider(provider blueprint.AnyProviderKey, value any) SetProvider(provider blueprint.AnyProviderKey, value any)
} }
var _ SetProviderContext = BaseModuleContext(nil) var _ SetProviderContext = BaseModuleContext(nil)
@@ -95,7 +95,7 @@ var _ SetProviderContext = TopDownMutatorContext(nil)
// SetProviderContext is a helper interface that accepts ModuleContext, BottomUpMutatorContext, or // SetProviderContext is a helper interface that accepts ModuleContext, BottomUpMutatorContext, or
// TopDownMutatorContext. // TopDownMutatorContext.
func SetProvider[K any](ctx SetProviderContext, provider blueprint.ProviderKey[K], value K) { func SetProvider[K any](ctx SetProviderContext, provider blueprint.ProviderKey[K], value K) {
ctx.setProvider(provider, value) ctx.SetProvider(provider, value)
} }
var _ OtherModuleProviderContext = (*otherModuleProviderAdaptor)(nil) var _ OtherModuleProviderContext = (*otherModuleProviderAdaptor)(nil)

View File

@@ -203,6 +203,16 @@ func (ctx *TestContext) HardCodedPreArchMutators(f RegisterMutatorFunc) {
ctx.PreArchMutators(f) ctx.PreArchMutators(f)
} }
func (ctx *TestContext) ModuleProvider(m blueprint.Module, p blueprint.AnyProviderKey) any {
value, _ := ctx.Context.ModuleProvider(m, p)
return value
}
func (ctx *TestContext) ModuleHasProvider(m blueprint.Module, p blueprint.AnyProviderKey) bool {
_, ok := ctx.Context.ModuleProvider(m, p)
return ok
}
func (ctx *TestContext) moduleProvider(m blueprint.Module, p blueprint.AnyProviderKey) (any, bool) { func (ctx *TestContext) moduleProvider(m blueprint.Module, p blueprint.AnyProviderKey) (any, bool) {
return ctx.Context.ModuleProvider(m, p) return ctx.Context.ModuleProvider(m, p)
} }