Skip to content

Commit f986d78

Browse files
committed
cargo dev crater: support multiple versions per crate
1 parent 588efa7 commit f986d78

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

clippy_dev/crater_crates.toml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
[crates]
22
# 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'
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']
1010
# 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'
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: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,24 @@ use std::collections::HashMap;
66
use std::process::Command;
77
use std::{fs::write, path::PathBuf};
88

9+
// crate data we stored in the toml, can have multiple versions.
10+
// if so, one TomlKrate maps to several KrateSources
11+
struct TomlKrate {
12+
name: String,
13+
versions: Vec<String>,
14+
}
15+
916
// represents an archive we download from crates.io
1017
#[derive(Debug, Serialize, Deserialize, Eq, Hash, PartialEq)]
1118
struct KrateSource {
12-
version: String,
1319
name: String,
20+
version: String,
1421
}
1522

1623
// use this to store the crates when interacting with the crates.toml file
1724
#[derive(Debug, Serialize, Deserialize)]
1825
struct CrateList {
19-
crates: HashMap<String, String>,
26+
crates: HashMap<String, Vec<String>>,
2027
}
2128

2229
// represents the extracted sourcecode of a crate
@@ -145,11 +152,24 @@ fn read_crates() -> Vec<KrateSource> {
145152
let crate_list: CrateList =
146153
toml::from_str(&toml_content).unwrap_or_else(|e| panic!("Failed to parse {}: \n{}", toml_path.display(), e));
147154
// parse the hashmap of the toml file into a list of crates
148-
crate_list
155+
let tomlkrates: Vec<TomlKrate> = crate_list
149156
.crates
150-
.iter()
151-
.map(|(name, version)| KrateSource::new(&name, &version))
152-
.collect()
157+
.into_iter()
158+
.map(|(name, versions)| TomlKrate { name, versions })
159+
.collect();
160+
161+
// flatten TomlKrates into KrateSources (one TomlKrates may represent several versions of a crate =>
162+
// multiple kratesources)
163+
let mut krate_sources = Vec::new();
164+
tomlkrates.into_iter().for_each(|tk| {
165+
tk.versions.iter().for_each(|ver| {
166+
krate_sources.push(KrateSource {
167+
name: tk.name.clone(),
168+
version: ver.to_string(),
169+
});
170+
})
171+
});
172+
krate_sources
153173
}
154174

155175
// the main fn

0 commit comments

Comments
 (0)