From b6ef1e282ef4c444ce7e5694547aaff4d55c5059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Sun, 27 Dec 2020 16:13:42 +0100 Subject: [PATCH] clippy dev crater: add option to only check a single one of the listed crates with --only crate --- clippy_dev/src/crater.rs | 26 +++++++++++++++++++------- clippy_dev/src/main.rs | 16 +++++++++++++--- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/clippy_dev/src/crater.rs b/clippy_dev/src/crater.rs index b0e7cb70c89..ee4ed451ed5 100644 --- a/clippy_dev/src/crater.rs +++ b/clippy_dev/src/crater.rs @@ -12,6 +12,7 @@ use std::process::Command; use std::{fmt, fs::write, path::PathBuf}; +use clap::ArgMatches; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -200,7 +201,7 @@ fn parse_json_message(json_message: &str, krate: &Crate) -> ClippyWarning { } // the main fn -pub fn run() { +pub fn run(clap_config: &ArgMatches) { let cargo_clippy_path: PathBuf = PathBuf::from("target/debug/cargo-clippy"); println!("Compiling clippy..."); @@ -217,12 +218,23 @@ pub fn run() { // download and extract the crates, then run clippy on them and collect clippys warnings // flatten into one big list of warnings - let clippy_warnings: Vec = read_crates() - .into_iter() - .map(|krate| krate.download_and_extract()) - .map(|krate| krate.run_clippy_lints(&cargo_clippy_path)) - .flatten() - .collect(); + let clippy_warnings: Vec = if let Some(only_one_crate) = clap_config.value_of("only") { + // only check a single + read_crates() + .into_iter() + .map(|krate| krate.download_and_extract()) + .filter(|krate| krate.name == only_one_crate) + .map(|krate| krate.run_clippy_lints(&cargo_clippy_path)) + .flatten() + .collect() + } else { + read_crates() + .into_iter() + .map(|krate| krate.download_and_extract()) + .map(|krate| krate.run_clippy_lints(&cargo_clippy_path)) + .flatten() + .collect() + }; // generate some stats: diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 6fb8b6f2899..c4688ba3000 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -10,8 +10,8 @@ fn main() { ("bless", Some(matches)) => { bless::bless(matches.is_present("ignore-timestamp")); }, - ("crater", Some(_)) => { - crater::run(); + ("crater", Some(matches)) => { + crater::run(&matches); }, ("fmt", Some(matches)) => { fmt::run(matches.is_present("check"), matches.is_present("verbose")); @@ -59,7 +59,17 @@ fn get_clap_config<'a>() -> ArgMatches<'a> { .help("Include files updated before clippy was built"), ), ) - .subcommand(SubCommand::with_name("crater").about("run clippy on a set of crates and check output")) + .subcommand( + SubCommand::with_name("crater") + .about("run clippy on a set of crates and check output") + .arg( + Arg::with_name("only") + .takes_value(true) + .value_name("CRATE") + .long("only") + .help("only process a single crate of the list"), + ), + ) .subcommand( SubCommand::with_name("fmt") .about("Run rustfmt on all projects and tests")