Skip to content

Commit

Permalink
Be more consistent about detecting CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Jul 25, 2019
1 parent 4f6553a commit 51a8206
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions crates/resolver-tests/tests/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;

use cargo::core::dependency::Kind;
use cargo::core::{enable_nightly_features, Dependency};
use cargo::util::Config;
use cargo::util::{is_ci, Config};

use resolver_tests::{
assert_contains, assert_same, dep, dep_kind, dep_loc, dep_req, dep_req_kind, loc_names, names,
Expand All @@ -22,7 +22,7 @@ use proptest::prelude::*;
proptest! {
#![proptest_config(ProptestConfig {
max_shrink_iters:
if env::var("CI").is_ok() || !atty::is(atty::Stream::Stderr) {
if is_ci() || !atty::is(atty::Stream::Stderr) {
// This attempts to make sure that CI will fail fast,
0
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ pub fn validate_package_name(name: &str, what: &str, help: &str) -> CargoResult<
}
Ok(())
}

/// Whether or not this running in a Continuous Integration environment.
pub fn is_ci() -> bool {
std::env::var("CI").is_ok() || std::env::var("TF_BUILD").is_ok()
}
4 changes: 2 additions & 2 deletions src/cargo/util/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::env;
use std::time::{Duration, Instant};

use crate::core::shell::Verbosity;
use crate::util::{CargoResult, Config};
use crate::util::{is_ci, CargoResult, Config};

use unicode_width::UnicodeWidthChar;

Expand Down Expand Up @@ -45,7 +45,7 @@ impl<'cfg> Progress<'cfg> {
Ok(term) => term == "dumb",
Err(_) => false,
};
if cfg.shell().verbosity() == Verbosity::Quiet || dumb || env::var("CI").is_ok() {
if cfg.shell().verbosity() == Verbosity::Quiet || dumb || is_ci() {
return Progress { state: None };
}

Expand Down
10 changes: 7 additions & 3 deletions tests/testsuite/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ use std::time::{self, Duration};
use std::usize;

use cargo;
use cargo::util::{CargoResult, ProcessBuilder, ProcessError, Rustc};
use cargo::util::{is_ci, CargoResult, ProcessBuilder, ProcessError, Rustc};
use filetime;
use serde_json::{self, Value};
use url::Url;
Expand Down Expand Up @@ -855,7 +855,7 @@ impl Execs {
fn match_process(&self, process: &ProcessBuilder) -> MatchResult {
println!("running {}", process);
let res = if self.stream_output {
if env::var("CI").is_ok() {
if is_ci() {
panic!("`.stream()` is for local debugging")
}
process.exec_with_streaming(
Expand Down Expand Up @@ -1746,7 +1746,7 @@ 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() || env::var("TF_BUILD").is_ok())
cfg!(target_os = "macos") && is_ci()
}

/// Some CI setups are much slower then the equipment used by Cargo itself.
Expand All @@ -1772,6 +1772,10 @@ pub fn clippy_is_available() -> bool {

#[cfg(windows)]
pub fn symlink_supported() -> bool {
if is_ci() {
// We want to be absolutely sure this runs on CI.
return true;
}
let src = paths::root().join("symlink_src");
fs::write(&src, "").unwrap();
let dst = paths::root().join("symlink_dst");
Expand Down

0 comments on commit 51a8206

Please sign in to comment.