Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate --color option to rustc #2779

Merged
merged 1 commit into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/cargo/core/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ pub enum ColorConfig {
Never
}

impl fmt::Display for ColorConfig {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
ColorConfig::Auto => "auto",
ColorConfig::Always => "always",
ColorConfig::Never => "never",
}.fmt(f)
}
}

#[derive(Clone, Copy)]
pub struct ShellConfig {
pub color_config: ColorConfig,
Expand Down Expand Up @@ -129,6 +139,11 @@ impl MultiShell {
pub fn get_verbose(&self) -> Verbosity {
self.verbosity
}

pub fn color_config(&self) -> ColorConfig {
assert!(self.out.config.color_config == self.err.config.color_config);
self.out.config.color_config
}
}

impl Shell {
Expand Down
6 changes: 6 additions & 0 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::Arc;

use core::{Package, PackageId, PackageSet, Target, Resolve};
use core::{Profile, Profiles};
use core::shell::ColorConfig;
use util::{self, CargoResult, human};
use util::{Config, internal, ChainError, profile, join_paths};

Expand Down Expand Up @@ -461,6 +462,11 @@ fn build_base_args(cx: &Context,

cmd.arg(&root_path(cx, unit));

let color_config = cx.config.shell().color_config();
if color_config != ColorConfig::Auto {
cmd.arg("--color").arg(&color_config.to_string());
}

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

for crate_type in crate_types.iter() {
Expand Down
28 changes: 28 additions & 0 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2212,3 +2212,31 @@ fn panic_abort_compiles_with_panic_abort() {
execs().with_status(0)
.with_stderr_contains("[..] -C panic=abort [..]"));
}

#[test]
fn explicit_color_config_is_propagated_to_rustc() {
let mut p = project("foo");
p = p
.file("Cargo.toml", r#"
[package]

name = "test"
version = "0.0.0"
authors = []
"#)
.file("src/lib.rs", "");

assert_that(p.cargo_process("build").arg("-v").arg("--color").arg("always"),
execs().with_status(0).with_stderr_contains(
"[..]rustc src[..]lib.rs --color always[..]"));

assert_that(p.cargo_process("build").arg("-v").arg("--color").arg("never"),
execs().with_status(0).with_stderr("\
[COMPILING] test v0.0.0 ([..])
[RUNNING] `rustc src[..]lib.rs --color never --crate-name test --crate-type lib -g \
--out-dir [..]target[..]debug \
--emit=dep-info,link \
-L dependency=[..]target[..]debug \
-L dependency=[..]target[..]debug[..]deps`
"));
}