aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Rostovtsev <arostovtsev@google.com>2023-08-04 15:27:15 -0400
committerGitHub <noreply@github.com>2023-08-04 15:27:15 -0400
commitd90cbcfb5a91f3a7dacb64a59c7ea62d0091b615 (patch)
tree7b18c2798aabc2b6615960c15809eab4422ae5a6
parentabe8c1d1bbbe874e594ce0fc41f16b1566f1891a (diff)
downloadstardoc-d90cbcfb5a91f3a7dacb64a59c7ea62d0091b615.tar.gz
Replace dict union "|" with dict.update for Bazel 5 compatibility (#177)
Surprisingly, the release tarballs of Stardoc 0.6 almost works with Bazel 5 - except for two usages of the dict union operator. Temporarily (until ~ Stardoc 0.7 release, which will require Bazel 7) replace the union operator with dict.update; it doesn't affect readability much. Fixes #175
-rw-r--r--stardoc/private/stardoc.bzl88
1 files changed, 49 insertions, 39 deletions
diff --git a/stardoc/private/stardoc.bzl b/stardoc/private/stardoc.bzl
index 9eeb270..16d1122 100644
--- a/stardoc/private/stardoc.bzl
+++ b/stardoc/private/stardoc.bzl
@@ -143,32 +143,29 @@ _common_renderer_attrs = {
),
}
-stardoc = rule(
- _stardoc_impl,
- doc = """
-Generates documentation for starlark skylark rule definitions in a target starlark file.
-""",
- attrs = {
- "input": attr.label(
- doc = "The starlark file to generate documentation for.",
- allow_single_file = [".bzl"],
- mandatory = True,
- ),
- "format": attr.string(
- doc = "The format of the output file. Valid values: 'markdown' or 'proto'.",
- values = ["markdown", "proto"],
- mandatory = True,
- ),
- "symbol_names": attr.string_list(
- doc = """
+# TODO(arostovtsev): replace with ... attrs = { ... } | _common_renderer_attrs
+# in rule definition below after we drop support for Bazel 5.
+_stardoc_attrs = {
+ "input": attr.label(
+ doc = "The starlark file to generate documentation for.",
+ allow_single_file = [".bzl"],
+ mandatory = True,
+ ),
+ "format": attr.string(
+ doc = "The format of the output file. Valid values: 'markdown' or 'proto'.",
+ values = ["markdown", "proto"],
+ mandatory = True,
+ ),
+ "symbol_names": attr.string_list(
+ doc = """
A list of symbol names to generate documentation for. These should correspond to
the names of rule definitions in the input file. If this list is empty, then
documentation for all exported rule definitions will be generated.
""",
- mandatory = True,
- ),
- "semantic_flags": attr.string_list(
- doc = """
+ mandatory = True,
+ ),
+ "semantic_flags": attr.string_list(
+ doc = """
A list of canonical flags to affect Starlark semantics for the Starlark interpretter
during documentation generation. This should only be used to maintain compatibility with
non-default semantic flags required to use the given Starlark symbols.
@@ -177,16 +174,24 @@ For example, if `//foo:bar.bzl` does not build except when a user would specify
`--incompatible_foo_semantic=false`, then this attribute should contain
"--incompatible_foo_semantic=false".
""",
- mandatory = True,
- ),
- "stardoc": attr.label(
- doc = "The location of the stardoc tool.",
- allow_files = True,
- cfg = "exec",
- executable = True,
- mandatory = True,
- ),
- } | _common_renderer_attrs,
+ mandatory = True,
+ ),
+ "stardoc": attr.label(
+ doc = "The location of the stardoc tool.",
+ allow_files = True,
+ cfg = "exec",
+ executable = True,
+ mandatory = True,
+ ),
+}
+_stardoc_attrs.update(_common_renderer_attrs.items())
+
+stardoc = rule(
+ _stardoc_impl,
+ doc = """
+Generates documentation for starlark skylark rule definitions in a target starlark file.
+""",
+ attrs = _stardoc_attrs,
)
def _stardoc_markdown_renderer_impl(ctx):
@@ -199,16 +204,21 @@ def _stardoc_markdown_renderer_impl(ctx):
outputs = [out_file]
return [DefaultInfo(files = depset(outputs), runfiles = ctx.runfiles(files = outputs))]
+# TODO(arostovtsev): replace with ... attrs = { ... } | _common_renderer_attrs
+# in rule definition below after we drop support for Bazel 5.
+_stardoc_markdown_renderer_attrs = {
+ "src": attr.label(
+ doc = "The .binaryproto file from which to generate documentation.",
+ allow_single_file = [".binaryproto"],
+ mandatory = True,
+ ),
+}
+_stardoc_markdown_renderer_attrs.update(_common_renderer_attrs.items())
+
stardoc_markdown_renderer = rule(
_stardoc_markdown_renderer_impl,
doc = """
Generates markdown documentation for starlark rule definitions from the corresponding binary proto.
""",
- attrs = {
- "src": attr.label(
- doc = "The .binaryproto file from which to generate documentation.",
- allow_single_file = [".binaryproto"],
- mandatory = True,
- ),
- } | _common_renderer_attrs,
+ attrs = _stardoc_markdown_renderer_attrs,
)