Skip to content

Commit ecf8df5

Browse files
committed
Address the pull request review comments.
1 parent 91bfbb9 commit ecf8df5

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/tools/compiletest/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ serde_json = "1.0"
1515
serde_derive = "1.0"
1616
rustfix = "0.4.1"
1717
lazy_static = "1.0"
18+
walkdir = "2"
1819

1920
[target.'cfg(unix)'.dependencies]
2021
libc = "0.2"

src/tools/compiletest/src/main.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern crate serde_derive;
2828
extern crate serde_json;
2929
extern crate test;
3030
extern crate rustfix;
31+
extern crate walkdir;
3132

3233
use common::CompareMode;
3334
use common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS};
@@ -43,6 +44,7 @@ use std::path::{Path, PathBuf};
4344
use std::process::Command;
4445
use test::ColorConfig;
4546
use util::logv;
47+
use walkdir::WalkDir;
4648

4749
use self::header::{EarlyProps, Ignore};
4850

@@ -682,18 +684,13 @@ fn stamp(config: &Config, testpaths: &TestPaths, revision: Option<&str>) -> Path
682684
output_base_dir(config, testpaths, revision).join("stamp")
683685
}
684686

685-
/// Walk the directory at `path` and collect timestamps of all files into `inputs`.
686-
fn collect_timestamps(path: &PathBuf, inputs: &mut Vec<FileTime>) {
687-
let mut entries = path.read_dir().unwrap().collect::<Vec<_>>();
688-
while let Some(entry) = entries.pop() {
689-
let entry = entry.unwrap();
690-
let path = entry.path();
691-
if entry.metadata().unwrap().is_file() {
692-
inputs.push(mtime(&path));
693-
} else {
694-
entries.extend(path.read_dir().unwrap());
695-
}
696-
}
687+
/// Return an iterator over timestamps of files in the directory at `path`.
688+
fn collect_timestamps(path: &PathBuf) -> impl Iterator<Item=FileTime> {
689+
WalkDir::new(path)
690+
.into_iter()
691+
.map(|entry| entry.unwrap())
692+
.filter(|entry| entry.metadata().unwrap().is_file())
693+
.map(|entry| mtime(entry.path()))
697694
}
698695

699696
fn up_to_date(
@@ -739,7 +736,7 @@ fn up_to_date(
739736
for pretty_printer_file in &pretty_printer_files {
740737
inputs.push(mtime(&rust_src_dir.join(pretty_printer_file)));
741738
}
742-
collect_timestamps(&config.run_lib_path, &mut inputs);
739+
inputs.extend(collect_timestamps(&config.run_lib_path));
743740
if let Some(ref rustdoc_path) = config.rustdoc_path {
744741
inputs.push(mtime(&rustdoc_path));
745742
inputs.push(mtime(&rust_src_dir.join("src/etc/htmldocck.py")));
@@ -752,7 +749,7 @@ fn up_to_date(
752749
}
753750

754751
// Compiletest itself.
755-
collect_timestamps(&rust_src_dir.join("src/tools/compiletest/"), &mut inputs);
752+
inputs.extend(collect_timestamps(&rust_src_dir.join("src/tools/compiletest/")));
756753

757754
inputs.iter().any(|input| *input > stamp)
758755
}

0 commit comments

Comments
 (0)