diff options
author | 2025-01-13 23:52:19 +0000 | |
---|---|---|
committer | 2025-01-15 20:52:06 +0000 | |
commit | 39f5fb3db37a307081cd96d334feb6a7fcc7a7d7 (patch) | |
tree | d32d73a9069d72578b16b963e1e6996cdd3f92de | |
parent | f6f8549664d1ab0ab944713cd96f27c2ed934582 (diff) |
Convert collectDeps and collectTransitiveHeaderJarsForR8 to use ModuleProxy.
Bug: 377723687
Test: Unit tests and compare the ninja and mk files generated.
Change-Id: I957c09bba8fc047cb8959461294d8879486185a6
-rw-r--r-- | java/aar.go | 2 | ||||
-rw-r--r-- | java/base.go | 48 | ||||
-rw-r--r-- | java/droiddoc.go | 8 | ||||
-rw-r--r-- | java/java.go | 12 | ||||
-rw-r--r-- | java/plugin.go | 28 |
5 files changed, 63 insertions, 35 deletions
diff --git a/java/aar.go b/java/aar.go index 0db195c8a..b982b9571 100644 --- a/java/aar.go +++ b/java/aar.go @@ -1455,7 +1455,7 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) { var transitiveStaticLibsImplementationJars []depset.DepSet[android.Path] var transitiveStaticLibsResourceJars []depset.DepSet[android.Path] - ctx.VisitDirectDeps(func(module android.Module) { + ctx.VisitDirectDepsProxy(func(module android.ModuleProxy) { if dep, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok { tag := ctx.OtherModuleDependencyTag(module) switch tag { diff --git a/java/base.go b/java/base.go index 1e0d4bf85..9e448c64b 100644 --- a/java/base.go +++ b/java/base.go @@ -2151,7 +2151,7 @@ func (j *providesTransitiveHeaderJarsForR8) collectTransitiveHeaderJarsForR8(ctx directStaticLibs := android.Paths{} transitiveLibs := []depset.DepSet[android.Path]{} transitiveStaticLibs := []depset.DepSet[android.Path]{} - ctx.VisitDirectDeps(func(module android.Module) { + ctx.VisitDirectDepsProxy(func(module android.ModuleProxy) { // don't add deps of the prebuilt version of the same library if ctx.ModuleName() == android.RemoveOptionalPrebuiltPrefix(module.Name()) { return @@ -2433,7 +2433,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { var transitiveStaticJarsImplementationLibs []depset.DepSet[android.Path] var transitiveStaticJarsResourceLibs []depset.DepSet[android.Path] - ctx.VisitDirectDeps(func(module android.Module) { + ctx.VisitDirectDepsProxy(func(module android.ModuleProxy) { otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) @@ -2467,7 +2467,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { deps.bootClasspath = append(deps.bootClasspath, dep.HeaderJars...) transitiveBootClasspathHeaderJars = append(transitiveBootClasspathHeaderJars, dep.TransitiveStaticLibsHeaderJars) case sdkLibTag, libTag, instrumentationForTag: - if _, ok := module.(*Plugin); ok { + if _, ok := android.OtherModuleProvider(ctx, module, JavaPluginInfoProvider); ok { ctx.ModuleErrorf("a java_plugin (%s) cannot be used as a libs dependency", otherName) } deps.classpath = append(deps.classpath, dep.HeaderJars...) @@ -2485,7 +2485,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars...) transitiveJava9ClasspathHeaderJars = append(transitiveJava9ClasspathHeaderJars, dep.TransitiveStaticLibsHeaderJars) case staticLibTag: - if _, ok := module.(*Plugin); ok { + if _, ok := android.OtherModuleProvider(ctx, module, JavaPluginInfoProvider); ok { ctx.ModuleErrorf("a java_plugin (%s) cannot be used as a static_libs dependency", otherName) } deps.classpath = append(deps.classpath, dep.HeaderJars...) @@ -2505,40 +2505,40 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { transitiveStaticJarsImplementationLibs = append(transitiveStaticJarsImplementationLibs, dep.TransitiveStaticLibsImplementationJars) transitiveStaticJarsResourceLibs = append(transitiveStaticJarsResourceLibs, dep.TransitiveStaticLibsResourceJars) case pluginTag: - if plugin, ok := module.(*Plugin); ok { - if plugin.pluginProperties.Processor_class != nil { - addPlugins(&deps, dep.ImplementationAndResourcesJars, *plugin.pluginProperties.Processor_class) + if plugin, ok := android.OtherModuleProvider(ctx, module, JavaPluginInfoProvider); ok { + if plugin.ProcessorClass != nil { + addPlugins(&deps, dep.ImplementationAndResourcesJars, *plugin.ProcessorClass) } else { addPlugins(&deps, dep.ImplementationAndResourcesJars) } // Turbine doesn't run annotation processors, so any module that uses an // annotation processor that generates API is incompatible with the turbine // optimization. - deps.disableTurbine = deps.disableTurbine || Bool(plugin.pluginProperties.Generates_api) + deps.disableTurbine = deps.disableTurbine || plugin.GeneratesApi } else { ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName) } case errorpronePluginTag: - if _, ok := module.(*Plugin); ok { + if _, ok := android.OtherModuleProvider(ctx, module, JavaPluginInfoProvider); ok { deps.errorProneProcessorPath = append(deps.errorProneProcessorPath, dep.ImplementationAndResourcesJars...) } else { ctx.PropertyErrorf("plugins", "%q is not a java_plugin module", otherName) } case exportedPluginTag: - if plugin, ok := module.(*Plugin); ok { + if plugin, ok := android.OtherModuleProvider(ctx, module, JavaPluginInfoProvider); ok { j.exportedPluginJars = append(j.exportedPluginJars, dep.ImplementationAndResourcesJars...) - if plugin.pluginProperties.Processor_class != nil { - j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.pluginProperties.Processor_class) + if plugin.ProcessorClass != nil { + j.exportedPluginClasses = append(j.exportedPluginClasses, *plugin.ProcessorClass) } // Turbine doesn't run annotation processors, so any module that uses an // annotation processor that generates API is incompatible with the turbine // optimization. - j.exportedDisableTurbine = Bool(plugin.pluginProperties.Generates_api) + j.exportedDisableTurbine = plugin.GeneratesApi } else { ctx.PropertyErrorf("exported_plugins", "%q is not a java_plugin module", otherName) } case kotlinPluginTag: - if _, ok := module.(*KotlinPlugin); ok { + if _, ok := android.OtherModuleProvider(ctx, module, KotlinPluginInfoProvider); ok { deps.kotlinPlugins = append(deps.kotlinPlugins, dep.ImplementationAndResourcesJars...) } else { ctx.PropertyErrorf("kotlin_plugins", "%q is not a kotlin_plugin module", otherName) @@ -2550,21 +2550,21 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps { JavaInfo: dep, }) } - } else if dep, ok := module.(android.SourceFileProducer); ok { + } else if dep, ok := android.OtherModuleProvider(ctx, module, android.SourceFilesInfoKey); ok { switch tag { case sdkLibTag, libTag: - checkProducesJars(ctx, dep) - deps.classpath = append(deps.classpath, dep.Srcs()...) - deps.dexClasspath = append(deps.classpath, dep.Srcs()...) + checkProducesJars(ctx, dep, module) + deps.classpath = append(deps.classpath, dep.Srcs...) + deps.dexClasspath = append(deps.classpath, dep.Srcs...) transitiveClasspathHeaderJars = append(transitiveClasspathHeaderJars, - depset.New(depset.PREORDER, dep.Srcs(), nil)) + depset.New(depset.PREORDER, dep.Srcs, nil)) case staticLibTag: - checkProducesJars(ctx, dep) - deps.classpath = append(deps.classpath, dep.Srcs()...) - deps.staticJars = append(deps.staticJars, dep.Srcs()...) - deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs()...) + checkProducesJars(ctx, dep, module) + deps.classpath = append(deps.classpath, dep.Srcs...) + deps.staticJars = append(deps.staticJars, dep.Srcs...) + deps.staticHeaderJars = append(deps.staticHeaderJars, dep.Srcs...) - depHeaderJars := depset.New(depset.PREORDER, dep.Srcs(), nil) + depHeaderJars := depset.New(depset.PREORDER, dep.Srcs, nil) transitiveClasspathHeaderJars = append(transitiveClasspathHeaderJars, depHeaderJars) transitiveStaticJarsHeaderLibs = append(transitiveStaticJarsHeaderLibs, depHeaderJars) transitiveStaticJarsImplementationLibs = append(transitiveStaticJarsImplementationLibs, depHeaderJars) diff --git a/java/droiddoc.go b/java/droiddoc.go index 2dda72b0e..dcbe48dfb 100644 --- a/java/droiddoc.go +++ b/java/droiddoc.go @@ -357,7 +357,7 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { deps.aidlPreprocess = sdkDep.aidl } - ctx.VisitDirectDeps(func(module android.Module) { + ctx.VisitDirectDepsProxy(func(module android.ModuleProxy) { otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) @@ -381,9 +381,9 @@ func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { deps.classpath = append(deps.classpath, dep.HeaderJars...) deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...) deps.aconfigProtoFiles = append(deps.aconfigProtoFiles, dep.AconfigIntermediateCacheOutputPaths...) - } else if dep, ok := module.(android.SourceFileProducer); ok { - checkProducesJars(ctx, dep) - deps.classpath = append(deps.classpath, dep.Srcs()...) + } else if dep, ok := android.OtherModuleProvider(ctx, module, android.SourceFilesInfoKey); ok { + checkProducesJars(ctx, dep, module) + deps.classpath = append(deps.classpath, dep.Srcs...) } else { ctx.ModuleErrorf("depends on non-java module %q", otherName) } diff --git a/java/java.go b/java/java.go index 3a1bc335a..0a9381dad 100644 --- a/java/java.go +++ b/java/java.go @@ -640,11 +640,11 @@ type deps struct { transitiveStaticLibsResourceJars []depset.DepSet[android.Path] } -func checkProducesJars(ctx android.ModuleContext, dep android.SourceFileProducer) { - for _, f := range dep.Srcs() { +func checkProducesJars(ctx android.ModuleContext, dep android.SourceFilesInfo, module android.ModuleProxy) { + for _, f := range dep.Srcs { if f.Ext() != ".jar" { ctx.ModuleErrorf("genrule %q must generate files ending with .jar to be used as a libs or static_libs dependency", - ctx.OtherModuleName(dep.(blueprint.Module))) + ctx.OtherModuleName(module)) } } } @@ -2761,7 +2761,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) { var staticJars android.Paths var staticResourceJars android.Paths var staticHeaderJars android.Paths - ctx.VisitDirectDeps(func(module android.Module) { + ctx.VisitDirectDepsProxy(func(module android.ModuleProxy) { tag := ctx.OtherModuleDependencyTag(module) if dep, ok := android.OtherModuleProvider(ctx, module, JavaInfoProvider); ok { switch tag { @@ -3395,7 +3395,7 @@ var String = proptools.String var inList = android.InList[string] // Add class loader context (CLC) of a given dependency to the current CLC. -func addCLCFromDep(ctx android.ModuleContext, depModule android.Module, +func addCLCFromDep(ctx android.ModuleContext, depModule android.ModuleProxy, clcMap dexpreopt.ClassLoaderContextMap) { dep, ok := android.OtherModuleProvider(ctx, depModule, JavaInfoProvider) @@ -3455,7 +3455,7 @@ func addCLCFromDep(ctx android.ModuleContext, depModule android.Module, } } -func addMissingOptionalUsesLibsFromDep(ctx android.ModuleContext, depModule android.Module, +func addMissingOptionalUsesLibsFromDep(ctx android.ModuleContext, depModule android.ModuleProxy, usesLibrary *usesLibrary) { dep, ok := android.OtherModuleProvider(ctx, depModule, JavaInfoProvider) diff --git a/java/plugin.go b/java/plugin.go index 610c9fd11..3534c7b13 100644 --- a/java/plugin.go +++ b/java/plugin.go @@ -16,8 +16,21 @@ package java import ( "android/soong/android" + "github.com/google/blueprint" ) +type JavaPluginInfo struct { + ProcessorClass *string + GeneratesApi bool +} + +var JavaPluginInfoProvider = blueprint.NewProvider[JavaPluginInfo]() + +type KotlinPluginInfo struct { +} + +var KotlinPluginInfoProvider = blueprint.NewProvider[KotlinPluginInfo]() + func init() { registerJavaPluginBuildComponents(android.InitRegistrationContext) } @@ -65,7 +78,22 @@ type PluginProperties struct { Generates_api *bool } +func (p *Plugin) GenerateAndroidBuildActions(ctx android.ModuleContext) { + p.Library.GenerateAndroidBuildActions(ctx) + + android.SetProvider(ctx, JavaPluginInfoProvider, JavaPluginInfo{ + ProcessorClass: p.pluginProperties.Processor_class, + GeneratesApi: Bool(p.pluginProperties.Generates_api), + }) +} + // Plugin describes a kotlin_plugin module, a host java/kotlin library that will be used by kotlinc as a compiler plugin. type KotlinPlugin struct { Library } + +func (p *KotlinPlugin) GenerateAndroidBuildActions(ctx android.ModuleContext) { + p.Library.GenerateAndroidBuildActions(ctx) + + android.SetProvider(ctx, KotlinPluginInfoProvider, KotlinPluginInfo{}) +} |