mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Use a single WalkBuilder for multiple paths
This commit is contained in:
parent
d26a15563d
commit
19b272a94b
@ -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
|
||||
// (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 extension = file.extension();
|
||||
let scripts = ["py", "sh", "ps1"];
|
||||
|
@ -49,8 +49,9 @@ fn check_entries(tests_path: &Path, bad: &mut bool) {
|
||||
|
||||
pub fn check(path: &Path, bad: &mut bool) {
|
||||
check_entries(&path, bad);
|
||||
for path in &[&path.join("ui"), &path.join("ui-fulldeps")] {
|
||||
crate::walk::walk_no_read(path, |_| false, &mut |entry| {
|
||||
let (ui, ui_fulldeps) = (path.join("ui"), path.join("ui-fulldeps"));
|
||||
let paths = [ui.as_path(), ui_fulldeps.as_path()];
|
||||
crate::walk::walk_no_read(&paths, |_| false, &mut |entry| {
|
||||
let file_path = entry.path();
|
||||
if let Some(ext) = file_path.extension() {
|
||||
if ext == "stderr" || ext == "stdout" {
|
||||
@ -81,5 +82,4 @@ pub fn check(path: &Path, bad: &mut bool) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -35,26 +35,24 @@ pub fn filter_dirs(path: &Path) -> bool {
|
||||
|
||||
/// Filter for only files that end in `.rs`.
|
||||
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(
|
||||
paths: &[&Path],
|
||||
skip: impl Clone + Send + Sync + 'static + Fn(&Path) -> bool,
|
||||
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();
|
||||
walk_no_read(path, skip, &mut |entry| {
|
||||
walk_no_read(paths, skip, &mut |entry| {
|
||||
contents.clear();
|
||||
let mut file = t!(File::open(entry.path()), entry.path());
|
||||
t!(file.read_to_end(&mut contents), entry.path());
|
||||
@ -67,11 +65,14 @@ pub fn walk(
|
||||
}
|
||||
|
||||
pub(crate) fn walk_no_read(
|
||||
path: &Path,
|
||||
paths: &[&Path],
|
||||
skip: impl Send + Sync + 'static + Fn(&Path) -> bool,
|
||||
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()));
|
||||
for entry in walker.build() {
|
||||
if let Ok(entry) = entry {
|
||||
|
Loading…
Reference in New Issue
Block a user