Skip to content

Commit f1c783b

Browse files
committed
Always forward --color to rustc and rustdoc.
This prepares us for capturing output from these compilers.
1 parent d079551 commit f1c783b

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
580580
rustdoc.arg("--crate-name").arg(&unit.target.crate_name());
581581
add_path_args(bcx, unit, &mut rustdoc);
582582
add_cap_lints(bcx, unit, &mut rustdoc);
583+
add_color(bcx, &mut rustdoc);
583584

584585
if unit.kind != Kind::Host {
585586
if let Some(ref target) = bcx.build_config.requested_target {
@@ -672,6 +673,15 @@ fn add_cap_lints(bcx: &BuildContext, unit: &Unit, cmd: &mut ProcessBuilder) {
672673
}
673674
}
674675

676+
fn add_color(bcx: &BuildContext, cmd: &mut ProcessBuilder) {
677+
let capture_output = bcx.config.cli_unstable().compile_progress;
678+
let shell = bcx.config.shell();
679+
if capture_output || shell.color_choice() != ColorChoice::CargoAuto {
680+
let color = if shell.supports_color() { "always" } else { "never" };
681+
cmd.args(&["--color", color]);
682+
}
683+
}
684+
675685
fn build_base_args<'a, 'cfg>(
676686
cx: &mut Context<'a, 'cfg>,
677687
cmd: &mut ProcessBuilder,
@@ -696,17 +706,8 @@ fn build_base_args<'a, 'cfg>(
696706

697707
cmd.arg("--crate-name").arg(&unit.target.crate_name());
698708

699-
add_path_args(&cx.bcx, unit, cmd);
700-
701-
match bcx.config.shell().color_choice() {
702-
ColorChoice::Always => {
703-
cmd.arg("--color").arg("always");
704-
}
705-
ColorChoice::Never => {
706-
cmd.arg("--color").arg("never");
707-
}
708-
ColorChoice::CargoAuto => {}
709-
}
709+
add_path_args(bcx, unit, cmd);
710+
add_color(bcx, cmd);
710711

711712
if bcx.build_config.json_messages() {
712713
cmd.arg("--error-format").arg("json");

src/cargo/core/shell.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ impl Shell {
231231
ShellOut::Write(_) => ColorChoice::Never,
232232
}
233233
}
234+
235+
/// Whether the shell supports color.
236+
pub fn supports_color(&self) -> bool {
237+
match &self.err {
238+
ShellOut::Write(_) => false,
239+
ShellOut::Stream { stream, .. } => stream.supports_color(),
240+
}
241+
}
234242
}
235243

236244
impl Default for Shell {

0 commit comments

Comments
 (0)