diff --git a/java/base.go b/java/base.go index f820629e9..daa50ef86 100644 --- a/java/base.go +++ b/java/base.go @@ -2374,16 +2374,24 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { case bootClasspathTag: // If a system modules dependency has been added to the bootclasspath // then add its libs to the bootclasspath. - sm := module.(SystemModulesProvider) - deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...) + if sm, ok := android.OtherModuleProvider(ctx, module, SystemModulesProvider); ok { + depHeaderJars := sm.HeaderJars + deps.bootClasspath = append(deps.bootClasspath, depHeaderJars...) + } else { + ctx.PropertyErrorf("boot classpath dependency %q does not provide SystemModulesProvider", + ctx.OtherModuleName(module)) + } case systemModulesTag: if deps.systemModules != nil { panic("Found two system module dependencies") } - sm := module.(SystemModulesProvider) - outputDir, outputDeps := sm.OutputDirAndDeps() - deps.systemModules = &systemModules{outputDir, outputDeps} + if sm, ok := android.OtherModuleProvider(ctx, module, SystemModulesProvider); ok { + deps.systemModules = &systemModules{sm.OutputDir, sm.OutputDirDeps} + } else { + ctx.PropertyErrorf("system modules dependency %q does not provide SystemModulesProvider", + ctx.OtherModuleName(module)) + } case instrumentationForTag: ctx.PropertyErrorf("instrumentation_for", "dependency %q of type %q does not provide JavaInfo so is unsuitable for use with this property", ctx.OtherModuleName(module), ctx.OtherModuleType(module)) diff --git a/java/droiddoc.go b/java/droiddoc.go index 730f23696..f81c5bac5 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -365,10 +365,10 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { case bootClasspathTag: if dep, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok { deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars...) - } else if sm, ok := module.(SystemModulesProvider); ok { + } else if sm, ok := android.OtherModuleProvider(ctx, module, SystemModulesProvider); ok { // A system modules dependency has been added to the bootclasspath // so add its libs to the bootclasspath. - deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...) + deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars...) } else { panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) } @@ -396,9 +396,12 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { if deps.systemModules != nil { panic("Found two system module dependencies") } - sm := module.(SystemModulesProvider) - outputDir, outputDeps := sm.OutputDirAndDeps() - deps.systemModules = &systemModules{outputDir, outputDeps} + if sm, ok := android.OtherModuleProvider(ctx, module, SystemModulesProvider); ok { + deps.systemModules = &systemModules{sm.OutputDir, sm.OutputDirDeps} + } else { + ctx.PropertyErrorf("boot classpath dependency %q does not provide SystemModulesProvider", + ctx.OtherModuleName(module)) + } case aconfigDeclarationTag: if dep, ok := android.OtherModuleProvider(ctx, module, android.AconfigDeclarationsProviderKey); ok { deps.aconfigProtoFiles = append(deps.aconfigProtoFiles, dep.IntermediateCacheOutputPath) diff --git a/java/java.go b/java/java.go index be3f90b20..126d8f3a4 100644 --- a/java/java.go +++ b/java/java.go @@ -2261,8 +2261,9 @@ func (al *ApiLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) { staticLibs = append(staticLibs, provider.HeaderJars...) } case systemModulesTag: - module := dep.(SystemModulesProvider) - systemModulesPaths = append(systemModulesPaths, module.HeaderJars()...) + if sm, ok := android.OtherModuleProvider(ctx, dep, SystemModulesProvider); ok { + systemModulesPaths = append(systemModulesPaths, sm.HeaderJars...) + } case metalavaCurrentApiTimestampTag: if currentApiTimestampProvider, ok := dep.(currentApiTimestampProvider); ok { al.validationPaths = append(al.validationPaths, currentApiTimestampProvider.CurrentApiTimestamp()) diff --git a/java/system_modules.go b/java/system_modules.go index 48b33ba57..5b00079f7 100644 --- a/java/system_modules.go +++ b/java/system_modules.go @@ -120,14 +120,16 @@ func SystemModulesFactory() android.Module { return module } -type SystemModulesProvider interface { - HeaderJars() android.Paths - OutputDirAndDeps() (android.Path, android.Paths) +type SystemModulesProviderInfo struct { + // The aggregated header jars from all jars specified in the libs property. + // Used when system module is added as a dependency to bootclasspath. + HeaderJars android.Paths + + OutputDir android.Path + OutputDirDeps android.Paths } -var _ SystemModulesProvider = (*SystemModules)(nil) - -var _ SystemModulesProvider = (*systemModulesImport)(nil) +var SystemModulesProvider = blueprint.NewProvider[*SystemModulesProviderInfo]() type SystemModules struct { android.ModuleBase @@ -135,9 +137,6 @@ type SystemModules struct { properties SystemModulesProperties - // The aggregated header jars from all jars specified in the libs property. - // Used when system module is added as a dependency to bootclasspath. - headerJars android.Paths outputDir android.Path outputDeps android.Paths } @@ -147,17 +146,6 @@ type SystemModulesProperties struct { Libs []string } -func (system *SystemModules) HeaderJars() android.Paths { - return system.headerJars -} - -func (system *SystemModules) OutputDirAndDeps() (android.Path, android.Paths) { - if system.outputDir == nil || len(system.outputDeps) == 0 { - panic("Missing directory for system module dependency") - } - return system.outputDir, system.outputDeps -} - func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleContext) { var jars android.Paths @@ -167,9 +155,13 @@ func (system *SystemModules) GenerateAndroidBuildActions(ctx android.ModuleConte } }) - system.headerJars = jars - system.outputDir, system.outputDeps = TransformJarsToSystemModules(ctx, jars) + + android.SetProvider(ctx, SystemModulesProvider, &SystemModulesProviderInfo{ + HeaderJars: jars, + OutputDir: system.outputDir, + OutputDirDeps: system.outputDeps, + }) } // ComponentDepsMutator is called before prebuilt modules without a corresponding source module are