Skip to content

Commit 90a3c7d

Browse files
committed
Auto merge of #6254 - ehuss:fix-travis-slow, r=alexcrichton
Fix slow MacOS Travis issue. OS X 10.13 images on Travis are running very slow and causing timeouts. This PR does two things: - Use OS X 10.12 (`xode9.2`) which is much faster. - Implement a change to the testsuite to handle 1-second resolution mtimes on HFS. When a test executes cargo multiple times, and the first run finishes in under 1 second, the second one will think it needs to rebuild because the mtime of the files equals the mtime of the output. This change forces the mtime of every project to be created 1 second in the past. Tests that are still sensitive to mtimes are adjusted on a case-by-case basis. Closes #6239, Closes #5940
2 parents 5998a46 + 20b5ca3 commit 90a3c7d

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ matrix:
2222
- env: TARGET=x86_64-apple-darwin
2323
ALT=i686-apple-darwin
2424
os: osx
25+
osx_image: xcode9.2
2526
if: branch != master OR type = pull_request
2627

2728
- env: TARGET=x86_64-unknown-linux-gnu

tests/testsuite/metabuild.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use glob::glob;
22
use serde_json;
33
use std::str;
44
use support::{
5-
basic_lib_manifest, basic_manifest, project, registry::Package, rustc_host, Project,
5+
basic_lib_manifest, basic_manifest, is_coarse_mtime, project, registry::Package, rustc_host,
6+
Project,
67
};
78

89
#[test]
@@ -212,6 +213,14 @@ fn metabuild_lib_name() {
212213

213214
#[test]
214215
fn metabuild_fresh() {
216+
if is_coarse_mtime() {
217+
// This test doesn't work on coarse mtimes very well. Because the
218+
// metabuild script is created at build time, its mtime is almost
219+
// always equal to the mtime of the output. The second call to `build`
220+
// will then think it needs to be rebuilt when it should be fresh.
221+
return;
222+
}
223+
215224
// Check that rebuild is fresh.
216225
let p = project()
217226
.file(

tests/testsuite/support/mod.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ use std::os;
113113
use std::path::{Path, PathBuf};
114114
use std::process::{Command, Output};
115115
use std::str;
116-
use std::time::Duration;
116+
use std::time::{self, Duration};
117117
use std::usize;
118118

119119
use cargo;
120120
use cargo::util::{CargoResult, ProcessBuilder, ProcessError, Rustc};
121+
use filetime;
121122
use serde_json::{self, Value};
122123
use url::Url;
123124

@@ -279,8 +280,19 @@ impl ProjectBuilder {
279280
self._file(Path::new("Cargo.toml"), &basic_manifest("foo", "0.0.1"))
280281
}
281282

283+
let past = time::SystemTime::now() - Duration::new(1, 0);
284+
let ftime = filetime::FileTime::from_system_time(past);
285+
282286
for file in self.files.iter() {
283287
file.mk();
288+
if is_coarse_mtime() {
289+
// Place the entire project 1 second in the past to ensure
290+
// that if cargo is called multiple times, the 2nd call will
291+
// see targets as "fresh". Without this, if cargo finishes in
292+
// under 1 second, the second call will see the mtime of
293+
// source == mtime of output and consider it dirty.
294+
filetime::set_file_times(&file.path, ftime, ftime).unwrap();
295+
}
284296
}
285297

286298
for symlink in self.symlinks.iter() {
@@ -1510,3 +1522,11 @@ pub fn git_process(s: &str) -> ProcessBuilder {
15101522
pub fn sleep_ms(ms: u64) {
15111523
::std::thread::sleep(Duration::from_millis(ms));
15121524
}
1525+
1526+
/// Returns true if the local filesystem has low-resolution mtimes.
1527+
pub fn is_coarse_mtime() -> bool {
1528+
// This should actually be a test that $CARGO_TARGET_DIR is on an HFS
1529+
// filesystem, (or any filesystem with low-resolution mtimes). However,
1530+
// that's tricky to detect, so for now just deal with CI.
1531+
cfg!(target_os = "macos") && env::var("CI").is_ok()
1532+
}

0 commit comments

Comments
 (0)