33load ("@io_bazel_rules_scala//scala/private:common.bzl" , "collect_plugin_paths" )
44
55ScaladocAspectInfo = provider (fields = [
6- "src_files" ,
7- "compile_jars" ,
8- "plugins" ,
6+ "src_files" , #depset[File]
7+ "compile_jars" , #depset[File]
8+ "plugins" , #depset[Target]
99])
1010
1111def _scaladoc_intransitive_aspect_impl (target , ctx ):
@@ -15,40 +15,39 @@ def _scaladoc_intransitive_aspect_impl(target, ctx):
1515def _scaladoc_aspect_impl (target , ctx , transitive = True ):
1616 """Collect source files and compile_jars from JavaInfo-returning deps."""
1717
18+ src_files = depset ()
19+ plugins = depset ()
20+ compile_jars = depset ()
21+
1822 # We really only care about visited targets with srcs, so only look at those.
1923 if hasattr (ctx .rule .attr , "srcs" ):
2024 # Collect only Java and Scala sources enumerated in visited targets, including src_files in deps.
21- direct_deps = [file for file in ctx .rule .files .srcs if file .extension .lower () in ["java" , "scala" ]]
22-
23- # Sometimes we only want to generate scaladocs for a single target and not all of its
24- # dependencies
25- if transitive :
26- transitive_deps = [dep [ScaladocAspectInfo ].src_files for dep in ctx .rule .attr .deps if ScaladocAspectInfo in dep ]
27- else :
28- transitive_deps = []
29-
30- src_files = depset (direct = direct_deps , transitive = transitive_deps )
31-
32- # Collect compile_jars from visited targets' deps.
33- compile_jars = depset (
34- direct = [file for file in ctx .rule .files .deps ],
35- transitive = (
36- [dep [JavaInfo ].compile_jars for dep in ctx .rule .attr .deps if JavaInfo in dep ] +
37- [dep [ScaladocAspectInfo ].compile_jars for dep in ctx .rule .attr .deps if ScaladocAspectInfo in dep ]
38- ),
39- )
25+ src_files = depset ([file for file in ctx .rule .files .srcs if file .extension .lower () in ["java" , "scala" ]])
26+
27+ compile_jars = target [JavaInfo ].transitive_compile_time_jars
4028
41- plugins = depset ()
4229 if hasattr (ctx .rule .attr , "plugins" ):
43- plugins = depset (direct = ctx .rule .attr .plugins )
44-
45- return [ScaladocAspectInfo (
46- src_files = src_files ,
47- compile_jars = compile_jars ,
48- plugins = plugins ,
49- )]
50- else :
51- return []
30+ plugins = depset (ctx .rule .attr .plugins )
31+
32+ # Sometimes we only want to generate scaladocs for a single target and not all of its
33+ # dependencies
34+ transitive_srcs = depset ()
35+ transitive_compile_jars = depset ()
36+ transitive_plugins = depset ()
37+
38+ if transitive :
39+ for dep in ctx .rule .attr .deps :
40+ if ScaladocAspectInfo in dep :
41+ aspec_info = dep [ScaladocAspectInfo ]
42+ transitive_srcs = aspec_info .src_files
43+ transitive_compile_jars = aspec_info .compile_jars
44+ transitive_plugins = aspec_info .plugins
45+
46+ return [ScaladocAspectInfo (
47+ src_files = depset (transitive = [src_files , transitive_srcs ]),
48+ compile_jars = depset (transitive = [compile_jars , transitive_compile_jars ]),
49+ plugins = depset (transitive = [plugins , transitive_plugins ]),
50+ )]
5251
5352_scaladoc_transitive_aspect = aspect (
5453 implementation = _scaladoc_aspect_impl ,
0 commit comments