]> git.lizzy.rs Git - rust.git/blobdiff - clippy_dev/src/crater.rs
clippy dev crater: address more review commetns
[rust.git] / clippy_dev / src / crater.rs
index ee4ed451ed5d0d047e08ed96d2f6a5d7673b6845..98a4af3591ea21b224a7737bed7659ce2e62fd03 100644 (file)
@@ -4,6 +4,7 @@
 // When a new lint is introduced, we can search the results for new warnings and check for false
 // positives.
 
+#![cfg(feature = "crater")]
 #![allow(clippy::filter_map)]
 
 use crate::clippy_project_root;
@@ -215,12 +216,29 @@ pub fn run(clap_config: &ArgMatches) {
         cargo_clippy_path.display()
     );
 
+    let clippy_ver = std::process::Command::new("target/debug/cargo-clippy")
+        .arg("--version")
+        .output()
+        .map(|o| String::from_utf8_lossy(&o.stdout).into_owned())
+        .expect("could not get clippy version!");
+
     // download and extract the crates, then run clippy on them and collect clippys warnings
     // flatten into one big list of warnings
 
+    let crates = read_crates();
+
     let clippy_warnings: Vec<ClippyWarning> = if let Some(only_one_crate) = clap_config.value_of("only") {
-        // only check a single
-        read_crates()
+        // if we don't have the specified crated in the .toml, throw an error
+        if !crates.iter().any(|krate| krate.name == only_one_crate) {
+            eprintln!(
+                "ERROR: could not find crate '{}' in clippy_dev/crater_crates.toml",
+                only_one_crate
+            );
+            std::process::exit(1);
+        }
+
+        // only check a single crate that was passed via cmdline
+        crates
             .into_iter()
             .map(|krate| krate.download_and_extract())
             .filter(|krate| krate.name == only_one_crate)
@@ -228,7 +246,8 @@ pub fn run(clap_config: &ArgMatches) {
             .flatten()
             .collect()
     } else {
-        read_crates()
+        // check all crates (default)
+        crates
             .into_iter()
             .map(|krate| krate.download_and_extract())
             .map(|krate| krate.run_clippy_lints(&cargo_clippy_path))
@@ -261,6 +280,7 @@ pub fn run(clap_config: &ArgMatches) {
     all_msgs.push(stats_formatted);
 
     // save the text into mini-crater/logs.txt
-    let text = all_msgs.join("");
+    let mut text = clippy_ver; // clippy version number on top
+    text.push_str(&format!("\n{}", all_msgs.join("")));
     write("mini-crater/logs.txt", text).unwrap();
 }