Skip to content

Commit

Permalink
remove compiletest's dependency on filetime
Browse files Browse the repository at this point in the history
  • Loading branch information
euclio committed May 13, 2019
1 parent a9ec99f commit 01bc58c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
Expand Up @@ -459,7 +459,6 @@ version = "0.0.0"
dependencies = [
"diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
"filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down
1 change: 0 additions & 1 deletion src/tools/compiletest/Cargo.toml
Expand Up @@ -7,7 +7,6 @@ edition = "2018"
[dependencies]
diff = "0.1.10"
env_logger = { version = "0.5", default-features = false }
filetime = "0.2"
getopts = "0.2"
log = "0.4"
regex = "1.0"
Expand Down
27 changes: 16 additions & 11 deletions src/tools/compiletest/src/main.rs
Expand Up @@ -9,14 +9,14 @@ use crate::common::CompareMode;
use crate::common::{expected_output_path, output_base_dir, output_relative_path, UI_EXTENSIONS};
use crate::common::{Config, TestPaths};
use crate::common::{DebugInfoBoth, DebugInfoGdb, DebugInfoLldb, Mode, Pretty};
use filetime::FileTime;
use getopts::Options;
use std::env;
use std::ffi::OsString;
use std::fs;
use std::io::{self, ErrorKind};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::time::SystemTime;
use test::ColorConfig;
use crate::util::logv;
use walkdir::WalkDir;
Expand Down Expand Up @@ -752,31 +752,36 @@ fn up_to_date(

#[derive(Debug, PartialEq, PartialOrd, Ord, Eq)]
struct Stamp {
time: FileTime,
time: SystemTime,
file: PathBuf,
}

impl Stamp {
fn from_path(p: &Path) -> Self {
let time = fs::metadata(p)
.and_then(|metadata| metadata.modified())
.unwrap_or(SystemTime::UNIX_EPOCH);

Stamp {
time: mtime(&p),
time,
file: p.into(),
}
}

fn from_dir(path: &Path) -> impl Iterator<Item=Stamp> {
fn from_dir(path: &Path) -> impl Iterator<Item = Stamp> {
WalkDir::new(path)
.into_iter()
.map(|entry| entry.unwrap())
.filter(|entry| entry.file_type().is_file())
.map(|entry| Stamp::from_path(entry.path()))
}
}
.map(|entry| {
let time = (|| -> io::Result<_> { entry.metadata()?.modified() })();

fn mtime(path: &Path) -> FileTime {
fs::metadata(path)
.map(|f| FileTime::from_last_modification_time(&f))
.unwrap_or_else(|_| FileTime::zero())
Stamp {
time: time.unwrap_or(SystemTime::UNIX_EPOCH),
file: entry.path().into(),
}
})
}
}

fn make_test_name(
Expand Down
3 changes: 1 addition & 2 deletions src/tools/compiletest/src/runtest.rs
Expand Up @@ -9,7 +9,6 @@ use crate::common::{Config, TestPaths};
use crate::common::{Incremental, MirOpt, RunMake, Ui, JsDocTest, Assembly};
use diff;
use crate::errors::{self, Error, ErrorKind};
use filetime::FileTime;
use crate::header::TestProps;
use crate::json;
use regex::{Captures, Regex};
Expand Down Expand Up @@ -3032,7 +3031,7 @@ impl<'test> TestCx<'test> {
}

fn check_mir_test_timestamp(&self, test_name: &str, output_file: &Path) {
let t = |file| FileTime::from_last_modification_time(&fs::metadata(file).unwrap());
let t = |file| fs::metadata(file).unwrap().modified().unwrap();
let source_file = &self.testpaths.file;
let output_time = t(output_file);
let source_time = t(source_file);
Expand Down

0 comments on commit 01bc58c

Please sign in to comment.