Convert checkSdkVersions to use ModuleProxy.
Bug: 377723687
Test: Unit tests and compare the ninja and mk files generated.
Change-Id: I5d7150feb8dbb84ac4e01059e76f451fbfc5f7eb
diff --git a/java/base.go b/java/base.go
index ac8619e..49a60f0 100644
--- a/java/base.go
+++ b/java/base.go
@@ -652,14 +652,17 @@
// Make sure this module doesn't statically link to modules with lower-ranked SDK link type.
// See rank() for details.
- ctx.VisitDirectDeps(func(module android.Module) {
+ ctx.VisitDirectDepsProxy(func(module android.ModuleProxy) {
tag := ctx.OtherModuleDependencyTag(module)
- switch module.(type) {
- // TODO(satayev): cover other types as well, e.g. imports
- case *Library, *AndroidLibrary:
+ _, isJavaLibrary := android.OtherModuleProvider(ctx, module, JavaLibraryInfoProvider)
+ _, isAndroidLibrary := android.OtherModuleProvider(ctx, module, AndroidLibraryInfoProvider)
+ _, isJavaAconfigLibrary := android.OtherModuleProvider(ctx, module, android.CodegenInfoProvider)
+ // Exclude java_aconfig_library modules to maintain consistency with existing behavior.
+ if (isJavaLibrary && !isJavaAconfigLibrary) || isAndroidLibrary {
+ // TODO(satayev): cover other types as well, e.g. imports
switch tag {
case bootClasspathTag, sdkLibTag, libTag, staticLibTag, java9LibTag:
- j.checkSdkLinkType(ctx, module.(moduleWithSdkDep), tag.(dependencyTag))
+ j.checkSdkLinkType(ctx, module)
}
}
})
@@ -2375,7 +2378,7 @@
// checkSdkLinkType make sures the given dependency doesn't have a lower SDK link type rank than
// this module's. See the comment on rank() for details and an example.
func (j *Module) checkSdkLinkType(
- ctx android.ModuleContext, dep moduleWithSdkDep, tag dependencyTag) {
+ ctx android.ModuleContext, dep android.ModuleProxy) {
if ctx.Host() {
return
}
@@ -2384,7 +2387,12 @@
if stubs {
return
}
- depLinkType, _ := dep.getSdkLinkType(ctx, ctx.OtherModuleName(dep))
+ info, ok := android.OtherModuleProvider(ctx, dep, JavaInfoProvider)
+ if !ok || info.ModuleWithSdkDepInfo == nil {
+ panic(fmt.Errorf("dependency doesn't have ModuleWithSdkDepInfo: %v", dep))
+ }
+
+ depLinkType := info.ModuleWithSdkDepInfo.SdkLinkType
if myLinkType.rank() < depLinkType.rank() {
ctx.ModuleErrorf("compiles against %v, but dependency %q is compiling against %v. "+