Skip to content

Commit 588efa7

Browse files
committed
use a .toml file to list the crates we want to check
Also sort lint results alphabetically.
1 parent a9fce6d commit 588efa7

File tree

4 files changed

+1348
-1332
lines changed

4 files changed

+1348
-1332
lines changed

clippy_dev/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ flate2 = "1.0.19"
1111
itertools = "0.9"
1212
opener = "0.4"
1313
regex = "1"
14+
serde = {version = "1.0", features = ["derive"]}
1415
shell-escape = "0.1"
1516
tar = "0.4.30"
17+
toml = "0.5"
1618
ureq = "2.0.0-rc3"
1719
walkdir = "2"
1820

clippy_dev/crater_crates.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[crates]
2+
# some of these are from cargotest
3+
cargo = '0.49.0'
4+
iron = '0.6.1'
5+
ripgrep = '12.1.1'
6+
xsv = '0.13.0'
7+
#tokei = '12.0.4'
8+
rayon = '1.5.0'
9+
serde = '1.0.118'
10+
# top 10 crates.io dls
11+
bitflags = '1.2.1'
12+
libc = '0.2.81'
13+
log = '0.4.11'
14+
proc-macro2 = '1.0.24'
15+
quote = '1.0.7'
16+
rand = '0.7.3'
17+
rand_core = '0.6.0'
18+
regex = '1.3.2'
19+
syn = '1.0.54'
20+
unicode-xid = '0.2.1'

clippy_dev/src/crater.rs

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
#![allow(clippy::filter_map)]
22

33
use crate::clippy_project_root;
4-
use std::path::PathBuf;
4+
use serde::{Deserialize, Serialize};
5+
use std::collections::HashMap;
56
use std::process::Command;
7+
use std::{fs::write, path::PathBuf};
68

79
// represents an archive we download from crates.io
8-
#[derive(Debug)]
10+
#[derive(Debug, Serialize, Deserialize, Eq, Hash, PartialEq)]
911
struct KrateSource {
1012
version: String,
1113
name: String,
1214
}
1315

16+
// use this to store the crates when interacting with the crates.toml file
17+
#[derive(Debug, Serialize, Deserialize)]
18+
struct CrateList {
19+
crates: HashMap<String, String>,
20+
}
21+
1422
// represents the extracted sourcecode of a crate
1523
#[derive(Debug)]
1624
struct Krate {
@@ -129,33 +137,25 @@ fn build_clippy() {
129137
.expect("Failed to build clippy!");
130138
}
131139

140+
// get a list of KrateSources we want to check from a "crater_crates.toml" file.
141+
fn read_crates() -> Vec<KrateSource> {
142+
let toml_path = PathBuf::from("clippy_dev/crater_crates.toml");
143+
let toml_content: String =
144+
std::fs::read_to_string(&toml_path).unwrap_or_else(|_| panic!("Failed to read {}", toml_path.display()));
145+
let crate_list: CrateList =
146+
toml::from_str(&toml_content).unwrap_or_else(|e| panic!("Failed to parse {}: \n{}", toml_path.display(), e));
147+
// parse the hashmap of the toml file into a list of crates
148+
crate_list
149+
.crates
150+
.iter()
151+
.map(|(name, version)| KrateSource::new(&name, &version))
152+
.collect()
153+
}
154+
132155
// the main fn
133156
pub fn run() {
134157
let cargo_clippy_path: PathBuf = PathBuf::from("target/debug/cargo-clippy");
135158

136-
// crates we want to check:
137-
let krates: Vec<KrateSource> = vec![
138-
// some of these are form cargotest
139-
KrateSource::new("cargo", "0.49.0"),
140-
KrateSource::new("iron", "0.6.1"),
141-
KrateSource::new("ripgrep", "12.1.1"),
142-
//KrateSource::new("tokei", "12.0.4"),
143-
KrateSource::new("xsv", "0.13.0"),
144-
KrateSource::new("serde", "1.0.118"),
145-
KrateSource::new("rayon", "1.5.0"),
146-
// top 10 crates.io dls
147-
KrateSource::new("rand", "0.7.3"),
148-
KrateSource::new("syn", "1.0.54"),
149-
KrateSource::new("libc", "0.2.81"),
150-
KrateSource::new("quote", "1.0.7"),
151-
KrateSource::new("rand_core", "0.6.0"),
152-
KrateSource::new("unicode-xid", "0.2.1"),
153-
KrateSource::new("proc-macro2", "1.0.24"),
154-
KrateSource::new("bitflags", "1.2.1"),
155-
KrateSource::new("log", "0.4.11"),
156-
KrateSource::new("regex", "1.4.2"),
157-
];
158-
159159
println!("Compiling clippy...");
160160
build_clippy();
161161
println!("Done compiling");
@@ -168,15 +168,17 @@ pub fn run() {
168168
);
169169

170170
// download and extract the crates, then run clippy on them and collect clippys warnings
171-
let clippy_lint_results: Vec<Vec<String>> = krates
171+
172+
let clippy_lint_results: Vec<Vec<String>> = read_crates()
172173
.into_iter()
173174
.map(|krate| krate.download_and_extract())
174175
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path))
175176
.collect();
176177

177-
let all_warnings: Vec<String> = clippy_lint_results.into_iter().flatten().collect();
178+
let mut all_warnings: Vec<String> = clippy_lint_results.into_iter().flatten().collect();
179+
all_warnings.sort();
178180

179181
// save the text into mini-crater/logs.txt
180182
let text = all_warnings.join("");
181-
std::fs::write("mini-crater/logs.txt", text).unwrap();
183+
write("mini-crater/logs.txt", text).unwrap();
182184
}

0 commit comments

Comments
 (0)