cargo dev crater: lay out the base plan

This commit is contained in:
Matthias Krüger 2020-12-18 13:21:13 +01:00
parent 70386ff352
commit bec916d02d
2 changed files with 70 additions and 0 deletions

69
clippy_dev/src/crater.rs Normal file
View file

@ -0,0 +1,69 @@
use std::path::PathBuf;
use std::process::Command;
// represents an archive we download from crates.io
struct KrateSource {
version: String,
name: String,
}
// represents the extracted sourcecode of a crate
struct Krate {
version: String,
name: String,
}
impl KrateSource {
fn new(version: &str, name: &str) -> Self {
KrateSource {
version: version.into(),
name: name.into(),
}
}
fn download_and_extract(self) -> Krate {
// download
// extract
Krate {
version: self.version,
name: self.name,
}
}
}
impl Krate {
fn run_clippy_lints(&self) -> String {
todo!();
}
}
fn build_clippy() {
Command::new("cargo")
.arg("build")
.output()
.expect("Failed to build clippy!");
}
// the main fn
pub(crate) fn run() {
let cargo_clippy_path: PathBuf = PathBuf::from("target/debug/cargo-clippy");
let clippy_driver_path: PathBuf = PathBuf::from("target/debug/cargo-driver");
// crates we want to check:
let krates: Vec<KrateSource> = vec![KrateSource::new("cargo", "0.49.0"), KrateSource::new("regex", "1.4.2")];
build_clippy();
// assert that clippy is found
assert!(
cargo_clippy_path.is_file(),
"target/debug/cargo-clippy binary not found!"
);
assert!(
clippy_driver_path.is_file(),
"target/debug/clippy-driver binary not found!"
);
let clippy_lint_results: Vec<String> = krates.into_iter().map(|krate| krate.download_and_extract()).map(|krate| krate.run_clippy_lints()).collect::<Vec<String>>();
}

View file

@ -11,6 +11,7 @@ use std::path::{Path, PathBuf};
use walkdir::WalkDir;
pub mod bless;
pub mod crater;
pub mod fmt;
pub mod new_lint;
pub mod ra_setup;