From 51a8206c38601402fe739f1553f40af7f038001d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 24 Jul 2019 21:48:15 -0700 Subject: [PATCH] Be more consistent about detecting CI. --- crates/resolver-tests/tests/resolve.rs | 4 ++-- src/cargo/util/mod.rs | 5 +++++ src/cargo/util/progress.rs | 4 ++-- tests/testsuite/support/mod.rs | 10 +++++++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/resolver-tests/tests/resolve.rs b/crates/resolver-tests/tests/resolve.rs index 1fd59d3c149..0c6512186d7 100644 --- a/crates/resolver-tests/tests/resolve.rs +++ b/crates/resolver-tests/tests/resolve.rs @@ -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, @@ -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 { diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index a8806f577e5..50fbd8c2b1b 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -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() +} diff --git a/src/cargo/util/progress.rs b/src/cargo/util/progress.rs index 69b9aad0fb5..42a6f162f6b 100644 --- a/src/cargo/util/progress.rs +++ b/src/cargo/util/progress.rs @@ -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; @@ -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 }; } diff --git a/tests/testsuite/support/mod.rs b/tests/testsuite/support/mod.rs index 05094af819f..01abfdba550 100644 --- a/tests/testsuite/support/mod.rs +++ b/tests/testsuite/support/mod.rs @@ -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; @@ -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( @@ -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. @@ -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");