Skip to content

Commit

Permalink
Rollup merge of #79004 - jyn514:bacon, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Add `--color` support to bootstrap

When running under external utilities which wrap x.py, it can be convenient to force color support on.
  • Loading branch information
jonas-schievink authored Nov 15, 2020
2 parents 8825942 + 31741aa commit e0c378a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
30 changes: 30 additions & 0 deletions src/bootstrap/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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`"),
}
}
}
Expand Down

0 comments on commit e0c378a

Please sign in to comment.