diff --git a/buf/internal/breaking.bzl b/buf/internal/breaking.bzl index 4eda6fe..ab4b1d9 100644 --- a/buf/internal/breaking.bzl +++ b/buf/internal/breaking.bzl @@ -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. """ @@ -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( @@ -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, diff --git a/buf/internal/lint.bzl b/buf/internal/lint.bzl index b9fb5f3..ff4a33c 100644 --- a/buf/internal/lint.bzl +++ b/buf/internal/lint.bzl @@ -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, @@ -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, diff --git a/buf/internal/plugin.bzl b/buf/internal/plugin.bzl index 45ee608..2c4a63b 100644 --- a/buf/internal/plugin.bzl +++ b/buf/internal/plugin.bzl @@ -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: @@ -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 """ @@ -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))