Skip to content

Commit ab033ab

Browse files
committed
add another opt-out flag
1 parent db97303 commit ab033ab

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

bazel/private/toolchains/prebuilt/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ load("//toolchain:platforms.bzl", "PROTOBUF_PLATFORMS")
2020
for platform, meta in PROTOBUF_PLATFORMS.items()
2121
]
2222

23+
2324
# Support verification of user-registered toolchains
2425
protoc_authenticity(
2526
name = "authenticity_validation",
27+
fail_on_mismatch = select({
28+
"//bazel/toolchains:allow_nonstandard_protoc.flag_set": False,
29+
"//conditions:default": True,
30+
}),
2631
visibility = ["//visibility:public"],
2732
)

bazel/private/toolchains/prebuilt/protoc_authenticity.bzl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,37 @@ def _protoc_authenticity_impl(ctx):
2626
exit 0
2727
}}
2828
grep -q "^libprotoc {RELEASE_VERSION}" {validation_output} || {{
29-
echo 'ERROR: protoc version does not match protobuf Bazel module; we do not support this.
30-
It is considered undefined behavior that is expected to break in the future even if it appears to work today.
31-
To suppress this error, run Bazel with --norun_validations'
29+
echo '{severity}: protoc version does not match protobuf Bazel module; we do not support this.
30+
It is considered undefined behavior that is expected to break in the future even if it appears to work today.'
31+
echo '{suppression_note}'
3232
echo 'Expected: libprotoc {RELEASE_VERSION}'
3333
echo -n 'Actual: '
3434
cat {validation_output}
35-
exit 1
35+
exit {mismatch_exit_code}
3636
}} >&2
3737
""".format(
3838
protoc = proto_lang_toolchain_info.proto_compiler.executable.path,
3939
validation_output = validation_output.path,
4040
RELEASE_VERSION = RELEASE_VERSION.removeprefix("v"),
41+
suppression_note = (
42+
"To suppress this error, run Bazel with --@com_google_protobuf//bazel/toolchains:allow_nonstandard_protoc"
43+
if ctx.attr.fail_on_mismatch else ""
44+
),
45+
mismatch_exit_code = 1 if ctx.attr.fail_on_mismatch else 0,
46+
severity = "ERROR" if ctx.attr.fail_on_mismatch else "INFO",
4147
),
4248
)
4349
return [OutputGroupInfo(_validation = depset([validation_output]))]
4450

4551
protoc_authenticity = rule(
4652
implementation = _protoc_authenticity_impl,
4753
fragments = ["proto"],
48-
attrs = toolchains.if_legacy_toolchain({
54+
attrs = {
55+
"fail_on_mismatch": attr.bool(
56+
default = True,
57+
doc = "If true, the build will fail when the protoc binary does not match the expected version.",
58+
),
59+
} | toolchains.if_legacy_toolchain({
4960
"_proto_compiler": attr.label(
5061
cfg = "exec",
5162
executable = True,

bazel/toolchains/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,14 @@ config_setting(
5454
name = "prefer_prebuilt_protoc.flag_set",
5555
flag_values = {":prefer_prebuilt_protoc": "true"},
5656
)
57+
58+
# The public API users set to disable the validation action failing.
59+
bool_flag(
60+
name = "allow_nonstandard_protoc",
61+
build_setting_default = False,
62+
)
63+
64+
config_setting(
65+
name = "allow_nonstandard_protoc.flag_set",
66+
flag_values = {":allow_nonstandard_protoc": "true"},
67+
)

tmp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
libprotoc 34.0-dev

0 commit comments

Comments
 (0)