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

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