Skip to content

Commit c8e0d04

Browse files
committed
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.
1 parent 9ad13c8 commit c8e0d04

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

src/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/compiletest/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ version = "0.0.0"
77
log = "0.3"
88
env_logger = { version = "0.3.5", default-features = false }
99
rustc-serialize = "0.3"
10+
filetime = "0.1"

src/tools/compiletest/src/header.rs

+6
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ use extract_gdb_version;
2525
pub struct EarlyProps {
2626
pub ignore: bool,
2727
pub should_fail: bool,
28+
pub aux: Vec<String>,
2829
}
2930

3031
impl EarlyProps {
3132
pub fn from_file(config: &Config, testfile: &Path) -> Self {
3233
let mut props = EarlyProps {
3334
ignore: false,
3435
should_fail: false,
36+
aux: Vec::new(),
3537
};
3638

3739
iter_header(testfile,
@@ -50,6 +52,10 @@ impl EarlyProps {
5052
ignore_lldb(config, ln) ||
5153
ignore_llvm(config, ln);
5254

55+
if let Some(s) = parse_aux_build(ln) {
56+
props.aux.push(s);
57+
}
58+
5359
props.should_fail = props.should_fail || parse_name_directive(ln, "should-fail");
5460
});
5561

src/tools/compiletest/src/main.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ extern crate rustc_serialize;
2525
#[macro_use]
2626
extern crate log;
2727
extern crate env_logger;
28+
extern crate filetime;
2829

2930
use std::env;
3031
use std::ffi::OsString;
3132
use std::fs;
3233
use std::io;
3334
use std::path::{Path, PathBuf};
3435
use std::process::Command;
36+
use filetime::FileTime;
3537
use getopts::{optopt, optflag, reqopt};
3638
use common::Config;
3739
use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Mode};
@@ -457,7 +459,7 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn
457459
};
458460

459461
// Debugging emscripten code doesn't make sense today
460-
let mut ignore = early_props.ignore;
462+
let mut ignore = early_props.ignore || !up_to_date(config, testpaths, &early_props);
461463
if (config.mode == DebugInfoGdb || config.mode == DebugInfoLldb) &&
462464
config.target.contains("emscripten") {
463465
ignore = true;
@@ -473,6 +475,42 @@ pub fn make_test(config: &Config, testpaths: &TestPaths) -> test::TestDescAndFn
473475
}
474476
}
475477

478+
fn stamp(config: &Config, testpaths: &TestPaths) -> PathBuf {
479+
let stamp_name = format!("{}-H-{}-T-{}-S-{}.stamp",
480+
testpaths.file.file_name().unwrap()
481+
.to_str().unwrap(),
482+
config.host,
483+
config.target,
484+
config.stage_id);
485+
config.build_base.canonicalize()
486+
.unwrap_or(config.build_base.clone())
487+
.join(stamp_name)
488+
}
489+
490+
fn up_to_date(config: &Config, testpaths: &TestPaths, props: &EarlyProps) -> bool {
491+
let stamp = mtime(&stamp(config, testpaths));
492+
let mut inputs = vec![
493+
mtime(&testpaths.file),
494+
mtime(&config.rustc_path),
495+
];
496+
for aux in props.aux.iter() {
497+
inputs.push(mtime(&testpaths.file.parent().unwrap()
498+
.join("auxiliary")
499+
.join(aux)));
500+
}
501+
for lib in config.run_lib_path.read_dir().unwrap() {
502+
let lib = lib.unwrap();
503+
inputs.push(mtime(&lib.path()));
504+
}
505+
inputs.iter().any(|input| *input > stamp)
506+
}
507+
508+
fn mtime(path: &Path) -> FileTime {
509+
fs::metadata(path).map(|f| {
510+
FileTime::from_last_modification_time(&f)
511+
}).unwrap_or(FileTime::zero())
512+
}
513+
476514
pub fn make_test_name(config: &Config, testpaths: &TestPaths) -> test::TestName {
477515
// Convert a complete path to something like
478516
//

src/tools/compiletest/src/runtest.rs

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ pub fn run(config: Config, testpaths: &TestPaths) {
8080
}
8181

8282
base_cx.complete_all();
83+
84+
File::create(::stamp(&config, &testpaths)).unwrap();
8385
}
8486

8587
struct TestCx<'test> {

0 commit comments

Comments
 (0)