Skip to content

Commit ff9c488

Browse files
committed
Move force_coloring_in_ci from builder_helper to bootstrap
It was only used in bootstrap. This move allows us to modify the function to work with `BootstrapCommand`, rather than `Command`.
1 parent 8cffb47 commit ff9c488

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

src/bootstrap/src/core/build_steps/test.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2095,9 +2095,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
20952095
let git_config = builder.config.git_config();
20962096
cmd.arg("--git-repository").arg(git_config.git_repository);
20972097
cmd.arg("--nightly-branch").arg(git_config.nightly_branch);
2098-
2099-
// FIXME: Move CiEnv back to bootstrap, it is only used here anyway
2100-
builder.ci_env.force_coloring_in_ci(cmd.as_command_mut());
2098+
cmd.force_coloring_in_ci(builder.ci_env);
21012099

21022100
#[cfg(feature = "build-metrics")]
21032101
builder.metrics.begin_test_suite(

src/bootstrap/src/core/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ impl<'a> Builder<'a> {
21052105
// Try to use a sysroot-relative bindir, in case it was configured absolutely.
21062106
cargo.env("RUSTC_INSTALL_BINDIR", self.config.bindir_relative());
21072107

2108-
self.ci_env.force_coloring_in_ci(cargo.as_command_mut());
2108+
cargo.force_coloring_in_ci(self.ci_env);
21092109

21102110
// When we build Rust dylibs they're all intended for intermediate
21112111
// usage, so make sure we pass the -Cprefer-dynamic flag instead of

src/bootstrap/src/utils/exec.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::Build;
2+
use build_helper::ci::CiEnv;
23
use build_helper::drop_bomb::DropBomb;
34
use std::ffi::OsStr;
45
use std::fmt::{Debug, Formatter};
@@ -171,6 +172,18 @@ impl BootstrapCommand {
171172
pub fn get_created_location(&self) -> std::panic::Location<'static> {
172173
self.drop_bomb.get_created_location()
173174
}
175+
176+
/// If in a CI environment, forces the command to run with colors.
177+
pub fn force_coloring_in_ci(&mut self, ci_env: CiEnv) {
178+
if ci_env != CiEnv::None {
179+
// Due to use of stamp/docker, the output stream of bootstrap is not
180+
// a TTY in CI, so coloring is by-default turned off.
181+
// The explicit `TERM=xterm` environment is needed for
182+
// `--color always` to actually work. This env var was lost when
183+
// compiling through the Makefile. Very strange.
184+
self.env("TERM", "xterm").args(["--color", "always"]);
185+
}
186+
}
174187
}
175188

176189
impl Debug for BootstrapCommand {

src/tools/build_helper/src/ci.rs

-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::process::Command;
2-
31
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
42
pub enum CiEnv {
53
/// Not a CI environment.
@@ -21,18 +19,6 @@ impl CiEnv {
2119
pub fn is_ci() -> bool {
2220
Self::current() != CiEnv::None
2321
}
24-
25-
/// If in a CI environment, forces the command to run with colors.
26-
pub fn force_coloring_in_ci(self, cmd: &mut Command) {
27-
if self != CiEnv::None {
28-
// Due to use of stamp/docker, the output stream of bootstrap is not
29-
// a TTY in CI, so coloring is by-default turned off.
30-
// The explicit `TERM=xterm` environment is needed for
31-
// `--color always` to actually work. This env var was lost when
32-
// compiling through the Makefile. Very strange.
33-
cmd.env("TERM", "xterm").args(&["--color", "always"]);
34-
}
35-
}
3622
}
3723

3824
pub mod gha {

0 commit comments

Comments
 (0)