Skip to content

Commit

Permalink
Auto merge of #6254 - ehuss:fix-travis-slow, r=alexcrichton
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Nov 3, 2018
2 parents 5998a46 + 20b5ca3 commit 90a3c7d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ matrix:
- env: TARGET=x86_64-apple-darwin
ALT=i686-apple-darwin
os: osx
osx_image: xcode9.2
if: branch != master OR type = pull_request

- env: TARGET=x86_64-unknown-linux-gnu
Expand Down
11 changes: 10 additions & 1 deletion tests/testsuite/metabuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use glob::glob;
use serde_json;
use std::str;
use support::{
basic_lib_manifest, basic_manifest, project, registry::Package, rustc_host, Project,
basic_lib_manifest, basic_manifest, is_coarse_mtime, project, registry::Package, rustc_host,
Project,
};

#[test]
Expand Down Expand Up @@ -212,6 +213,14 @@ fn metabuild_lib_name() {

#[test]
fn metabuild_fresh() {
if is_coarse_mtime() {
// This test doesn't work on coarse mtimes very well. Because the
// metabuild script is created at build time, its mtime is almost
// always equal to the mtime of the output. The second call to `build`
// will then think it needs to be rebuilt when it should be fresh.
return;
}

// Check that rebuild is fresh.
let p = project()
.file(
Expand Down
22 changes: 21 additions & 1 deletion tests/testsuite/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ use std::os;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use std::str;
use std::time::Duration;
use std::time::{self, Duration};
use std::usize;

use cargo;
use cargo::util::{CargoResult, ProcessBuilder, ProcessError, Rustc};
use filetime;
use serde_json::{self, Value};
use url::Url;

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

let past = time::SystemTime::now() - Duration::new(1, 0);
let ftime = filetime::FileTime::from_system_time(past);

for file in self.files.iter() {
file.mk();
if is_coarse_mtime() {
// Place the entire project 1 second in the past to ensure
// that if cargo is called multiple times, the 2nd call will
// see targets as "fresh". Without this, if cargo finishes in
// under 1 second, the second call will see the mtime of
// source == mtime of output and consider it dirty.
filetime::set_file_times(&file.path, ftime, ftime).unwrap();
}
}

for symlink in self.symlinks.iter() {
Expand Down Expand Up @@ -1510,3 +1522,11 @@ pub fn git_process(s: &str) -> ProcessBuilder {
pub fn sleep_ms(ms: u64) {
::std::thread::sleep(Duration::from_millis(ms));
}

/// Returns true if the local filesystem has low-resolution mtimes.
pub fn is_coarse_mtime() -> bool {
// This should actually be a test that $CARGO_TARGET_DIR is on an HFS
// filesystem, (or any filesystem with low-resolution mtimes). However,
// that's tricky to detect, so for now just deal with CI.
cfg!(target_os = "macos") && env::var("CI").is_ok()
}

0 comments on commit 90a3c7d

Please sign in to comment.