From a841c81b246e1ff86d8791f6959ca2f32112dd4d Mon Sep 17 00:00:00 2001 From: Long Cao Date: Tue, 28 May 2019 23:03:47 -0700 Subject: [PATCH 01/14] move collect_plugin_paths to common.bzl --- scala/private/common.bzl | 17 +++++++++++++++++ scala/private/rule_impls.bzl | 19 ++----------------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/scala/private/common.bzl b/scala/private/common.bzl index 2cea9ffd3..4fcabc2f6 100644 --- a/scala/private/common.bzl +++ b/scala/private/common.bzl @@ -36,6 +36,23 @@ def collect_jars( else: return _collect_jars_when_dependency_analyzer_is_on(dep_targets) +def collect_plugin_paths(plugins): + """Get the actual jar paths of plugins as a depset.""" + paths = [] + for p in plugins: + if hasattr(p, "path"): + paths.append(p) + elif hasattr(p, "scala"): + paths.extend([j.class_jar for j in p.scala.outputs.jars]) + elif hasattr(p, "java"): + paths.extend([j.class_jar for j in p.java.outputs.jars]) + # support http_file pointed at a jar. http_jar uses ijar, + # which breaks scala macros + + elif hasattr(p, "files"): + paths.extend([f for f in p.files if not_sources_jar(f.basename)]) + return depset(paths) + def _collect_jars_when_dependency_analyzer_is_off( dep_targets, unused_dependency_checker_is_off, diff --git a/scala/private/rule_impls.bzl b/scala/private/rule_impls.bzl index 0d2c4ce8c..216dd97b2 100644 --- a/scala/private/rule_impls.bzl +++ b/scala/private/rule_impls.bzl @@ -26,6 +26,7 @@ load( ":common.bzl", "add_labels_of_jars_to", "collect_jars", + "collect_plugin_paths", "collect_srcjars", "create_java_provider", "not_sources_jar", @@ -127,22 +128,6 @@ touch {statsfile} arguments = [], ) -def _collect_plugin_paths(plugins): - paths = [] - for p in plugins: - if hasattr(p, "path"): - paths.append(p) - elif hasattr(p, "scala"): - paths.extend([j.class_jar for j in p.scala.outputs.jars]) - elif hasattr(p, "java"): - paths.extend([j.class_jar for j in p.java.outputs.jars]) - # support http_file pointed at a jar. http_jar uses ijar, - # which breaks scala macros - - elif hasattr(p, "files"): - paths.extend([f for f in p.files if not_sources_jar(f.basename)]) - return depset(paths) - def _expand_location(ctx, flags): return [ctx.expand_location(f, ctx.attr.data) for f in flags] @@ -172,7 +157,7 @@ def compile_scala( unused_dependency_checker_mode = "off", unused_dependency_checker_ignored_targets = []): # look for any plugins: - plugins = _collect_plugin_paths(plugins) + plugins = collect_plugin_paths(plugins) internal_plugin_jars = [] dependency_analyzer_mode = "off" compiler_classpath_jars = cjars From 4d1597c3834177f157aa243e33395c1e49014166 Mon Sep 17 00:00:00 2001 From: Long Cao Date: Tue, 28 May 2019 23:32:20 -0700 Subject: [PATCH 02/14] add scala_doc rule + aspect implementations --- scala/scala.bzl | 6 ++ scala/scala_doc.bzl | 86 +++++++++++++++++++ .../bazel/rules_scala/scaladoc_support/BUILD | 17 ++++ 3 files changed, 109 insertions(+) create mode 100644 scala/scala_doc.bzl create mode 100644 src/scala/io/bazel/rules_scala/scaladoc_support/BUILD diff --git a/scala/scala.bzl b/scala/scala.bzl index 375fa0d1c..f85b5dd78 100644 --- a/scala/scala.bzl +++ b/scala/scala.bzl @@ -32,6 +32,10 @@ load( "@io_bazel_rules_scala//scala:plusone.bzl", _collect_plus_one_deps_aspect = "collect_plus_one_deps_aspect", ) +load( + "@io_bazel_rules_scala//scala:scala_doc.bzl", + _scala_doc = "scala_doc", +) _launcher_template = { "_java_stub_template": attr.label( @@ -700,3 +704,5 @@ def scala_specs2_junit_test(name, **kwargs): suite_class = "io.bazel.rulesscala.specs2.Specs2DiscoveredTestSuite", **kwargs ) + +scala_doc = _scala_doc \ No newline at end of file diff --git a/scala/scala_doc.bzl b/scala/scala_doc.bzl new file mode 100644 index 000000000..5b571d2d1 --- /dev/null +++ b/scala/scala_doc.bzl @@ -0,0 +1,86 @@ +"""Scaladoc support""" + +load("@io_bazel_rules_scala//scala/private:common.bzl", "collect_plugin_paths") + +ScaladocAspectInfo = provider(fields = [ + "src_files", + "compile_jars", +]) + +def _scaladoc_aspect_impl(target, ctx): + """Collect source files and compile_jars from JavaInfo-returning deps.""" + + # We really only care about visited targets with srcs, so only look at those. + if hasattr(ctx.rule.attr, "srcs"): + # Collect only Java and Scala sources enumerated in visited targets. + src_files = depset(direct = [file for file in ctx.rule.files.srcs if file.extension.lower() in ["java", "scala"]]) + + # Collect compile_jars from visited targets' deps. + compile_jars = depset(transitive = [dep[JavaInfo].compile_jars for dep in ctx.rule.attr.deps if JavaInfo in dep]) + + return [ScaladocAspectInfo( + src_files = src_files, + compile_jars = compile_jars, + )] + else: + return [] + +scaladoc_aspect = aspect( + implementation = _scaladoc_aspect_impl, + attr_aspects = ["deps"], + required_aspect_providers = [ + [JavaInfo], + ], +) + +def _scala_doc_impl(ctx): + output_path = ctx.outputs.html + + # Collect all source files and compile_jars to pass to scaladoc by way of an aspect. + src_files = depset(transitive = [dep[ScaladocAspectInfo].src_files for dep in ctx.attr.deps]) + compile_jars = depset(transitive = [dep[ScaladocAspectInfo].compile_jars for dep in ctx.attr.deps]) + + # Get the 'real' paths to the plugin jars. + plugins = collect_plugin_paths(ctx.attr.plugins) + + # Construct the full classpath depset since we need to add compiler plugins too. + classpath = depset(transitive = [plugins, compile_jars]) + + # Construct scaladoc args, which also include scalac args. + # See `scaladoc -help` for more information. + args = ctx.actions.args() + args.add("-usejavacp") + args.add("-d", output_path) + args.add_all(plugins, format_each = "-Xplugin:%s") + args.add_joined("-classpath", classpath, join_with = ":") + args.add_all(src_files) + + # Run the scaladoc tool! + ctx.actions.run( + inputs = depset(transitive = [src_files, classpath]), + outputs = [output_path], + executable = ctx.attr._scaladoc.files_to_run.executable, + mnemonic = "ScalaDoc", + progress_message = "scaladoc {}".format(ctx.label), + arguments = [args], + ) + + return [DefaultInfo(files = depset(direct = [output_path]))] + +scala_doc = rule( + attrs = { + "deps": attr.label_list( + aspects = [scaladoc_aspect], + providers = [JavaInfo], + ), + "plugins": attr.label_list(allow_files = [".jar"]), + "_scaladoc": attr.label( + cfg = "host", + executable = True, + default = Label("//src/scala/io/bazel/rules_scala/scaladoc_support:scaladoc_generator"), + ), + }, + doc = "Generate Scaladoc HTML documentation for source files in from the given dependencies.", + outputs = {"html": "%{name}.html"}, + implementation = _scala_doc_impl, +) diff --git a/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD b/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD new file mode 100644 index 000000000..b48ad5fb4 --- /dev/null +++ b/src/scala/io/bazel/rules_scala/scaladoc_support/BUILD @@ -0,0 +1,17 @@ +load("//scala:scala.bzl", "scala_binary") + +# A simple scala_binary to run scaladoc. +# `bazel run` this target with "-help" as a param for usage text: +# bazel run -- "//src/scala/io/bazel/rules_scala/scaladoc_support:scaladoc_generator" -help +scala_binary( + name = "scaladoc_generator", + main_class = "scala.tools.nsc.ScalaDoc", + visibility = ["//visibility:public"], + runtime_deps = [ + "//external:io_bazel_rules_scala/dependency/scala/parser_combinators", + "//external:io_bazel_rules_scala/dependency/scala/scala_compiler", + "//external:io_bazel_rules_scala/dependency/scala/scala_library", + "//external:io_bazel_rules_scala/dependency/scala/scala_reflect", + "//external:io_bazel_rules_scala/dependency/scala/scala_xml", + ], +) From 3cf7a25617443eecd9e8dd3808c57bc4218cff44 Mon Sep 17 00:00:00 2001 From: Long Cao Date: Wed, 29 May 2019 11:17:15 -0700 Subject: [PATCH 03/14] add basic scala_doc Markdown documentation --- README.md | 1 + docs/scala_doc.md | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 docs/scala_doc.md diff --git a/README.md b/README.md index c9f01f2d5..eaf4be9e8 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This project defines core build rules for [Scala](https://www.scala-lang.org/) t * [scalapb_proto_library](docs/scalapb_proto_library.md) * [scala_toolchain](docs/scala_toolchain.md) * [scala_import](docs/scala_import.md) +* [scala_doc](docs/scala_doc.md) ## Getting started diff --git a/docs/scala_doc.md b/docs/scala_doc.md new file mode 100644 index 000000000..248809bcd --- /dev/null +++ b/docs/scala_doc.md @@ -0,0 +1,20 @@ +# scala_doc + +```python +scala_binary( + name, + deps, + plugins, +) +``` + +`scala_doc` generates [Scaladoc](https://docs.scala-lang.org/style/scaladoc.html) for sources +for targets, including sources from upstream deps. Readily hostable HTML is written to a `name.html` output folder. + +## Attributes + +| Attribute name | Description | +| --------------------- | ----------------------------------------------------- | +| name | `Name, required`
A unique name for this target. +| deps | `List of labels, optional`
Labels for which you want to create scaladoc. +| plugins | `List of labels, optional`
Scala compiler plugins to pass through to the scaladoc tool. \ No newline at end of file From 1691e8d1d0f6bb4deb7c4f1815c7fe9ffd803b15 Mon Sep 17 00:00:00 2001 From: Long Cao Date: Wed, 29 May 2019 12:05:25 -0700 Subject: [PATCH 04/14] add scala_doc example --- docs/scala_doc.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/scala_doc.md b/docs/scala_doc.md index 248809bcd..437af45eb 100644 --- a/docs/scala_doc.md +++ b/docs/scala_doc.md @@ -11,6 +11,28 @@ scala_binary( `scala_doc` generates [Scaladoc](https://docs.scala-lang.org/style/scaladoc.html) for sources for targets, including sources from upstream deps. Readily hostable HTML is written to a `name.html` output folder. +## Example + +scala_doc( + name = "scala_docs", + plugins = ["//external:path/to/kind-projector.jar], + tags = ["manual"], + deps = [ + ":target1", + ":target2", + ":anothertarget", + ], +) + +# Use pkg_tar to tarball up +# https://docs.bazel.build/versions/master/be/pkg.html#pkg_tar +pkg_tar( + name = "scala_docs_archive", + srcs = [":scala_docs"], + extension = "tar.gz", +) +``` + ## Attributes | Attribute name | Description | From 85450eea984bafe986e1e48a588b18dbf691d22d Mon Sep 17 00:00:00 2001 From: Long Cao Date: Wed, 29 May 2019 13:28:19 -0700 Subject: [PATCH 05/14] collect plugins in aspect too --- docs/scala_doc.md | 5 +---- scala/scala_doc.bzl | 9 +++++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/scala_doc.md b/docs/scala_doc.md index 437af45eb..19ed6715f 100644 --- a/docs/scala_doc.md +++ b/docs/scala_doc.md @@ -4,7 +4,6 @@ scala_binary( name, deps, - plugins, ) ``` @@ -15,7 +14,6 @@ for targets, including sources from upstream deps. Readily hostable HTML is writ scala_doc( name = "scala_docs", - plugins = ["//external:path/to/kind-projector.jar], tags = ["manual"], deps = [ ":target1", @@ -38,5 +36,4 @@ pkg_tar( | Attribute name | Description | | --------------------- | ----------------------------------------------------- | | name | `Name, required`
A unique name for this target. -| deps | `List of labels, optional`
Labels for which you want to create scaladoc. -| plugins | `List of labels, optional`
Scala compiler plugins to pass through to the scaladoc tool. \ No newline at end of file +| deps | `List of labels, optional`
Labels for which you want to create scaladoc. \ No newline at end of file diff --git a/scala/scala_doc.bzl b/scala/scala_doc.bzl index 5b571d2d1..5d57d5840 100644 --- a/scala/scala_doc.bzl +++ b/scala/scala_doc.bzl @@ -5,6 +5,7 @@ load("@io_bazel_rules_scala//scala/private:common.bzl", "collect_plugin_paths") ScaladocAspectInfo = provider(fields = [ "src_files", "compile_jars", + "plugins", ]) def _scaladoc_aspect_impl(target, ctx): @@ -18,9 +19,14 @@ def _scaladoc_aspect_impl(target, ctx): # Collect compile_jars from visited targets' deps. compile_jars = depset(transitive = [dep[JavaInfo].compile_jars for dep in ctx.rule.attr.deps if JavaInfo in dep]) + plugins = depset() + if hasattr(ctx.rule.attr, "plugins"): + plugins = depset(direct = ctx.rule.attr.plugins) + return [ScaladocAspectInfo( src_files = src_files, compile_jars = compile_jars, + plugins = plugins, )] else: return [] @@ -41,7 +47,7 @@ def _scala_doc_impl(ctx): compile_jars = depset(transitive = [dep[ScaladocAspectInfo].compile_jars for dep in ctx.attr.deps]) # Get the 'real' paths to the plugin jars. - plugins = collect_plugin_paths(ctx.attr.plugins) + plugins = collect_plugin_paths(depset(transitive = [dep[ScaladocAspectInfo].plugins for dep in ctx.attr.deps])) # Construct the full classpath depset since we need to add compiler plugins too. classpath = depset(transitive = [plugins, compile_jars]) @@ -73,7 +79,6 @@ scala_doc = rule( aspects = [scaladoc_aspect], providers = [JavaInfo], ), - "plugins": attr.label_list(allow_files = [".jar"]), "_scaladoc": attr.label( cfg = "host", executable = True, From 3fb233efb79a0dc7597fbb99f0dc72057fe22bda Mon Sep 17 00:00:00 2001 From: Long Cao Date: Wed, 29 May 2019 13:51:16 -0700 Subject: [PATCH 06/14] declare_directory for scaldoc output path or else it complains --- scala/scala_doc.bzl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scala/scala_doc.bzl b/scala/scala_doc.bzl index 5d57d5840..cacbffc5c 100644 --- a/scala/scala_doc.bzl +++ b/scala/scala_doc.bzl @@ -40,7 +40,8 @@ scaladoc_aspect = aspect( ) def _scala_doc_impl(ctx): - output_path = ctx.outputs.html + # scaladoc warns if you don't have the output directory already created, which is annoying. + output_path = ctx.actions.declare_directory("{}.html".format(ctx.attr.name)) # Collect all source files and compile_jars to pass to scaladoc by way of an aspect. src_files = depset(transitive = [dep[ScaladocAspectInfo].src_files for dep in ctx.attr.deps]) @@ -56,7 +57,7 @@ def _scala_doc_impl(ctx): # See `scaladoc -help` for more information. args = ctx.actions.args() args.add("-usejavacp") - args.add("-d", output_path) + args.add("-d", output_path.path) args.add_all(plugins, format_each = "-Xplugin:%s") args.add_joined("-classpath", classpath, join_with = ":") args.add_all(src_files) @@ -86,6 +87,5 @@ scala_doc = rule( ), }, doc = "Generate Scaladoc HTML documentation for source files in from the given dependencies.", - outputs = {"html": "%{name}.html"}, implementation = _scala_doc_impl, ) From 15ef44ad6d3ad915411e61fa8ad2457ca460e73c Mon Sep 17 00:00:00 2001 From: Long Cao Date: Wed, 29 May 2019 13:53:25 -0700 Subject: [PATCH 07/14] add a simple test target for scala_doc rule --- test/BUILD | 10 ++++++++++ .../scala/scalarules/test/compiler_plugin/BUILD.bazel | 7 ++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/test/BUILD b/test/BUILD index 319d20edc..a1be14ae4 100644 --- a/test/BUILD +++ b/test/BUILD @@ -3,6 +3,7 @@ package(default_testonly = 1) load( "//scala:scala.bzl", "scala_binary", + "scala_doc", "scala_library", "scala_test", "scala_macro_library", @@ -137,6 +138,15 @@ scala_library( deps = ["ExportOnly"], ) +scala_doc( + name = "ScalaDoc", + deps = [ + ":HelloLib", + ":OtherLib", + "//test/src/main/scala/scalarules/test/compiler_plugin", # brings kind-projector compiler plugin with it + ] +) + scala_library( name = "UnusedLib", srcs = ["UnusedLib.scala"] diff --git a/test/src/main/scala/scalarules/test/compiler_plugin/BUILD.bazel b/test/src/main/scala/scalarules/test/compiler_plugin/BUILD.bazel index 368ae414c..53db39a9b 100644 --- a/test/src/main/scala/scalarules/test/compiler_plugin/BUILD.bazel +++ b/test/src/main/scala/scalarules/test/compiler_plugin/BUILD.bazel @@ -2,6 +2,7 @@ load("//scala:scala.bzl", "scala_library") scala_library( name = "compiler_plugin", - srcs = [ "KindProjected.scala" ], - plugins = ["@org_spire_math_kind_projector//jar"] -) \ No newline at end of file + srcs = ["KindProjected.scala"], + plugins = ["@org_spire_math_kind_projector//jar"], + visibility = ["//visibility:public"], +) From 9f3c69e541b3933d400ed2e6295fdeb869c2abc7 Mon Sep 17 00:00:00 2001 From: Long Cao Date: Wed, 29 May 2019 14:00:11 -0700 Subject: [PATCH 08/14] add doc note about scaladoc being kind of slow --- docs/scala_doc.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/scala_doc.md b/docs/scala_doc.md index 19ed6715f..594425614 100644 --- a/docs/scala_doc.md +++ b/docs/scala_doc.md @@ -10,6 +10,9 @@ scala_binary( `scala_doc` generates [Scaladoc](https://docs.scala-lang.org/style/scaladoc.html) for sources for targets, including sources from upstream deps. Readily hostable HTML is written to a `name.html` output folder. +Scaladoc can be somewhat slow to build. In that case, you can tell Bazel to build this target manually, +i.e. only when named explicitly and not through wildcards: `tags = ["manual"]`. + ## Example scala_doc( From a381a43e02ad3921ad5b4d3d7bf1817f3c893aeb Mon Sep 17 00:00:00 2001 From: Long Cao Date: Wed, 29 May 2019 14:20:23 -0700 Subject: [PATCH 09/14] fix scala_doc.md code block --- docs/scala_doc.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/scala_doc.md b/docs/scala_doc.md index 594425614..9cc2c35c6 100644 --- a/docs/scala_doc.md +++ b/docs/scala_doc.md @@ -15,6 +15,7 @@ i.e. only when named explicitly and not through wildcards: `tags = ["manual"]`. ## Example +```python scala_doc( name = "scala_docs", tags = ["manual"], From 10b0af4db8f23715abacfd585c60a809d51f3221 Mon Sep 17 00:00:00 2001 From: Long Cao Date: Wed, 29 May 2019 14:30:05 -0700 Subject: [PATCH 10/14] privatize scaladoc aspect --- scala/scala_doc.bzl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scala/scala_doc.bzl b/scala/scala_doc.bzl index cacbffc5c..38619d6f1 100644 --- a/scala/scala_doc.bzl +++ b/scala/scala_doc.bzl @@ -2,7 +2,7 @@ load("@io_bazel_rules_scala//scala/private:common.bzl", "collect_plugin_paths") -ScaladocAspectInfo = provider(fields = [ +_ScaladocAspectInfo = provider(fields = [ "src_files", "compile_jars", "plugins", @@ -23,7 +23,7 @@ def _scaladoc_aspect_impl(target, ctx): if hasattr(ctx.rule.attr, "plugins"): plugins = depset(direct = ctx.rule.attr.plugins) - return [ScaladocAspectInfo( + return [_ScaladocAspectInfo( src_files = src_files, compile_jars = compile_jars, plugins = plugins, @@ -31,7 +31,7 @@ def _scaladoc_aspect_impl(target, ctx): else: return [] -scaladoc_aspect = aspect( +_scaladoc_aspect = aspect( implementation = _scaladoc_aspect_impl, attr_aspects = ["deps"], required_aspect_providers = [ @@ -44,11 +44,11 @@ def _scala_doc_impl(ctx): output_path = ctx.actions.declare_directory("{}.html".format(ctx.attr.name)) # Collect all source files and compile_jars to pass to scaladoc by way of an aspect. - src_files = depset(transitive = [dep[ScaladocAspectInfo].src_files for dep in ctx.attr.deps]) - compile_jars = depset(transitive = [dep[ScaladocAspectInfo].compile_jars for dep in ctx.attr.deps]) + src_files = depset(transitive = [dep[_ScaladocAspectInfo].src_files for dep in ctx.attr.deps]) + compile_jars = depset(transitive = [dep[_ScaladocAspectInfo].compile_jars for dep in ctx.attr.deps]) # Get the 'real' paths to the plugin jars. - plugins = collect_plugin_paths(depset(transitive = [dep[ScaladocAspectInfo].plugins for dep in ctx.attr.deps])) + plugins = collect_plugin_paths(depset(transitive = [dep[_ScaladocAspectInfo].plugins for dep in ctx.attr.deps])) # Construct the full classpath depset since we need to add compiler plugins too. classpath = depset(transitive = [plugins, compile_jars]) @@ -77,7 +77,7 @@ def _scala_doc_impl(ctx): scala_doc = rule( attrs = { "deps": attr.label_list( - aspects = [scaladoc_aspect], + aspects = [_scaladoc_aspect], providers = [JavaInfo], ), "_scaladoc": attr.label( From 48fc3d4f63219b90fe30afaaf1eea2bb41dc5c50 Mon Sep 17 00:00:00 2001 From: Long Cao Date: Wed, 29 May 2019 17:30:06 -0700 Subject: [PATCH 11/14] get more src_files/compile_jars --- scala/scala_doc.bzl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scala/scala_doc.bzl b/scala/scala_doc.bzl index 38619d6f1..d55252937 100644 --- a/scala/scala_doc.bzl +++ b/scala/scala_doc.bzl @@ -13,11 +13,20 @@ def _scaladoc_aspect_impl(target, ctx): # We really only care about visited targets with srcs, so only look at those. if hasattr(ctx.rule.attr, "srcs"): - # Collect only Java and Scala sources enumerated in visited targets. - src_files = depset(direct = [file for file in ctx.rule.files.srcs if file.extension.lower() in ["java", "scala"]]) + # Collect only Java and Scala sources enumerated in visited targets, including src_files in deps. + src_files = depset( + direct = [file for file in ctx.rule.files.srcs if file.extension.lower() in ["java", "scala"]], + transitive = [dep[_ScaladocAspectInfo].src_files for dep in ctx.rule.attr.deps if _ScaladocAspectInfo in dep], + ) # Collect compile_jars from visited targets' deps. - compile_jars = depset(transitive = [dep[JavaInfo].compile_jars for dep in ctx.rule.attr.deps if JavaInfo in dep]) + compile_jars = depset( + direct = [file for file in ctx.rule.files.deps], + transitive = ( + [dep[JavaInfo].compile_jars for dep in ctx.rule.attr.deps if JavaInfo in dep] + + [dep[_ScaladocAspectInfo].compile_jars for dep in ctx.rule.attr.deps if _ScaladocAspectInfo in dep] + ), + ) plugins = depset() if hasattr(ctx.rule.attr, "plugins"): From c3197a4696416fc36c40c8544b2d90af271d1134 Mon Sep 17 00:00:00 2001 From: Long Cao Date: Wed, 29 May 2019 18:14:01 -0700 Subject: [PATCH 12/14] also accept scalacopts in scala_doc --- docs/scala_doc.md | 7 ++++++- scala/scala_doc.bzl | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/scala_doc.md b/docs/scala_doc.md index 9cc2c35c6..5a7fe34cc 100644 --- a/docs/scala_doc.md +++ b/docs/scala_doc.md @@ -24,6 +24,10 @@ scala_doc( ":target2", ":anothertarget", ], + scalacopts = [ + "-Ypartial-unification", + "-Ywarn-unused-import", + ], ) # Use pkg_tar to tarball up @@ -40,4 +44,5 @@ pkg_tar( | Attribute name | Description | | --------------------- | ----------------------------------------------------- | | name | `Name, required`
A unique name for this target. -| deps | `List of labels, optional`
Labels for which you want to create scaladoc. \ No newline at end of file +| deps | `List of labels, optional`
Labels for which you want to create scaladoc. +| scalacopts | `List of strings, optional`
Extra compiler options for this library to be passed to scalac. \ No newline at end of file diff --git a/scala/scala_doc.bzl b/scala/scala_doc.bzl index d55252937..9aec0bbe2 100644 --- a/scala/scala_doc.bzl +++ b/scala/scala_doc.bzl @@ -66,6 +66,7 @@ def _scala_doc_impl(ctx): # See `scaladoc -help` for more information. args = ctx.actions.args() args.add("-usejavacp") + args.add_all(ctx.attr.scalacopts) args.add("-d", output_path.path) args.add_all(plugins, format_each = "-Xplugin:%s") args.add_joined("-classpath", classpath, join_with = ":") @@ -89,6 +90,7 @@ scala_doc = rule( aspects = [_scaladoc_aspect], providers = [JavaInfo], ), + "scalacopts": attr.string_list(), "_scaladoc": attr.label( cfg = "host", executable = True, From 25c7b48256d99599888b39f46f6f5c449df37478 Mon Sep 17 00:00:00 2001 From: Long Cao Date: Wed, 29 May 2019 18:23:14 -0700 Subject: [PATCH 13/14] turn off scaladoc warnings for now --- scala/scala_doc.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/scala/scala_doc.bzl b/scala/scala_doc.bzl index 9aec0bbe2..24524f956 100644 --- a/scala/scala_doc.bzl +++ b/scala/scala_doc.bzl @@ -66,6 +66,7 @@ def _scala_doc_impl(ctx): # See `scaladoc -help` for more information. args = ctx.actions.args() args.add("-usejavacp") + args.add("-nowarn") # turn off warnings for now since they can obscure actual errors for large scala_doc targets args.add_all(ctx.attr.scalacopts) args.add("-d", output_path.path) args.add_all(plugins, format_each = "-Xplugin:%s") From 87cd04f3ae090016a96df4f002235d895d49c154 Mon Sep 17 00:00:00 2001 From: Long Cao Date: Thu, 30 May 2019 16:19:35 -0700 Subject: [PATCH 14/14] use host_path_separator in classpath --- scala/scala_doc.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scala/scala_doc.bzl b/scala/scala_doc.bzl index 24524f956..2aed41c78 100644 --- a/scala/scala_doc.bzl +++ b/scala/scala_doc.bzl @@ -70,7 +70,7 @@ def _scala_doc_impl(ctx): args.add_all(ctx.attr.scalacopts) args.add("-d", output_path.path) args.add_all(plugins, format_each = "-Xplugin:%s") - args.add_joined("-classpath", classpath, join_with = ":") + args.add_joined("-classpath", classpath, join_with = ctx.configuration.host_path_separator) args.add_all(src_files) # Run the scaladoc tool!