Skip to content

Commit

Permalink
Don't add --color when --json is passed to rustc. fixes mozilla#488
Browse files Browse the repository at this point in the history
  • Loading branch information
chmanchester committed Aug 5, 2019
1 parent 01a59a5 commit b6ea0f7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ pub struct ParsedArguments {
emit: HashSet<String>,
/// The value of any `--color` option passed on the commandline.
color_mode: ColorMode,
/// Whether `--json` was passed to this invocation.
has_json: bool,
}

/// A struct on which to hang a `Compilation` impl.
Expand Down Expand Up @@ -675,6 +677,7 @@ ArgData!{
Emit(String),
Extern(ArgExtern),
Color(String),
Json(String),
CrateName(String),
CrateType(ArgCrateTypes),
OutDir(PathBuf),
Expand All @@ -693,6 +696,7 @@ counted_array!(static ARGS: [ArgInfo<ArgData>; _] = [
take_arg!("--cfg", OsString, CanBeSeparated('='), PassThrough),
take_arg!("--codegen", ArgCodegen, CanBeSeparated('='), CodeGen),
take_arg!("--color", String, CanBeSeparated('='), Color),
take_arg!("--json", String, CanBeSeparated('='), Json),
take_arg!("--crate-name", String, CanBeSeparated('='), CrateName),
take_arg!("--crate-type", ArgCrateTypes, CanBeSeparated('='), CrateType),
take_arg!("--deny", OsString, CanBeSeparated('='), PassThrough),
Expand Down Expand Up @@ -738,6 +742,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
let mut static_lib_names = vec![];
let mut static_link_paths: Vec<PathBuf> = vec![];
let mut color_mode = ColorMode::Auto;
let mut has_json = false;

for arg in ArgsIter::new(arguments.iter().map(|s| s.clone()), &ARGS[..]) {
let arg = try_or_cannot_cache!(arg, "argument parse");
Expand Down Expand Up @@ -811,6 +816,9 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
_ => ColorMode::Auto,
};
}
Some(Json(_)) => {
has_json = true;
}
Some(PassThrough(_)) => (),
Some(Target(target)) => {
match target {
Expand Down Expand Up @@ -917,6 +925,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
dep_info: dep_info.map(|s| s.into()),
emit,
color_mode,
has_json,
})
}

Expand Down Expand Up @@ -950,6 +959,7 @@ impl<T> CompilerHasher<T> for RustHasher
dep_info,
emit,
color_mode: _,
has_json,
},
} = me;
trace!("[{}]: generate_hash_key", crate_name);
Expand Down Expand Up @@ -1100,8 +1110,12 @@ impl<T> CompilerHasher<T> for RustHasher
None
};
let mut arguments = arguments;
// Always request color output, the client will strip colors if needed.
arguments.push(Argument::WithValue("--color", ArgData::Color("always".into()), ArgDisposition::Separated));
// Request color output unless json was requested. The client will strip colors if needed.
if !has_json {
arguments.push(Argument::WithValue("--color", ArgData::Color("always".into()),
ArgDisposition::Separated));
}

let inputs = source_files.into_iter().chain(abs_externs).chain(abs_staticlibs).collect();

HashResult {
Expand Down

0 comments on commit b6ea0f7

Please # to comment.