From da84aa2b600ee4fdd3f69d840b9afa75896ad481 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Thu, 1 Jul 2021 17:35:44 -0700 Subject: [PATCH] Added support for `noclippy` tag --- docs/rust_clippy.vm | 2 ++ rust/private/clippy.bzl | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/rust_clippy.vm b/docs/rust_clippy.vm index e059e8d136..d444a04543 100644 --- a/docs/rust_clippy.vm +++ b/docs/rust_clippy.vm @@ -20,3 +20,5 @@ build --output_groups=+clippy_checks ``` This will enable clippy on all [Rust targets](./defs.md). + +Note that targets tagged with `noclippy` will not perform clippy checks diff --git a/rust/private/clippy.bzl b/rust/private/clippy.bzl index 913accd39e..a10d388be8 100644 --- a/rust/private/clippy.bzl +++ b/rust/private/clippy.bzl @@ -23,11 +23,12 @@ load( ) load("//rust/private:utils.bzl", "determine_output_hash", "find_cc_toolchain", "find_toolchain") -def _get_clippy_ready_crate_info(target): +def _get_clippy_ready_crate_info(target, aspect_ctx): """Check that a target is suitable for clippy and extract the `CrateInfo` provider from it. Args: target (Target): The target the aspect is running on. + aspect_ctx (ctx, optional): The aspect's context object. Returns: CrateInfo, optional: A `CrateInfo` provider if clippy should be run or `None`. @@ -37,6 +38,10 @@ def _get_clippy_ready_crate_info(target): if target.label.workspace_root.startswith("external"): return None + # Targets annotated with `noclippy` will not be formatted + if aspect_ctx and "noclippy" in aspect_ctx.rule.attr.tags: + return None + # Obviously ignore any targets that don't contain `CrateInfo` if rust_common.crate_info not in target: return None @@ -44,7 +49,7 @@ def _get_clippy_ready_crate_info(target): return target[rust_common.crate_info] def _clippy_aspect_impl(target, ctx): - crate_info = _get_clippy_ready_crate_info(target) + crate_info = _get_clippy_ready_crate_info(target, ctx) if not crate_info: return []