Skip to content

Commit ec1902c

Browse files
committed
cargo dev crater: throw an error if we can't find our specified crate in the .toml list
1 parent b6ef1e2 commit ec1902c

File tree

3 files changed

+48
-25
lines changed

3 files changed

+48
-25
lines changed

clippy_dev/Cargo.toml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@ version = "0.0.1"
44
authors = ["Philipp Hansch <dev@phansch.net>"]
55
edition = "2018"
66

7+
78
[dependencies]
89
bytecount = "0.6"
910
clap = "2.33"
10-
flate2 = "1.0.19"
11+
flate2 = { version = "1.0.19" , optional = true}
1112
itertools = "0.9"
1213
opener = "0.4"
1314
regex = "1"
14-
serde = {version = "1.0", features = ["derive"]}
15-
serde_json = "1.0"
15+
serde = { version = "1.0", features = ["derive"]}
16+
serde_json = { version = "1.0" , optional = true}
1617
shell-escape = "0.1"
17-
tar = "0.4.30"
18-
toml = "0.5"
19-
ureq = "2.0.0-rc3"
18+
tar = { version = "0.4.30" , optional = true}
19+
toml = { version = "0.5" , optional = true}
20+
ureq = { version = "2.0.0-rc3" , optional = true}
2021
walkdir = "2"
2122

2223
[features]
24+
crater = ["flate2", "serde_json", "tar", "toml", "ureq"]
2325
deny-warnings = []

clippy_dev/src/crater.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// When a new lint is introduced, we can search the results for new warnings and check for false
55
// positives.
66

7+
#![cfg(feature = "crater")]
78
#![allow(clippy::filter_map)]
89

910
use crate::clippy_project_root;
@@ -218,17 +219,29 @@ pub fn run(clap_config: &ArgMatches) {
218219
// download and extract the crates, then run clippy on them and collect clippys warnings
219220
// flatten into one big list of warnings
220221

222+
let crates = read_crates();
223+
221224
let clippy_warnings: Vec<ClippyWarning> = if let Some(only_one_crate) = clap_config.value_of("only") {
222-
// only check a single
223-
read_crates()
225+
// if we don't have the specified crated in the .toml, throw an error
226+
if !crates.iter().any(|krate| krate.name == only_one_crate) {
227+
eprintln!(
228+
"ERROR: could not find crate '{}' in clippy_dev/crater_crates.toml",
229+
only_one_crate
230+
);
231+
std::process::exit(1);
232+
}
233+
234+
// only check a single crate that was passed via cmdline
235+
crates
224236
.into_iter()
225237
.map(|krate| krate.download_and_extract())
226238
.filter(|krate| krate.name == only_one_crate)
227239
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path))
228240
.flatten()
229241
.collect()
230242
} else {
231-
read_crates()
243+
// check all crates (default)
244+
crates
232245
.into_iter()
233246
.map(|krate| krate.download_and_extract())
234247
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path))

clippy_dev/src/main.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
22

33
use clap::{App, Arg, ArgMatches, SubCommand};
4-
use clippy_dev::{bless, crater, fmt, new_lint, ra_setup, serve, stderr_length_check, update_lints};
4+
use clippy_dev::{bless, fmt, new_lint, ra_setup, serve, stderr_length_check, update_lints};
5+
6+
#[cfg(feature = "crater")]
7+
use clippy_dev::crater;
58

69
fn main() {
710
let matches = get_clap_config();
@@ -10,6 +13,7 @@ fn main() {
1013
("bless", Some(matches)) => {
1114
bless::bless(matches.is_present("ignore-timestamp"));
1215
},
16+
#[cfg(feature = "crater")]
1317
("crater", Some(matches)) => {
1418
crater::run(&matches);
1519
},
@@ -49,8 +53,19 @@ fn main() {
4953
}
5054

5155
fn get_clap_config<'a>() -> ArgMatches<'a> {
52-
App::new("Clippy developer tooling")
53-
.subcommand(
56+
#[cfg(feature = "crater")]
57+
let crater_sbcmd = SubCommand::with_name("crater")
58+
.about("run clippy on a set of crates and check output")
59+
.arg(
60+
Arg::with_name("only")
61+
.takes_value(true)
62+
.value_name("CRATE")
63+
.long("only")
64+
.help("only process a single crate of the list"),
65+
);
66+
67+
let app = App::new("Clippy developer tooling")
68+
.subcommand(
5469
SubCommand::with_name("bless")
5570
.about("bless the test output changes")
5671
.arg(
@@ -59,17 +74,6 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
5974
.help("Include files updated before clippy was built"),
6075
),
6176
)
62-
.subcommand(
63-
SubCommand::with_name("crater")
64-
.about("run clippy on a set of crates and check output")
65-
.arg(
66-
Arg::with_name("only")
67-
.takes_value(true)
68-
.value_name("CRATE")
69-
.long("only")
70-
.help("only process a single crate of the list"),
71-
),
72-
)
7377
.subcommand(
7478
SubCommand::with_name("fmt")
7579
.about("Run rustfmt on all projects and tests")
@@ -177,6 +181,10 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
177181
.validator_os(serve::validate_port),
178182
)
179183
.arg(Arg::with_name("lint").help("Which lint's page to load initially (optional)")),
180-
)
181-
.get_matches()
184+
);
185+
186+
#[cfg(feature = "crater")]
187+
let app = app.subcommand(crater_sbcmd);
188+
189+
app.get_matches()
182190
}

0 commit comments

Comments
 (0)