lintcheck: add support for path sources

This commit is contained in:
Matthias Krüger 2021-02-10 11:32:10 +01:00
parent cfe154be8c
commit 5e29aa6fdf
4 changed files with 54 additions and 6 deletions

View File

@ -9,6 +9,7 @@ edition = "2018"
bytecount = "0.6"
clap = "2.33"
flate2 = { version = "1.0.19", optional = true }
fs_extra = { version = "1.2.0", optional = true }
itertools = "0.9"
opener = "0.4"
regex = "1"
@ -21,5 +22,5 @@ ureq = { version = "2.0.0-rc3", optional = true }
walkdir = "2"
[features]
lintcheck = ["flate2", "serde_json", "tar", "toml", "ureq", "serde"]
lintcheck = ["flate2", "serde_json", "tar", "toml", "ureq", "serde", "fs_extra"]
deny-warnings = []

View File

@ -1,8 +1,10 @@
## Clippy-dev is a tool to ease clippys development, similar to `rustc`s `x.py`.
# Clippy Dev Tool
The Clippy Dev Tool is a tool to ease Clippy development, similar to `rustc`s `x.py`.
Functionalities (incomplete):
# lintcheck
## `lintcheck`
Runs clippy on a fixed set of crates read from `clippy_dev/lintcheck_crates.toml`
and saves logs of the lint warnings into the repo.
We can then check the diff and spot new or disappearing warnings.

View File

@ -10,6 +10,7 @@ rayon = {name = "rayon", versions = ['1.5.0']}
serde = {name = "serde", versions = ['1.0.118']}
# top 10 crates.io dls
bitflags = {name = "bitflags", versions = ['1.2.1']}
# crash = {name = "clippy_crash", path = "/tmp/clippy_crash"}
libc = {name = "libc", versions = ['0.2.81']}
log = {name = "log", versions = ['0.4.11']}
proc-macro2 = {name = "proc-macro2", versions = ['1.0.24']}

View File

@ -31,13 +31,15 @@ struct TomlCrate {
versions: Option<Vec<String>>,
git_url: Option<String>,
git_hash: Option<String>,
path: Option<String>,
}
// represents an archive we download from crates.io
// represents an archive we download from crates.io, or a git repo, or a local repo
#[derive(Debug, Serialize, Deserialize, Eq, Hash, PartialEq)]
enum CrateSource {
CratesIo { name: String, version: String },
Git { name: String, url: String, commit: String },
Path { name: String, path: PathBuf },
}
// represents the extracted sourcecode of a crate
@ -111,7 +113,7 @@ impl CrateSource {
},
CrateSource::Git { name, url, commit } => {
let repo_path = {
let mut repo_path = PathBuf::from("target/lintcheck/downloads");
let mut repo_path = PathBuf::from("target/lintcheck/crates");
// add a -git suffix in case we have the same crate from crates.io and a git repo
repo_path.push(format!("{}-git", name));
repo_path
@ -139,6 +141,37 @@ impl CrateSource {
path: repo_path,
}
},
CrateSource::Path { name, path } => {
use fs_extra::dir;
// simply copy the entire directory into our target dir
let copy_dest = PathBuf::from("target/lintcheck/crates/");
// the source path of the crate we copied, ${copy_dest}/crate_name
let crate_root = copy_dest.join(name); // .../crates/local_crate
if !crate_root.exists() {
println!("Copying {} to {}", path.display(), copy_dest.display());
dir::copy(path, &copy_dest, &dir::CopyOptions::new()).expect(&format!(
"Failed to copy from {}, to {}",
path.display(),
crate_root.display()
));
} else {
println!(
"Not copying {} to {}, destination already exists",
path.display(),
crate_root.display()
);
}
Crate {
version: String::from("local"),
name: name.clone(),
path: crate_root,
}
},
}
}
}
@ -211,6 +244,13 @@ fn read_crates(toml_path: Option<&str>) -> (String, Vec<CrateSource>) {
// multiple Cratesources)
let mut crate_sources = Vec::new();
tomlcrates.into_iter().for_each(|tk| {
if let Some(ref path) = tk.path {
crate_sources.push(CrateSource::Path {
name: tk.name.clone(),
path: PathBuf::from(path),
});
}
// if we have multiple versions, save each one
if let Some(ref versions) = tk.versions {
versions.iter().for_each(|ver| {
@ -234,7 +274,10 @@ fn read_crates(toml_path: Option<&str>) -> (String, Vec<CrateSource>) {
{
eprintln!("tomlkrate: {:?}", tk);
if tk.git_hash.is_some() != tk.git_url.is_some() {
panic!("Encountered TomlCrate with only one of git_hash and git_url!")
panic!("Error: Encountered TomlCrate with only one of git_hash and git_url!");
}
if tk.path.is_some() && (tk.git_hash.is_some() || tk.versions.is_some()) {
panic!("Error: TomlCrate can only have one of 'git_.*', 'version' or 'path' fields");
}
unreachable!("Failed to translate TomlCrate into CrateSource!");
}
@ -298,6 +341,7 @@ pub fn run(clap_config: &ArgMatches) {
let name = match krate {
CrateSource::CratesIo { name, .. } => name,
CrateSource::Git { name, .. } => name,
CrateSource::Path { name, .. } => name,
};
name == only_one_crate
}) {