@@ -8,16 +8,26 @@ _ScaladocAspectInfo = provider(fields = [
88 "plugins" ,
99])
1010
11- def _scaladoc_aspect_impl (target , ctx ):
11+ def _scaladoc_intransitive_aspect_impl (target , ctx ):
12+ """Build scaladocs only for the provided targets."""
13+ return _scaladoc_aspect_impl (target , ctx , transitive = False )
14+
15+ def _scaladoc_aspect_impl (target , ctx , transitive = True ):
1216 """Collect source files and compile_jars from JavaInfo-returning deps."""
1317
1418 # We really only care about visited targets with srcs, so only look at those.
1519 if hasattr (ctx .rule .attr , "srcs" ):
1620 # Collect only Java and Scala sources enumerated in visited targets, including src_files in deps.
17- src_files = depset (
18- direct = [file for file in ctx .rule .files .srcs if file .extension .lower () in ["java" , "scala" ]],
19- transitive = [dep [_ScaladocAspectInfo ].src_files for dep in ctx .rule .attr .deps if _ScaladocAspectInfo in dep ],
20- )
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 )
2131
2232 # Collect compile_jars from visited targets' deps.
2333 compile_jars = depset (
@@ -40,14 +50,22 @@ def _scaladoc_aspect_impl(target, ctx):
4050 else :
4151 return []
4252
43- _scaladoc_aspect = aspect (
53+ _scaladoc_transitive_aspect = aspect (
4454 implementation = _scaladoc_aspect_impl ,
4555 attr_aspects = ["deps" ],
4656 required_aspect_providers = [
4757 [JavaInfo ],
4858 ],
4959)
5060
61+ scaladoc_intransitive_aspect = aspect (
62+ implementation = _scaladoc_intransitive_aspect_impl ,
63+ attr_aspects = ["deps" ],
64+ required_aspect_providers = [
65+ [JavaInfo ],
66+ ],
67+ )
68+
5169def _scala_doc_impl (ctx ):
5270 # scaladoc warns if you don't have the output directory already created, which is annoying.
5371 output_path = ctx .actions .declare_directory ("{}.html" .format (ctx .attr .name ))
@@ -85,19 +103,20 @@ def _scala_doc_impl(ctx):
85103
86104 return [DefaultInfo (files = depset (direct = [output_path ]))]
87105
88- scala_doc = rule (
89- attrs = {
90- "deps" : attr .label_list (
91- aspects = [_scaladoc_aspect ],
92- providers = [JavaInfo ],
93- ),
94- "scalacopts" : attr .string_list (),
95- "_scaladoc" : attr .label (
96- cfg = "host" ,
97- executable = True ,
98- default = Label ("//src/scala/io/bazel/rules_scala/scaladoc_support:scaladoc_generator" ),
99- ),
100- },
101- doc = "Generate Scaladoc HTML documentation for source files in from the given dependencies." ,
102- implementation = _scala_doc_impl ,
103- )
106+ def make_scala_doc_rule (aspect = _scaladoc_transitive_aspect ):
107+ return rule (
108+ attrs = {
109+ "deps" : attr .label_list (
110+ aspects = [aspect ],
111+ providers = [JavaInfo ],
112+ ),
113+ "scalacopts" : attr .string_list (),
114+ "_scaladoc" : attr .label (
115+ cfg = "exec" ,
116+ executable = True ,
117+ default = Label ("//src/scala/io/bazel/rules_scala/scaladoc_support:scaladoc_generator" ),
118+ ),
119+ },
120+ doc = "Generate Scaladoc HTML documentation for source files in from the given dependencies." ,
121+ implementation = _scala_doc_impl ,
122+ )
0 commit comments