Skip to content

Commit

Permalink
Add doc_template_compile, closes rules-proto-grpc#121
Browse files Browse the repository at this point in the history
  • Loading branch information
aaliddell committed Sep 20, 2021
1 parent 3c16bf8 commit d143d46
Show file tree
Hide file tree
Showing 65 changed files with 741 additions and 88 deletions.
22 changes: 22 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,28 @@ tasks:
build_targets:
- "//..."
working_directory: example/doc/doc_markdown_compile
doc_doc_template_compile_ubuntu1804:
name: 'doc: doc_template_compile'
platform: ubuntu1804
build_flags:
build_targets:
- "//..."
working_directory: example/doc/doc_template_compile
doc_doc_template_compile_windows:
name: 'doc: doc_template_compile'
platform: windows
build_flags:
build_targets:
- "//..."
working_directory: example/doc/doc_template_compile
doc_doc_template_compile_macos:
name: 'doc: doc_template_compile'
platform: macos
build_flags:
- "--copt=-DGRPC_BAZEL_BUILD"
build_targets:
- "//..."
working_directory: example/doc/doc_template_compile
fsharp_fsharp_proto_compile_ubuntu1804:
name: 'fsharp: fsharp_proto_compile'
platform: ubuntu1804
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Full documentation for the current and previous versions [can be found here](htt
| [Documentation](https://rules-proto-grpc.com/en/latest/lang/doc.html) | [doc_html_compile](https://rules-proto-grpc.com/en/latest/lang/doc.html#doc-html-compile) | Generates ``.html`` documentation file ([example](/example/doc/doc_html_compile)) |
| [Documentation](https://rules-proto-grpc.com/en/latest/lang/doc.html) | [doc_json_compile](https://rules-proto-grpc.com/en/latest/lang/doc.html#doc-json-compile) | Generates ``.json`` documentation file ([example](/example/doc/doc_json_compile)) |
| [Documentation](https://rules-proto-grpc.com/en/latest/lang/doc.html) | [doc_markdown_compile](https://rules-proto-grpc.com/en/latest/lang/doc.html#doc-markdown-compile) | Generates Markdown ``.md`` documentation file ([example](/example/doc/doc_markdown_compile)) |
| [Documentation](https://rules-proto-grpc.com/en/latest/lang/doc.html) | [doc_template_compile](https://rules-proto-grpc.com/en/latest/lang/doc.html#doc-template-compile) | Generates documentation file using Go template file ([example](/example/doc/doc_template_compile)) |
| [F#](https://rules-proto-grpc.com/en/latest/lang/fsharp.html) | [fsharp_proto_compile](https://rules-proto-grpc.com/en/latest/lang/fsharp.html#fsharp-proto-compile) | Generates F# protobuf ``.fs`` files ([example](/example/fsharp/fsharp_proto_compile)) |
| [F#](https://rules-proto-grpc.com/en/latest/lang/fsharp.html) | [fsharp_grpc_compile](https://rules-proto-grpc.com/en/latest/lang/fsharp.html#fsharp-grpc-compile) | Generates F# protobuf and gRPC ``.fs`` files ([example](/example/fsharp/fsharp_grpc_compile)) |
| [F#](https://rules-proto-grpc.com/en/latest/lang/fsharp.html) | [fsharp_proto_library](https://rules-proto-grpc.com/en/latest/lang/fsharp.html#fsharp-proto-library) | Generates a F# protobuf library using ``fsharp_library`` from ``rules_dotnet``. Note that the library name must end in ``.dll`` ([example](/example/fsharp/fsharp_proto_library)) |
Expand Down
2 changes: 1 addition & 1 deletion android/android_grpc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def android_grpc_library(name, **kwargs):
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos"] + proto_compile_attrs.keys()
if k in proto_compile_attrs.keys()
} # Forward args
)

Expand Down
2 changes: 1 addition & 1 deletion android/android_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def android_proto_library(name, **kwargs):
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos"] + proto_compile_attrs.keys()
if k in proto_compile_attrs.keys()
} # Forward args
)

Expand Down
2 changes: 1 addition & 1 deletion c/c_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def c_proto_library(name, **kwargs): # buildifier: disable=function-docstring
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos"] + proto_compile_attrs.keys()
if k in proto_compile_attrs.keys()
} # Forward args
)

Expand Down
2 changes: 1 addition & 1 deletion cpp/cpp_grpc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def cpp_grpc_library(name, **kwargs): # buildifier: disable=function-docstring
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos"] + proto_compile_attrs.keys()
if k in proto_compile_attrs.keys()
} # Forward args
)

Expand Down
2 changes: 1 addition & 1 deletion cpp/cpp_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def cpp_proto_library(name, **kwargs): # buildifier: disable=function-docstring
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos"] + proto_compile_attrs.keys()
if k in proto_compile_attrs.keys()
} # Forward args
)

Expand Down
2 changes: 1 addition & 1 deletion csharp/csharp_grpc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def csharp_grpc_library(name, **kwargs):
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos"] + proto_compile_attrs.keys()
if k in proto_compile_attrs.keys()
} # Forward args
)

Expand Down
2 changes: 1 addition & 1 deletion csharp/csharp_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def csharp_proto_library(name, **kwargs):
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos"] + proto_compile_attrs.keys()
if k in proto_compile_attrs.keys()
} # Forward args
)

Expand Down
2 changes: 1 addition & 1 deletion d/d_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def d_proto_library(name, **kwargs):
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos"] + proto_compile_attrs.keys()
if k in proto_compile_attrs.keys()
} # Forward args
)

Expand Down
16 changes: 16 additions & 0 deletions doc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,19 @@ proto_plugin(
}),
visibility = ["//visibility:public"],
)

proto_plugin(
name = "template_plugin",
out = "{name}",
separate_options_flag = True,
quirks = [
"QUIRK_OUT_PASS_ROOT",
"QUIRK_DIRECT_MODE",
],
tool = select({
"@bazel_tools//src/conditions:darwin_x86_64": "@protoc_gen_doc_darwin_x86_64//:protoc-gen-doc",
"@bazel_tools//src/conditions:linux_x86_64": "@protoc_gen_doc_linux_x86_64//:protoc-gen-doc",
"@bazel_tools//src/conditions:windows": "@protoc_gen_doc_windows_x86_64//:protoc-gen-doc.exe",
}),
visibility = ["//visibility:public"],
)
2 changes: 2 additions & 0 deletions doc/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ load(":doc_docbook_compile.bzl", _doc_docbook_compile = "doc_docbook_compile")
load(":doc_html_compile.bzl", _doc_html_compile = "doc_html_compile")
load(":doc_json_compile.bzl", _doc_json_compile = "doc_json_compile")
load(":doc_markdown_compile.bzl", _doc_markdown_compile = "doc_markdown_compile")
load(":doc_template_compile.bzl", _doc_template_compile = "doc_template_compile")

# Export doc rules
doc_docbook_compile = _doc_docbook_compile
doc_html_compile = _doc_html_compile
doc_json_compile = _doc_json_compile
doc_markdown_compile = _doc_markdown_compile
doc_template_compile = _doc_template_compile
48 changes: 48 additions & 0 deletions doc/doc_template_compile.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Generated definition of doc_template_compile."""

load(
"//:defs.bzl",
"ProtoPluginInfo",
"proto_compile_attrs",
"proto_compile_impl",
)
load("//internal:compile.bzl", "proto_compile",)

# Create compile rule
def doc_template_compile_impl(ctx):
# Load attrs that we pass as args
options = ctx.attr.options
extra_protoc_args = getattr(ctx.attr, "extra_protoc_args", [])
extra_protoc_files = ctx.files.extra_protoc_files

# Make mutable
options = {k: v for (k, v) in options.items()}
extra_protoc_files = [] + extra_protoc_files

# Mutate args with template
options["*"] = [
ctx.file.template.path, ctx.attr.name
]
extra_protoc_files += [ctx.file.template]

# Execute with extracted attrs
return proto_compile(ctx, options, extra_protoc_args, extra_protoc_files)

doc_template_compile = rule(
implementation = doc_template_compile_impl,
attrs = dict(
proto_compile_attrs,
template = attr.label(
allow_single_file = True,
doc = "The documentation template file.",
),
_plugins = attr.label_list(
providers = [ProtoPluginInfo],
default = [
Label("//doc:template_plugin"),
],
doc = "List of protoc plugins to apply",
),
),
toolchains = [str(Label("//protobuf:toolchain_type"))],
)
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Doc
***

- Updated ``protoc-gen-doc`` to 1.5.0
- Added ``doc_template_compile`` to generate output using a custom Go template file.

Go
**
Expand Down
20 changes: 20 additions & 0 deletions docs/lang/android.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution

Plugins
*******
Expand Down Expand Up @@ -202,6 +207,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution

Plugins
*******
Expand Down Expand Up @@ -315,6 +325,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution
* - ``deps``
- ``label_list``
- false
Expand Down Expand Up @@ -424,6 +439,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution
* - ``deps``
- ``label_list``
- false
Expand Down
10 changes: 10 additions & 0 deletions docs/lang/c.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution

Plugins
*******
Expand Down Expand Up @@ -193,6 +198,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution
* - ``deps``
- ``label_list``
- false
Expand Down
20 changes: 20 additions & 0 deletions docs/lang/cpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution

Plugins
*******
Expand Down Expand Up @@ -188,6 +193,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution

Plugins
*******
Expand Down Expand Up @@ -277,6 +287,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution
* - ``deps``
- ``label_list``
- false
Expand Down Expand Up @@ -408,6 +423,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution
* - ``deps``
- ``label_list``
- false
Expand Down
20 changes: 20 additions & 0 deletions docs/lang/csharp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution

Plugins
*******
Expand Down Expand Up @@ -223,6 +228,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution

Plugins
*******
Expand Down Expand Up @@ -330,6 +340,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution
* - ``deps``
- ``label_list``
- false
Expand Down Expand Up @@ -433,6 +448,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution
* - ``deps``
- ``label_list``
- false
Expand Down
10 changes: 10 additions & 0 deletions docs/lang/d.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution

Plugins
*******
Expand Down Expand Up @@ -197,3 +202,8 @@ Attributes
- false
- ``[]``
- A list of extra args to pass directly to protoc, not as plugin options
* - ``extra_protoc_files``
- ``label_list``
- false
- ``[]``
- List of labels that provide extra files to be available during protoc execution
Loading

0 comments on commit d143d46

Please sign in to comment.