Convert ModuleProvder to generic providers API

Convert all of the callers of ModuleProvider/ModuleHasProvider to use the
type-safe android.SingletonModuleProvider API.

Bug: 316410648
Test: builds
Change-Id: I6f11638546b64749e451cebbf33140248dc1d193
This commit is contained in:
Colin Cross 2023-12-14 14:46:23 -08:00
parent 313aa5475f
commit 5a37718c95
31 changed files with 51 additions and 88 deletions

View file

@ -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") {

View file

@ -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())
}

View file

@ -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)
}

View file

@ -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)
})

View file

@ -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)
})

View file

@ -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,

View file

@ -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
}

View file

@ -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

View file

@ -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)
}

View file

@ -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)

View file

@ -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")

View file

@ -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())

View file

@ -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)

View file

@ -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 {

View file

@ -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",

View file

@ -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 {

View file

@ -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 {

View file

@ -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")
}

View file

@ -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)

View file

@ -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",
) {

View file

@ -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())
}

View file

@ -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)

View file

@ -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.

View file

@ -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

View file

@ -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",

View file

@ -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

View file

@ -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",
) {

View file

@ -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 {

View file

@ -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
}

View file

@ -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,
)
},
)

View file

@ -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)