@@ -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
4551protoc_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 ,
0 commit comments