@@ -312,9 +312,14 @@ fn filter_clippy_warnings(line: &str) -> bool {
312
312
313
313
/// get the path to lintchecks crate sources .toml file, check LINTCHECK_TOML first but if it's
314
314
/// empty use the default path
315
- fn lintcheck_config_toml ( ) -> PathBuf {
315
+ fn lintcheck_config_toml ( toml_path : Option < & str > ) -> PathBuf {
316
316
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
+ ) ,
318
323
)
319
324
}
320
325
@@ -332,7 +337,7 @@ fn build_clippy() {
332
337
333
338
/// Read a `toml` file and return a list of `CrateSources` that we want to check with clippy
334
339
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 ) ;
336
341
// save it so that we can use the name of the sources.toml as name for the logfile later.
337
342
let toml_filename = toml_path. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
338
343
let toml_content: String =
@@ -444,10 +449,10 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> String {
444
449
445
450
/// check if the latest modification of the logfile is older than the modification date of the
446
451
/// 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 {
448
453
let clippy_modified: std:: time:: SystemTime = {
449
454
let mut times = [ "target/debug/clippy-driver" , "target/debug/cargo-clippy" ]
450
- . into_iter ( )
455
+ . iter ( )
451
456
. map ( |p| {
452
457
std:: fs:: metadata ( p)
453
458
. expect ( "failed to get metadata of file" )
@@ -458,7 +463,7 @@ fn lintcheck_needs_rerun() -> bool {
458
463
std:: cmp:: max ( times. next ( ) . unwrap ( ) , times. next ( ) . unwrap ( ) )
459
464
} ;
460
465
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 ) )
462
467
. expect ( "failed to get metadata of file" )
463
468
. modified ( )
464
469
. expect ( "failed to get modification date" ) ;
@@ -473,16 +478,22 @@ pub fn run(clap_config: &ArgMatches) {
473
478
build_clippy ( ) ;
474
479
println ! ( "Done compiling" ) ;
475
480
481
+ let clap_toml_path = clap_config. value_of ( "crates-toml" ) ;
482
+
476
483
// if the clippy bin is newer than our logs, throw away target dirs to force clippy to
477
484
// refresh the logs
478
- if lintcheck_needs_rerun ( ) {
485
+ if lintcheck_needs_rerun ( clap_toml_path ) {
479
486
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
+ } ,
486
497
}
487
498
}
488
499
@@ -506,7 +517,7 @@ pub fn run(clap_config: &ArgMatches) {
506
517
// download and extract the crates, then run clippy on them and collect clippys warnings
507
518
// flatten into one big list of warnings
508
519
509
- let ( filename, crates) = read_crates ( clap_config . value_of ( "crates-toml" ) ) ;
520
+ let ( filename, crates) = read_crates ( clap_toml_path ) ;
510
521
511
522
let clippy_warnings: Vec < ClippyWarning > = if let Some ( only_one_crate) = clap_config. value_of ( "only" ) {
512
523
// if we don't have the specified crate in the .toml, throw an error
0 commit comments