Skip to content

Commit a5c5c8f

Browse files
committed
Auto merge of #6781 - matthiaskrgr:lintcheck_fix, r=matthiaskrgr
lintcheck fix build (forgot to pass function parameter) and runtime (… …don't check metadata of directory if it does not exist) Accidentally broke lintcheck in my previous commit. changelog: None
2 parents f02df27 + eaae95b commit a5c5c8f

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

clippy_dev/src/lintcheck.rs

+25-14
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,14 @@ fn filter_clippy_warnings(line: &str) -> bool {
312312

313313
/// get the path to lintchecks crate sources .toml file, check LINTCHECK_TOML first but if it's
314314
/// empty use the default path
315-
fn lintcheck_config_toml() -> PathBuf {
315+
fn lintcheck_config_toml(toml_path: Option<&str>) -> PathBuf {
316316
PathBuf::from(
317-
env::var("LINTCHECK_TOML").unwrap_or(toml_path.unwrap_or("clippy_dev/lintcheck_crates.toml").to_string()),
317+
env::var("LINTCHECK_TOML").unwrap_or(
318+
toml_path
319+
.clone()
320+
.unwrap_or("clippy_dev/lintcheck_crates.toml")
321+
.to_string(),
322+
),
318323
)
319324
}
320325

@@ -332,7 +337,7 @@ fn build_clippy() {
332337

333338
/// Read a `toml` file and return a list of `CrateSources` that we want to check with clippy
334339
fn read_crates(toml_path: Option<&str>) -> (String, Vec<CrateSource>) {
335-
let toml_path = lintcheck_config_toml();
340+
let toml_path = lintcheck_config_toml(toml_path);
336341
// save it so that we can use the name of the sources.toml as name for the logfile later.
337342
let toml_filename = toml_path.file_stem().unwrap().to_str().unwrap().to_string();
338343
let toml_content: String =
@@ -444,10 +449,10 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> String {
444449

445450
/// check if the latest modification of the logfile is older than the modification date of the
446451
/// clippy binary, if this is true, we should clean the lintchec shared target directory and recheck
447-
fn lintcheck_needs_rerun() -> bool {
452+
fn lintcheck_needs_rerun(toml_path: Option<&str>) -> bool {
448453
let clippy_modified: std::time::SystemTime = {
449454
let mut times = ["target/debug/clippy-driver", "target/debug/cargo-clippy"]
450-
.into_iter()
455+
.iter()
451456
.map(|p| {
452457
std::fs::metadata(p)
453458
.expect("failed to get metadata of file")
@@ -458,7 +463,7 @@ fn lintcheck_needs_rerun() -> bool {
458463
std::cmp::max(times.next().unwrap(), times.next().unwrap())
459464
};
460465

461-
let logs_modified: std::time::SystemTime = std::fs::metadata(lintcheck_config_toml())
466+
let logs_modified: std::time::SystemTime = std::fs::metadata(lintcheck_config_toml(toml_path))
462467
.expect("failed to get metadata of file")
463468
.modified()
464469
.expect("failed to get modification date");
@@ -473,16 +478,22 @@ pub fn run(clap_config: &ArgMatches) {
473478
build_clippy();
474479
println!("Done compiling");
475480

481+
let clap_toml_path = clap_config.value_of("crates-toml");
482+
476483
// if the clippy bin is newer than our logs, throw away target dirs to force clippy to
477484
// refresh the logs
478-
if lintcheck_needs_rerun() {
485+
if lintcheck_needs_rerun(clap_toml_path) {
479486
let shared_target_dir = "target/lintcheck/shared_target_dir";
480-
if std::fs::metadata(&shared_target_dir)
481-
.expect("failed to get metadata of shared target dir")
482-
.is_dir()
483-
{
484-
println!("Clippy is newer than lint check logs, clearing lintcheck shared target dir...");
485-
std::fs::remove_dir_all(&shared_target_dir).expect("failed to remove target/lintcheck/shared_target_dir");
487+
match std::fs::metadata(&shared_target_dir) {
488+
Ok(metadata) => {
489+
if metadata.is_dir() {
490+
println!("Clippy is newer than lint check logs, clearing lintcheck shared target dir...");
491+
std::fs::remove_dir_all(&shared_target_dir)
492+
.expect("failed to remove target/lintcheck/shared_target_dir");
493+
}
494+
},
495+
Err(_) => { // dir probably does not exist, don't remove anything
496+
},
486497
}
487498
}
488499

@@ -506,7 +517,7 @@ pub fn run(clap_config: &ArgMatches) {
506517
// download and extract the crates, then run clippy on them and collect clippys warnings
507518
// flatten into one big list of warnings
508519

509-
let (filename, crates) = read_crates(clap_config.value_of("crates-toml"));
520+
let (filename, crates) = read_crates(clap_toml_path);
510521

511522
let clippy_warnings: Vec<ClippyWarning> = if let Some(only_one_crate) = clap_config.value_of("only") {
512523
// if we don't have the specified crate in the .toml, throw an error

0 commit comments

Comments
 (0)