Skip to content

Commit 9fd68c9

Browse files
committed
Add colors
1 parent cbd1b0b commit 9fd68c9

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ dependencies = [
183183
"pretty_assertions",
184184
"serde",
185185
"serde_json",
186+
"termcolor",
186187
"time",
187188
"toml",
188189
"winapi 0.3.9",

src/bootstrap/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ time = "0.1"
5050
ignore = "0.4.10"
5151
opener = "0.4"
5252
merge = "0.1.0"
53+
termcolor = "1.0"
5354

5455
[target.'cfg(windows)'.dependencies.winapi]
5556
version = "0.3"

src/bootstrap/builder.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::time::{Duration, Instant};
1414

1515
use build_helper::{output, t};
1616
use lazy_static::lazy_static;
17+
use termcolor::{ColorSpec, WriteColor};
1718

1819
use crate::cache::{Cache, Interned, INTERNER};
1920
use crate::check;
@@ -1562,6 +1563,7 @@ impl<'a> Builder<'a> {
15621563
let paths = S::should_run(ShouldRun::new(self)).paths;
15631564
let path = paths.iter().map(|pathset| pathset.path(self)).next();
15641565
let instructions = ReplicationStep {
1566+
color: self.build.config.color,
15651567
name: step.name(),
15661568
cmd: self.kind,
15671569
path: path.expect("no paths for step"),
@@ -1600,6 +1602,7 @@ impl<'a> Builder<'a> {
16001602
}
16011603

16021604
struct ReplicationStep {
1605+
color: Color,
16031606
cmd: Kind,
16041607
name: &'static str,
16051608
path: PathBuf,
@@ -1610,11 +1613,26 @@ lazy_static! {
16101613
}
16111614

16121615
pub(crate) extern "C" fn print_replication_steps() {
1616+
use std::io::Write;
16131617
if let Some(step) = CURRENT_INSTRUCTIONS.lock().expect("mutex guard is dropped on panic").take()
16141618
{
1615-
println!("note: failed while building {}", step.name);
1616-
println!(
1617-
"help: to replicate this failure, run `./x.py {} {}`",
1619+
let mut stdout = termcolor::StandardStream::stdout(step.color.into());
1620+
// ignore errors; we're exiting anyway
1621+
let mut yellow = ColorSpec::new();
1622+
yellow.set_fg(Some(termcolor::Color::Yellow));
1623+
let _ = stdout.set_color(&yellow);
1624+
let _ = write!(stdout, "note");
1625+
let _ = stdout.reset();
1626+
let _ = writeln!(stdout, ": failed while building {}", step.name);
1627+
1628+
let mut blue = ColorSpec::new();
1629+
blue.set_fg(Some(termcolor::Color::Blue));
1630+
let _ = stdout.set_color(&blue);
1631+
let _ = write!(stdout, "help");
1632+
let _ = stdout.reset();
1633+
let _ = writeln!(
1634+
stdout,
1635+
": to replicate this failure, run `./x.py {} {}`",
16181636
step.cmd,
16191637
step.path.display()
16201638
);

src/bootstrap/flags.rs

+12
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use std::process;
99

1010
use build_helper::t;
1111
use getopts::Options;
12+
use termcolor::ColorChoice;
1213

1314
use crate::builder::Builder;
1415
use crate::config::{Config, TargetSelection};
1516
use crate::setup::Profile;
1617
use crate::{Build, DocTests};
1718

19+
#[derive(Copy, Clone)]
1820
pub enum Color {
1921
Always,
2022
Never,
@@ -27,6 +29,16 @@ impl Default for Color {
2729
}
2830
}
2931

32+
impl From<Color> for ColorChoice {
33+
fn from(c: Color) -> Self {
34+
match c {
35+
Color::Always => ColorChoice::Always,
36+
Color::Never => ColorChoice::Never,
37+
Color::Auto => ColorChoice::Auto,
38+
}
39+
}
40+
}
41+
3042
impl std::str::FromStr for Color {
3143
type Err = ();
3244

0 commit comments

Comments
 (0)