Skip to content

Commit

Permalink
Remove protoc from proto_lang_toolchain rule
Browse files Browse the repository at this point in the history
The protoc should be provided with a new proto_toolchain rule.

Issue: bazelbuild/rules_proto#179

RELNOTES[INC]: proto_compiler attribute removed from proto_lang_toolchain
(it was recently introduced, and there is no evidence of use)

PiperOrigin-RevId: 566937038
Change-Id: I7133be4d5cbcc816764c0ba35607329ea50d2406
  • Loading branch information
comius committed Jan 17, 2024
1 parent 2053317 commit e95f116
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 156 deletions.
2 changes: 1 addition & 1 deletion src/main/starlark/builtins_bzl/common/exports.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ load("@_builtins//:common/objc/compilation_support.bzl", "compilation_support")
load("@_builtins//:common/objc/linking_support.bzl", "linking_support")
load("@_builtins//:common/proto/proto_common.bzl", "proto_common_do_not_use")
load("@_builtins//:common/proto/proto_library.bzl", "proto_library")
load("@_builtins//:common/proto/proto_lang_toolchain_wrapper.bzl", "proto_lang_toolchain")
load("@_builtins//:common/proto/proto_lang_toolchain.bzl", "proto_lang_toolchain")
load("@_builtins//:common/python/py_runtime_macro.bzl", "py_runtime")
load("@_builtins//:common/python/providers.bzl", "PyInfo", "PyRuntimeInfo")
load("@_builtins//:common/java/proto/java_lite_proto_library.bzl", "java_lite_proto_library")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ def _rule_impl(ctx):
if ctx.attr.plugin != None:
plugin = ctx.attr.plugin[DefaultInfo].files_to_run

proto_compiler = getattr(ctx.attr, "proto_compiler", None)
proto_compiler = getattr(ctx.attr, "_proto_compiler", proto_compiler)

return [
DefaultInfo(
files = depset(),
Expand All @@ -46,46 +43,37 @@ def _rule_impl(ctx):
plugin = plugin,
runtime = ctx.attr.runtime,
provided_proto_sources = provided_proto_sources,
proto_compiler = proto_compiler.files_to_run,
proto_compiler = ctx.attr._proto_compiler.files_to_run,
protoc_opts = ctx.fragments.proto.experimental_protoc_opts,
progress_message = ctx.attr.progress_message,
mnemonic = ctx.attr.mnemonic,
),
]

def make_proto_lang_toolchain(custom_proto_compiler):
return rule(
_rule_impl,
attrs = dict(
{
"progress_message": attr.string(default = "Generating proto_library %{label}"),
"mnemonic": attr.string(default = "GenProto"),
"command_line": attr.string(mandatory = True),
"output_files": attr.string(values = ["single", "multiple", "legacy"], default = "legacy"),
"plugin_format_flag": attr.string(),
"plugin": attr.label(
executable = True,
cfg = "exec",
),
"runtime": attr.label(),
"blacklisted_protos": attr.label_list(
providers = [ProtoInfo],
),
},
**({
"proto_compiler": attr.label(
cfg = "exec",
executable = True,
),
} if custom_proto_compiler else {
"_proto_compiler": attr.label(
cfg = "exec",
executable = True,
allow_files = True,
default = configuration_field("proto", "proto_compiler"),
),
})
),
provides = [ProtoLangToolchainInfo],
fragments = ["proto"] + semantics.EXTRA_FRAGMENTS,
)
proto_lang_toolchain = rule(
_rule_impl,
attrs =
{
"progress_message": attr.string(default = "Generating proto_library %{label}"),
"mnemonic": attr.string(default = "GenProto"),
"command_line": attr.string(mandatory = True),
"output_files": attr.string(values = ["single", "multiple", "legacy"], default = "legacy"),
"plugin_format_flag": attr.string(),
"plugin": attr.label(
executable = True,
cfg = "exec",
),
"runtime": attr.label(),
"blacklisted_protos": attr.label_list(
providers = [ProtoInfo],
),
"_proto_compiler": attr.label(
cfg = "exec",
executable = True,
allow_files = True,
default = configuration_field("proto", "proto_compiler"),
),
},
provides = [ProtoLangToolchainInfo],
fragments = ["proto"],
)

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,6 @@ public void protoToolchain() throws Exception {
validateProtoCompiler(toolchain, ProtoConstants.DEFAULT_PROTOC_LABEL);
}

@Test
public void protoToolchain_setProtoCompiler() throws Exception {
scratch.file(
"third_party/x/BUILD",
"licenses(['unencumbered'])",
"cc_binary(name = 'plugin', srcs = ['plugin.cc'])",
"cc_library(name = 'runtime', srcs = ['runtime.cc'])",
"filegroup(name = 'descriptors', srcs = ['metadata.proto', 'descriptor.proto'])",
"filegroup(name = 'any', srcs = ['any.proto'])",
"proto_library(name = 'denied', srcs = [':descriptors', ':any'])",
"cc_binary(name = 'compiler')");

scratch.file(
"foo/BUILD",
TestConstants.LOAD_PROTO_LANG_TOOLCHAIN,
"licenses(['unencumbered'])",
"proto_lang_toolchain(",
" name = 'toolchain',",
" command_line = 'cmd-line:$(OUT)',",
" plugin_format_flag = '--plugin=%s',",
" plugin = '//third_party/x:plugin',",
" runtime = '//third_party/x:runtime',",
" progress_message = 'Progress Message %{label}',",
" mnemonic = 'MyMnemonic',",
" proto_compiler = '//third_party/x:compiler',",
")");

ProtoLangToolchainProvider toolchain =
ProtoLangToolchainProvider.get(getConfiguredTarget("//foo:toolchain"));

validateProtoLangToolchain(toolchain);
validateProtoCompiler(toolchain, "//third_party/x:compiler");
}

@Test
public void protoToolchainBlacklistProtoLibraries() throws Exception {
scratch.file(
Expand Down

0 comments on commit e95f116

Please sign in to comment.