cargo dev crater: support multiple versions per crate

This commit is contained in:
Matthias Krüger 2020-12-23 01:21:31 +01:00
parent 588efa7da9
commit f986d78c5e
2 changed files with 43 additions and 23 deletions

View file

@ -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']

View file

@ -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