Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/tools/tidy/src/mir_opt_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
use std::collections::HashSet;
use std::path::{Path, PathBuf};

use crate::walk::walk_no_read;

fn check_unused_files(path: &Path, bless: bool, bad: &mut bool) {
let mut rs_files = Vec::<PathBuf>::new();
let mut output_files = HashSet::<PathBuf>::new();
let files = walkdir::WalkDir::new(&path.join("mir-opt")).into_iter();

for file in files.filter_map(Result::ok).filter(|e| e.file_type().is_file()) {
let filepath = file.path();
if filepath.extension() == Some("rs".as_ref()) {
rs_files.push(filepath.to_owned());
} else {
output_files.insert(filepath.to_owned());
}
}
walk_no_read(
&[&path.join("mir-opt")],
|path| path.file_name() == Some("README.md".as_ref()),
&mut |file| {
let filepath = file.path();
if filepath.extension() == Some("rs".as_ref()) {
rs_files.push(filepath.to_owned());
} else {
output_files.insert(filepath.to_owned());
}
},
);

for file in rs_files {
for bw in [32, 64] {
Expand All @@ -26,16 +31,14 @@ fn check_unused_files(path: &Path, bless: bool, bad: &mut bool) {
}

for extra in output_files {
if extra.file_name() != Some("README.md".as_ref()) {
if !bless {
tidy_error!(
bad,
"the following output file is not associated with any mir-opt test, you can remove it: {}",
extra.display()
);
} else {
let _ = std::fs::remove_file(extra);
}
if !bless {
tidy_error!(
bad,
"the following output file is not associated with any mir-opt test, you can remove it: {}",
extra.display()
);
} else {
let _ = std::fs::remove_file(extra);
}
}
}
Expand Down