Add doc_template_compile, closes #121

This commit is contained in:
Adam Liddell 2021-09-21 00:20:19 +01:00
parent 3c16bf815c
commit d143d46d42
65 changed files with 741 additions and 88 deletions

View File

@ -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

View File

@ -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)) |

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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
)

View File

@ -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"],
)

View File

@ -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

View File

@ -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"))],
)

View File

@ -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
**

View File

@ -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
*******
@ -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
*******
@ -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
@ -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

View File

@ -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
*******
@ -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

View File

@ -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
*******
@ -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
*******
@ -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
@ -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

View File

@ -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
*******
@ -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
*******
@ -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
@ -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

View File

@ -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
*******
@ -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

View File

@ -22,14 +22,14 @@ Rules for generating protobuf Markdown, JSON, HTML or DocBook documentation with
- Generates ``.json`` documentation file
* - `doc_markdown_compile`_
- Generates Markdown ``.md`` documentation file
* - `doc_template_compile`_
- Generates documentation file using Go template file
.. _doc_docbook_compile:
doc_docbook_compile
-------------------
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
Generates DocBook ``.xml`` documentation file
Example
@ -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
*******
@ -116,8 +121,6 @@ Plugins
doc_html_compile
----------------
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
Generates ``.html`` documentation file
Example
@ -193,6 +196,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
*******
@ -204,8 +212,6 @@ Plugins
doc_json_compile
----------------
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
Generates ``.json`` documentation file
Example
@ -281,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
Plugins
*******
@ -292,8 +303,6 @@ Plugins
doc_markdown_compile
--------------------
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
Generates Markdown ``.md`` documentation file
Example
@ -369,8 +378,105 @@ 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
*******
- `@rules_proto_grpc//doc:markdown_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/doc/BUILD.bazel>`__
.. _doc_template_compile:
doc_template_compile
--------------------
.. warning:: This rule is experimental. It may not work correctly or may change in future releases!
Generates documentation file using Go template file
Example
*******
Full example project can be found `here <https://github.com/rules-proto-grpc/rules_proto_grpc/tree/master/example/doc/doc_template_compile>`__
``WORKSPACE``
^^^^^^^^^^^^^
.. code-block:: python
load("@rules_proto_grpc//doc:repositories.bzl", rules_proto_grpc_doc_repos = "doc_repos")
rules_proto_grpc_doc_repos()
``BUILD.bazel``
^^^^^^^^^^^^^^^
.. code-block:: python
load("@rules_proto_grpc//doc:defs.bzl", "doc_template_compile")
doc_template_compile(
name = "greeter_doc_proto",
protos = [
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:thing_proto",
],
template = "template.txt",
)
Attributes
**********
.. list-table:: Attributes for doc_template_compile
:widths: 1 1 1 1 4
:header-rows: 1
* - Name
- Type
- Mandatory
- Default
- Description
* - ``protos``
- ``label_list``
- true
-
- List of labels that provide the ``ProtoInfo`` provider (such as ``proto_library`` from ``rules_proto``)
* - ``options``
- ``string_list_dict``
- false
- ``[]``
- Extra options to pass to plugins, as a dict of plugin label -> list of strings. The key * can be used exclusively to apply to all plugins
* - ``verbose``
- ``int``
- false
- ``0``
- The verbosity level. Supported values and results are 1: *show command*, 2: *show command and sandbox after running protoc*, 3: *show command and sandbox before and after running protoc*, 4. *show env, command, expected outputs and sandbox before and after running protoc*
* - ``prefix_path``
- ``string``
- false
- ``""``
- Path to prefix to the generated files in the output directory
* - ``extra_protoc_args``
- ``string_list``
- 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
* - ``template``
- ``label``
- true
- ``None``
- The documentation template file.
Plugins
*******
- `@rules_proto_grpc//doc:template_plugin <https://github.com/rules-proto-grpc/rules_proto_grpc/blob/master/doc/BUILD.bazel>`__

View File

@ -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
*******
@ -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
*******
@ -329,6 +339,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
@ -432,6 +447,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

View File

@ -125,6 +125,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
*******
@ -224,6 +229,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
*******
@ -326,6 +336,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
*******
@ -427,6 +442,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
@ -530,6 +550,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
@ -635,6 +660,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

View File

@ -111,6 +111,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
*******
@ -211,6 +216,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
*******
@ -310,6 +320,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

View File

@ -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
*******
@ -184,6 +189,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
*******
@ -273,6 +283,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
@ -378,6 +393,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

View File

@ -128,6 +128,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
*******
@ -218,6 +223,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
*******
@ -310,6 +320,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
*******
@ -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
@ -513,6 +533,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
@ -618,6 +643,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

View File

@ -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
*******
@ -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
*******
@ -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
@ -410,6 +425,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

View File

@ -99,6 +99,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
*******
@ -184,6 +189,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
*******

View File

@ -111,6 +111,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
*******
@ -196,6 +201,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
*******
@ -290,6 +300,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
*******
@ -379,6 +394,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
@ -465,6 +485,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
@ -559,6 +584,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

View File

@ -118,6 +118,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
*******
@ -218,6 +223,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
*******
@ -322,6 +332,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
@ -423,6 +438,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

View File

@ -111,6 +111,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
*******
@ -200,6 +205,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
*******
@ -289,6 +299,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
@ -376,6 +391,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

View File

@ -119,6 +119,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
*******
@ -220,6 +225,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
*******
@ -324,6 +334,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
@ -431,6 +446,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

View File

@ -110,6 +110,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
*******
@ -198,6 +203,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
*******
@ -286,6 +296,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
@ -377,6 +392,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

View File

@ -126,8 +126,13 @@ doc_doc_markdown_compile_example:
cd example/doc/doc_markdown_compile; \
bazel --batch build --verbose_failures --disk_cache=../../bazel-disk-cache //...
.PHONY: doc_doc_template_compile_example
doc_doc_template_compile_example:
cd example/doc/doc_template_compile; \
bazel --batch build --verbose_failures --disk_cache=../../bazel-disk-cache //...
.PHONY: doc_examples
doc_examples: doc_doc_docbook_compile_example doc_doc_html_compile_example doc_doc_json_compile_example doc_doc_markdown_compile_example
doc_examples: doc_doc_docbook_compile_example doc_doc_html_compile_example doc_doc_json_compile_example doc_doc_markdown_compile_example doc_doc_template_compile_example
.PHONY: fsharp_fsharp_proto_compile_example
fsharp_fsharp_proto_compile_example:
@ -421,4 +426,4 @@ swift_swift_grpc_library_example:
swift_examples: swift_swift_proto_compile_example swift_swift_grpc_compile_example swift_swift_proto_library_example swift_swift_grpc_library_example
.PHONY: all_examples
all_examples: android_android_proto_compile_example android_android_grpc_compile_example android_android_proto_library_example android_android_grpc_library_example buf_buf_proto_breaking_test_example buf_buf_proto_lint_test_example c_c_proto_compile_example c_c_proto_library_example cpp_cpp_proto_compile_example cpp_cpp_grpc_compile_example cpp_cpp_proto_library_example cpp_cpp_grpc_library_example csharp_csharp_proto_compile_example csharp_csharp_grpc_compile_example csharp_csharp_proto_library_example csharp_csharp_grpc_library_example d_d_proto_compile_example d_d_proto_library_example doc_doc_docbook_compile_example doc_doc_html_compile_example doc_doc_json_compile_example doc_doc_markdown_compile_example fsharp_fsharp_proto_compile_example fsharp_fsharp_grpc_compile_example fsharp_fsharp_proto_library_example fsharp_fsharp_grpc_library_example go_go_proto_compile_example go_go_grpc_compile_example go_go_validate_compile_example go_go_proto_library_example go_go_grpc_library_example go_go_validate_library_example grpc-gateway_gateway_grpc_compile_example grpc-gateway_gateway_openapiv2_compile_example grpc-gateway_gateway_grpc_library_example java_java_proto_compile_example java_java_grpc_compile_example java_java_proto_library_example java_java_grpc_library_example js_js_proto_compile_example js_js_grpc_node_compile_example js_js_grpc_web_compile_example js_js_proto_library_example js_js_grpc_node_library_example js_js_grpc_web_library_example objc_objc_proto_compile_example objc_objc_grpc_compile_example objc_objc_proto_library_example objc_objc_grpc_library_example php_php_proto_compile_example php_php_grpc_compile_example python_python_proto_compile_example python_python_grpc_compile_example python_python_grpclib_compile_example python_python_proto_library_example python_python_grpc_library_example python_python_grpclib_library_example ruby_ruby_proto_compile_example ruby_ruby_grpc_compile_example ruby_ruby_proto_library_example ruby_ruby_grpc_library_example rust_rust_proto_compile_example rust_rust_grpc_compile_example rust_rust_proto_library_example rust_rust_grpc_library_example scala_scala_proto_compile_example scala_scala_grpc_compile_example scala_scala_proto_library_example scala_scala_grpc_library_example swift_swift_proto_compile_example swift_swift_grpc_compile_example swift_swift_proto_library_example swift_swift_grpc_library_example
all_examples: android_android_proto_compile_example android_android_grpc_compile_example android_android_proto_library_example android_android_grpc_library_example buf_buf_proto_breaking_test_example buf_buf_proto_lint_test_example c_c_proto_compile_example c_c_proto_library_example cpp_cpp_proto_compile_example cpp_cpp_grpc_compile_example cpp_cpp_proto_library_example cpp_cpp_grpc_library_example csharp_csharp_proto_compile_example csharp_csharp_grpc_compile_example csharp_csharp_proto_library_example csharp_csharp_grpc_library_example d_d_proto_compile_example d_d_proto_library_example doc_doc_docbook_compile_example doc_doc_html_compile_example doc_doc_json_compile_example doc_doc_markdown_compile_example doc_doc_template_compile_example fsharp_fsharp_proto_compile_example fsharp_fsharp_grpc_compile_example fsharp_fsharp_proto_library_example fsharp_fsharp_grpc_library_example go_go_proto_compile_example go_go_grpc_compile_example go_go_validate_compile_example go_go_proto_library_example go_go_grpc_library_example go_go_validate_library_example grpc-gateway_gateway_grpc_compile_example grpc-gateway_gateway_openapiv2_compile_example grpc-gateway_gateway_grpc_library_example java_java_proto_compile_example java_java_grpc_compile_example java_java_proto_library_example java_java_grpc_library_example js_js_proto_compile_example js_js_grpc_node_compile_example js_js_grpc_web_compile_example js_js_proto_library_example js_js_grpc_node_library_example js_js_grpc_web_library_example objc_objc_proto_compile_example objc_objc_grpc_compile_example objc_objc_proto_library_example objc_objc_grpc_library_example php_php_proto_compile_example php_php_grpc_compile_example python_python_proto_compile_example python_python_grpc_compile_example python_python_grpclib_compile_example python_python_proto_library_example python_python_grpc_library_example python_python_grpclib_library_example ruby_ruby_proto_compile_example ruby_ruby_grpc_compile_example ruby_ruby_proto_library_example ruby_ruby_grpc_library_example rust_rust_proto_compile_example rust_rust_grpc_compile_example rust_rust_proto_library_example rust_rust_grpc_library_example scala_scala_proto_compile_example scala_scala_grpc_compile_example scala_scala_proto_library_example scala_scala_grpc_library_example swift_swift_proto_compile_example swift_swift_grpc_compile_example swift_swift_proto_library_example swift_swift_grpc_library_example

View File

@ -0,0 +1,10 @@
load("@rules_proto_grpc//doc:defs.bzl", "doc_template_compile")
doc_template_compile(
name = "greeter_doc_proto",
protos = [
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:thing_proto",
],
template = "template.txt",
)

View File

@ -0,0 +1,20 @@
local_repository(
name = "rules_proto_grpc",
path = "../../../",
)
load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_repos", "rules_proto_grpc_toolchains")
rules_proto_grpc_toolchains()
rules_proto_grpc_repos()
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()
load("@rules_proto_grpc//doc:repositories.bzl", rules_proto_grpc_doc_repos = "doc_repos")
rules_proto_grpc_doc_repos()

View File

@ -0,0 +1 @@
TEST

View File

@ -12,7 +12,7 @@ def fsharp_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
)

View File

@ -12,7 +12,7 @@ def fsharp_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
)

View File

@ -14,11 +14,7 @@ def go_grpc_library(name, **kwargs):
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos" if "protos" in kwargs else "deps"] + [
key
for key in proto_compile_attrs.keys()
if key != "prefix_path"
]
if k in proto_compile_attrs.keys() and k != "prefix_path"
} # Forward args
)

View File

@ -13,11 +13,7 @@ def go_proto_library(name, **kwargs):
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos" if "protos" in kwargs else "deps"] + [
key
for key in proto_compile_attrs.keys()
if key != "prefix_path"
]
if k in proto_compile_attrs.keys() and k != "prefix_path"
} # Forward args
)

View File

@ -14,11 +14,7 @@ def go_validate_library(name, **kwargs):
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos" if "protos" in kwargs else "deps"] + [
key
for key in proto_compile_attrs.keys()
if key != "prefix_path"
]
if k in proto_compile_attrs.keys() and k != "prefix_path"
} # Forward args
)

View File

@ -14,11 +14,7 @@ def gateway_grpc_library(name, **kwargs):
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos" if "protos" in kwargs else "deps"] + [
key
for key in proto_compile_attrs.keys()
if key != "prefix_path"
]
if k in proto_compile_attrs.keys() and k != "prefix_path"
} # Forward args
)

View File

@ -30,6 +30,10 @@ proto_compile_attrs = {
"extra_protoc_args": attr.string_list(
doc = "A list of extra args to pass directly to protoc, not as plugin options",
),
"extra_protoc_files": attr.label_list(
allow_files = True,
doc = "List of labels that provide extra files to be available during protoc execution",
),
}
def proto_compile_impl(ctx):
@ -46,14 +50,38 @@ def proto_compile_impl(ctx):
"""
###
### Setup common state
###
# Load attrs that we pass as args
# This is done to allow writing rules that can call proto_compile with mutable attributes,
# such as in doc_template_compile
options = ctx.attr.options
extra_protoc_args = getattr(ctx.attr, "extra_protoc_args", [])
extra_protoc_files = ctx.files.extra_protoc_files
# Execute with extracted attrs
return proto_compile(ctx, options, extra_protoc_args, extra_protoc_files)
def proto_compile(ctx, options, extra_protoc_args, extra_protoc_files):
"""
Common implementation function for lang_*_compile rules.
Args:
ctx: The Bazel rule execution context object.
options: The mutable options dict.
extra_protoc_args: The mutable extra_protoc_args list.
extra_protoc_files: The mutable extra_protoc_files list.
Returns:
Providers:
- ProtoCompileInfo
- DefaultInfo
"""
# Load attrs
proto_infos = [dep[ProtoInfo] for dep in ctx.attr.protos]
verbose = ctx.attr.verbose
plugins = [plugin[ProtoPluginInfo] for plugin in ctx.attr._plugins]
verbose = ctx.attr.verbose
# Load toolchain and tools
protoc_toolchain_info = ctx.toolchains[str(Label("//protobuf:toolchain_type"))]
@ -75,8 +103,8 @@ def proto_compile_impl(ctx):
# Convert options dict to label keys
plugin_labels = [plugin.label for plugin in plugins]
per_plugin_options = {
Label(plugin_label): options
for plugin_label, options in ctx.attr.options.items()
Label(plugin_label): opts
for plugin_label, opts in options.items()
if plugin_label != "*"
}
@ -85,10 +113,10 @@ def proto_compile_impl(ctx):
all_plugin_options = [] # Options applied to all plugins, from the '*' key
# Only allow '*' by itself
if "*" in ctx.attr.options:
if len(ctx.attr.options) > 1:
if "*" in options:
if len(options) > 1:
fail("The options attr on target {} cannot contain '*' and other labels. Use either '*' or labels".format(ctx.label))
all_plugin_options = ctx.attr.options["*"]
all_plugin_options = options["*"]
# Check all labels match a plugin in use
for plugin_label in per_plugin_options:
@ -258,7 +286,7 @@ def proto_compile_impl(ctx):
proto_infos,
out_arg,
extra_options = all_plugin_options + per_plugin_options.get(plugin.label, []),
extra_protoc_args = getattr(ctx.attr, "extra_protoc_args", []),
extra_protoc_args = extra_protoc_args,
)
args = ctx.actions.args()
args.add_all(args_list)
@ -283,7 +311,7 @@ def proto_compile_impl(ctx):
mnemonic = "ProtoCompile"
command = ("mkdir -p '{}' && ".format(premerge_root)) + protoc.path + " $@" # $@ is replaced with args list
inputs = cmd_inputs
cmd_inputs += extra_protoc_files
tools = [protoc] + ([plugin.tool_executable] if plugin.tool_executable else [])
# Amend command with debug options
@ -298,7 +326,7 @@ def proto_compile_impl(ctx):
if verbose > 3:
command = "env && " + command
for f in inputs:
for f in cmd_inputs:
print("INPUT:", f.path) # buildifier: disable=print
for f in protos:
print("TARGET PROTO:", f.path) # buildifier: disable=print
@ -312,7 +340,7 @@ def proto_compile_impl(ctx):
mnemonic = mnemonic,
command = command,
arguments = [args],
inputs = inputs,
inputs = cmd_inputs,
tools = tools,
outputs = plugin_protoc_outputs,
use_default_shell_env = plugin.use_built_in_shell_environment,
@ -369,17 +397,17 @@ def proto_compile_impl(ctx):
))
# Add debug options
if ctx.attr.verbose > 1:
if verbose > 1:
command_parts = command_parts + [
"echo '\n##### SANDBOX AFTER MERGING DIRECTORIES'",
"find . -type l",
]
if ctx.attr.verbose > 2:
if verbose > 2:
command_parts = [
"echo '\n##### SANDBOX BEFORE MERGING DIRECTORIES'",
"find . -type l",
] + command_parts
if ctx.attr.verbose > 0:
if verbose > 0:
print(
"Directory merge command: {}".format(" && ".join(command_parts)),
) # buildifier: disable=print

View File

@ -12,7 +12,7 @@ def java_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
)

View File

@ -12,7 +12,7 @@ def java_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
)

View File

@ -12,7 +12,7 @@ def js_grpc_node_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
)

View File

@ -12,7 +12,7 @@ def js_grpc_web_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
)

View File

@ -12,7 +12,7 @@ def js_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
)

View File

@ -13,7 +13,7 @@ def objc_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
)

View File

@ -13,7 +13,7 @@ def objc_proto_library(name, **kwargs): # buildifier: disable=function-docstrin
**{
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
)

View File

@ -12,7 +12,7 @@ def python_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
)

View File

@ -12,7 +12,7 @@ def python_grpclib_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
)

View File

@ -12,7 +12,7 @@ def python_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
)

View File

@ -12,7 +12,7 @@ def ruby_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
)

View File

@ -12,7 +12,7 @@ def ruby_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
)

View File

@ -14,7 +14,7 @@ def rust_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
)

View File

@ -14,7 +14,7 @@ def rust_proto_library(name, **kwargs): # buildifier: disable=function-docstrin
**{
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
)

View File

@ -13,7 +13,7 @@ def scala_grpc_library(name, **kwargs): # buildifier: disable=function-docstrin
**{
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
)

View File

@ -13,7 +13,7 @@ def scala_proto_library(name, **kwargs): # buildifier: disable=function-docstri
**{
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
)

View File

@ -12,7 +12,7 @@ def swift_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
)

View File

@ -12,7 +12,7 @@ def swift_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
)

View File

@ -40,6 +40,13 @@ var compileRuleAttrs = []*Attr{
Doc: "A list of extra args to pass directly to protoc, not as plugin options",
Mandatory: false,
},
&Attr{
Name: "extra_protoc_files",
Type: "label_list",
Default: "[]",
Doc: "List of labels that provide extra files to be available during protoc execution",
Mandatory: false,
},
}
@ -81,7 +88,7 @@ var compileRuleTemplate = mustTemplate(`load(
var argsForwardingSnippet = `**{
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`

View File

@ -1,5 +1,73 @@
package main
var docCustomRuleTemplateString = mustTemplate(`load(
"//:defs.bzl",
"ProtoPluginInfo",
"proto_compile_attrs",
"proto_compile_impl",
)
load("//internal:compile.bzl", "proto_compile",)
# Create compile rule
def {{ .Rule.Name }}_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)
{{ .Rule.Name }} = rule(
implementation = {{ .Rule.Name }}_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 = [{{ range .Rule.Plugins }}
Label("{{ . }}"),{{ end }}
],
doc = "List of protoc plugins to apply",
),
),
toolchains = [str(Label("//protobuf:toolchain_type"))],
)`)
var docCustomExampleTemplate = mustTemplate(`load("@rules_proto_grpc//{{ .Lang.Dir }}:defs.bzl", "{{ .Rule.Name }}")
{{ .Rule.Name }}(
name = "greeter_{{ .Lang.Name }}_{{ .Rule.Kind }}",
protos = [
"@rules_proto_grpc//example/proto:greeter_grpc",
"@rules_proto_grpc//example/proto:thing_proto",
],
template = "template.txt",
)`)
var docTemplateRuleAttrs = append(append([]*Attr(nil), compileRuleAttrs...), []*Attr{
&Attr{
Name: "template",
Type: "label",
Default: "None",
Doc: "The documentation template file.",
Mandatory: true,
},
}...)
func makeDoc() *Language {
return &Language{
Dir: "doc",
@ -17,7 +85,6 @@ func makeDoc() *Language {
BuildExample: protoCompileExampleTemplate,
Doc: "Generates DocBook ``.xml`` documentation file",
Attrs: compileRuleAttrs,
Experimental: true,
},
&Rule{
Name: "doc_html_compile",
@ -28,7 +95,6 @@ func makeDoc() *Language {
BuildExample: protoCompileExampleTemplate,
Doc: "Generates ``.html`` documentation file",
Attrs: compileRuleAttrs,
Experimental: true,
},
&Rule{
Name: "doc_json_compile",
@ -39,7 +105,6 @@ func makeDoc() *Language {
BuildExample: protoCompileExampleTemplate,
Doc: "Generates ``.json`` documentation file",
Attrs: compileRuleAttrs,
Experimental: true,
},
&Rule{
Name: "doc_markdown_compile",
@ -50,6 +115,16 @@ func makeDoc() *Language {
BuildExample: protoCompileExampleTemplate,
Doc: "Generates Markdown ``.md`` documentation file",
Attrs: compileRuleAttrs,
},
&Rule{
Name: "doc_template_compile",
Kind: "proto",
Implementation: docCustomRuleTemplateString,
Plugins: []string{"//doc:template_plugin"},
WorkspaceExample: protoWorkspaceTemplate,
BuildExample: docCustomExampleTemplate,
Doc: "Generates documentation file using Go template file",
Attrs: docTemplateRuleAttrs,
Experimental: true,
},
},

View File

@ -35,11 +35,7 @@ def {{ .Rule.Name }}(name, **kwargs):
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos" if "protos" in kwargs else "deps"] + [
key
for key in proto_compile_attrs.keys()
if key != "prefix_path"
]
if k in proto_compile_attrs.keys() and k != "prefix_path"
} # Forward args
)
`

View File

@ -40,11 +40,7 @@ def {{ .Rule.Name }}(name, **kwargs):
**{
k: v
for (k, v) in kwargs.items()
if k in ["protos" if "protos" in kwargs else "deps"] + [
key
for key in proto_compile_attrs.keys()
if key != "prefix_path"
]
if k in proto_compile_attrs.keys() and k != "prefix_path"
} # Forward args
)