]> git.proxmox.com Git - rustc.git/blob - src/tools/build_helper/src/ci.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / src / tools / build_helper / src / ci.rs
1 use std::process::Command;
2
3 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
4 pub enum CiEnv {
5 /// Not a CI environment.
6 None,
7 /// The Azure Pipelines environment, for Linux (including Docker), Windows, and macOS builds.
8 AzurePipelines,
9 /// The GitHub Actions environment, for Linux (including Docker), Windows and macOS builds.
10 GitHubActions,
11 }
12
13 impl CiEnv {
14 /// Obtains the current CI environment.
15 pub fn current() -> CiEnv {
16 if std::env::var("TF_BUILD").map_or(false, |e| e == "True") {
17 CiEnv::AzurePipelines
18 } else if std::env::var("GITHUB_ACTIONS").map_or(false, |e| e == "true") {
19 CiEnv::GitHubActions
20 } else {
21 CiEnv::None
22 }
23 }
24
25 pub fn is_ci() -> bool {
26 Self::current() != CiEnv::None
27 }
28
29 /// If in a CI environment, forces the command to run with colors.
30 pub fn force_coloring_in_ci(self, cmd: &mut Command) {
31 if self != CiEnv::None {
32 // Due to use of stamp/docker, the output stream of rustbuild is not
33 // a TTY in CI, so coloring is by-default turned off.
34 // The explicit `TERM=xterm` environment is needed for
35 // `--color always` to actually work. This env var was lost when
36 // compiling through the Makefile. Very strange.
37 cmd.env("TERM", "xterm").args(&["--color", "always"]);
38 }
39 }
40 }