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.
This commit is contained in:
Jonas Schievink 2020-11-15 13:39:45 +01:00 committed by GitHub
commit e0c378a673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 2 deletions

View File

@ -19,7 +19,7 @@ use crate::compile;
use crate::config::TargetSelection;
use crate::dist;
use crate::doc;
use crate::flags::Subcommand;
use crate::flags::{Color, Subcommand};
use crate::install;
use crate::native;
use crate::run;
@ -811,6 +811,16 @@ impl<'a> Builder<'a> {
cargo.env("REAL_LIBRARY_PATH", e);
}
match self.build.config.color {
Color::Always => {
cargo.arg("--color=always");
}
Color::Never => {
cargo.arg("--color=never");
}
Color::Auto => {} // nothing to do
}
if cmd != "install" {
cargo.arg("--target").arg(target.rustc_target_arg());
} else {

View File

@ -13,8 +13,8 @@ use std::path::{Path, PathBuf};
use std::str::FromStr;
use crate::cache::{Interned, INTERNER};
use crate::flags::Flags;
pub use crate::flags::Subcommand;
use crate::flags::{Color, Flags};
use crate::util::exe;
use build_helper::t;
use merge::Merge;
@ -67,6 +67,7 @@ pub struct Config {
pub json_output: bool,
pub test_compare_mode: bool,
pub llvm_libunwind: Option<LlvmLibunwind>,
pub color: Color,
pub on_fail: Option<String>,
pub stage: u32,
@ -577,6 +578,7 @@ impl Config {
config.keep_stage = flags.keep_stage;
config.keep_stage_std = flags.keep_stage_std;
config.bindir = "bin".into(); // default
config.color = flags.color;
if let Some(value) = flags.deny_warnings {
config.deny_warnings = value;
}

View File

@ -15,6 +15,31 @@ use crate::config::{Config, TargetSelection};
use crate::setup::Profile;
use crate::{Build, DocTests};
pub enum Color {
Always,
Never,
Auto,
}
impl Default for Color {
fn default() -> Self {
Self::Auto
}
}
impl std::str::FromStr for Color {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"always" => Ok(Self::Always),
"never" => Ok(Self::Never),
"auto" => Ok(Self::Auto),
_ => Err(()),
}
}
}
/// Deserialized version of all flags for this compile.
pub struct Flags {
pub verbose: usize, // number of -v args; each extra -v after the first is passed to Cargo
@ -34,6 +59,7 @@ pub struct Flags {
pub rustc_error_format: Option<String>,
pub json_output: bool,
pub dry_run: bool,
pub color: Color,
// This overrides the deny-warnings configuration option,
// which passes -Dwarnings to the compiler invocations.
@ -184,6 +210,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
);
opts.optopt("", "error-format", "rustc error format", "FORMAT");
opts.optflag("", "json-output", "use message-format=json");
opts.optopt("", "color", "whether to use color in cargo and rustc output", "STYLE");
opts.optopt(
"",
"llvm-skip-rebuild",
@ -644,6 +671,9 @@ Arguments:
llvm_skip_rebuild: matches.opt_str("llvm-skip-rebuild").map(|s| s.to_lowercase()).map(
|s| s.parse::<bool>().expect("`llvm-skip-rebuild` should be either true or false"),
),
color: matches
.opt_get_default("color", Color::Auto)
.expect("`color` should be `always`, `never`, or `auto`"),
}
}
}