From 0c25a25ffcadb59906b593d29f3dac36e3deb979 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 31 Dec 2020 09:50:21 +1000 Subject: [PATCH] support clippy aspect in unit tests as well Unit tests with a 'crate = ...' argument have no rust_srcs, so clippy was not running for them. --- rust/private/clippy.bzl | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rust/private/clippy.bzl b/rust/private/clippy.bzl index b61f74df15..59fa1fe20f 100644 --- a/rust/private/clippy.bzl +++ b/rust/private/clippy.bzl @@ -46,12 +46,17 @@ def _clippy_aspect_impl(target, ctx): if CrateInfo not in target: return [] rust_srcs = _rust_sources(target, ctx.rule) - if rust_srcs == []: - return [] toolchain = find_toolchain(ctx) crate_info = target[CrateInfo] - root = crate_root_src(ctx.rule.attr, rust_srcs, crate_info.type) + + if crate_info.is_test: + root = crate_info.root + else: + if rust_srcs == []: + # nothing to do + return [] + root = crate_root_src(ctx.rule.attr, rust_srcs, crate_info.type) dep_info, build_info = collect_deps( ctx.label,