Skip to content

Commit

Permalink
Move force_coloring_in_ci from builder_helper to bootstrap
Browse files Browse the repository at this point in the history
It was only used in bootstrap. This move allows us to modify the function to work with `BootstrapCommand`, rather than `Command`.
  • Loading branch information
Kobzol committed Jul 15, 2024
1 parent 8cffb47 commit ff9c488
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
4 changes: 1 addition & 3 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2095,9 +2095,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
let git_config = builder.config.git_config();
cmd.arg("--git-repository").arg(git_config.git_repository);
cmd.arg("--nightly-branch").arg(git_config.nightly_branch);

// FIXME: Move CiEnv back to bootstrap, it is only used here anyway
builder.ci_env.force_coloring_in_ci(cmd.as_command_mut());
cmd.force_coloring_in_ci(builder.ci_env);

#[cfg(feature = "build-metrics")]
builder.metrics.begin_test_suite(
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,7 @@ impl<'a> Builder<'a> {
// Try to use a sysroot-relative bindir, in case it was configured absolutely.
cargo.env("RUSTC_INSTALL_BINDIR", self.config.bindir_relative());

self.ci_env.force_coloring_in_ci(cargo.as_command_mut());
cargo.force_coloring_in_ci(self.ci_env);

// When we build Rust dylibs they're all intended for intermediate
// usage, so make sure we pass the -Cprefer-dynamic flag instead of
Expand Down
13 changes: 13 additions & 0 deletions src/bootstrap/src/utils/exec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::Build;
use build_helper::ci::CiEnv;
use build_helper::drop_bomb::DropBomb;
use std::ffi::OsStr;
use std::fmt::{Debug, Formatter};
Expand Down Expand Up @@ -171,6 +172,18 @@ impl BootstrapCommand {
pub fn get_created_location(&self) -> std::panic::Location<'static> {
self.drop_bomb.get_created_location()
}

/// If in a CI environment, forces the command to run with colors.
pub fn force_coloring_in_ci(&mut self, ci_env: CiEnv) {
if ci_env != CiEnv::None {
// Due to use of stamp/docker, the output stream of bootstrap is not
// a TTY in CI, so coloring is by-default turned off.
// The explicit `TERM=xterm` environment is needed for
// `--color always` to actually work. This env var was lost when
// compiling through the Makefile. Very strange.
self.env("TERM", "xterm").args(["--color", "always"]);
}
}
}

impl Debug for BootstrapCommand {
Expand Down
14 changes: 0 additions & 14 deletions src/tools/build_helper/src/ci.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::process::Command;

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum CiEnv {
/// Not a CI environment.
Expand All @@ -21,18 +19,6 @@ impl CiEnv {
pub fn is_ci() -> bool {
Self::current() != CiEnv::None
}

/// If in a CI environment, forces the command to run with colors.
pub fn force_coloring_in_ci(self, cmd: &mut Command) {
if self != CiEnv::None {
// Due to use of stamp/docker, the output stream of bootstrap is not
// a TTY in CI, so coloring is by-default turned off.
// The explicit `TERM=xterm` environment is needed for
// `--color always` to actually work. This env var was lost when
// compiling through the Makefile. Very strange.
cmd.env("TERM", "xterm").args(&["--color", "always"]);
}
}
}

pub mod gha {
Expand Down

0 comments on commit ff9c488

Please sign in to comment.