Skip to content

Commit 70d952e

Browse files
committed
lintcheck: more fixes
fix a couple of issues when checking if lintcheck needed rerun after clippy binary changed. I was apparently still comparing the times wrongly, but it should be fixed™ now... I actually looked at the date of the sources.toml and not at the date of the log file! Also fix progress report counter not advancing in squential mode
1 parent b9a7a2a commit 70d952e

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

clippy_dev/src/lintcheck.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ fn gather_stats(clippy_warnings: &[ClippyWarning]) -> (String, HashMap<&String,
496496

497497
/// check if the latest modification of the logfile is older than the modification date of the
498498
/// clippy binary, if this is true, we should clean the lintchec shared target directory and recheck
499-
fn lintcheck_needs_rerun(toml_path: &PathBuf) -> bool {
499+
fn lintcheck_needs_rerun(lintcheck_logs_path: &PathBuf) -> bool {
500500
let clippy_modified: std::time::SystemTime = {
501501
let mut times = [CLIPPY_DRIVER_PATH, CARGO_CLIPPY_PATH].iter().map(|p| {
502502
std::fs::metadata(p)
@@ -505,17 +505,17 @@ fn lintcheck_needs_rerun(toml_path: &PathBuf) -> bool {
505505
.expect("failed to get modification date")
506506
});
507507
// the oldest modification of either of the binaries
508-
std::cmp::min(times.next().unwrap(), times.next().unwrap())
508+
std::cmp::max(times.next().unwrap(), times.next().unwrap())
509509
};
510510

511-
let logs_modified: std::time::SystemTime = std::fs::metadata(toml_path)
511+
let logs_modified: std::time::SystemTime = std::fs::metadata(lintcheck_logs_path)
512512
.expect("failed to get metadata of file")
513513
.modified()
514514
.expect("failed to get modification date");
515515

516-
// if clippys modification time is smaller (older) than the logs mod time, we need to rerun
517-
// lintcheck
518-
clippy_modified < logs_modified
516+
// time is represented in seconds since X
517+
// logs_modified 2 and clippy_modified 5 means clippy binary is older and we need to recheck
518+
logs_modified < clippy_modified
519519
}
520520

521521
/// lintchecks `main()` function
@@ -528,7 +528,7 @@ pub fn run(clap_config: &ArgMatches) {
528528

529529
// if the clippy bin is newer than our logs, throw away target dirs to force clippy to
530530
// refresh the logs
531-
if lintcheck_needs_rerun(&config.sources_toml_path) {
531+
if lintcheck_needs_rerun(&config.lintcheck_results_path) {
532532
let shared_target_dir = "target/lintcheck/shared_target_dir";
533533
match std::fs::metadata(&shared_target_dir) {
534534
Ok(metadata) => {
@@ -538,8 +538,7 @@ pub fn run(clap_config: &ArgMatches) {
538538
.expect("failed to remove target/lintcheck/shared_target_dir");
539539
}
540540
},
541-
Err(_) => { // dir probably does not exist, don't remove anything
542-
},
541+
Err(_) => { /* dir probably does not exist, don't remove anything */ },
543542
}
544543
}
545544

@@ -566,6 +565,8 @@ pub fn run(clap_config: &ArgMatches) {
566565
let crates = read_crates(&config.sources_toml_path);
567566
let old_stats = read_stats_from_file(&config.lintcheck_results_path);
568567

568+
let counter = AtomicUsize::new(1);
569+
569570
let clippy_warnings: Vec<ClippyWarning> = if let Some(only_one_crate) = clap_config.value_of("only") {
570571
// if we don't have the specified crate in the .toml, throw an error
571572
if !crates.iter().any(|krate| {
@@ -595,8 +596,6 @@ pub fn run(clap_config: &ArgMatches) {
595596
if config.max_jobs > 1 {
596597
// run parallel with rayon
597598

598-
let counter = AtomicUsize::new(0);
599-
600599
// Ask rayon for thread count. Assume that half of that is the number of physical cores
601600
// Use one target dir for each core so that we can run N clippys in parallel.
602601
// We need to use different target dirs because cargo would lock them for a single build otherwise,
@@ -623,7 +622,7 @@ pub fn run(clap_config: &ArgMatches) {
623622
crates
624623
.into_iter()
625624
.map(|krate| krate.download_and_extract())
626-
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &AtomicUsize::new(0), 1, num_crates))
625+
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path, &counter, 1, num_crates))
627626
.flatten()
628627
.collect()
629628
}

0 commit comments

Comments
 (0)