Skip to content

Commit e0c378a

Browse files
Rollup merge of #79004 - jyn514:bacon, r=Mark-Simulacrum
Add `--color` support to bootstrap When running under external utilities which wrap x.py, it can be convenient to force color support on.
2 parents 8825942 + 31741aa commit e0c378a

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

src/bootstrap/builder.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::compile;
1919
use crate::config::TargetSelection;
2020
use crate::dist;
2121
use crate::doc;
22-
use crate::flags::Subcommand;
22+
use crate::flags::{Color, Subcommand};
2323
use crate::install;
2424
use crate::native;
2525
use crate::run;
@@ -811,6 +811,16 @@ impl<'a> Builder<'a> {
811811
cargo.env("REAL_LIBRARY_PATH", e);
812812
}
813813

814+
match self.build.config.color {
815+
Color::Always => {
816+
cargo.arg("--color=always");
817+
}
818+
Color::Never => {
819+
cargo.arg("--color=never");
820+
}
821+
Color::Auto => {} // nothing to do
822+
}
823+
814824
if cmd != "install" {
815825
cargo.arg("--target").arg(target.rustc_target_arg());
816826
} else {

src/bootstrap/config.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use std::path::{Path, PathBuf};
1313
use std::str::FromStr;
1414

1515
use crate::cache::{Interned, INTERNER};
16-
use crate::flags::Flags;
1716
pub use crate::flags::Subcommand;
17+
use crate::flags::{Color, Flags};
1818
use crate::util::exe;
1919
use build_helper::t;
2020
use merge::Merge;
@@ -67,6 +67,7 @@ pub struct Config {
6767
pub json_output: bool,
6868
pub test_compare_mode: bool,
6969
pub llvm_libunwind: Option<LlvmLibunwind>,
70+
pub color: Color,
7071

7172
pub on_fail: Option<String>,
7273
pub stage: u32,
@@ -577,6 +578,7 @@ impl Config {
577578
config.keep_stage = flags.keep_stage;
578579
config.keep_stage_std = flags.keep_stage_std;
579580
config.bindir = "bin".into(); // default
581+
config.color = flags.color;
580582
if let Some(value) = flags.deny_warnings {
581583
config.deny_warnings = value;
582584
}

src/bootstrap/flags.rs

+30
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,31 @@ use crate::config::{Config, TargetSelection};
1515
use crate::setup::Profile;
1616
use crate::{Build, DocTests};
1717

18+
pub enum Color {
19+
Always,
20+
Never,
21+
Auto,
22+
}
23+
24+
impl Default for Color {
25+
fn default() -> Self {
26+
Self::Auto
27+
}
28+
}
29+
30+
impl std::str::FromStr for Color {
31+
type Err = ();
32+
33+
fn from_str(s: &str) -> Result<Self, Self::Err> {
34+
match s.to_lowercase().as_str() {
35+
"always" => Ok(Self::Always),
36+
"never" => Ok(Self::Never),
37+
"auto" => Ok(Self::Auto),
38+
_ => Err(()),
39+
}
40+
}
41+
}
42+
1843
/// Deserialized version of all flags for this compile.
1944
pub struct Flags {
2045
pub verbose: usize, // number of -v args; each extra -v after the first is passed to Cargo
@@ -34,6 +59,7 @@ pub struct Flags {
3459
pub rustc_error_format: Option<String>,
3560
pub json_output: bool,
3661
pub dry_run: bool,
62+
pub color: Color,
3763

3864
// This overrides the deny-warnings configuration option,
3965
// which passes -Dwarnings to the compiler invocations.
@@ -184,6 +210,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
184210
);
185211
opts.optopt("", "error-format", "rustc error format", "FORMAT");
186212
opts.optflag("", "json-output", "use message-format=json");
213+
opts.optopt("", "color", "whether to use color in cargo and rustc output", "STYLE");
187214
opts.optopt(
188215
"",
189216
"llvm-skip-rebuild",
@@ -644,6 +671,9 @@ Arguments:
644671
llvm_skip_rebuild: matches.opt_str("llvm-skip-rebuild").map(|s| s.to_lowercase()).map(
645672
|s| s.parse::<bool>().expect("`llvm-skip-rebuild` should be either true or false"),
646673
),
674+
color: matches
675+
.opt_get_default("color", Color::Auto)
676+
.expect("`color` should be `always`, `never`, or `auto`"),
647677
}
648678
}
649679
}

0 commit comments

Comments
 (0)