clippy: use --cap-lints=warn; apply clippy_flags when capture_output=True (#2451)

Instead of using `-Wclippy::all` to override deny-by-default clippy
lints into warnings, use `--cap-lints=warn`.
This allows users to provide whatever lint flags they like and the
compiler will still succeed.

Co-authored-by: Krasimir Georgiev <krasimir@google.com>
Co-authored-by: scentini <rosica@google.com>
This commit is contained in:
Geoffry Song 2024-04-10 17:15:13 +09:00 committed by GitHub
parent 6489c3881f
commit 8802f4ddbd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -141,12 +141,11 @@ def _clippy_aspect_impl(target, ctx):
args.process_wrapper_flags.add("--stderr-file", clippy_out)
if clippy_flags:
fail("""Combining @rules_rust//:clippy_flags with @rules_rust//:capture_clippy_output=true is currently not supported.
See https://github.com/bazelbuild/rules_rust/pull/1264#discussion_r853241339 for more detail.""")
args.rustc_flags.add_all(clippy_flags)
# If we are capturing the output, we want the build system to be able to keep going
# and consume the output. Some clippy lints are denials, so we treat them as warnings.
args.rustc_flags.add("-Wclippy::all")
# and consume the output. Some clippy lints are denials, so we cap everything at warn.
args.rustc_flags.add("--cap-lints=warn")
else:
# A marker file indicating clippy has executed successfully.
# This file is necessary because "ctx.actions.run" mandates an output.

View File

@ -102,6 +102,7 @@ EOF
check_build_result $BUILD_OK bad_static_library_clippy $CAPTURE_OUTPUT
check_build_result $BUILD_OK bad_test_clippy $CAPTURE_OUTPUT
check_build_result $BUILD_OK bad_proc_macro_clippy $CAPTURE_OUTPUT
check_build_result $BUILD_OK ok_library_clippy $CAPTURE_OUTPUT --@rules_rust//:clippy_flags=-Dclippy::pedantic
# Test that we can make the ok_library_clippy fail when using an extra config file.
# Proves that the config file is used and overrides default settings.