Skip to content

Commit f5fb2f6

Browse files
comiuscopybara-github
authored andcommitted
Remove protoc from proto_lang_toolchain rule
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
1 parent 3acab6f commit f5fb2f6

File tree

6 files changed

+34
-161
lines changed

6 files changed

+34
-161
lines changed

src/main/starlark/builtins_bzl/common/exports.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ load("@_builtins//:common/objc/linking_support.bzl", "linking_support")
2929
load("@_builtins//:common/proto/proto_common.bzl", "proto_common_do_not_use")
3030
load("@_builtins//:common/proto/proto_library.bzl", "proto_library")
3131
load("@_builtins//:common/proto/proto_info.bzl", "ProtoInfo")
32-
load("@_builtins//:common/proto/proto_lang_toolchain_wrapper.bzl", "proto_lang_toolchain")
32+
load("@_builtins//:common/proto/proto_lang_toolchain.bzl", "proto_lang_toolchain")
3333
load("@_builtins//:common/python/py_runtime_macro.bzl", "py_runtime")
3434
load("@_builtins//:common/python/providers.bzl", "PyCcLinkParamsProvider", "PyInfo", "PyRuntimeInfo")
3535
load("@_builtins//:common/java/proto/java_lite_proto_library.bzl", "java_lite_proto_library")

src/main/starlark/builtins_bzl/common/proto/proto_lang_toolchain.bzl

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ def _rule_impl(ctx):
3232
if ctx.attr.plugin != None:
3333
plugin = ctx.attr.plugin[DefaultInfo].files_to_run
3434

35-
proto_compiler = getattr(ctx.attr, "proto_compiler", None)
36-
proto_compiler = getattr(ctx.attr, "_proto_compiler", proto_compiler)
37-
3835
return [
3936
DefaultInfo(
4037
files = depset(),
@@ -47,52 +44,43 @@ def _rule_impl(ctx):
4744
plugin = plugin,
4845
runtime = ctx.attr.runtime,
4946
provided_proto_sources = provided_proto_sources,
50-
proto_compiler = proto_compiler.files_to_run,
47+
proto_compiler = ctx.attr._proto_compiler.files_to_run,
5148
protoc_opts = ctx.fragments.proto.experimental_protoc_opts,
5249
progress_message = ctx.attr.progress_message,
5350
mnemonic = ctx.attr.mnemonic,
5451
allowlist_different_package = ctx.attr.allowlist_different_package,
5552
),
5653
]
5754

58-
def make_proto_lang_toolchain(custom_proto_compiler):
59-
return rule(
60-
_rule_impl,
61-
attrs = dict(
62-
{
63-
"progress_message": attr.string(default = "Generating proto_library %{label}"),
64-
"mnemonic": attr.string(default = "GenProto"),
65-
"command_line": attr.string(mandatory = True),
66-
"output_files": attr.string(values = ["single", "multiple", "legacy"], default = "legacy"),
67-
"plugin_format_flag": attr.string(),
68-
"plugin": attr.label(
69-
executable = True,
70-
cfg = "exec",
71-
),
72-
"runtime": attr.label(),
73-
"blacklisted_protos": attr.label_list(
74-
providers = [ProtoInfo],
75-
),
76-
"allowlist_different_package": attr.label(
77-
default = semantics.allowlist_different_package,
78-
cfg = "exec",
79-
providers = [PackageSpecificationInfo],
80-
),
81-
},
82-
**({
83-
"proto_compiler": attr.label(
84-
cfg = "exec",
85-
executable = True,
86-
),
87-
} if custom_proto_compiler else {
88-
"_proto_compiler": attr.label(
89-
cfg = "exec",
90-
executable = True,
91-
allow_files = True,
92-
default = configuration_field("proto", "proto_compiler"),
93-
),
94-
})
95-
),
96-
provides = [ProtoLangToolchainInfo],
97-
fragments = ["proto"],
98-
)
55+
proto_lang_toolchain = rule(
56+
_rule_impl,
57+
attrs =
58+
{
59+
"progress_message": attr.string(default = "Generating proto_library %{label}"),
60+
"mnemonic": attr.string(default = "GenProto"),
61+
"command_line": attr.string(mandatory = True),
62+
"output_files": attr.string(values = ["single", "multiple", "legacy"], default = "legacy"),
63+
"plugin_format_flag": attr.string(),
64+
"plugin": attr.label(
65+
executable = True,
66+
cfg = "exec",
67+
),
68+
"runtime": attr.label(),
69+
"blacklisted_protos": attr.label_list(
70+
providers = [ProtoInfo],
71+
),
72+
"allowlist_different_package": attr.label(
73+
default = semantics.allowlist_different_package,
74+
cfg = "exec",
75+
providers = [PackageSpecificationInfo],
76+
),
77+
"_proto_compiler": attr.label(
78+
cfg = "exec",
79+
executable = True,
80+
allow_files = True,
81+
default = configuration_field("proto", "proto_compiler"),
82+
),
83+
},
84+
provides = [ProtoLangToolchainInfo],
85+
fragments = ["proto"],
86+
)

src/main/starlark/builtins_bzl/common/proto/proto_lang_toolchain_custom_protoc.bzl

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/starlark/builtins_bzl/common/proto/proto_lang_toolchain_default_protoc.bzl

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/main/starlark/builtins_bzl/common/proto/proto_lang_toolchain_wrapper.bzl

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/test/java/com/google/devtools/build/lib/rules/proto/ProtoLangToolchainTest.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -99,40 +99,6 @@ public void protoToolchain() throws Exception {
9999
validateProtoCompiler(toolchain, ProtoConstants.DEFAULT_PROTOC_LABEL);
100100
}
101101

102-
@Test
103-
public void protoToolchain_setProtoCompiler() throws Exception {
104-
scratch.file(
105-
"third_party/x/BUILD",
106-
"licenses(['unencumbered'])",
107-
"cc_binary(name = 'plugin', srcs = ['plugin.cc'])",
108-
"cc_library(name = 'runtime', srcs = ['runtime.cc'])",
109-
"filegroup(name = 'descriptors', srcs = ['metadata.proto', 'descriptor.proto'])",
110-
"filegroup(name = 'any', srcs = ['any.proto'])",
111-
"proto_library(name = 'denied', srcs = [':descriptors', ':any'])",
112-
"cc_binary(name = 'compiler')");
113-
114-
scratch.file(
115-
"foo/BUILD",
116-
TestConstants.LOAD_PROTO_LANG_TOOLCHAIN,
117-
"licenses(['unencumbered'])",
118-
"proto_lang_toolchain(",
119-
" name = 'toolchain',",
120-
" command_line = 'cmd-line:$(OUT)',",
121-
" plugin_format_flag = '--plugin=%s',",
122-
" plugin = '//third_party/x:plugin',",
123-
" runtime = '//third_party/x:runtime',",
124-
" progress_message = 'Progress Message %{label}',",
125-
" mnemonic = 'MyMnemonic',",
126-
" proto_compiler = '//third_party/x:compiler',",
127-
")");
128-
129-
ProtoLangToolchainProvider toolchain =
130-
ProtoLangToolchainProvider.get(getConfiguredTarget("//foo:toolchain"));
131-
132-
validateProtoLangToolchain(toolchain);
133-
validateProtoCompiler(toolchain, "//third_party/x:compiler");
134-
}
135-
136102
@Test
137103
public void protoToolchainBlacklistProtoLibraries() throws Exception {
138104
scratch.file(

0 commit comments

Comments
 (0)