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 14, 2024
1 parent 8cffb47 commit e05789c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::core::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
use crate::core::config::flags::get_completion;
use crate::core::config::flags::Subcommand;
use crate::core::config::TargetSelection;
use crate::utils::exec::{command, BootstrapCommand};
use crate::utils::exec::{command, force_coloring_in_ci, BootstrapCommand};
use crate::utils::helpers::{
self, add_link_lib_path, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var,
linker_args, linker_flags, t, target_supports_cranelift_backend, up_to_date, LldThreads,
Expand Down Expand Up @@ -2096,8 +2096,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
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());
force_coloring_in_ci(builder.ci_env, &mut cmd);

#[cfg(feature = "build-metrics")]
builder.metrics.begin_test_suite(
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::utils::helpers::{check_cfg_arg, libdir, linker_flags, t, LldThreads};
use crate::EXTRA_CHECK_CFGS;
use crate::{Build, CLang, Crate, DocTests, GitRepo, Mode};

use crate::utils::exec::{command, BootstrapCommand};
use crate::utils::exec::{command, force_coloring_in_ci, BootstrapCommand};
pub use crate::Compiler;

use clap::ValueEnum;
Expand Down 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());
force_coloring_in_ci(self.ci_env, &mut cargo);

// 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 @@ -286,3 +287,15 @@ impl From<Output> for CommandOutput {
}
}
}

/// If in a CI environment, forces the command to run with colors.
pub fn force_coloring_in_ci(ci_env: CiEnv, cmd: &mut BootstrapCommand) {
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.
cmd.env("TERM", "xterm").args(["--color", "always"]);
}
}
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 e05789c

Please sign in to comment.