Bug 1315785 - Invoke cargo with --color=always when original stdout is a TTY; r?glandium draft
authorGregory Szorc <gps@mozilla.com>
Mon, 07 Nov 2016 13:46:15 -0800
changeset 435492 a61a37415e90f13ad79535daab0ea1ea98b1f4a9
parent 435491 51d7cc8c5521fade2297bceb08cfabcdda7900b4
child 536331 58f26d051f810bba2e19ebe8fb48da1b4675c372
push id35066
push userbmo:gps@mozilla.com
push dateTue, 08 Nov 2016 20:22:43 +0000
Bug 1315785 - Invoke cargo with --color=always when original stdout is a TTY; r?glandium Combined with the previous patch that sets MACH_STDOUT_ISATTY, the practical effect of this patch is that cargo is invoked with `--color=always` when mach was attached to a TTY and colorized output is sent to the terminal. Note: this doesn't work with Rust/Cargo 1.10 for reasons unknown to me. It appears there was a bug with Rust/Cargo because `--color=never` still sent colorized output on that version! Cargo/Rust 1.12.1 works fine. MozReview-Commit-ID: 6uXS3t3413i
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -916,16 +916,25 @@ endif
 cargo_build_flags += --frozen
 cargo_build_flags += --manifest-path $(CARGO_FILE)
 cargo_build_flags += --target=$(RUST_TARGET)
 cargo_build_flags += --verbose
+# Enable color output if original stdout was a TTY and color settings
+# aren't already present. This essentially restores the default behavior
+# of cargo when running via `mach`.
+ifeq (,$(findstring --color,$(cargo_build_flags)))
+cargo_build_flags += --color=always
 # Assume any system libraries rustc links against are already in the target's LIBS.
 # We need to run cargo unconditionally, because cargo is the only thing that
 # has full visibility into how changes in Rust sources might affect the final
 # build.
 	env CARGO_TARGET_DIR=. RUSTC=$(RUSTC) $(CARGO) build $(cargo_build_flags) --