diff --git a/aconfig/aconfig_declarations.go b/aconfig/aconfig_declarations.go index c4fc31aae..272ab038e 100644 --- a/aconfig/aconfig_declarations.go +++ b/aconfig/aconfig_declarations.go @@ -120,7 +120,7 @@ type DeclarationsProviderData struct { IntermediateDumpOutputPath android.WritablePath } -var DeclarationsProviderKey = blueprint.NewProvider(DeclarationsProviderData{}) +var DeclarationsProviderKey = blueprint.NewProvider[DeclarationsProviderData]() // This is used to collect the aconfig declarations info on the transitive closure, // the data is keyed on the container. @@ -128,7 +128,7 @@ type TransitiveDeclarationsInfo struct { AconfigFiles map[string]android.Paths } -var TransitiveDeclarationsInfoProvider = blueprint.NewProvider(TransitiveDeclarationsInfo{}) +var TransitiveDeclarationsInfoProvider = blueprint.NewProvider[TransitiveDeclarationsInfo]() func (module *DeclarationsModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { // Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag diff --git a/aconfig/aconfig_value_set.go b/aconfig/aconfig_value_set.go index 94c322a42..4f142e518 100644 --- a/aconfig/aconfig_value_set.go +++ b/aconfig/aconfig_value_set.go @@ -54,7 +54,7 @@ type valueSetProviderData struct { AvailablePackages map[string]android.Paths } -var valueSetProviderKey = blueprint.NewProvider(valueSetProviderData{}) +var valueSetProviderKey = blueprint.NewProvider[valueSetProviderData]() func (module *ValueSetModule) DepsMutator(ctx android.BottomUpMutatorContext) { deps := ctx.AddDependency(ctx.Module(), valueSetTag, module.properties.Values...) diff --git a/aconfig/aconfig_values.go b/aconfig/aconfig_values.go index 621aae8cf..10205bb18 100644 --- a/aconfig/aconfig_values.go +++ b/aconfig/aconfig_values.go @@ -52,7 +52,7 @@ type valuesProviderData struct { Values android.Paths } -var valuesProviderKey = blueprint.NewProvider(valuesProviderData{}) +var valuesProviderKey = blueprint.NewProvider[valuesProviderData]() func (module *ValuesModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { if len(module.properties.Package) == 0 { diff --git a/aidl_library/aidl_library.go b/aidl_library/aidl_library.go index b49c51619..c2f97d96c 100644 --- a/aidl_library/aidl_library.go +++ b/aidl_library/aidl_library.go @@ -64,7 +64,7 @@ type AidlLibraryInfo struct { } // AidlLibraryProvider provides the srcs and the transitive include dirs -var AidlLibraryProvider = blueprint.NewProvider(AidlLibraryInfo{}) +var AidlLibraryProvider = blueprint.NewProvider[AidlLibraryInfo]() func (lib *AidlLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { includeDirsDepSetBuilder := android.NewDepSetBuilder[android.Path](android.PREORDER) diff --git a/android/Android.bp b/android/Android.bp index 2ac1d5fbe..26317b8e4 100644 --- a/android/Android.bp +++ b/android/Android.bp @@ -79,6 +79,7 @@ bootstrap_go_package { "prebuilt.go", "prebuilt_build_tool.go", "proto.go", + "provider.go", "register.go", "rule_builder.go", "sandbox.go", diff --git a/android/androidmk.go b/android/androidmk.go index c4b93c77f..097075e5b 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -159,7 +159,7 @@ type AndroidMkEntriesContext interface { } type AndroidMkExtraEntriesContext interface { - Provider(provider blueprint.ProviderKey) interface{} + Provider(provider blueprint.AnyProviderKey) (any, bool) } type androidMkExtraEntriesContext struct { @@ -167,8 +167,8 @@ type androidMkExtraEntriesContext struct { mod blueprint.Module } -func (a *androidMkExtraEntriesContext) Provider(provider blueprint.ProviderKey) interface{} { - return a.ctx.ModuleProvider(a.mod, provider) +func (a *androidMkExtraEntriesContext) Provider(provider blueprint.AnyProviderKey) (any, bool) { + return a.ctx.moduleProvider(a.mod, provider) } type AndroidMkExtraEntriesFunc func(ctx AndroidMkExtraEntriesContext, entries *AndroidMkEntries) @@ -492,8 +492,9 @@ type fillInEntriesContext interface { ModuleDir(module blueprint.Module) string ModuleSubDir(module blueprint.Module) string Config() Config - ModuleProvider(module blueprint.Module, provider blueprint.ProviderKey) interface{} - ModuleHasProvider(module blueprint.Module, provider blueprint.ProviderKey) bool + ModuleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) any + ModuleHasProvider(module blueprint.Module, provider blueprint.AnyProviderKey) bool + moduleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) ModuleType(module blueprint.Module) string } diff --git a/android/apex.go b/android/apex.go index c6d994033..c0907a758 100644 --- a/android/apex.go +++ b/android/apex.go @@ -89,7 +89,7 @@ type ApexInfo struct { TestApexes []string } -var ApexInfoProvider = blueprint.NewMutatorProvider(ApexInfo{}, "apex") +var ApexInfoProvider = blueprint.NewMutatorProvider[ApexInfo]("apex") func (i ApexInfo) AddJSONData(d *map[string]interface{}) { (*d)["Apex"] = map[string]interface{}{ @@ -145,7 +145,7 @@ type ApexTestForInfo struct { ApexContents []*ApexContents } -var ApexTestForInfoProvider = blueprint.NewMutatorProvider(ApexTestForInfo{}, "apex_test_for") +var ApexTestForInfoProvider = blueprint.NewMutatorProvider[ApexTestForInfo]("apex_test_for") // DepIsInSameApex defines an interface that should be used to determine whether a given dependency // should be considered as part of the same APEX as the current module or not. Note: this was diff --git a/android/apex_contributions.go b/android/apex_contributions.go index f13659a6d..89058fd5a 100644 --- a/android/apex_contributions.go +++ b/android/apex_contributions.go @@ -124,7 +124,7 @@ func (a *allApexContributions) SetPrebuiltSelectionInfoProvider(ctx BaseModuleCo // A provider containing metadata about whether source or prebuilt should be used // This provider will be used in prebuilt_select mutator to redirect deps -var PrebuiltSelectionInfoProvider = blueprint.NewMutatorProvider(PrebuiltSelectionInfoMap{}, "prebuilt_select") +var PrebuiltSelectionInfoProvider = blueprint.NewMutatorProvider[PrebuiltSelectionInfoMap]("prebuilt_select") // Map of baseModuleName to the selected source or prebuilt type PrebuiltSelectionInfoMap map[string]PrebuiltSelectionInfo diff --git a/android/base_module_context.go b/android/base_module_context.go index 4312e9bd4..2a4b12ee5 100644 --- a/android/base_module_context.go +++ b/android/base_module_context.go @@ -79,26 +79,30 @@ type BaseModuleContext interface { // 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{} + 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.ProviderKey) bool + OtherModuleHasProvider(m blueprint.Module, provider blueprint.AnyProviderKey) 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 // 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{} + Provider(provider blueprint.AnyProviderKey) any // HasProvider returns true if the provider for the current module has been set. - HasProvider(provider blueprint.ProviderKey) bool + HasProvider(provider blueprint.AnyProviderKey) bool + + provider(provider blueprint.AnyProviderKey) (any, 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{}) + SetProvider(provider blueprint.AnyProviderKey, value interface{}) GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module @@ -260,19 +264,35 @@ 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{} { +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) { 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.AnyProviderKey) any { + value, _ := b.bp.Provider(provider) + return value } -func (b *baseModuleContext) Provider(provider blueprint.ProviderKey) interface{} { + +func (b *baseModuleContext) HasProvider(provider blueprint.AnyProviderKey) bool { + _, ok := b.bp.Provider(provider) + return ok +} + +func (b *baseModuleContext) provider(provider blueprint.AnyProviderKey) (any, bool) { 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{}) { + +func (b *baseModuleContext) SetProvider(provider blueprint.AnyProviderKey, value any) { b.bp.SetProvider(provider, value) } diff --git a/android/deapexer.go b/android/deapexer.go index 6a93f6087..a674b424e 100644 --- a/android/deapexer.go +++ b/android/deapexer.go @@ -98,7 +98,7 @@ func (i DeapexerInfo) PrebuiltExportPath(apexRelativePath string) WritablePath { // Provider that can be used from within the `GenerateAndroidBuildActions` of a module that depends // on a `deapexer` module to retrieve its `DeapexerInfo`. -var DeapexerProvider = blueprint.NewProvider(DeapexerInfo{}) +var DeapexerProvider = blueprint.NewProvider[DeapexerInfo]() // NewDeapexerInfo creates and initializes a DeapexerInfo that is suitable // for use with a prebuilt_apex module. diff --git a/android/license_metadata.go b/android/license_metadata.go index 609ca7935..b2ba5e57c 100644 --- a/android/license_metadata.go +++ b/android/license_metadata.go @@ -200,7 +200,7 @@ func isContainerFromFileExtensions(installPaths InstallPaths, builtPaths Paths) } // LicenseMetadataProvider is used to propagate license metadata paths between modules. -var LicenseMetadataProvider = blueprint.NewProvider(&LicenseMetadataInfo{}) +var LicenseMetadataProvider = blueprint.NewProvider[*LicenseMetadataInfo]() // LicenseMetadataInfo stores the license metadata path for a module. type LicenseMetadataInfo struct { diff --git a/android/licenses.go b/android/licenses.go index c6b32432b..45c914fa1 100644 --- a/android/licenses.go +++ b/android/licenses.go @@ -322,7 +322,7 @@ type LicenseInfo struct { Licenses []string } -var LicenseInfoProvider = blueprint.NewProvider(LicenseInfo{}) +var LicenseInfoProvider = blueprint.NewProvider[LicenseInfo]() func init() { RegisterMakeVarsProvider(pctx, licensesMakeVarsProvider) diff --git a/android/makevars.go b/android/makevars.go index 0800190c3..5a9fe7c66 100644 --- a/android/makevars.go +++ b/android/makevars.go @@ -92,7 +92,8 @@ type MakeVarsContext interface { ModuleDir(module blueprint.Module) string ModuleSubDir(module blueprint.Module) string ModuleType(module blueprint.Module) string - ModuleProvider(module blueprint.Module, key blueprint.ProviderKey) interface{} + ModuleProvider(module blueprint.Module, key blueprint.AnyProviderKey) any + moduleProvider(module blueprint.Module, key blueprint.AnyProviderKey) (any, bool) BlueprintFile(module blueprint.Module) string ModuleErrorf(module blueprint.Module, format string, args ...interface{}) diff --git a/android/mutator.go b/android/mutator.go index 0d391a47b..93c519d27 100644 --- a/android/mutator.go +++ b/android/mutator.go @@ -325,7 +325,7 @@ type BottomUpMutatorContext interface { // 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{}) + SetVariationProvider(module blueprint.Module, provider blueprint.AnyProviderKey, value interface{}) } type bottomUpMutatorContext struct { @@ -746,6 +746,6 @@ func (b *bottomUpMutatorContext) CreateAliasVariation(fromVariationName, toVaria b.bp.CreateAliasVariation(fromVariationName, toVariationName) } -func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.ProviderKey, value interface{}) { +func (b *bottomUpMutatorContext) SetVariationProvider(module blueprint.Module, provider blueprint.AnyProviderKey, value interface{}) { b.bp.SetVariationProvider(module, provider, value) } diff --git a/android/provider.go b/android/provider.go new file mode 100644 index 000000000..b2cc7c06d --- /dev/null +++ b/android/provider.go @@ -0,0 +1,120 @@ +package android + +import ( + "github.com/google/blueprint" +) + +// OtherModuleProviderContext is a helper interface that is a subset of ModuleContext, BottomUpMutatorContext, or +// TopDownMutatorContext for use in OtherModuleProvider. +type OtherModuleProviderContext interface { + otherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) +} + +var _ OtherModuleProviderContext = BaseModuleContext(nil) +var _ OtherModuleProviderContext = ModuleContext(nil) +var _ OtherModuleProviderContext = BottomUpMutatorContext(nil) +var _ OtherModuleProviderContext = TopDownMutatorContext(nil) + +// OtherModuleProvider reads the provider for the given module. If the provider has been set the value is +// returned and the boolean is true. If it has not been set the zero value of the provider's type is returned +// and the boolean is false. The value returned may be a deep copy of the value originally passed to SetProvider. +// +// OtherModuleProviderContext is a helper interface that accepts ModuleContext, BottomUpMutatorContext, or +// TopDownMutatorContext. +func OtherModuleProvider[K any](ctx OtherModuleProviderContext, module blueprint.Module, provider blueprint.ProviderKey[K]) (K, bool) { + value, ok := ctx.otherModuleProvider(module, provider) + if !ok { + var k K + return k, false + } + return value.(K), ok +} + +// ModuleProviderContext is a helper interface that is a subset of ModuleContext, BottomUpMutatorContext, or +// TopDownMutatorContext for use in ModuleProvider. +type ModuleProviderContext interface { + provider(provider blueprint.AnyProviderKey) (any, bool) +} + +var _ ModuleProviderContext = BaseModuleContext(nil) +var _ ModuleProviderContext = ModuleContext(nil) +var _ ModuleProviderContext = BottomUpMutatorContext(nil) +var _ ModuleProviderContext = TopDownMutatorContext(nil) + +// ModuleProvider reads the provider for the current module. If the provider has been set the value is +// returned and the boolean is true. If it has not been set the zero value of the provider's type is returned +// and the boolean is false. The value returned may be a deep copy of the value originally passed to SetProvider. +// +// ModuleProviderContext is a helper interface that accepts ModuleContext, BottomUpMutatorContext, or +// TopDownMutatorContext. +func ModuleProvider[K any](ctx ModuleProviderContext, provider blueprint.ProviderKey[K]) (K, bool) { + value, ok := ctx.provider(provider) + if !ok { + var k K + return k, false + } + return value.(K), ok +} + +type SingletonModuleProviderContext interface { + moduleProvider(blueprint.Module, blueprint.AnyProviderKey) (any, bool) +} + +var _ SingletonModuleProviderContext = SingletonContext(nil) +var _ SingletonModuleProviderContext = (*TestContext)(nil) + +// SingletonModuleProvider wraps blueprint.SingletonModuleProvider to provide a type-safe method to retrieve the value +// of the given provider from a module using a SingletonContext. If the provider has not been set the first return +// value will be the zero value of the provider's type, and the second return value will be false. If the provider has +// been set the second return value will be true. +func SingletonModuleProvider[K any](ctx SingletonModuleProviderContext, module blueprint.Module, provider blueprint.ProviderKey[K]) (K, bool) { + value, ok := ctx.moduleProvider(module, provider) + if !ok { + var k K + return k, false + } + return value.(K), ok +} + +// SetProviderContext is a helper interface that is a subset of ModuleContext, BottomUpMutatorContext, or +// TopDownMutatorContext for use in SetProvider. +type SetProviderContext interface { + SetProvider(provider blueprint.AnyProviderKey, value any) +} + +var _ SetProviderContext = BaseModuleContext(nil) +var _ SetProviderContext = ModuleContext(nil) +var _ SetProviderContext = BottomUpMutatorContext(nil) +var _ SetProviderContext = TopDownMutatorContext(nil) + +// 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. +// +// SetProviderContext is a helper interface that accepts ModuleContext, BottomUpMutatorContext, or +// TopDownMutatorContext. +func SetProvider[K any](ctx SetProviderContext, provider blueprint.ProviderKey[K], value K) { + ctx.SetProvider(provider, value) +} + +var _ OtherModuleProviderContext = (*otherModuleProviderAdaptor)(nil) + +// An OtherModuleProviderFunc can be passed to NewOtherModuleProviderAdaptor to create an OtherModuleProviderContext +// for use in tests. +type OtherModuleProviderFunc func(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) + +type otherModuleProviderAdaptor struct { + otherModuleProviderFunc OtherModuleProviderFunc +} + +func (p *otherModuleProviderAdaptor) otherModuleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) { + return p.otherModuleProviderFunc(module, provider) +} + +// NewOtherModuleProviderAdaptor returns an OtherModuleProviderContext that proxies calls to otherModuleProvider to +// the provided OtherModuleProviderFunc. It can be used in tests to unit test methods that need to call +// android.OtherModuleProvider. +func NewOtherModuleProviderAdaptor(otherModuleProviderFunc OtherModuleProviderFunc) OtherModuleProviderContext { + return &otherModuleProviderAdaptor{otherModuleProviderFunc} +} diff --git a/android/sdk.go b/android/sdk.go index 6b598ab9e..6d5293e65 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -860,11 +860,11 @@ type ExportedComponentsInfo struct { Components []string } -var ExportedComponentsInfoProvider = blueprint.NewProvider(ExportedComponentsInfo{}) +var ExportedComponentsInfoProvider = blueprint.NewProvider[ExportedComponentsInfo]() // AdditionalSdkInfo contains additional properties to add to the generated SDK info file. type AdditionalSdkInfo struct { Properties map[string]interface{} } -var AdditionalSdkInfoProvider = blueprint.NewProvider(AdditionalSdkInfo{}) +var AdditionalSdkInfoProvider = blueprint.NewProvider[AdditionalSdkInfo]() diff --git a/android/singleton.go b/android/singleton.go index 7c6cf4fd6..8936cac65 100644 --- a/android/singleton.go +++ b/android/singleton.go @@ -20,6 +20,8 @@ import ( // SingletonContext type SingletonContext interface { + blueprintSingletonContext() blueprint.SingletonContext + Config() Config DeviceConfig() DeviceConfig @@ -38,10 +40,12 @@ type SingletonContext interface { // 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{} + ModuleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) any // ModuleHasProvider returns true if the provider for the given module has been set. - ModuleHasProvider(module blueprint.Module, provider blueprint.ProviderKey) bool + ModuleHasProvider(module blueprint.Module, provider blueprint.AnyProviderKey) bool + + moduleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) ModuleErrorf(module blueprint.Module, format string, args ...interface{}) Errorf(format string, args ...interface{}) @@ -135,6 +139,10 @@ type singletonContextAdaptor struct { ruleParams map[blueprint.Rule]blueprint.RuleParams } +func (s *singletonContextAdaptor) blueprintSingletonContext() blueprint.SingletonContext { + return s.SingletonContext +} + func (s *singletonContextAdaptor) Config() Config { return s.SingletonContext.Config().(Config) } @@ -282,3 +290,18 @@ func (s *singletonContextAdaptor) ModuleVariantsFromName(referer Module, name st } return result } + +func (s *singletonContextAdaptor) ModuleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) any { + value, _ := s.SingletonContext.ModuleProvider(module, provider) + return value +} + +// ModuleHasProvider returns true if the provider for the given module has been set. +func (s *singletonContextAdaptor) ModuleHasProvider(module blueprint.Module, provider blueprint.AnyProviderKey) bool { + _, ok := s.SingletonContext.ModuleProvider(module, provider) + return ok +} + +func (s *singletonContextAdaptor) moduleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) { + return s.SingletonContext.ModuleProvider(module, provider) +} diff --git a/android/testing.go b/android/testing.go index fa4dffd9b..39a268b23 100644 --- a/android/testing.go +++ b/android/testing.go @@ -203,7 +203,17 @@ func (ctx *TestContext) HardCodedPreArchMutators(f RegisterMutatorFunc) { ctx.PreArchMutators(f) } -func (ctx *TestContext) ModuleProvider(m blueprint.Module, p blueprint.ProviderKey) interface{} { +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) { return ctx.Context.ModuleProvider(m, p) } @@ -225,6 +235,12 @@ func (ctx *TestContext) PreArchBp2BuildMutators(f RegisterMutatorFunc) { ctx.bp2buildPreArch = append(ctx.bp2buildPreArch, f) } +func (ctx *TestContext) OtherModuleProviderAdaptor() OtherModuleProviderContext { + return NewOtherModuleProviderAdaptor(func(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) { + return ctx.moduleProvider(module, provider) + }) +} + // registeredComponentOrder defines the order in which a sortableComponent type is registered at // runtime and provides support for reordering the components registered for a test in the same // way. diff --git a/apex/apex.go b/apex/apex.go index 38a166eb3..53727644a 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -912,13 +912,13 @@ type DCLAInfo struct { ProvidedLibs []string } -var DCLAInfoProvider = blueprint.NewMutatorProvider(DCLAInfo{}, "apex_info") +var DCLAInfoProvider = blueprint.NewMutatorProvider[DCLAInfo]("apex_info") type ApexBundleInfo struct { Contents *android.ApexContents } -var ApexBundleInfoProvider = blueprint.NewMutatorProvider(ApexBundleInfo{}, "apex_info") +var ApexBundleInfoProvider = blueprint.NewMutatorProvider[ApexBundleInfo]("apex_info") var _ ApexInfoMutator = (*apexBundle)(nil) diff --git a/apex/classpath_element_test.go b/apex/classpath_element_test.go index 9142eed99..1ce60ced9 100644 --- a/apex/classpath_element_test.go +++ b/apex/classpath_element_test.go @@ -33,11 +33,11 @@ type testClasspathElementContext struct { errs []error } -func (t *testClasspathElementContext) OtherModuleHasProvider(module blueprint.Module, provider blueprint.ProviderKey) bool { +func (t *testClasspathElementContext) OtherModuleHasProvider(module blueprint.Module, provider blueprint.AnyProviderKey) bool { return t.testContext.ModuleHasProvider(module, provider) } -func (t *testClasspathElementContext) OtherModuleProvider(module blueprint.Module, provider blueprint.ProviderKey) interface{} { +func (t *testClasspathElementContext) OtherModuleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) interface{} { return t.testContext.ModuleProvider(module, provider) } diff --git a/bloaty/bloaty.go b/bloaty/bloaty.go index 3cff60fe6..97eba7055 100644 --- a/bloaty/bloaty.go +++ b/bloaty/bloaty.go @@ -26,7 +26,7 @@ const bloatyDescriptorExt = ".bloaty.csv" const protoFilename = "binary_sizes.pb.gz" var ( - fileSizeMeasurerKey blueprint.ProviderKey + fileSizeMeasurerKey blueprint.ProviderKey[measuredFiles] pctx = android.NewPackageContext("android/soong/bloaty") // bloaty is used to measure a binary section sizes. @@ -52,7 +52,7 @@ func init() { pctx.SourcePathVariable("bloaty", "prebuilts/build-tools/${hostPrebuiltTag}/bin/bloaty") pctx.HostBinToolVariable("bloatyMerger", "bloaty_merger") android.RegisterParallelSingletonType("file_metrics", fileSizesSingleton) - fileSizeMeasurerKey = blueprint.NewProvider(measuredFiles{}) + fileSizeMeasurerKey = blueprint.NewProvider[measuredFiles]() } // measuredFiles contains the paths of the files measured by a module. diff --git a/cc/fdo_profile.go b/cc/fdo_profile.go index 02f68b515..74d511aad 100644 --- a/cc/fdo_profile.go +++ b/cc/fdo_profile.go @@ -43,7 +43,7 @@ type FdoProfileInfo struct { } // FdoProfileProvider is used to provide path to an fdo profile -var FdoProfileProvider = blueprint.NewMutatorProvider(FdoProfileInfo{}, "fdo_profile") +var FdoProfileProvider = blueprint.NewMutatorProvider[FdoProfileInfo]("fdo_profile") // FdoProfileMutatorInterface is the interface implemented by fdo_profile module type // module types that can depend on an fdo_profile module diff --git a/cc/linkable.go b/cc/linkable.go index 994517c0a..a009c6c7c 100644 --- a/cc/linkable.go +++ b/cc/linkable.go @@ -368,7 +368,7 @@ type SharedLibraryInfo struct { TransitiveStaticLibrariesForOrdering *android.DepSet[android.Path] } -var SharedLibraryInfoProvider = blueprint.NewProvider(SharedLibraryInfo{}) +var SharedLibraryInfoProvider = blueprint.NewProvider[SharedLibraryInfo]() // SharedStubLibrary is a struct containing information about a stub shared library. // Stub libraries are used for cross-APEX dependencies; when a library is to depend on a shared @@ -391,7 +391,7 @@ type SharedLibraryStubsInfo struct { IsLLNDK bool } -var SharedLibraryStubsProvider = blueprint.NewProvider(SharedLibraryStubsInfo{}) +var SharedLibraryStubsProvider = blueprint.NewProvider[SharedLibraryStubsInfo]() // StaticLibraryInfo is a provider to propagate information about a static C++ library. type StaticLibraryInfo struct { @@ -410,14 +410,14 @@ type StaticLibraryInfo struct { TransitiveStaticLibrariesForOrdering *android.DepSet[android.Path] } -var StaticLibraryInfoProvider = blueprint.NewProvider(StaticLibraryInfo{}) +var StaticLibraryInfoProvider = blueprint.NewProvider[StaticLibraryInfo]() // HeaderLibraryInfo is a marker provider that identifies a module as a header library. type HeaderLibraryInfo struct { } // HeaderLibraryInfoProvider is a marker provider that identifies a module as a header library. -var HeaderLibraryInfoProvider = blueprint.NewProvider(HeaderLibraryInfo{}) +var HeaderLibraryInfoProvider = blueprint.NewProvider[HeaderLibraryInfo]() // FlagExporterInfo is a provider to propagate transitive library information // pertaining to exported include paths and flags. @@ -429,4 +429,4 @@ type FlagExporterInfo struct { GeneratedHeaders android.Paths } -var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{}) +var FlagExporterInfoProvider = blueprint.NewProvider[FlagExporterInfo]() diff --git a/cc/sanitize_test.go b/cc/sanitize_test.go index 31e668ea9..cfc9ed215 100644 --- a/cc/sanitize_test.go +++ b/cc/sanitize_test.go @@ -49,7 +49,7 @@ var prepareForTsanTest = android.FixtureAddFile("tsan/Android.bp", []byte(` `)) type providerInterface interface { - ModuleProvider(blueprint.Module, blueprint.ProviderKey) interface{} + ModuleProvider(blueprint.Module, blueprint.AnyProviderKey) interface{} } // expectSharedLinkDep verifies that the from module links against the to module as a diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go index e29c446e7..a9c4c853e 100644 --- a/cc/snapshot_prebuilt.go +++ b/cc/snapshot_prebuilt.go @@ -209,7 +209,7 @@ type SnapshotInfo struct { HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs, Dylibs map[string]string } -var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps") +var SnapshotInfoProvider = blueprint.NewMutatorProvider[SnapshotInfo]("deps") var _ android.ImageInterface = (*snapshotModule)(nil) diff --git a/java/aar.go b/java/aar.go index af99cd0eb..bb24f2dae 100644 --- a/java/aar.go +++ b/java/aar.go @@ -1069,7 +1069,7 @@ type JniPackageInfo struct { JniPackages android.Paths } -var JniPackageProvider = blueprint.NewProvider(JniPackageInfo{}) +var JniPackageProvider = blueprint.NewProvider[JniPackageInfo]() // Unzip an AAR and extract the JNI libs for $archString. var extractJNI = pctx.AndroidStaticRule("extractJNI", @@ -1256,11 +1256,11 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { }, }) } - - ctx.SetProvider(JniPackageProvider, JniPackageInfo{ - JniPackages: a.jniPackages, - }) } + + ctx.SetProvider(JniPackageProvider, JniPackageInfo{ + JniPackages: a.jniPackages, + }) } func (a *AARImport) HeaderJars() android.Paths { diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 191a65ec1..4eb916d59 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -352,7 +352,7 @@ func (m *BootclasspathFragmentModule) bootclasspathFragmentPropertyCheck(ctx and } } -var BootclasspathFragmentApexContentInfoProvider = blueprint.NewProvider(BootclasspathFragmentApexContentInfo{}) +var BootclasspathFragmentApexContentInfoProvider = blueprint.NewProvider[BootclasspathFragmentApexContentInfo]() // BootclasspathFragmentApexContentInfo contains the bootclasspath_fragments contributions to the // apex contents. diff --git a/java/classpath_element.go b/java/classpath_element.go index 496291678..af99fb4fb 100644 --- a/java/classpath_element.go +++ b/java/classpath_element.go @@ -72,8 +72,8 @@ var _ ClasspathElement = (*ClasspathLibraryElement)(nil) // ClasspathElementContext defines the context methods needed by CreateClasspathElements type ClasspathElementContext interface { - OtherModuleHasProvider(m blueprint.Module, provider blueprint.ProviderKey) bool - OtherModuleProvider(m blueprint.Module, provider blueprint.ProviderKey) interface{} + OtherModuleHasProvider(m blueprint.Module, provider blueprint.AnyProviderKey) bool + OtherModuleProvider(m blueprint.Module, provider blueprint.AnyProviderKey) interface{} ModuleErrorf(fmt string, args ...interface{}) } diff --git a/java/classpath_fragment.go b/java/classpath_fragment.go index bc9de5043..eecaebdb9 100644 --- a/java/classpath_fragment.go +++ b/java/classpath_fragment.go @@ -211,7 +211,7 @@ func (c *ClasspathFragmentBase) androidMkEntries() []android.AndroidMkEntries { }} } -var ClasspathFragmentProtoContentInfoProvider = blueprint.NewProvider(ClasspathFragmentProtoContentInfo{}) +var ClasspathFragmentProtoContentInfoProvider = blueprint.NewProvider[ClasspathFragmentProtoContentInfo]() type ClasspathFragmentProtoContentInfo struct { // Whether the classpaths.proto config is generated for the fragment. diff --git a/java/code_metadata_test.go b/java/code_metadata_test.go index 4b05d9ea6..8f8abd7cc 100644 --- a/java/code_metadata_test.go +++ b/java/code_metadata_test.go @@ -114,7 +114,7 @@ func TestCodeMetadata(t *testing.T) { } } func runCodeMetadataTest( - t *testing.T, errorHandler android.FixtureErrorHandler, bp string, + t *testing.T, errorHandler android.FixtureErrorHandler, bp string, ) *android.TestResult { return android.GroupFixturePreparers( soongTesting.PrepareForTestWithTestingBuildComponents, prepareForJavaTest, diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go index fbc0197d6..3fc0883ce 100644 --- a/java/hiddenapi_modular.go +++ b/java/hiddenapi_modular.go @@ -600,7 +600,7 @@ func (i *HiddenAPIInfo) FlagSubset() SignatureCsvSubset { return SignatureCsvSubset{i.FilteredFlagsPath, i.SignaturePatternsPath} } -var HiddenAPIInfoProvider = blueprint.NewProvider(HiddenAPIInfo{}) +var HiddenAPIInfoProvider = blueprint.NewProvider[HiddenAPIInfo]() // HiddenAPIInfoForSdk contains information provided by the hidden API processing for use // by the sdk snapshot. @@ -617,7 +617,7 @@ type HiddenAPIInfoForSdk struct { } // Provides hidden API info for the sdk snapshot. -var HiddenAPIInfoForSdkProvider = blueprint.NewProvider(HiddenAPIInfoForSdk{}) +var HiddenAPIInfoForSdkProvider = blueprint.NewProvider[HiddenAPIInfoForSdk]() // ModuleStubDexJars contains the stub dex jars provided by a single module. // @@ -749,7 +749,7 @@ type HiddenAPIPropertyInfo struct { SplitPackages []string } -var hiddenAPIPropertyInfoProvider = blueprint.NewProvider(HiddenAPIPropertyInfo{}) +var hiddenAPIPropertyInfoProvider = blueprint.NewProvider[HiddenAPIPropertyInfo]() // newHiddenAPIPropertyInfo creates a new initialized HiddenAPIPropertyInfo struct. func newHiddenAPIPropertyInfo() HiddenAPIPropertyInfo { diff --git a/java/hiddenapi_monolithic.go b/java/hiddenapi_monolithic.go index 5956e3c6c..c1594e9a2 100644 --- a/java/hiddenapi_monolithic.go +++ b/java/hiddenapi_monolithic.go @@ -90,4 +90,4 @@ func (i *MonolithicHiddenAPIInfo) append(other *HiddenAPIInfo) { i.FlagSubsets = append(i.FlagSubsets, other.FlagSubset()) } -var MonolithicHiddenAPIInfoProvider = blueprint.NewProvider(MonolithicHiddenAPIInfo{}) +var MonolithicHiddenAPIInfoProvider = blueprint.NewProvider[MonolithicHiddenAPIInfo]() diff --git a/java/java.go b/java/java.go index 9be8bfd28..d38af13d0 100644 --- a/java/java.go +++ b/java/java.go @@ -239,7 +239,7 @@ type ProguardSpecInfo struct { UnconditionallyExportedProguardFlags *android.DepSet[android.Path] } -var ProguardSpecInfoProvider = blueprint.NewProvider(ProguardSpecInfo{}) +var ProguardSpecInfoProvider = blueprint.NewProvider[ProguardSpecInfo]() // JavaInfo contains information about a java module for use by modules that depend on it. type JavaInfo struct { @@ -295,7 +295,7 @@ type JavaInfo struct { JacocoReportClassesFile android.Path } -var JavaInfoProvider = blueprint.NewProvider(JavaInfo{}) +var JavaInfoProvider = blueprint.NewProvider[JavaInfo]() // SyspropPublicStubInfo contains info about the sysprop public stub library that corresponds to // the sysprop implementation library. @@ -305,7 +305,7 @@ type SyspropPublicStubInfo struct { JavaInfo JavaInfo } -var SyspropPublicStubInfoProvider = blueprint.NewProvider(SyspropPublicStubInfo{}) +var SyspropPublicStubInfoProvider = blueprint.NewProvider[SyspropPublicStubInfo]() // Methods that need to be implemented for a module that is added to apex java_libs property. type ApexDependency interface { @@ -1624,7 +1624,7 @@ type JavaApiImportInfo struct { ApiSurface string } -var JavaApiImportProvider = blueprint.NewProvider(JavaApiImportInfo{}) +var JavaApiImportProvider = blueprint.NewProvider[JavaApiImportInfo]() func (ap *JavaApiContribution) GenerateAndroidBuildActions(ctx android.ModuleContext) { var apiFile android.Path = nil diff --git a/java/test_spec_test.go b/java/test_spec_test.go index 7f06785b0..1409b28ae 100644 --- a/java/test_spec_test.go +++ b/java/test_spec_test.go @@ -122,7 +122,7 @@ func TestTestSpec(t *testing.T) { } func runTestSpecTest( - t *testing.T, errorHandler android.FixtureErrorHandler, bp string, + t *testing.T, errorHandler android.FixtureErrorHandler, bp string, ) *android.TestResult { return android.GroupFixturePreparers( soongTesting.PrepareForTestWithTestingBuildComponents, diff --git a/multitree/api_imports.go b/multitree/api_imports.go index 07ec7bc10..e4c21f895 100644 --- a/multitree/api_imports.go +++ b/multitree/api_imports.go @@ -64,7 +64,7 @@ type ApiImportInfo struct { SharedLibs, HeaderLibs, ApexSharedLibs map[string]string } -var ApiImportsProvider = blueprint.NewMutatorProvider(ApiImportInfo{}, "deps") +var ApiImportsProvider = blueprint.NewMutatorProvider[ApiImportInfo]("deps") // Store module lists into ApiImportInfo and share it over mutator provider. func (imports *ApiImports) DepsMutator(ctx android.BottomUpMutatorContext) { diff --git a/rust/rust.go b/rust/rust.go index 02ec22d7e..c07966bdc 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -527,7 +527,7 @@ type FlagExporterInfo struct { LinkObjects []string // TODO: this should be android.Paths } -var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{}) +var FlagExporterInfoProvider = blueprint.NewProvider[FlagExporterInfo]() func (mod *Module) isCoverageVariant() bool { return mod.coverage.Properties.IsCoverageVariant diff --git a/testing/code_metadata.go b/testing/code_metadata.go index 9e20ec637..53bd07be5 100644 --- a/testing/code_metadata.go +++ b/testing/code_metadata.go @@ -20,6 +20,7 @@ import ( "android/soong/android" "android/soong/testing/code_metadata_internal_proto" "github.com/google/blueprint" + "google.golang.org/protobuf/proto" ) @@ -83,7 +84,7 @@ type CodeMetadataProviderData struct { IntermediatePath android.WritablePath } -var CodeMetadataProviderKey = blueprint.NewProvider(CodeMetadataProviderData{}) +var CodeMetadataProviderKey = blueprint.NewProvider[CodeMetadataProviderData]() func (module *CodeMetadataModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { metadataList := make( diff --git a/testing/test_spec.go b/testing/test_spec.go index 58d9c2345..2a05456d5 100644 --- a/testing/test_spec.go +++ b/testing/test_spec.go @@ -20,8 +20,9 @@ import ( "android/soong/android" "android/soong/testing/test_spec_proto" - "github.com/google/blueprint" "google.golang.org/protobuf/proto" + + "github.com/google/blueprint" ) // ErrTestModuleDataNotFound is the error message for missing test module provider data. @@ -81,12 +82,12 @@ type TestSpecProviderData struct { IntermediatePath android.WritablePath } -var TestSpecProviderKey = blueprint.NewProvider(TestSpecProviderData{}) +var TestSpecProviderKey = blueprint.NewProvider[TestSpecProviderData]() type TestModuleProviderData struct { } -var TestModuleProviderKey = blueprint.NewProvider(TestModuleProviderData{}) +var TestModuleProviderKey = blueprint.NewProvider[TestModuleProviderData]() func (module *TestSpecModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { for _, m := range ctx.GetDirectDepsWithTag(testsDepTag) {