diff --git a/aconfig/aconfig_declarations_test.go b/aconfig/aconfig_declarations_test.go index 9035c710d..1b4acabeb 100644 --- a/aconfig/aconfig_declarations_test.go +++ b/aconfig/aconfig_declarations_test.go @@ -38,7 +38,7 @@ func TestAconfigDeclarations(t *testing.T) { module := result.ModuleForTests("module_name", "").Module().(*DeclarationsModule) // Check that the provider has the right contents - depData := result.ModuleProvider(module, DeclarationsProviderKey).(DeclarationsProviderData) + depData, _ := android.SingletonModuleProvider(result, module, DeclarationsProviderKey) android.AssertStringEquals(t, "package", depData.Package, "com.example.package") android.AssertStringEquals(t, "container", depData.Container, "com.android.foo") if !strings.HasSuffix(depData.IntermediateCacheOutputPath.String(), "/intermediate.pb") { diff --git a/aconfig/aconfig_value_set_test.go b/aconfig/aconfig_value_set_test.go index 91278729e..7d1899926 100644 --- a/aconfig/aconfig_value_set_test.go +++ b/aconfig/aconfig_value_set_test.go @@ -38,6 +38,6 @@ func TestAconfigValueSet(t *testing.T) { module := result.ModuleForTests("module_name", "").Module().(*ValueSetModule) // Check that the provider has the right contents - depData := result.ModuleProvider(module, valueSetProviderKey).(valueSetProviderData) + depData, _ := android.SingletonModuleProvider(result, module, valueSetProviderKey) android.AssertStringEquals(t, "AvailablePackages", "blah.aconfig_values", depData.AvailablePackages["foo.package"][0].String()) } diff --git a/aconfig/aconfig_values_test.go b/aconfig/aconfig_values_test.go index ab457f06a..526579c40 100644 --- a/aconfig/aconfig_values_test.go +++ b/aconfig/aconfig_values_test.go @@ -33,7 +33,7 @@ func TestAconfigValues(t *testing.T) { module := result.ModuleForTests("module_name", "").Module().(*ValuesModule) // Check that the provider has the right contents - depData := result.ModuleProvider(module, valuesProviderKey).(valuesProviderData) + depData, _ := android.SingletonModuleProvider(result, module, valuesProviderKey) android.AssertStringEquals(t, "package", "foo.package", depData.Package) android.AssertPathsEndWith(t, "srcs", []string{"blah.aconfig_values"}, depData.Values) } diff --git a/aconfig/all_aconfig_declarations.go b/aconfig/all_aconfig_declarations.go index 2686e760e..d8604985b 100644 --- a/aconfig/all_aconfig_declarations.go +++ b/aconfig/all_aconfig_declarations.go @@ -37,10 +37,10 @@ func (this *allAconfigDeclarationsSingleton) GenerateBuildActions(ctx android.Si // Find all of the aconfig_declarations modules var cacheFiles android.Paths ctx.VisitAllModules(func(module android.Module) { - if !ctx.ModuleHasProvider(module, DeclarationsProviderKey) { + decl, ok := android.SingletonModuleProvider(ctx, module, DeclarationsProviderKey) + if !ok { return } - decl := ctx.ModuleProvider(module, DeclarationsProviderKey).(DeclarationsProviderData) cacheFiles = append(cacheFiles, decl.IntermediateCacheOutputPath) }) diff --git a/aconfig/exported_java_aconfig_library.go b/aconfig/exported_java_aconfig_library.go index 45c5e3990..864481065 100644 --- a/aconfig/exported_java_aconfig_library.go +++ b/aconfig/exported_java_aconfig_library.go @@ -30,10 +30,10 @@ func (this *exportedJavaDeclarationsLibrarySingleton) GenerateBuildActions(ctx a // Find all of the aconfig_declarations modules var cacheFiles android.Paths ctx.VisitAllModules(func(module android.Module) { - if !ctx.ModuleHasProvider(module, DeclarationsProviderKey) { + decl, ok := android.SingletonModuleProvider(ctx, module, DeclarationsProviderKey) + if !ok { return } - decl := ctx.ModuleProvider(module, DeclarationsProviderKey).(DeclarationsProviderData) cacheFiles = append(cacheFiles, decl.IntermediateCacheOutputPath) }) diff --git a/aidl_library/aidl_library_test.go b/aidl_library/aidl_library_test.go index 020562904..01eab0eaf 100644 --- a/aidl_library/aidl_library_test.go +++ b/aidl_library/aidl_library_test.go @@ -46,7 +46,7 @@ func TestAidlLibrary(t *testing.T) { ).RunTest(t).TestContext foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary) - actualInfo := ctx.ModuleProvider(foo, AidlLibraryProvider).(AidlLibraryInfo) + actualInfo, _ := android.SingletonModuleProvider(ctx, foo, AidlLibraryProvider) android.AssertArrayString( t, @@ -95,7 +95,7 @@ func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) { ).RunTest(t).TestContext foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary) - actualInfo := ctx.ModuleProvider(foo, AidlLibraryProvider).(AidlLibraryInfo) + actualInfo, _ := android.SingletonModuleProvider(ctx, foo, AidlLibraryProvider) android.AssertArrayString( t, diff --git a/android/androidmk.go b/android/androidmk.go index 6b6c3f13b..a0ed1e449 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -492,8 +492,6 @@ type fillInEntriesContext interface { ModuleDir(module blueprint.Module) string ModuleSubDir(module blueprint.Module) string Config() Config - 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/makevars.go b/android/makevars.go index 5a9fe7c66..d4cfd299e 100644 --- a/android/makevars.go +++ b/android/makevars.go @@ -92,7 +92,6 @@ type MakeVarsContext interface { ModuleDir(module blueprint.Module) string ModuleSubDir(module blueprint.Module) string ModuleType(module blueprint.Module) string - ModuleProvider(module blueprint.Module, key blueprint.AnyProviderKey) any moduleProvider(module blueprint.Module, key blueprint.AnyProviderKey) (any, bool) BlueprintFile(module blueprint.Module) string diff --git a/android/singleton.go b/android/singleton.go index 8936cac65..47cfb2818 100644 --- a/android/singleton.go +++ b/android/singleton.go @@ -35,16 +35,6 @@ type SingletonContext interface { // Allows generating build actions for `referer` based on the metadata for `name` deferred until the singleton context. ModuleVariantsFromName(referer Module, name string) []Module - // 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.AnyProviderKey) any - - // ModuleHasProvider returns true if the provider for the given module has been set. - 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{}) @@ -291,17 +281,6 @@ 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/apex/apex_singleton.go b/apex/apex_singleton.go index a63344fc1..25c0cc444 100644 --- a/apex/apex_singleton.go +++ b/apex/apex_singleton.go @@ -83,7 +83,7 @@ func (s *apexDepsInfoSingleton) GenerateBuildActions(ctx android.SingletonContex updatableFlatLists := android.Paths{} ctx.VisitAllModules(func(module android.Module) { if binaryInfo, ok := module.(android.ApexBundleDepsInfoIntf); ok { - apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) + apexInfo, _ := android.SingletonModuleProvider(ctx, module, android.ApexInfoProvider) if path := binaryInfo.FlatListPath(); path != nil { if binaryInfo.Updatable() || apexInfo.Updatable { updatableFlatLists = append(updatableFlatLists, path) diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go index 43be310bb..42f5cd444 100644 --- a/apex/bootclasspath_fragment_test.go +++ b/apex/bootclasspath_fragment_test.go @@ -152,7 +152,7 @@ func TestBootclasspathFragments_FragmentDependency(t *testing.T) { // Check stub dex paths exported by art. artFragment := result.Module("art-bootclasspath-fragment", "android_common") - artInfo := result.ModuleProvider(artFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo) + artInfo, _ := android.SingletonModuleProvider(result, artFragment, java.HiddenAPIInfoProvider) bazPublicStubs := "out/soong/.intermediates/baz.stubs/android_common/dex/baz.stubs.jar" bazSystemStubs := "out/soong/.intermediates/baz.stubs.system/android_common/dex/baz.stubs.system.jar" @@ -165,7 +165,7 @@ func TestBootclasspathFragments_FragmentDependency(t *testing.T) { // Check stub dex paths exported by other. otherFragment := result.Module("other-bootclasspath-fragment", "android_common") - otherInfo := result.ModuleProvider(otherFragment, java.HiddenAPIInfoProvider).(java.HiddenAPIInfo) + otherInfo, _ := android.SingletonModuleProvider(result, otherFragment, java.HiddenAPIInfoProvider) fooPublicStubs := "out/soong/.intermediates/foo.stubs/android_common/dex/foo.stubs.jar" fooSystemStubs := "out/soong/.intermediates/foo.stubs.system/android_common/dex/foo.stubs.system.jar" @@ -655,7 +655,7 @@ func TestBootclasspathFragmentContentsNoName(t *testing.T) { // Make sure that the fragment provides the hidden API encoded dex jars to the APEX. fragment := result.Module("mybootclasspathfragment", "android_common_apex10000") - info := result.ModuleProvider(fragment, java.BootclasspathFragmentApexContentInfoProvider).(java.BootclasspathFragmentApexContentInfo) + info, _ := android.SingletonModuleProvider(result, fragment, java.BootclasspathFragmentApexContentInfoProvider) checkFragmentExportedDexJar := func(name string, expectedDexJar string) { module := result.Module(name, "android_common_apex10000") diff --git a/apex/platform_bootclasspath_test.go b/apex/platform_bootclasspath_test.go index 05bb13689..b741963c8 100644 --- a/apex/platform_bootclasspath_test.go +++ b/apex/platform_bootclasspath_test.go @@ -152,7 +152,7 @@ func TestPlatformBootclasspath_Fragments(t *testing.T) { ).RunTest(t) pbcp := result.Module("platform-bootclasspath", "android_common") - info := result.ModuleProvider(pbcp, java.MonolithicHiddenAPIInfoProvider).(java.MonolithicHiddenAPIInfo) + info, _ := android.SingletonModuleProvider(result, pbcp, java.MonolithicHiddenAPIInfoProvider) for _, category := range java.HiddenAPIFlagFileCategories { name := category.PropertyName @@ -234,7 +234,7 @@ func TestPlatformBootclasspath_LegacyPrebuiltFragment(t *testing.T) { ) pbcp := result.Module("myplatform-bootclasspath", "android_common") - info := result.ModuleProvider(pbcp, java.MonolithicHiddenAPIInfoProvider).(java.MonolithicHiddenAPIInfo) + info, _ := android.SingletonModuleProvider(result, pbcp, java.MonolithicHiddenAPIInfoProvider) android.AssertArrayString(t, "stub flags", []string{"prebuilt-stub-flags.csv:out/soong/.intermediates/mybootclasspath-fragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv"}, info.StubFlagSubsets.RelativeToTop()) android.AssertArrayString(t, "all flags", []string{"prebuilt-all-flags.csv:out/soong/.intermediates/mybootclasspath-fragment/android_common_myapex/modular-hiddenapi/signature-patterns.csv"}, info.FlagSubsets.RelativeToTop()) diff --git a/bloaty/bloaty.go b/bloaty/bloaty.go index 29a14607f..43fb71dd2 100644 --- a/bloaty/bloaty.go +++ b/bloaty/bloaty.go @@ -85,10 +85,10 @@ func fileSizesSingleton() android.Singleton { func (singleton *sizesSingleton) GenerateBuildActions(ctx android.SingletonContext) { var deps android.Paths ctx.VisitAllModules(func(m android.Module) { - if !ctx.ModuleHasProvider(m, fileSizeMeasurerKey) { + filePaths, ok := android.SingletonModuleProvider(ctx, m, fileSizeMeasurerKey) + if !ok { return } - filePaths := ctx.ModuleProvider(m, fileSizeMeasurerKey).(measuredFiles) for _, path := range filePaths.paths { filePath := path.(android.ModuleOutPath) sizeFile := filePath.InSameDir(ctx, filePath.Base()+bloatyDescriptorExt) diff --git a/cc/cc_test.go b/cc/cc_test.go index 3631f1998..cebf129ec 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -2544,8 +2544,8 @@ func TestStaticLibDepReordering(t *testing.T) { variant := "android_arm64_armv8-a_static" moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) - actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo). - TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() + staticLibInfo, _ := android.SingletonModuleProvider(ctx, moduleA, StaticLibraryInfoProvider) + actual := android.Paths(staticLibInfo.TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"}) if !reflect.DeepEqual(actual, expected) { @@ -2580,8 +2580,8 @@ func TestStaticLibDepReorderingWithShared(t *testing.T) { variant := "android_arm64_armv8-a_static" moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) - actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo). - TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() + staticLibInfo, _ := android.SingletonModuleProvider(ctx, moduleA, StaticLibraryInfoProvider) + actual := android.Paths(staticLibInfo.TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"}) if !reflect.DeepEqual(actual, expected) { @@ -2681,7 +2681,7 @@ func TestLlndkLibrary(t *testing.T) { checkExportedIncludeDirs := func(module, variant string, expectedDirs ...string) { t.Helper() m := result.ModuleForTests(module, variant).Module() - f := result.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo) + f, _ := android.SingletonModuleProvider(result, m, FlagExporterInfoProvider) android.AssertPathsRelativeToTopEquals(t, "exported include dirs for "+module+"["+variant+"]", expectedDirs, f.IncludeDirs) } @@ -4113,7 +4113,7 @@ func TestIncludeDirsExporting(t *testing.T) { checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) { t.Helper() - exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo) + exported, _ := android.SingletonModuleProvider(ctx, module, FlagExporterInfoProvider) name := module.Name() for _, checker := range checkers { diff --git a/cc/sanitize_test.go b/cc/sanitize_test.go index cfc9ed215..44f38e10a 100644 --- a/cc/sanitize_test.go +++ b/cc/sanitize_test.go @@ -22,8 +22,6 @@ import ( "testing" "android/soong/android" - - "github.com/google/blueprint" ) var prepareForAsanTest = android.FixtureAddFile("asan/Android.bp", []byte(` @@ -49,7 +47,7 @@ var prepareForTsanTest = android.FixtureAddFile("tsan/Android.bp", []byte(` `)) type providerInterface interface { - ModuleProvider(blueprint.Module, blueprint.AnyProviderKey) interface{} + android.SingletonModuleProviderContext } // expectSharedLinkDep verifies that the from module links against the to module as a @@ -57,7 +55,7 @@ type providerInterface interface { func expectSharedLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) { t.Helper() fromLink := from.Description("link") - toInfo := ctx.ModuleProvider(to.Module(), SharedLibraryInfoProvider).(SharedLibraryInfo) + toInfo, _ := android.SingletonModuleProvider(ctx, to.Module(), SharedLibraryInfoProvider) if g, w := fromLink.OrderOnly.Strings(), toInfo.SharedLibrary.RelativeToTop().String(); !android.InList(w, g) { t.Errorf("%s should link against %s, expected %q, got %q", @@ -70,7 +68,7 @@ func expectSharedLinkDep(t *testing.T, ctx providerInterface, from, to android.T func expectNoSharedLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) { t.Helper() fromLink := from.Description("link") - toInfo := ctx.ModuleProvider(to.Module(), SharedLibraryInfoProvider).(SharedLibraryInfo) + toInfo, _ := android.SingletonModuleProvider(ctx, to.Module(), SharedLibraryInfoProvider) if g, w := fromLink.OrderOnly.Strings(), toInfo.SharedLibrary.RelativeToTop().String(); android.InList(w, g) { t.Errorf("%s should not link against %s, expected %q, got %q", @@ -83,7 +81,7 @@ func expectNoSharedLinkDep(t *testing.T, ctx providerInterface, from, to android func expectStaticLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) { t.Helper() fromLink := from.Description("link") - toInfo := ctx.ModuleProvider(to.Module(), StaticLibraryInfoProvider).(StaticLibraryInfo) + toInfo, _ := android.SingletonModuleProvider(ctx, to.Module(), StaticLibraryInfoProvider) if g, w := fromLink.Implicits.Strings(), toInfo.StaticLibrary.RelativeToTop().String(); !android.InList(w, g) { t.Errorf("%s should link against %s, expected %q, got %q", @@ -97,7 +95,7 @@ func expectStaticLinkDep(t *testing.T, ctx providerInterface, from, to android.T func expectNoStaticLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) { t.Helper() fromLink := from.Description("link") - toInfo := ctx.ModuleProvider(to.Module(), StaticLibraryInfoProvider).(StaticLibraryInfo) + toInfo, _ := android.SingletonModuleProvider(ctx, to.Module(), StaticLibraryInfoProvider) if g, w := fromLink.Implicits.Strings(), toInfo.StaticLibrary.RelativeToTop().String(); android.InList(w, g) { t.Errorf("%s should not link against %s, expected %q, got %q", diff --git a/cc/vendor_snapshot.go b/cc/vendor_snapshot.go index e8e930e8f..a33ed5fc3 100644 --- a/cc/vendor_snapshot.go +++ b/cc/vendor_snapshot.go @@ -275,7 +275,7 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS var propOut string if m.IsSnapshotLibrary() { - exporterInfo := ctx.ModuleProvider(m.Module(), FlagExporterInfoProvider).(FlagExporterInfo) + exporterInfo, _ := android.SingletonModuleProvider(ctx, m.Module(), FlagExporterInfoProvider) // library flags prop.ExportedFlags = exporterInfo.Flags @@ -407,7 +407,7 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS moduleDir := ctx.ModuleDir(module) inProprietaryPath := s.Image.IsProprietaryPath(moduleDir, ctx.DeviceConfig()) - apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) + apexInfo, _ := android.SingletonModuleProvider(ctx, module, android.ApexInfoProvider) if s.Image.ExcludeFromSnapshot(m) { if inProprietaryPath { diff --git a/cc/vndk.go b/cc/vndk.go index a84945521..b2c6e0d1e 100644 --- a/cc/vndk.go +++ b/cc/vndk.go @@ -772,7 +772,7 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex prop.MinSdkVersion = m.MinSdkVersion() if ctx.Config().VndkSnapshotBuildArtifacts() { - exportedInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo) + exportedInfo, _ := android.SingletonModuleProvider(ctx, m, FlagExporterInfoProvider) prop.ExportedFlags = exportedInfo.Flags prop.ExportedDirs = exportedInfo.IncludeDirs.Strings() prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings() @@ -797,7 +797,7 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex return } - apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) + apexInfo, _ := android.SingletonModuleProvider(ctx, module, android.ApexInfoProvider) vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo) if !ok { diff --git a/java/aar_test.go b/java/aar_test.go index 8afa039c4..4d4e5d025 100644 --- a/java/aar_test.go +++ b/java/aar_test.go @@ -52,7 +52,7 @@ func TestAarImportProducesJniPackages(t *testing.T) { appMod := ctx.Module(tc.name, "android_common") appTestMod := ctx.ModuleForTests(tc.name, "android_common") - info, ok := ctx.ModuleProvider(appMod, JniPackageProvider).(JniPackageInfo) + info, ok := android.SingletonModuleProvider(ctx, appMod, JniPackageProvider) if !ok { t.Errorf("expected android_library_import to have JniPackageProvider") } diff --git a/java/bootclasspath_fragment_test.go b/java/bootclasspath_fragment_test.go index 828de2179..216c3b348 100644 --- a/java/bootclasspath_fragment_test.go +++ b/java/bootclasspath_fragment_test.go @@ -272,7 +272,7 @@ func TestBootclasspathFragment_StubLibs(t *testing.T) { `) fragment := result.Module("myfragment", "android_common") - info := result.ModuleProvider(fragment, HiddenAPIInfoProvider).(HiddenAPIInfo) + info, _ := android.SingletonModuleProvider(result, fragment, HiddenAPIInfoProvider) stubsJar := "out/soong/.intermediates/mystublib/android_common/dex/mystublib.jar" @@ -456,7 +456,7 @@ func TestSnapshotWithBootclasspathFragment_HiddenAPI(t *testing.T) { // Make sure that the library exports hidden API properties for use by the bootclasspath_fragment. library := result.Module("mynewlibrary", "android_common") - info := result.ModuleProvider(library, hiddenAPIPropertyInfoProvider).(HiddenAPIPropertyInfo) + info, _ := android.SingletonModuleProvider(result, library, hiddenAPIPropertyInfoProvider) android.AssertArrayString(t, "split packages", []string{"sdklibrary", "newlibrary"}, info.SplitPackages) android.AssertArrayString(t, "package prefixes", []string{"newlibrary.all.mine"}, info.PackagePrefixes) android.AssertArrayString(t, "single packages", []string{"newlibrary.mine"}, info.SinglePackages) diff --git a/java/code_metadata_test.go b/java/code_metadata_test.go index 8f8abd7cc..509e70112 100644 --- a/java/code_metadata_test.go +++ b/java/code_metadata_test.go @@ -30,9 +30,7 @@ func TestCodeMetadata(t *testing.T) { ).Module().(*soongTesting.CodeMetadataModule) // Check that the provider has the right contents - data := result.ModuleProvider( - module, soongTesting.CodeMetadataProviderKey, - ).(soongTesting.CodeMetadataProviderData) + data, _ := android.SingletonModuleProvider(result, module, soongTesting.CodeMetadataProviderKey) if !strings.HasSuffix( data.IntermediatePath.String(), "/intermediateCodeMetadata.pb", ) { diff --git a/java/java_test.go b/java/java_test.go index 8e83fc412..e21018c39 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -2226,7 +2226,8 @@ func TestTransitiveSrcFiles(t *testing.T) { } `) c := ctx.ModuleForTests("c", "android_common").Module() - transitiveSrcFiles := android.Paths(ctx.ModuleProvider(c, JavaInfoProvider).(JavaInfo).TransitiveSrcFiles.ToList()) + javaInfo, _ := android.SingletonModuleProvider(ctx, c, JavaInfoProvider) + transitiveSrcFiles := android.Paths(javaInfo.TransitiveSrcFiles.ToList()) android.AssertArrayString(t, "unexpected jar deps", []string{"b.java", "c.java"}, transitiveSrcFiles.Strings()) } diff --git a/java/jdeps.go b/java/jdeps.go index 7e3a14f55..91f7ce715 100644 --- a/java/jdeps.go +++ b/java/jdeps.go @@ -89,8 +89,7 @@ func (j *jdepsGeneratorSingleton) GenerateBuildActions(ctx android.SingletonCont dpInfo.Classes = append(dpInfo.Classes, data.Class) } - if ctx.ModuleHasProvider(module, JavaInfoProvider) { - dep := ctx.ModuleProvider(module, JavaInfoProvider).(JavaInfo) + if dep, ok := android.SingletonModuleProvider(ctx, module, JavaInfoProvider); ok { dpInfo.Installed_paths = append(dpInfo.Installed_paths, dep.ImplementationJars.Strings()...) } dpInfo.Classes = android.FirstUniqueStrings(dpInfo.Classes) diff --git a/java/lint.go b/java/lint.go index 095323625..5a684a8c0 100644 --- a/java/lint.go +++ b/java/lint.go @@ -660,7 +660,7 @@ func (l *lintSingleton) generateLintReportZips(ctx android.SingletonContext) { } if apex, ok := m.(android.ApexModule); ok && apex.NotAvailableForPlatform() { - apexInfo := ctx.ModuleProvider(m, android.ApexInfoProvider).(android.ApexInfo) + apexInfo, _ := android.SingletonModuleProvider(ctx, m, android.ApexInfoProvider) if apexInfo.IsForPlatform() { // There are stray platform variants of modules in apexes that are not available for // the platform, and they sometimes can't be built. Don't depend on them. diff --git a/java/sdk.go b/java/sdk.go index ad71fb236..352b24319 100644 --- a/java/sdk.go +++ b/java/sdk.go @@ -262,8 +262,7 @@ func createFrameworkAidl(stubsModules []string, path android.WritablePath, ctx a ctx.VisitAllModules(func(module android.Module) { // Collect dex jar paths for the modules listed above. - if ctx.ModuleHasProvider(module, JavaInfoProvider) { - j := ctx.ModuleProvider(module, JavaInfoProvider).(JavaInfo) + if j, ok := android.SingletonModuleProvider(ctx, module, JavaInfoProvider); ok { name := ctx.ModuleName(module) if i := android.IndexList(name, stubsModules); i != -1 { stubsJars[i] = j.HeaderJars diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go index a136818ca..0965fc2c7 100644 --- a/java/sdk_library_test.go +++ b/java/sdk_library_test.go @@ -132,7 +132,7 @@ func TestJavaSdkLibrary(t *testing.T) { result.ModuleForTests("foo.api.system.28", "") result.ModuleForTests("foo.api.test.28", "") - exportedComponentsInfo := result.ModuleProvider(foo.Module(), android.ExportedComponentsInfoProvider).(android.ExportedComponentsInfo) + exportedComponentsInfo, _ := android.SingletonModuleProvider(result, foo.Module(), android.ExportedComponentsInfoProvider) expectedFooExportedComponents := []string{ "foo-removed.api.public.latest", "foo-removed.api.system.latest", diff --git a/java/system_modules_test.go b/java/system_modules_test.go index 7b5a3867e..2ceca5d0b 100644 --- a/java/system_modules_test.go +++ b/java/system_modules_test.go @@ -24,7 +24,7 @@ func getModuleHeaderJarsAsRelativeToTopPaths(result *android.TestResult, moduleN paths := []string{} for _, moduleName := range moduleNames { module := result.Module(moduleName, "android_common") - info := result.ModuleProvider(module, JavaInfoProvider).(JavaInfo) + info, _ := android.SingletonModuleProvider(result, module, JavaInfoProvider) paths = append(paths, info.HeaderJars.RelativeToTop().Strings()...) } return paths diff --git a/java/test_spec_test.go b/java/test_spec_test.go index 1409b28ae..f628b4b74 100644 --- a/java/test_spec_test.go +++ b/java/test_spec_test.go @@ -34,9 +34,7 @@ func TestTestSpec(t *testing.T) { ).Module().(*soongTesting.TestSpecModule) // Check that the provider has the right contents - data := result.ModuleProvider( - module, soongTesting.TestSpecProviderKey, - ).(soongTesting.TestSpecProviderData) + data, _ := android.SingletonModuleProvider(result, module, soongTesting.TestSpecProviderKey) if !strings.HasSuffix( data.IntermediatePath.String(), "/intermediateTestSpecMetadata.pb", ) { diff --git a/java/testing.go b/java/testing.go index e883bcb4c..d55cffc40 100644 --- a/java/testing.go +++ b/java/testing.go @@ -617,7 +617,7 @@ func CheckPlatformBootclasspathModules(t *testing.T, result *android.TestResult, func CheckClasspathFragmentProtoContentInfoProvider(t *testing.T, result *android.TestResult, generated bool, contents, outputFilename, installDir string) { t.Helper() p := result.Module("platform-bootclasspath", "android_common").(*platformBootclasspathModule) - info := result.ModuleProvider(p, ClasspathFragmentProtoContentInfoProvider).(ClasspathFragmentProtoContentInfo) + info, _ := android.SingletonModuleProvider(result, p, ClasspathFragmentProtoContentInfoProvider) android.AssertBoolEquals(t, "classpath proto generated", generated, info.ClasspathFragmentProtoGenerated) android.AssertStringEquals(t, "classpath proto contents", contents, info.ClasspathFragmentProtoContents.String()) @@ -637,7 +637,7 @@ func ApexNamePairsFromModules(ctx *android.TestContext, modules []android.Module func apexNamePairFromModule(ctx *android.TestContext, module android.Module) string { name := module.Name() var apex string - apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) + apexInfo, _ := android.SingletonModuleProvider(ctx, module, android.ApexInfoProvider) if apexInfo.IsForPlatform() { apex = "platform" } else { diff --git a/snapshot/host_fake_snapshot.go b/snapshot/host_fake_snapshot.go index c4cfbb5ce..63cd4e1b6 100644 --- a/snapshot/host_fake_snapshot.go +++ b/snapshot/host_fake_snapshot.go @@ -119,7 +119,7 @@ func (c *hostFakeSingleton) GenerateBuildActions(ctx android.SingletonContext) { if !module.Enabled() || module.IsHideFromMake() { return } - apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) + apexInfo, _ := android.SingletonModuleProvider(ctx, module, android.ApexInfoProvider) if !apexInfo.IsForPlatform() { return } diff --git a/testing/all_code_metadata.go b/testing/all_code_metadata.go index 16d7aae66..12aa7b51f 100644 --- a/testing/all_code_metadata.go +++ b/testing/all_code_metadata.go @@ -21,14 +21,9 @@ func (this *allCodeMetadataSingleton) GenerateBuildActions(ctx android.Singleton ctx.VisitAllModules( func(module android.Module) { - if !ctx.ModuleHasProvider(module, CodeMetadataProviderKey) { - return + if metadata, ok := android.SingletonModuleProvider(ctx, module, CodeMetadataProviderKey); ok { + intermediateMetadataPaths = append(intermediateMetadataPaths, metadata.IntermediatePath) } - intermediateMetadataPaths = append( - intermediateMetadataPaths, ctx.ModuleProvider( - module, CodeMetadataProviderKey, - ).(CodeMetadataProviderData).IntermediatePath, - ) }, ) diff --git a/testing/all_test_specs.go b/testing/all_test_specs.go index 9d4645b37..b035435db 100644 --- a/testing/all_test_specs.go +++ b/testing/all_test_specs.go @@ -21,10 +21,9 @@ func (this *allTestSpecsSingleton) GenerateBuildActions(ctx android.SingletonCon var intermediateMetadataPaths android.Paths ctx.VisitAllModules(func(module android.Module) { - if !ctx.ModuleHasProvider(module, TestSpecProviderKey) { - return + if metadata, ok := android.SingletonModuleProvider(ctx, module, TestSpecProviderKey); ok { + intermediateMetadataPaths = append(intermediateMetadataPaths, metadata.IntermediatePath) } - intermediateMetadataPaths = append(intermediateMetadataPaths, ctx.ModuleProvider(module, TestSpecProviderKey).(TestSpecProviderData).IntermediatePath) }) rspFile := android.PathForOutput(ctx, fileContainingFilePaths)