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) module := result.ModuleForTests("module_name", "").Module().(*DeclarationsModule)
// Check that the provider has the right contents // 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, "package", depData.Package, "com.example.package")
android.AssertStringEquals(t, "container", depData.Container, "com.android.foo") android.AssertStringEquals(t, "container", depData.Container, "com.android.foo")
if !strings.HasSuffix(depData.IntermediateCacheOutputPath.String(), "/intermediate.pb") { 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) module := result.ModuleForTests("module_name", "").Module().(*ValueSetModule)
// Check that the provider has the right contents // 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()) 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) module := result.ModuleForTests("module_name", "").Module().(*ValuesModule)
// Check that the provider has the right contents // 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.AssertStringEquals(t, "package", "foo.package", depData.Package)
android.AssertPathsEndWith(t, "srcs", []string{"blah.aconfig_values"}, depData.Values) 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 // Find all of the aconfig_declarations modules
var cacheFiles android.Paths var cacheFiles android.Paths
ctx.VisitAllModules(func(module android.Module) { ctx.VisitAllModules(func(module android.Module) {
if !ctx.ModuleHasProvider(module, DeclarationsProviderKey) { decl, ok := android.SingletonModuleProvider(ctx, module, DeclarationsProviderKey)
if !ok {
return return
} }
decl := ctx.ModuleProvider(module, DeclarationsProviderKey).(DeclarationsProviderData)
cacheFiles = append(cacheFiles, decl.IntermediateCacheOutputPath) cacheFiles = append(cacheFiles, decl.IntermediateCacheOutputPath)
}) })

View file

@ -30,10 +30,10 @@ func (this *exportedJavaDeclarationsLibrarySingleton) GenerateBuildActions(ctx a
// Find all of the aconfig_declarations modules // Find all of the aconfig_declarations modules
var cacheFiles android.Paths var cacheFiles android.Paths
ctx.VisitAllModules(func(module android.Module) { ctx.VisitAllModules(func(module android.Module) {
if !ctx.ModuleHasProvider(module, DeclarationsProviderKey) { decl, ok := android.SingletonModuleProvider(ctx, module, DeclarationsProviderKey)
if !ok {
return return
} }
decl := ctx.ModuleProvider(module, DeclarationsProviderKey).(DeclarationsProviderData)
cacheFiles = append(cacheFiles, decl.IntermediateCacheOutputPath) cacheFiles = append(cacheFiles, decl.IntermediateCacheOutputPath)
}) })

View file

@ -46,7 +46,7 @@ func TestAidlLibrary(t *testing.T) {
).RunTest(t).TestContext ).RunTest(t).TestContext
foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary) foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary)
actualInfo := ctx.ModuleProvider(foo, AidlLibraryProvider).(AidlLibraryInfo) actualInfo, _ := android.SingletonModuleProvider(ctx, foo, AidlLibraryProvider)
android.AssertArrayString( android.AssertArrayString(
t, t,
@ -95,7 +95,7 @@ func TestAidlLibraryWithoutStripImportPrefix(t *testing.T) {
).RunTest(t).TestContext ).RunTest(t).TestContext
foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary) foo := ctx.ModuleForTests("foo", "").Module().(*AidlLibrary)
actualInfo := ctx.ModuleProvider(foo, AidlLibraryProvider).(AidlLibraryInfo) actualInfo, _ := android.SingletonModuleProvider(ctx, foo, AidlLibraryProvider)
android.AssertArrayString( android.AssertArrayString(
t, t,

View file

@ -492,8 +492,6 @@ type fillInEntriesContext interface {
ModuleDir(module blueprint.Module) string ModuleDir(module blueprint.Module) string
ModuleSubDir(module blueprint.Module) string ModuleSubDir(module blueprint.Module) string
Config() Config 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) moduleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool)
ModuleType(module blueprint.Module) string ModuleType(module blueprint.Module) string
} }

View file

@ -92,7 +92,6 @@ type MakeVarsContext interface {
ModuleDir(module blueprint.Module) string ModuleDir(module blueprint.Module) string
ModuleSubDir(module blueprint.Module) string ModuleSubDir(module blueprint.Module) string
ModuleType(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) moduleProvider(module blueprint.Module, key blueprint.AnyProviderKey) (any, bool)
BlueprintFile(module blueprint.Module) string 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. // Allows generating build actions for `referer` based on the metadata for `name` deferred until the singleton context.
ModuleVariantsFromName(referer Module, name string) []Module 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) moduleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool)
ModuleErrorf(module blueprint.Module, format string, args ...interface{}) ModuleErrorf(module blueprint.Module, format string, args ...interface{})
@ -291,17 +281,6 @@ func (s *singletonContextAdaptor) ModuleVariantsFromName(referer Module, name st
return result 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) { func (s *singletonContextAdaptor) moduleProvider(module blueprint.Module, provider blueprint.AnyProviderKey) (any, bool) {
return s.SingletonContext.ModuleProvider(module, provider) return s.SingletonContext.ModuleProvider(module, provider)
} }

View file

@ -83,7 +83,7 @@ func (s *apexDepsInfoSingleton) GenerateBuildActions(ctx android.SingletonContex
updatableFlatLists := android.Paths{} updatableFlatLists := android.Paths{}
ctx.VisitAllModules(func(module android.Module) { ctx.VisitAllModules(func(module android.Module) {
if binaryInfo, ok := module.(android.ApexBundleDepsInfoIntf); ok { 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 path := binaryInfo.FlatListPath(); path != nil {
if binaryInfo.Updatable() || apexInfo.Updatable { if binaryInfo.Updatable() || apexInfo.Updatable {
updatableFlatLists = append(updatableFlatLists, path) updatableFlatLists = append(updatableFlatLists, path)

View file

@ -152,7 +152,7 @@ func TestBootclasspathFragments_FragmentDependency(t *testing.T) {
// Check stub dex paths exported by art. // Check stub dex paths exported by art.
artFragment := result.Module("art-bootclasspath-fragment", "android_common") 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" 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" 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. // Check stub dex paths exported by other.
otherFragment := result.Module("other-bootclasspath-fragment", "android_common") 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" 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" 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. // Make sure that the fragment provides the hidden API encoded dex jars to the APEX.
fragment := result.Module("mybootclasspathfragment", "android_common_apex10000") 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) { checkFragmentExportedDexJar := func(name string, expectedDexJar string) {
module := result.Module(name, "android_common_apex10000") module := result.Module(name, "android_common_apex10000")

View file

@ -152,7 +152,7 @@ func TestPlatformBootclasspath_Fragments(t *testing.T) {
).RunTest(t) ).RunTest(t)
pbcp := result.Module("platform-bootclasspath", "android_common") 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 { for _, category := range java.HiddenAPIFlagFileCategories {
name := category.PropertyName name := category.PropertyName
@ -234,7 +234,7 @@ func TestPlatformBootclasspath_LegacyPrebuiltFragment(t *testing.T) {
) )
pbcp := result.Module("myplatform-bootclasspath", "android_common") 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, "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()) 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) { func (singleton *sizesSingleton) GenerateBuildActions(ctx android.SingletonContext) {
var deps android.Paths var deps android.Paths
ctx.VisitAllModules(func(m android.Module) { ctx.VisitAllModules(func(m android.Module) {
if !ctx.ModuleHasProvider(m, fileSizeMeasurerKey) { filePaths, ok := android.SingletonModuleProvider(ctx, m, fileSizeMeasurerKey)
if !ok {
return return
} }
filePaths := ctx.ModuleProvider(m, fileSizeMeasurerKey).(measuredFiles)
for _, path := range filePaths.paths { for _, path := range filePaths.paths {
filePath := path.(android.ModuleOutPath) filePath := path.(android.ModuleOutPath)
sizeFile := filePath.InSameDir(ctx, filePath.Base()+bloatyDescriptorExt) sizeFile := filePath.InSameDir(ctx, filePath.Base()+bloatyDescriptorExt)

View file

@ -2544,8 +2544,8 @@ func TestStaticLibDepReordering(t *testing.T) {
variant := "android_arm64_armv8-a_static" variant := "android_arm64_armv8-a_static"
moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo). staticLibInfo, _ := android.SingletonModuleProvider(ctx, moduleA, StaticLibraryInfoProvider)
TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() actual := android.Paths(staticLibInfo.TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop()
expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"}) expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b", "d"})
if !reflect.DeepEqual(actual, expected) { if !reflect.DeepEqual(actual, expected) {
@ -2580,8 +2580,8 @@ func TestStaticLibDepReorderingWithShared(t *testing.T) {
variant := "android_arm64_armv8-a_static" variant := "android_arm64_armv8-a_static"
moduleA := ctx.ModuleForTests("a", variant).Module().(*Module) moduleA := ctx.ModuleForTests("a", variant).Module().(*Module)
actual := android.Paths(ctx.ModuleProvider(moduleA, StaticLibraryInfoProvider).(StaticLibraryInfo). staticLibInfo, _ := android.SingletonModuleProvider(ctx, moduleA, StaticLibraryInfoProvider)
TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop() actual := android.Paths(staticLibInfo.TransitiveStaticLibrariesForOrdering.ToList()).RelativeToTop()
expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"}) expected := GetOutputPaths(ctx, variant, []string{"a", "c", "b"})
if !reflect.DeepEqual(actual, expected) { if !reflect.DeepEqual(actual, expected) {
@ -2681,7 +2681,7 @@ func TestLlndkLibrary(t *testing.T) {
checkExportedIncludeDirs := func(module, variant string, expectedDirs ...string) { checkExportedIncludeDirs := func(module, variant string, expectedDirs ...string) {
t.Helper() t.Helper()
m := result.ModuleForTests(module, variant).Module() 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+"]", android.AssertPathsRelativeToTopEquals(t, "exported include dirs for "+module+"["+variant+"]",
expectedDirs, f.IncludeDirs) 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) { checkIncludeDirs := func(t *testing.T, ctx *android.TestContext, module android.Module, checkers ...exportedChecker) {
t.Helper() t.Helper()
exported := ctx.ModuleProvider(module, FlagExporterInfoProvider).(FlagExporterInfo) exported, _ := android.SingletonModuleProvider(ctx, module, FlagExporterInfoProvider)
name := module.Name() name := module.Name()
for _, checker := range checkers { for _, checker := range checkers {

View file

@ -22,8 +22,6 @@ import (
"testing" "testing"
"android/soong/android" "android/soong/android"
"github.com/google/blueprint"
) )
var prepareForAsanTest = android.FixtureAddFile("asan/Android.bp", []byte(` var prepareForAsanTest = android.FixtureAddFile("asan/Android.bp", []byte(`
@ -49,7 +47,7 @@ var prepareForTsanTest = android.FixtureAddFile("tsan/Android.bp", []byte(`
`)) `))
type providerInterface interface { type providerInterface interface {
ModuleProvider(blueprint.Module, blueprint.AnyProviderKey) interface{} android.SingletonModuleProviderContext
} }
// expectSharedLinkDep verifies that the from module links against the to module as a // 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) { func expectSharedLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) {
t.Helper() t.Helper()
fromLink := from.Description("link") 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) { 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", 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) { func expectNoSharedLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) {
t.Helper() t.Helper()
fromLink := from.Description("link") 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) { 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", 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) { func expectStaticLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) {
t.Helper() t.Helper()
fromLink := from.Description("link") 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) { 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", 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) { func expectNoStaticLinkDep(t *testing.T, ctx providerInterface, from, to android.TestingModule) {
t.Helper() t.Helper()
fromLink := from.Description("link") 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) { 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", 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 var propOut string
if m.IsSnapshotLibrary() { if m.IsSnapshotLibrary() {
exporterInfo := ctx.ModuleProvider(m.Module(), FlagExporterInfoProvider).(FlagExporterInfo) exporterInfo, _ := android.SingletonModuleProvider(ctx, m.Module(), FlagExporterInfoProvider)
// library flags // library flags
prop.ExportedFlags = exporterInfo.Flags prop.ExportedFlags = exporterInfo.Flags
@ -407,7 +407,7 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS
moduleDir := ctx.ModuleDir(module) moduleDir := ctx.ModuleDir(module)
inProprietaryPath := s.Image.IsProprietaryPath(moduleDir, ctx.DeviceConfig()) 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 s.Image.ExcludeFromSnapshot(m) {
if inProprietaryPath { if inProprietaryPath {

View file

@ -772,7 +772,7 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex
prop.MinSdkVersion = m.MinSdkVersion() prop.MinSdkVersion = m.MinSdkVersion()
if ctx.Config().VndkSnapshotBuildArtifacts() { if ctx.Config().VndkSnapshotBuildArtifacts() {
exportedInfo := ctx.ModuleProvider(m, FlagExporterInfoProvider).(FlagExporterInfo) exportedInfo, _ := android.SingletonModuleProvider(ctx, m, FlagExporterInfoProvider)
prop.ExportedFlags = exportedInfo.Flags prop.ExportedFlags = exportedInfo.Flags
prop.ExportedDirs = exportedInfo.IncludeDirs.Strings() prop.ExportedDirs = exportedInfo.IncludeDirs.Strings()
prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings() prop.ExportedSystemDirs = exportedInfo.SystemIncludeDirs.Strings()
@ -797,7 +797,7 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex
return return
} }
apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) apexInfo, _ := android.SingletonModuleProvider(ctx, module, android.ApexInfoProvider)
vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo) vndkType, ok := isVndkSnapshotAware(ctx.DeviceConfig(), m, apexInfo)
if !ok { if !ok {

View file

@ -52,7 +52,7 @@ func TestAarImportProducesJniPackages(t *testing.T) {
appMod := ctx.Module(tc.name, "android_common") appMod := ctx.Module(tc.name, "android_common")
appTestMod := ctx.ModuleForTests(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 { if !ok {
t.Errorf("expected android_library_import to have JniPackageProvider") 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") 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" 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. // Make sure that the library exports hidden API properties for use by the bootclasspath_fragment.
library := result.Module("mynewlibrary", "android_common") 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, "split packages", []string{"sdklibrary", "newlibrary"}, info.SplitPackages)
android.AssertArrayString(t, "package prefixes", []string{"newlibrary.all.mine"}, info.PackagePrefixes) android.AssertArrayString(t, "package prefixes", []string{"newlibrary.all.mine"}, info.PackagePrefixes)
android.AssertArrayString(t, "single packages", []string{"newlibrary.mine"}, info.SinglePackages) android.AssertArrayString(t, "single packages", []string{"newlibrary.mine"}, info.SinglePackages)

View file

@ -30,9 +30,7 @@ func TestCodeMetadata(t *testing.T) {
).Module().(*soongTesting.CodeMetadataModule) ).Module().(*soongTesting.CodeMetadataModule)
// Check that the provider has the right contents // Check that the provider has the right contents
data := result.ModuleProvider( data, _ := android.SingletonModuleProvider(result, module, soongTesting.CodeMetadataProviderKey)
module, soongTesting.CodeMetadataProviderKey,
).(soongTesting.CodeMetadataProviderData)
if !strings.HasSuffix( if !strings.HasSuffix(
data.IntermediatePath.String(), "/intermediateCodeMetadata.pb", data.IntermediatePath.String(), "/intermediateCodeMetadata.pb",
) { ) {

View file

@ -2226,7 +2226,8 @@ func TestTransitiveSrcFiles(t *testing.T) {
} }
`) `)
c := ctx.ModuleForTests("c", "android_common").Module() 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()) 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) dpInfo.Classes = append(dpInfo.Classes, data.Class)
} }
if ctx.ModuleHasProvider(module, JavaInfoProvider) { if dep, ok := android.SingletonModuleProvider(ctx, module, JavaInfoProvider); ok {
dep := ctx.ModuleProvider(module, JavaInfoProvider).(JavaInfo)
dpInfo.Installed_paths = append(dpInfo.Installed_paths, dep.ImplementationJars.Strings()...) dpInfo.Installed_paths = append(dpInfo.Installed_paths, dep.ImplementationJars.Strings()...)
} }
dpInfo.Classes = android.FirstUniqueStrings(dpInfo.Classes) 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() { 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() { if apexInfo.IsForPlatform() {
// There are stray platform variants of modules in apexes that are not available for // 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. // 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) { ctx.VisitAllModules(func(module android.Module) {
// Collect dex jar paths for the modules listed above. // Collect dex jar paths for the modules listed above.
if ctx.ModuleHasProvider(module, JavaInfoProvider) { if j, ok := android.SingletonModuleProvider(ctx, module, JavaInfoProvider); ok {
j := ctx.ModuleProvider(module, JavaInfoProvider).(JavaInfo)
name := ctx.ModuleName(module) name := ctx.ModuleName(module)
if i := android.IndexList(name, stubsModules); i != -1 { if i := android.IndexList(name, stubsModules); i != -1 {
stubsJars[i] = j.HeaderJars 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.system.28", "")
result.ModuleForTests("foo.api.test.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{ expectedFooExportedComponents := []string{
"foo-removed.api.public.latest", "foo-removed.api.public.latest",
"foo-removed.api.system.latest", "foo-removed.api.system.latest",

View file

@ -24,7 +24,7 @@ func getModuleHeaderJarsAsRelativeToTopPaths(result *android.TestResult, moduleN
paths := []string{} paths := []string{}
for _, moduleName := range moduleNames { for _, moduleName := range moduleNames {
module := result.Module(moduleName, "android_common") 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()...) paths = append(paths, info.HeaderJars.RelativeToTop().Strings()...)
} }
return paths return paths

View file

@ -34,9 +34,7 @@ func TestTestSpec(t *testing.T) {
).Module().(*soongTesting.TestSpecModule) ).Module().(*soongTesting.TestSpecModule)
// Check that the provider has the right contents // Check that the provider has the right contents
data := result.ModuleProvider( data, _ := android.SingletonModuleProvider(result, module, soongTesting.TestSpecProviderKey)
module, soongTesting.TestSpecProviderKey,
).(soongTesting.TestSpecProviderData)
if !strings.HasSuffix( if !strings.HasSuffix(
data.IntermediatePath.String(), "/intermediateTestSpecMetadata.pb", 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) { func CheckClasspathFragmentProtoContentInfoProvider(t *testing.T, result *android.TestResult, generated bool, contents, outputFilename, installDir string) {
t.Helper() t.Helper()
p := result.Module("platform-bootclasspath", "android_common").(*platformBootclasspathModule) 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.AssertBoolEquals(t, "classpath proto generated", generated, info.ClasspathFragmentProtoGenerated)
android.AssertStringEquals(t, "classpath proto contents", contents, info.ClasspathFragmentProtoContents.String()) 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 { func apexNamePairFromModule(ctx *android.TestContext, module android.Module) string {
name := module.Name() name := module.Name()
var apex string var apex string
apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) apexInfo, _ := android.SingletonModuleProvider(ctx, module, android.ApexInfoProvider)
if apexInfo.IsForPlatform() { if apexInfo.IsForPlatform() {
apex = "platform" apex = "platform"
} else { } else {

View file

@ -119,7 +119,7 @@ func (c *hostFakeSingleton) GenerateBuildActions(ctx android.SingletonContext) {
if !module.Enabled() || module.IsHideFromMake() { if !module.Enabled() || module.IsHideFromMake() {
return return
} }
apexInfo := ctx.ModuleProvider(module, android.ApexInfoProvider).(android.ApexInfo) apexInfo, _ := android.SingletonModuleProvider(ctx, module, android.ApexInfoProvider)
if !apexInfo.IsForPlatform() { if !apexInfo.IsForPlatform() {
return return
} }

View file

@ -21,14 +21,9 @@ func (this *allCodeMetadataSingleton) GenerateBuildActions(ctx android.Singleton
ctx.VisitAllModules( ctx.VisitAllModules(
func(module android.Module) { func(module android.Module) {
if !ctx.ModuleHasProvider(module, CodeMetadataProviderKey) { if metadata, ok := android.SingletonModuleProvider(ctx, module, CodeMetadataProviderKey); ok {
return 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 var intermediateMetadataPaths android.Paths
ctx.VisitAllModules(func(module android.Module) { ctx.VisitAllModules(func(module android.Module) {
if !ctx.ModuleHasProvider(module, TestSpecProviderKey) { if metadata, ok := android.SingletonModuleProvider(ctx, module, TestSpecProviderKey); ok {
return intermediateMetadataPaths = append(intermediateMetadataPaths, metadata.IntermediatePath)
} }
intermediateMetadataPaths = append(intermediateMetadataPaths, ctx.ModuleProvider(module, TestSpecProviderKey).(TestSpecProviderData).IntermediatePath)
}) })
rspFile := android.PathForOutput(ctx, fileContainingFilePaths) rspFile := android.PathForOutput(ctx, fileContainingFilePaths)