Skip to content

Commit bec916d

Browse files
committed
cargo dev crater: lay out the base plan
1 parent 70386ff commit bec916d

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

clippy_dev/src/crater.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
use std::path::PathBuf;
2+
use std::process::Command;
3+
4+
// represents an archive we download from crates.io
5+
struct KrateSource {
6+
version: String,
7+
name: String,
8+
}
9+
10+
// represents the extracted sourcecode of a crate
11+
struct Krate {
12+
version: String,
13+
name: String,
14+
}
15+
16+
impl KrateSource {
17+
fn new(version: &str, name: &str) -> Self {
18+
KrateSource {
19+
version: version.into(),
20+
name: name.into(),
21+
}
22+
}
23+
fn download_and_extract(self) -> Krate {
24+
// download
25+
// extract
26+
27+
Krate {
28+
version: self.version,
29+
name: self.name,
30+
}
31+
}
32+
}
33+
34+
impl Krate {
35+
fn run_clippy_lints(&self) -> String {
36+
todo!();
37+
}
38+
39+
40+
}
41+
42+
fn build_clippy() {
43+
Command::new("cargo")
44+
.arg("build")
45+
.output()
46+
.expect("Failed to build clippy!");
47+
}
48+
49+
// the main fn
50+
pub(crate) fn run() {
51+
let cargo_clippy_path: PathBuf = PathBuf::from("target/debug/cargo-clippy");
52+
let clippy_driver_path: PathBuf = PathBuf::from("target/debug/cargo-driver");
53+
54+
// crates we want to check:
55+
let krates: Vec<KrateSource> = vec![KrateSource::new("cargo", "0.49.0"), KrateSource::new("regex", "1.4.2")];
56+
57+
build_clippy();
58+
// assert that clippy is found
59+
assert!(
60+
cargo_clippy_path.is_file(),
61+
"target/debug/cargo-clippy binary not found!"
62+
);
63+
assert!(
64+
clippy_driver_path.is_file(),
65+
"target/debug/clippy-driver binary not found!"
66+
);
67+
68+
let clippy_lint_results: Vec<String> = krates.into_iter().map(|krate| krate.download_and_extract()).map(|krate| krate.run_clippy_lints()).collect::<Vec<String>>();
69+
}

clippy_dev/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::path::{Path, PathBuf};
1111
use walkdir::WalkDir;
1212

1313
pub mod bless;
14+
pub mod crater;
1415
pub mod fmt;
1516
pub mod new_lint;
1617
pub mod ra_setup;

0 commit comments

Comments
 (0)