From 77578dc30f357cc346bd4203ba87243a724d088a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 23 Jan 2017 15:55:35 -0800 Subject: [PATCH 1/2] std: Remove cfg(cargobuild) annotations These are all now no longer needed that we've only got rustbuild in tree. --- Cargo.toml | 1 - build.rs | 13 ------------- src/main.rs | 13 +------------ 3 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index 2982f29..3049875 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,6 @@ authors = ["The Rust Project Developers"] name = "compiletest" version = "0.0.0" -build = "build.rs" [dependencies] log = "0.3" diff --git a/build.rs b/build.rs deleted file mode 100644 index d5164b9..0000000 --- a/build.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - println!("cargo:rustc-cfg=cargobuild"); -} diff --git a/src/main.rs b/src/main.rs index 43d0247..c2997c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,16 +21,9 @@ extern crate libc; extern crate test; extern crate getopts; - -#[cfg(cargobuild)] extern crate rustc_serialize; -#[cfg(not(cargobuild))] -extern crate serialize as rustc_serialize; - #[macro_use] extern crate log; - -#[cfg(cargobuild)] extern crate env_logger; use std::env; @@ -58,11 +51,7 @@ mod raise_fd_limit; mod uidiff; fn main() { - #[cfg(cargobuild)] - fn log_init() { env_logger::init().unwrap(); } - #[cfg(not(cargobuild))] - fn log_init() {} - log_init(); + env_logger::init().unwrap(); let config = parse_config(env::args().collect()); From 41904a084e15eed9d44989abfa1fb5371efcd706 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 31 Jan 2017 19:16:45 -0800 Subject: [PATCH 2/2] compiletest: Add caching of test results Don't re-run tests in compiletest if all the inputs haven't changed, manage stamp files in the output directory. --- Cargo.toml | 1 + src/header.rs | 6 ++++++ src/main.rs | 40 +++++++++++++++++++++++++++++++++++++++- src/runtest.rs | 2 ++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3049875..1fc98a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ version = "0.0.0" log = "0.3" env_logger = { version = "0.3.5", default-features = false } rustc-serialize = "0.3" +filetime = "0.1" diff --git a/src/header.rs b/src/header.rs index 71d8d62..522cd22 100644 --- a/src/header.rs +++ b/src/header.rs @@ -25,6 +25,7 @@ use extract_gdb_version; pub struct EarlyProps { pub ignore: bool, pub should_fail: bool, + pub aux: Vec, } impl EarlyProps { @@ -32,6 +33,7 @@ impl EarlyProps { let mut props = EarlyProps { ignore: false, should_fail: false, + aux: Vec::new(), }; iter_header(testfile, @@ -50,6 +52,10 @@ impl EarlyProps { ignore_lldb(config, ln) || ignore_llvm(config, ln); + if let Some(s) = parse_aux_build(ln) { + props.aux.push(s); + } + props.should_fail = props.should_fail || parse_name_directive(ln, "should-fail"); }); diff --git a/src/main.rs b/src/main.rs index c2997c8..6c63661 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,7 @@ extern crate rustc_serialize; #[macro_use] extern crate log; extern crate env_logger; +extern crate filetime; use std::env; use std::ffi::OsString; @@ -32,6 +33,7 @@ use std::fs; use std::io; use std::path::{Path, PathBuf}; use std::process::Command; +use filetime::FileTime; use getopts::{optopt, optflag, reqopt}; use common::Config; use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Mode}; @@ -457,7 +459,7 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn }; // Debugging emscripten code doesn't make sense today - let mut ignore = early_props.ignore; + let mut ignore = early_props.ignore || !up_to_date(config, testpaths, &early_props); if (config.mode == DebugInfoGdb || config.mode == DebugInfoLldb) && config.target.contains("emscripten") { ignore = true; @@ -473,6 +475,42 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn } } +fn stamp(config: &Config, testpaths: &TestPaths) -> PathBuf { + let stamp_name = format!("{}-H-{}-T-{}-S-{}.stamp", + testpaths.file.file_name().unwrap() + .to_str().unwrap(), + config.host, + config.target, + config.stage_id); + config.build_base.canonicalize() + .unwrap_or(config.build_base.clone()) + .join(stamp_name) +} + +fn up_to_date(config: &Config, testpaths: &TestPaths, props: &EarlyProps) -> bool { + let stamp = mtime(&stamp(config, testpaths)); + let mut inputs = vec![ + mtime(&testpaths.file), + mtime(&config.rustc_path), + ]; + for aux in props.aux.iter() { + inputs.push(mtime(&testpaths.file.parent().unwrap() + .join("auxiliary") + .join(aux))); + } + for lib in config.run_lib_path.read_dir().unwrap() { + let lib = lib.unwrap(); + inputs.push(mtime(&lib.path())); + } + inputs.iter().any(|input| *input > stamp) +} + +fn mtime(path: &Path) -> FileTime { + fs::metadata(path).map(|f| { + FileTime::from_last_modification_time(&f) + }).unwrap_or(FileTime::zero()) +} + pub fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName { // Convert a complete path to something like // diff --git a/src/runtest.rs b/src/runtest.rs index a8c4672..10d5f0d 100644 --- a/src/runtest.rs +++ b/src/runtest.rs @@ -80,6 +80,8 @@ pub fn run(config: Config, testpaths: &TestPaths) { } base_cx.complete_all(); + + File::create(::stamp(&config, &testpaths)).unwrap(); } struct TestCx<'test> {