3
3
load ("@io_bazel_rules_scala//scala/private:common.bzl" , "collect_plugin_paths" )
4
4
5
5
ScaladocAspectInfo = provider (fields = [
6
- "src_files" ,
7
- "compile_jars" ,
8
- "plugins" ,
6
+ "src_files" , #depset[File]
7
+ "compile_jars" , #depset[File]
8
+ "plugins" , #depset[Target]
9
9
])
10
10
11
11
def _scaladoc_intransitive_aspect_impl (target , ctx ):
@@ -15,40 +15,39 @@ def _scaladoc_intransitive_aspect_impl(target, ctx):
15
15
def _scaladoc_aspect_impl (target , ctx , transitive = True ):
16
16
"""Collect source files and compile_jars from JavaInfo-returning deps."""
17
17
18
+ src_files = depset ()
19
+ plugins = depset ()
20
+ compile_jars = depset ()
21
+
18
22
# We really only care about visited targets with srcs, so only look at those.
19
23
if hasattr (ctx .rule .attr , "srcs" ):
20
24
# 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
40
28
41
- plugins = depset ()
42
29
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
+ )]
52
51
53
52
_scaladoc_transitive_aspect = aspect (
54
53
implementation = _scaladoc_aspect_impl ,
0 commit comments