Skip to content

Fix slow MacOS Travis issue. #6254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}