diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2020-12-23 01:21:31 +0100 |
|---|---|---|
| committer | Matthias Krüger <matthias.krueger@famsik.de> | 2021-01-23 02:18:11 +0100 |
| commit | f986d78c5e6d401ea3c57c7d00d24d1890675f0c (patch) | |
| tree | af31baa3df2967f8a256e23d23004a9a0c4a4875 | |
| parent | 588efa7da9af41e79f51935efeb9919ccef97f44 (diff) | |
| download | rust-f986d78c5e6d401ea3c57c7d00d24d1890675f0c.tar.gz rust-f986d78c5e6d401ea3c57c7d00d24d1890675f0c.zip | |
cargo dev crater: support multiple versions per crate
| -rw-r--r-- | clippy_dev/crater_crates.toml | 34 | ||||
| -rw-r--r-- | clippy_dev/src/crater.rs | 32 |
2 files changed, 43 insertions, 23 deletions
diff --git a/clippy_dev/crater_crates.toml b/clippy_dev/crater_crates.toml index e69056c9925..1fbf7930d3e 100644 --- a/clippy_dev/crater_crates.toml +++ b/clippy_dev/crater_crates.toml @@ -1,20 +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' +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' +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'] diff --git a/clippy_dev/src/crater.rs b/clippy_dev/src/crater.rs index f64ab897906..a681bf10496 100644 --- a/clippy_dev/src/crater.rs +++ b/clippy_dev/src/crater.rs @@ -6,17 +6,24 @@ use std::collections::HashMap; use std::process::Command; use std::{fs::write, path::PathBuf}; +// crate data we stored in the toml, can have multiple versions. +// if so, one TomlKrate maps to several KrateSources +struct TomlKrate { + name: String, + versions: Vec<String>, +} + // represents an archive we download from crates.io #[derive(Debug, Serialize, Deserialize, Eq, Hash, PartialEq)] struct KrateSource { - version: String, name: String, + version: String, } // use this to store the crates when interacting with the crates.toml file #[derive(Debug, Serialize, Deserialize)] struct CrateList { - crates: HashMap<String, String>, + crates: HashMap<String, Vec<String>>, } // represents the extracted sourcecode of a crate @@ -145,11 +152,24 @@ fn read_crates() -> Vec<KrateSource> { 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 + let tomlkrates: Vec<TomlKrate> = crate_list .crates - .iter() - .map(|(name, version)| KrateSource::new(&name, &version)) - .collect() + .into_iter() + .map(|(name, versions)| TomlKrate { name, versions }) + .collect(); + + // flatten TomlKrates into KrateSources (one TomlKrates may represent several versions of a crate => + // multiple kratesources) + let mut krate_sources = Vec::new(); + tomlkrates.into_iter().for_each(|tk| { + tk.versions.iter().for_each(|ver| { + krate_sources.push(KrateSource { + name: tk.name.clone(), + version: ver.to_string(), + }); + }) + }); + krate_sources } // the main fn |
