From d27e7b8e459b3ed89763c910bf97b40512cf5b40 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 2 Jul 2020 11:38:17 -0700 Subject: [PATCH] Add providers support Propagate the providers methods from https://github.com/google/blueprint/pull/309 to Soong. Test: m checkbuild Change-Id: Iad7a9023df4421cd01dbb0518be0e85382097481 --- android/module.go | 40 ++++++++++++++++++++++++++++++++++++++++ android/mutator.go | 12 ++++++++++++ android/singleton.go | 10 ++++++++++ 3 files changed, 62 insertions(+) diff --git a/android/module.go b/android/module.go index 1424f7694..9868c04ef 100644 --- a/android/module.go +++ b/android/module.go @@ -176,6 +176,31 @@ type BaseModuleContext interface { // It is intended for use inside the visit functions of Visit* and WalkDeps. OtherModuleType(m blueprint.Module) string + // OtherModuleProvider returns the value for a provider for the given module. If the value is + // 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. The value returned may be a deep copy of the + // value originally passed to SetProvider. + OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} + + // OtherModuleHasProvider returns true if the provider for the given module has been set. + OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool + + // Provider returns the value for a provider for the current module. If the value is + // 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 + // copy of the value originally passed to SetProvider. + Provider(provider blueprint.ProviderKey) interface{} + + // HasProvider returns true if the provider for the current module has been set. + HasProvider(provider blueprint.ProviderKey) bool + + // 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 + // 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. + SetProvider(provider blueprint.ProviderKey, value interface{}) + GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module // GetDirectDepWithTag returns the Module the direct dependency with the specified name, or nil if @@ -1667,6 +1692,21 @@ func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name strin func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string { return b.bp.OtherModuleType(m) } +func (b *baseModuleContext) OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} { + return b.bp.OtherModuleProvider(m, provider) +} +func (b *baseModuleContext) OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool { + return b.bp.OtherModuleHasProvider(m, provider) +} +func (b *baseModuleContext) Provider(provider blueprint.ProviderKey) interface{} { + return b.bp.Provider(provider) +} +func (b *baseModuleContext) HasProvider(provider blueprint.ProviderKey) bool { + return b.bp.HasProvider(provider) +} +func (b *baseModuleContext) SetProvider(provider blueprint.ProviderKey, value interface{}) { + b.bp.SetProvider(provider, value) +} func (b *baseModuleContext) GetDirectDepWithTag(name string, tag blueprint.DependencyTag) blueprint.Module { return b.bp.GetDirectDepWithTag(name, tag) diff --git a/android/mutator.go b/android/mutator.go index 5acd9926c..7a104772f 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -315,6 +315,14 @@ type BottomUpMutatorContext interface { // be used to add dependencies on the toVariationName variant using the fromVariationName // variant. CreateAliasVariation(fromVariationName, toVariationName string) + + // SetVariationProvider sets the value for a provider for the given newly created variant of + // the current module, i.e. one of the Modules returned by CreateVariations.. It panics if + // not called during the appropriate mutator or GenerateBuildActions pass for the provider, + // if the value is not of the appropriate type, or if the module is not a newly created + // variant of the current module. The value should not be modified after being passed to + // SetVariationProvider. + SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) } type bottomUpMutatorContext struct { @@ -550,3 +558,7 @@ func (b *bottomUpMutatorContext) AliasVariation(variationName string) { func (b *bottomUpMutatorContext) CreateAliasVariation(fromVariationName, toVariationName string) { b.bp.CreateAliasVariation(fromVariationName, toVariationName) } + +func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) { + b.bp.SetVariationProvider(module, provider, value) +} diff --git a/android/singleton.go b/android/singleton.go index 2c51c6c48..9832378d5 100644 --- a/android/singleton.go +++ b/android/singleton.go @@ -29,6 +29,16 @@ type SingletonContext interface { ModuleType(module blueprint.Module) string BlueprintFile(module blueprint.Module) string + // ModuleProvider returns the value, if any, for the provider for a module. If the value for the + // provider was not set it returns the zero value of the type of the provider, which means the + // return value can always be type-asserted to the type of the provider. The return value should + // always be considered read-only. It panics if called before the appropriate mutator or + // GenerateBuildActions pass for the provider on the module. + ModuleProvider(module blueprint.Module, provider blueprint.ProviderKey) interface{} + + // ModuleHasProvider returns true if the provider for the given module has been set. + ModuleHasProvider(module blueprint.Module, provider blueprint.ProviderKey) bool + ModuleErrorf(module blueprint.Module, format string, args ...interface{}) Errorf(format string, args ...interface{}) Failed() bool