Skip to content

Commit 51a8206

Browse files
committed
Be more consistent about detecting CI.
1 parent 4f6553a commit 51a8206

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

crates/resolver-tests/tests/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::env;
22

33
use cargo::core::dependency::Kind;
44
use cargo::core::{enable_nightly_features, Dependency};
5-
use cargo::util::Config;
5+
use cargo::util::{is_ci, Config};
66

77
use resolver_tests::{
88
assert_contains, assert_same, dep, dep_kind, dep_loc, dep_req, dep_req_kind, loc_names, names,
@@ -22,7 +22,7 @@ use proptest::prelude::*;
2222
proptest! {
2323
#![proptest_config(ProptestConfig {
2424
max_shrink_iters:
25-
if env::var("CI").is_ok() || !atty::is(atty::Stream::Stderr) {
25+
if is_ci() || !atty::is(atty::Stream::Stderr) {
2626
// This attempts to make sure that CI will fail fast,
2727
0
2828
} else {

src/cargo/util/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,8 @@ pub fn validate_package_name(name: &str, what: &str, help: &str) -> CargoResult<
8282
}
8383
Ok(())
8484
}
85+
86+
/// Whether or not this running in a Continuous Integration environment.
87+
pub fn is_ci() -> bool {
88+
std::env::var("CI").is_ok() || std::env::var("TF_BUILD").is_ok()
89+
}

src/cargo/util/progress.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::env;
33
use std::time::{Duration, Instant};
44

55
use crate::core::shell::Verbosity;
6-
use crate::util::{CargoResult, Config};
6+
use crate::util::{is_ci, CargoResult, Config};
77

88
use unicode_width::UnicodeWidthChar;
99

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

tests/testsuite/support/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ use std::time::{self, Duration};
118118
use std::usize;
119119

120120
use cargo;
121-
use cargo::util::{CargoResult, ProcessBuilder, ProcessError, Rustc};
121+
use cargo::util::{is_ci, CargoResult, ProcessBuilder, ProcessError, Rustc};
122122
use filetime;
123123
use serde_json::{self, Value};
124124
use url::Url;
@@ -855,7 +855,7 @@ impl Execs {
855855
fn match_process(&self, process: &ProcessBuilder) -> MatchResult {
856856
println!("running {}", process);
857857
let res = if self.stream_output {
858-
if env::var("CI").is_ok() {
858+
if is_ci() {
859859
panic!("`.stream()` is for local debugging")
860860
}
861861
process.exec_with_streaming(
@@ -1746,7 +1746,7 @@ pub fn is_coarse_mtime() -> bool {
17461746
// This should actually be a test that `$CARGO_TARGET_DIR` is on an HFS
17471747
// filesystem, (or any filesystem with low-resolution mtimes). However,
17481748
// that's tricky to detect, so for now just deal with CI.
1749-
cfg!(target_os = "macos") && (env::var("CI").is_ok() || env::var("TF_BUILD").is_ok())
1749+
cfg!(target_os = "macos") && is_ci()
17501750
}
17511751

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

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

0 commit comments

Comments
 (0)