Use a single WalkBuilder for multiple paths
This commit is contained in:
parent
d26a15563d
commit
19b272a94b
3 changed files with 45 additions and 44 deletions
|
@ -103,7 +103,7 @@ mod os_impl {
|
||||||
|
|
||||||
// FIXME: we don't need to look at all binaries, only files that have been modified in this branch
|
// FIXME: we don't need to look at all binaries, only files that have been modified in this branch
|
||||||
// (e.g. using `git ls-files`).
|
// (e.g. using `git ls-files`).
|
||||||
walk_no_read(path, |path| filter_dirs(path) || path.ends_with("src/etc"), &mut |entry| {
|
walk_no_read(&[path], |path| filter_dirs(path) || path.ends_with("src/etc"), &mut |entry| {
|
||||||
let file = entry.path();
|
let file = entry.path();
|
||||||
let extension = file.extension();
|
let extension = file.extension();
|
||||||
let scripts = ["py", "sh", "ps1"];
|
let scripts = ["py", "sh", "ps1"];
|
||||||
|
|
|
@ -49,37 +49,37 @@ fn check_entries(tests_path: &Path, bad: &mut bool) {
|
||||||
|
|
||||||
pub fn check(path: &Path, bad: &mut bool) {
|
pub fn check(path: &Path, bad: &mut bool) {
|
||||||
check_entries(&path, bad);
|
check_entries(&path, bad);
|
||||||
for path in &[&path.join("ui"), &path.join("ui-fulldeps")] {
|
let (ui, ui_fulldeps) = (path.join("ui"), path.join("ui-fulldeps"));
|
||||||
crate::walk::walk_no_read(path, |_| false, &mut |entry| {
|
let paths = [ui.as_path(), ui_fulldeps.as_path()];
|
||||||
let file_path = entry.path();
|
crate::walk::walk_no_read(&paths, |_| false, &mut |entry| {
|
||||||
if let Some(ext) = file_path.extension() {
|
let file_path = entry.path();
|
||||||
if ext == "stderr" || ext == "stdout" {
|
if let Some(ext) = file_path.extension() {
|
||||||
// Test output filenames have one of the formats:
|
if ext == "stderr" || ext == "stdout" {
|
||||||
// ```
|
// Test output filenames have one of the formats:
|
||||||
// $testname.stderr
|
// ```
|
||||||
// $testname.$mode.stderr
|
// $testname.stderr
|
||||||
// $testname.$revision.stderr
|
// $testname.$mode.stderr
|
||||||
// $testname.$revision.$mode.stderr
|
// $testname.$revision.stderr
|
||||||
// ```
|
// $testname.$revision.$mode.stderr
|
||||||
//
|
// ```
|
||||||
// For now, just make sure that there is a corresponding
|
//
|
||||||
// `$testname.rs` file.
|
// For now, just make sure that there is a corresponding
|
||||||
//
|
// `$testname.rs` file.
|
||||||
// NB: We do not use file_stem() as some file names have multiple `.`s and we
|
//
|
||||||
// must strip all of them.
|
// NB: We do not use file_stem() as some file names have multiple `.`s and we
|
||||||
let testname =
|
// must strip all of them.
|
||||||
file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0;
|
let testname =
|
||||||
if !file_path.with_file_name(testname).with_extension("rs").exists() {
|
file_path.file_name().unwrap().to_str().unwrap().split_once('.').unwrap().0;
|
||||||
tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path);
|
if !file_path.with_file_name(testname).with_extension("rs").exists() {
|
||||||
}
|
tidy_error!(bad, "Stray file with UI testing output: {:?}", file_path);
|
||||||
|
}
|
||||||
|
|
||||||
if let Ok(metadata) = fs::metadata(file_path) {
|
if let Ok(metadata) = fs::metadata(file_path) {
|
||||||
if metadata.len() == 0 {
|
if metadata.len() == 0 {
|
||||||
tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path);
|
tidy_error!(bad, "Empty file with UI testing output: {:?}", file_path);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,26 +35,24 @@ pub fn filter_dirs(path: &Path) -> bool {
|
||||||
|
|
||||||
/// Filter for only files that end in `.rs`.
|
/// Filter for only files that end in `.rs`.
|
||||||
pub fn filter_not_rust(path: &Path) -> bool {
|
pub fn filter_not_rust(path: &Path) -> bool {
|
||||||
!path.is_dir() && path.extension() != Some(OsStr::new("rs"))
|
path.extension() != Some(OsStr::new("rs")) && !path.is_dir()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn walk(
|
||||||
|
path: &Path,
|
||||||
|
skip: impl Clone + Send + Sync + 'static + Fn(&Path) -> bool,
|
||||||
|
f: &mut dyn FnMut(&DirEntry, &str),
|
||||||
|
) {
|
||||||
|
walk_many(&[path], skip, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_many(
|
pub fn walk_many(
|
||||||
paths: &[&Path],
|
paths: &[&Path],
|
||||||
skip: impl Clone + Send + Sync + 'static + Fn(&Path) -> bool,
|
skip: impl Clone + Send + Sync + 'static + Fn(&Path) -> bool,
|
||||||
f: &mut dyn FnMut(&DirEntry, &str),
|
f: &mut dyn FnMut(&DirEntry, &str),
|
||||||
) {
|
|
||||||
for path in paths {
|
|
||||||
walk(path, skip.clone(), f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn walk(
|
|
||||||
path: &Path,
|
|
||||||
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
|
|
||||||
f: &mut dyn FnMut(&DirEntry, &str),
|
|
||||||
) {
|
) {
|
||||||
let mut contents = Vec::new();
|
let mut contents = Vec::new();
|
||||||
walk_no_read(path, skip, &mut |entry| {
|
walk_no_read(paths, skip, &mut |entry| {
|
||||||
contents.clear();
|
contents.clear();
|
||||||
let mut file = t!(File::open(entry.path()), entry.path());
|
let mut file = t!(File::open(entry.path()), entry.path());
|
||||||
t!(file.read_to_end(&mut contents), entry.path());
|
t!(file.read_to_end(&mut contents), entry.path());
|
||||||
|
@ -67,11 +65,14 @@ pub fn walk(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn walk_no_read(
|
pub(crate) fn walk_no_read(
|
||||||
path: &Path,
|
paths: &[&Path],
|
||||||
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
|
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
|
||||||
f: &mut dyn FnMut(&DirEntry),
|
f: &mut dyn FnMut(&DirEntry),
|
||||||
) {
|
) {
|
||||||
let mut walker = ignore::WalkBuilder::new(path);
|
let mut walker = ignore::WalkBuilder::new(paths[0]);
|
||||||
|
for path in &paths[1..] {
|
||||||
|
walker.add(path);
|
||||||
|
}
|
||||||
let walker = walker.filter_entry(move |e| !skip(e.path()));
|
let walker = walker.filter_entry(move |e| !skip(e.path()));
|
||||||
for entry in walker.build() {
|
for entry in walker.build() {
|
||||||
if let Ok(entry) = entry {
|
if let Ok(entry) = entry {
|
||||||
|
|
Loading…
Add table
Reference in a new issue