Convert OtherModuleProvider to generic providers API
Convert all of the callers of OtherModuleProvider/OtherModuleHasProvider
to use the type-safe android.OtherModuleProvider API.
Bug: 316410648
Test: builds
Change-Id: Id77f514d68761a262d9ea830a601dbed804bbbe5
diff --git a/cc/afdo.go b/cc/afdo.go
index bad16a1..79fbae1 100644
--- a/cc/afdo.go
+++ b/cc/afdo.go
@@ -137,8 +137,7 @@
}
ctx.VisitDirectDepsWithTag(FdoProfileTag, func(m android.Module) {
- if ctx.OtherModuleHasProvider(m, FdoProfileProvider) {
- info := ctx.OtherModuleProvider(m, FdoProfileProvider).(FdoProfileInfo)
+ if info, ok := android.OtherModuleProvider(ctx, m, FdoProfileProvider); ok {
c.afdo.Properties.FdoProfilePath = proptools.StringPtr(info.Path.String())
}
})
diff --git a/cc/cc.go b/cc/cc.go
index c61773a..e6b9d8b 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -2370,7 +2370,7 @@
if actx.OtherModuleExists("api_imports") {
apiImportModule = actx.AddDependency(c, nil, "api_imports")
if len(apiImportModule) > 0 && apiImportModule[0] != nil {
- apiInfo := actx.OtherModuleProvider(apiImportModule[0], multitree.ApiImportsProvider).(multitree.ApiImportInfo)
+ apiInfo, _ := android.OtherModuleProvider(actx, apiImportModule[0], multitree.ApiImportsProvider)
apiImportInfo = apiInfo
android.SetProvider(actx, multitree.ApiImportsProvider, apiInfo)
}
@@ -2393,7 +2393,7 @@
snapshotModule = actx.AddVariationDependencies(nil, nil, "recovery_snapshot")
}
if len(snapshotModule) > 0 && snapshotModule[0] != nil {
- snapshot := actx.OtherModuleProvider(snapshotModule[0], SnapshotInfoProvider).(SnapshotInfo)
+ snapshot, _ := android.OtherModuleProvider(actx, snapshotModule[0], SnapshotInfoProvider)
*snapshotInfo = &snapshot
// republish the snapshot for use in later mutators on this module
android.SetProvider(actx, SnapshotInfoProvider, snapshot)
@@ -2994,7 +2994,7 @@
ctx.VisitDirectDeps(func(dep android.Module) {
if dep.Name() == "api_imports" {
- apiImportInfo = ctx.OtherModuleProvider(dep, multitree.ApiImportsProvider).(multitree.ApiImportInfo)
+ apiImportInfo, _ = android.OtherModuleProvider(ctx, dep, multitree.ApiImportsProvider)
hasApiImportInfo = true
}
})
@@ -3045,12 +3045,10 @@
}
if depTag == aidlLibraryTag {
- if ctx.OtherModuleHasProvider(dep, aidl_library.AidlLibraryProvider) {
+ if aidlLibraryInfo, ok := android.OtherModuleProvider(ctx, dep, aidl_library.AidlLibraryProvider); ok {
depPaths.AidlLibraryInfos = append(
depPaths.AidlLibraryInfos,
- ctx.OtherModuleProvider(
- dep,
- aidl_library.AidlLibraryProvider).(aidl_library.AidlLibraryInfo),
+ aidlLibraryInfo,
)
}
}
@@ -3115,10 +3113,10 @@
// version mutator, so the stubs variant is created from the shared variant that
// already has the reuseObjTag dependency on the static variant.
if !c.library.buildStubs() {
- staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
+ staticAnalogue, _ := android.OtherModuleProvider(ctx, dep, StaticLibraryInfoProvider)
objs := staticAnalogue.ReuseObjects
depPaths.Objs = depPaths.Objs.Append(objs)
- depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
+ depExporterInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
reexportExporter(depExporterInfo)
}
return
@@ -3139,7 +3137,7 @@
return
}
- depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
+ depExporterInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
var ptr *android.Paths
var depPtr *android.Paths
@@ -3148,7 +3146,7 @@
switch {
case libDepTag.header():
- if !ctx.OtherModuleHasProvider(dep, HeaderLibraryInfoProvider) {
+ if _, isHeaderLib := android.OtherModuleProvider(ctx, dep, HeaderLibraryInfoProvider); !isHeaderLib {
if !ctx.Config().AllowMissingDependencies() {
ctx.ModuleErrorf("module %q is not a header library", depName)
} else {
@@ -3157,7 +3155,7 @@
return
}
case libDepTag.shared():
- if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) {
+ if _, isSharedLib := android.OtherModuleProvider(ctx, dep, SharedLibraryInfoProvider); !isSharedLib {
if !ctx.Config().AllowMissingDependencies() {
ctx.ModuleErrorf("module %q is not a shared library", depName)
} else {
@@ -3194,7 +3192,8 @@
panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
}
case libDepTag.static():
- if !ctx.OtherModuleHasProvider(dep, StaticLibraryInfoProvider) {
+ staticLibraryInfo, isStaticLib := android.OtherModuleProvider(ctx, dep, StaticLibraryInfoProvider)
+ if !isStaticLib {
if !ctx.Config().AllowMissingDependencies() {
ctx.ModuleErrorf("module %q is not a static library", depName)
} else {
@@ -3209,7 +3208,6 @@
break
}
- staticLibraryInfo := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
if libDepTag.wholeStatic {
ptr = &depPaths.WholeStaticLibs
@@ -3319,7 +3317,7 @@
if lib.buildStubs() && dep.(android.ApexModule).InAnyApex() {
// Add the dependency to the APEX(es) providing the library so that
// m <module> can trigger building the APEXes as well.
- depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
+ depApexInfo, _ := android.OtherModuleProvider(ctx, dep, android.ApexInfoProvider)
for _, an := range depApexInfo.InApexVariants {
c.Properties.ApexesProvidingSharedLibs = append(
c.Properties.ApexesProvidingSharedLibs, an)
@@ -3484,9 +3482,9 @@
panic(fmt.Errorf("Unexpected dependency tag: %T", depTag))
}
- sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo)
- depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
- sharedLibraryStubsInfo := ctx.OtherModuleProvider(dep, SharedLibraryStubsProvider).(SharedLibraryStubsInfo)
+ sharedLibraryInfo, _ := android.OtherModuleProvider(ctx, dep, SharedLibraryInfoProvider)
+ depExporterInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
+ sharedLibraryStubsInfo, _ := android.OtherModuleProvider(ctx, dep, SharedLibraryStubsProvider)
if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedStubLibraries) > 0 {
// when to use (unspecified) stubs, use the latest one.
diff --git a/cc/fuzz.go b/cc/fuzz.go
index 6b3a739..f5642d6 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -544,7 +544,8 @@
if !IsValidSharedDependency(dep) {
return
}
- if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) {
+ sharedLibraryInfo, hasSharedLibraryInfo := android.OtherModuleProvider(ctx, dep, SharedLibraryInfoProvider)
+ if !hasSharedLibraryInfo {
return
}
if seen[ctx.OtherModuleName(dep)] {
@@ -553,7 +554,6 @@
seen[ctx.OtherModuleName(dep)] = true
deps = append(deps, dep)
- sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo)
installDestination := sharedLibraryInfo.SharedLibrary.Base()
ruleBuilderInstall := android.RuleBuilderInstall{android.OutputFileForModule(ctx, dep, "unstripped"), installDestination}
sharedLibraries = append(sharedLibraries, ruleBuilderInstall)
@@ -574,14 +574,14 @@
if !IsValidSharedDependency(child) {
return false
}
- if !ctx.OtherModuleHasProvider(child, SharedLibraryInfoProvider) {
+ sharedLibraryInfo, hasSharedLibraryInfo := android.OtherModuleProvider(ctx, child, SharedLibraryInfoProvider)
+ if !hasSharedLibraryInfo {
return false
}
if !seen[ctx.OtherModuleName(child)] {
seen[ctx.OtherModuleName(child)] = true
deps = append(deps, child)
- sharedLibraryInfo := ctx.OtherModuleProvider(child, SharedLibraryInfoProvider).(SharedLibraryInfo)
installDestination := sharedLibraryInfo.SharedLibrary.Base()
ruleBuilderInstall := android.RuleBuilderInstall{android.OutputFileForModule(ctx, child, "unstripped"), installDestination}
sharedLibraries = append(sharedLibraries, ruleBuilderInstall)
diff --git a/cc/library.go b/cc/library.go
index d9276d6..4c8deef 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -1235,7 +1235,7 @@
var transitiveStaticLibrariesForOrdering *android.DepSet[android.Path]
if static := ctx.GetDirectDepsWithTag(staticVariantTag); len(static) > 0 {
- s := ctx.OtherModuleProvider(static[0], StaticLibraryInfoProvider).(StaticLibraryInfo)
+ s, _ := android.OtherModuleProvider(ctx, static[0], StaticLibraryInfoProvider)
transitiveStaticLibrariesForOrdering = s.TransitiveStaticLibrariesForOrdering
}
@@ -1256,8 +1256,8 @@
if len(stubs) > 0 {
var stubsInfo []SharedStubLibrary
for _, stub := range stubs {
- stubInfo := ctx.OtherModuleProvider(stub, SharedLibraryInfoProvider).(SharedLibraryInfo)
- flagInfo := ctx.OtherModuleProvider(stub, FlagExporterInfoProvider).(FlagExporterInfo)
+ stubInfo, _ := android.OtherModuleProvider(ctx, stub, SharedLibraryInfoProvider)
+ flagInfo, _ := android.OtherModuleProvider(ctx, stub, FlagExporterInfoProvider)
stubsInfo = append(stubsInfo, SharedStubLibrary{
Version: moduleLibraryInterface(stub).stubsVersion(),
SharedLibraryInfo: stubInfo,
diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go
index 52e78d7..a65b1ba 100644
--- a/cc/library_sdk_member.go
+++ b/cc/library_sdk_member.go
@@ -511,7 +511,7 @@
}
}
- exportedInfo := ctx.SdkModuleContext().OtherModuleProvider(variant, FlagExporterInfoProvider).(FlagExporterInfo)
+ exportedInfo, _ := android.OtherModuleProvider(ctx.SdkModuleContext(), variant, FlagExporterInfoProvider)
// Separate out the generated include dirs (which are arch specific) from the
// include dirs (which may not be).
diff --git a/cc/library_stub.go b/cc/library_stub.go
index 619e694..1183b29 100644
--- a/cc/library_stub.go
+++ b/cc/library_stub.go
@@ -262,8 +262,8 @@
if len(stubs) > 0 {
var stubsInfo []SharedStubLibrary
for _, stub := range stubs {
- stubInfo := ctx.OtherModuleProvider(stub, SharedLibraryInfoProvider).(SharedLibraryInfo)
- flagInfo := ctx.OtherModuleProvider(stub, FlagExporterInfoProvider).(FlagExporterInfo)
+ stubInfo, _ := android.OtherModuleProvider(ctx, stub, SharedLibraryInfoProvider)
+ flagInfo, _ := android.OtherModuleProvider(ctx, stub, FlagExporterInfoProvider)
stubsInfo = append(stubsInfo, SharedStubLibrary{
Version: moduleLibraryInterface(stub).stubsVersion(),
SharedLibraryInfo: stubInfo,