Skip to content

Commit e05789c

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 e05789c

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::core::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
2525
use crate::core::config::flags::get_completion;
2626
use crate::core::config::flags::Subcommand;
2727
use crate::core::config::TargetSelection;
28-
use crate::utils::exec::{command, BootstrapCommand};
28+
use crate::utils::exec::{command, force_coloring_in_ci, BootstrapCommand};
2929
use crate::utils::helpers::{
3030
self, add_link_lib_path, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var,
3131
linker_args, linker_flags, t, target_supports_cranelift_backend, up_to_date, LldThreads,
@@ -2096,8 +2096,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
20962096
cmd.arg("--git-repository").arg(git_config.git_repository);
20972097
cmd.arg("--nightly-branch").arg(git_config.nightly_branch);
20982098

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());
2099+
force_coloring_in_ci(builder.ci_env, &mut cmd);
21012100

21022101
#[cfg(feature = "build-metrics")]
21032102
builder.metrics.begin_test_suite(

src/bootstrap/src/core/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::utils::helpers::{check_cfg_arg, libdir, linker_flags, t, LldThreads};
2424
use crate::EXTRA_CHECK_CFGS;
2525
use crate::{Build, CLang, Crate, DocTests, GitRepo, Mode};
2626

27-
use crate::utils::exec::{command, BootstrapCommand};
27+
use crate::utils::exec::{command, force_coloring_in_ci, BootstrapCommand};
2828
pub use crate::Compiler;
2929

3030
use clap::ValueEnum;
@@ -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+
force_coloring_in_ci(self.ci_env, &mut cargo);
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};
@@ -286,3 +287,15 @@ impl From<Output> for CommandOutput {
286287
}
287288
}
288289
}
290+
291+
/// If in a CI environment, forces the command to run with colors.
292+
pub fn force_coloring_in_ci(ci_env: CiEnv, cmd: &mut BootstrapCommand) {
293+
if ci_env != CiEnv::None {
294+
// Due to use of stamp/docker, the output stream of bootstrap is not
295+
// a TTY in CI, so coloring is by-default turned off.
296+
// The explicit `TERM=xterm` environment is needed for
297+
// `--color always` to actually work. This env var was lost when
298+
// compiling through the Makefile. Very strange.
299+
cmd.env("TERM", "xterm").args(["--color", "always"]);
300+
}
301+
}

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)