Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion buf/internal/breaking.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ load("@rules_proto//proto:defs.bzl", "ProtoInfo")
load(":plugin.bzl", "protoc_plugin_test")

_DOC = """
`buf_breaking_test` is a test rule that checks one or more `proto_library` targets for breaking changes.
`buf_breaking_test` is a test rule that checks one or more `proto_library` targets for breaking changes.

For more info please refer to the [`buf_breaking_test` section](https://docs.buf.build/build-systems/bazel#buf-lint-test) of the docs.
"""
Expand All @@ -44,6 +44,7 @@ def _buf_breaking_test_impl(ctx):
ctx.toolchains[_TOOLCHAIN].cli,
config,
files_to_include,
ctx.attr.protoc_args,
)

buf_breaking_test = rule(
Expand Down Expand Up @@ -80,6 +81,10 @@ buf_breaking_test = rule(
default = "",
doc = "error-format flag for buf breaking: https://buf.build/docs/reference/cli/buf/breaking#error-format",
),
"protoc_args": attr.string_list(
default = [],
doc = "Additional arguments to pass to protoc",
),
},
toolchains = [_TOOLCHAIN],
test = True,
Expand Down
14 changes: 13 additions & 1 deletion buf/internal/lint.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ def _buf_lint_test_impl(ctx):
files_to_include = []
if ctx.file.config != None:
files_to_include.append(ctx.file.config)
return protoc_plugin_test(ctx, proto_infos, ctx.executable._protoc, ctx.toolchains[_TOOLCHAIN].cli, config, files_to_include)
return protoc_plugin_test(
ctx,
proto_infos,
ctx.executable._protoc,
ctx.toolchains[_TOOLCHAIN].cli,
config,
files_to_include,
ctx.attr.protoc_args,
)

buf_lint_test = rule(
implementation = _buf_lint_test_impl,
Expand All @@ -58,6 +66,10 @@ buf_lint_test = rule(
default = "",
doc = "error-format flag for buf lint: https://buf.build/docs/reference/cli/buf/lint#error-format",
),
"protoc_args": attr.string_list(
default = [],
doc = "Additional arguments to pass to protoc",
),
},
toolchains = [_TOOLCHAIN],
test = True,
Expand Down
4 changes: 3 additions & 1 deletion buf/internal/plugin.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""protoc plugin based test rule"""

def protoc_plugin_test(ctx, proto_infos, protoc, plugin, config, files_to_include = []):
def protoc_plugin_test(ctx, proto_infos, protoc, plugin, config, files_to_include = [], protoc_args = []):
"""protoc_plugin_test creates a script file for a generic protoc plugin

Args:
Expand All @@ -24,6 +24,7 @@ def protoc_plugin_test(ctx, proto_infos, protoc, plugin, config, files_to_includ
plugin: plugin executable
config: plugin option to be passed to protoc
files_to_include: any additional files to be included as part of runfiles
protoc_args: extra arguments to be passed to protoc
Returns:
Runfiles required to run the test
"""
Expand Down Expand Up @@ -51,6 +52,7 @@ def protoc_plugin_test(ctx, proto_infos, protoc, plugin, config, files_to_includ
args.add_joined(["--buf-plugin_opt", config], join_with = "=")
args.add_joined("--descriptor_set_in", deps, join_with = ":", map_each = _short_path)
args.add_joined(["--buf-plugin_out", "."], join_with = "=")
args.add_all(protoc_args)
args.add_all(sources)

args_file = ctx.actions.declare_file("{}-args".format(ctx.label.name))
Expand Down