use a .toml file to list the crates we want to check

Also sort lint results alphabetically.
This commit is contained in:
Matthias Krüger 2020-12-22 13:07:55 +01:00
parent a9fce6d2d0
commit 588efa7da9
4 changed files with 1319 additions and 1303 deletions

View File

@ -11,8 +11,10 @@ flate2 = "1.0.19"
itertools = "0.9"
opener = "0.4"
regex = "1"
serde = {version = "1.0", features = ["derive"]}
shell-escape = "0.1"
tar = "0.4.30"
toml = "0.5"
ureq = "2.0.0-rc3"
walkdir = "2"

View File

@ -0,0 +1,20 @@
[crates]
# some of these are from cargotest
cargo = '0.49.0'
iron = '0.6.1'
ripgrep = '12.1.1'
xsv = '0.13.0'
#tokei = '12.0.4'
rayon = '1.5.0'
serde = '1.0.118'
# top 10 crates.io dls
bitflags = '1.2.1'
libc = '0.2.81'
log = '0.4.11'
proc-macro2 = '1.0.24'
quote = '1.0.7'
rand = '0.7.3'
rand_core = '0.6.0'
regex = '1.3.2'
syn = '1.0.54'
unicode-xid = '0.2.1'

View File

@ -1,16 +1,24 @@
#![allow(clippy::filter_map)]
use crate::clippy_project_root;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::process::Command;
use std::{fs::write, path::PathBuf};
// represents an archive we download from crates.io
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize, Eq, Hash, PartialEq)]
struct KrateSource {
version: String,
name: String,
}
// use this to store the crates when interacting with the crates.toml file
#[derive(Debug, Serialize, Deserialize)]
struct CrateList {
crates: HashMap<String, String>,
}
// represents the extracted sourcecode of a crate
#[derive(Debug)]
struct Krate {
@ -129,33 +137,25 @@ fn build_clippy() {
.expect("Failed to build clippy!");
}
// get a list of KrateSources we want to check from a "crater_crates.toml" file.
fn read_crates() -> Vec<KrateSource> {
let toml_path = PathBuf::from("clippy_dev/crater_crates.toml");
let toml_content: String =
std::fs::read_to_string(&toml_path).unwrap_or_else(|_| panic!("Failed to read {}", toml_path.display()));
let crate_list: CrateList =
toml::from_str(&toml_content).unwrap_or_else(|e| panic!("Failed to parse {}: \n{}", toml_path.display(), e));
// parse the hashmap of the toml file into a list of crates
crate_list
.crates
.iter()
.map(|(name, version)| KrateSource::new(&name, &version))
.collect()
}
// the main fn
pub fn run() {
let cargo_clippy_path: PathBuf = PathBuf::from("target/debug/cargo-clippy");
// crates we want to check:
let krates: Vec<KrateSource> = vec![
// some of these are form cargotest
KrateSource::new("cargo", "0.49.0"),
KrateSource::new("iron", "0.6.1"),
KrateSource::new("ripgrep", "12.1.1"),
//KrateSource::new("tokei", "12.0.4"),
KrateSource::new("xsv", "0.13.0"),
KrateSource::new("serde", "1.0.118"),
KrateSource::new("rayon", "1.5.0"),
// top 10 crates.io dls
KrateSource::new("rand", "0.7.3"),
KrateSource::new("syn", "1.0.54"),
KrateSource::new("libc", "0.2.81"),
KrateSource::new("quote", "1.0.7"),
KrateSource::new("rand_core", "0.6.0"),
KrateSource::new("unicode-xid", "0.2.1"),
KrateSource::new("proc-macro2", "1.0.24"),
KrateSource::new("bitflags", "1.2.1"),
KrateSource::new("log", "0.4.11"),
KrateSource::new("regex", "1.4.2"),
];
println!("Compiling clippy...");
build_clippy();
println!("Done compiling");
@ -168,15 +168,17 @@ pub fn run() {
);
// download and extract the crates, then run clippy on them and collect clippys warnings
let clippy_lint_results: Vec<Vec<String>> = krates
let clippy_lint_results: Vec<Vec<String>> = read_crates()
.into_iter()
.map(|krate| krate.download_and_extract())
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path))
.collect();
let all_warnings: Vec<String> = clippy_lint_results.into_iter().flatten().collect();
let mut all_warnings: Vec<String> = clippy_lint_results.into_iter().flatten().collect();
all_warnings.sort();
// save the text into mini-crater/logs.txt
let text = all_warnings.join("");
std::fs::write("mini-crater/logs.txt", text).unwrap();
write("mini-crater/logs.txt", text).unwrap();
}

File diff suppressed because it is too large Load Diff