diff --git a/src/bin/bench.rs b/src/bin/bench.rs index 1aa82dd9f87..a621e591c62 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -70,7 +70,7 @@ Options: -v, --verbose ... Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json [default: human] + --message-format FMT Error format: human, json, short [default: human] --no-fail-fast Run all benchmarks regardless of failure --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date diff --git a/src/bin/build.rs b/src/bin/build.rs index 883e30db6b1..3b8e4a3aea2 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -68,7 +68,7 @@ Options: -v, --verbose ... Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json [default: human] + --message-format FMT Error format: human, json, short [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date -Z FLAG ... Unstable (nightly-only) flags to Cargo diff --git a/src/bin/check.rs b/src/bin/check.rs index 8a2ab42dd22..2ca217e43eb 100644 --- a/src/bin/check.rs +++ b/src/bin/check.rs @@ -37,7 +37,7 @@ Options: -v, --verbose ... Use verbose output -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json [default: human] + --message-format FMT Error format: human, json, short [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date -Z FLAG ... Unstable (nightly-only) flags to Cargo diff --git a/src/bin/doc.rs b/src/bin/doc.rs index 6e17836963c..2566f4eb5cf 100644 --- a/src/bin/doc.rs +++ b/src/bin/doc.rs @@ -56,7 +56,7 @@ Options: -v, --verbose ... Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json [default: human] + --message-format FMT Error format: human, json, short [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date -Z FLAG ... Unstable (nightly-only) flags to Cargo diff --git a/src/bin/run.rs b/src/bin/run.rs index 21486baf6ea..360b2a2e57d 100644 --- a/src/bin/run.rs +++ b/src/bin/run.rs @@ -49,7 +49,7 @@ Options: -v, --verbose ... Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json [default: human] + --message-format FMT Error format: human, json, short [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date -Z FLAG ... Unstable (nightly-only) flags to Cargo diff --git a/src/bin/rustc.rs b/src/bin/rustc.rs index 747f2ead958..8335c6a9a91 100644 --- a/src/bin/rustc.rs +++ b/src/bin/rustc.rs @@ -67,7 +67,7 @@ Options: -v, --verbose ... Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json [default: human] + --message-format FMT Error format: human, json, short [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date -Z FLAG ... Unstable (nightly-only) flags to Cargo diff --git a/src/bin/rustdoc.rs b/src/bin/rustdoc.rs index 156a6b86796..416523c2f46 100644 --- a/src/bin/rustdoc.rs +++ b/src/bin/rustdoc.rs @@ -65,7 +65,7 @@ Options: -v, --verbose ... Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json [default: human] + --message-format FMT Error format: human, json, short [default: human] --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date -Z FLAG ... Unstable (nightly-only) flags to Cargo diff --git a/src/bin/test.rs b/src/bin/test.rs index a663e06091b..23aa483e836 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -74,7 +74,7 @@ Options: -v, --verbose ... Use verbose output (-vv very verbose/build.rs output) -q, --quiet No output printed to stdout --color WHEN Coloring: auto, always, never - --message-format FMT Error format: human, json [default: human] + --message-format FMT Error format: human, json, short [default: human] --no-fail-fast Run all tests regardless of failure --frozen Require Cargo.lock and cache are up to date --locked Require Cargo.lock is up to date diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index ff8249a60cb..f5e2db9b000 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -101,7 +101,14 @@ pub enum CompileMode { #[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)] pub enum MessageFormat { Human, - Json + Json, + Short, +} + +impl Default for MessageFormat { + fn default() -> Self { + MessageFormat::Human + } } #[derive(Clone, Copy, PartialEq, Eq, Debug)] @@ -306,7 +313,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>, let mut build_config = scrape_build_config(config, jobs, target)?; build_config.release = release; build_config.test = mode == CompileMode::Test || mode == CompileMode::Bench; - build_config.json_messages = message_format == MessageFormat::Json; + build_config.message_format = message_format; if let CompileMode::Doc { deps } = mode { build_config.doc_all = deps; } diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs index ee51b9b3bd0..45ea612dd94 100644 --- a/src/cargo/ops/cargo_rustc/custom_build.rs +++ b/src/cargo/ops/cargo_rustc/custom_build.rs @@ -5,6 +5,7 @@ use std::str; use std::sync::{Mutex, Arc}; use core::PackageId; +use ops::MessageFormat; use util::{Freshness, Cfg}; use util::errors::{CargoResult, CargoResultExt, CargoError}; use util::{internal, profile, paths}; @@ -188,7 +189,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) output_file.clone()); let build_scripts = super::load_build_deps(cx, unit); let kind = unit.kind; - let json_messages = cx.build_config.json_messages; + let json_messages = cx.build_config.message_format == MessageFormat::Json; // Check to see if the build script has already run, and if it has keep // track of whether it has told us about some explicit dependencies diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 8dce388c055..181b1b5330f 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -12,6 +12,7 @@ use serde_json; use core::{Package, PackageId, PackageSet, Target, Resolve}; use core::{Profile, Profiles, Workspace}; use core::shell::ColorChoice; +use ops::MessageFormat; use util::{self, ProcessBuilder, machine_message}; use util::{Config, internal, profile, join_paths}; use util::errors::{CargoResult, CargoResultExt}; @@ -67,8 +68,8 @@ pub struct BuildConfig { pub test: bool, /// Whether we are building documentation pub doc_all: bool, - /// Whether to print std output in json format (for machine reading) - pub json_messages: bool, + /// What format to use when outputting messages from the compiler + pub message_format: MessageFormat, } /// Information required to build for a target @@ -344,7 +345,7 @@ fn rustc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, rustc.args(&cx.incremental_args(unit)?); rustc.args(&cx.rustflags_args(unit)?); - let json_messages = cx.build_config.json_messages; + let json_messages = cx.build_config.message_format == MessageFormat::Json; let package_id = unit.pkg.package_id().clone(); let target = unit.target.clone(); @@ -501,7 +502,7 @@ fn link_targets<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, let features = cx.resolve.features_sorted(&package_id).into_iter() .map(|s| s.to_owned()) .collect(); - let json_messages = cx.build_config.json_messages; + let json_messages = cx.build_config.message_format == MessageFormat::Json; Ok(Work::new(move |_| { // If we're a "root crate", e.g. the target of this compilation, then we @@ -741,8 +742,10 @@ fn build_base_args<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, ColorChoice::CargoAuto => {} } - if cx.build_config.json_messages { - cmd.arg("--error-format").arg("json"); + match cx.build_config.message_format { + MessageFormat::Json => { cmd.arg("--error-format").arg("json"); } + MessageFormat::Short => { cmd.arg("--error-format").arg("short"); } + MessageFormat::Human => {} } if !test { diff --git a/tests/build.rs b/tests/build.rs index 523e42d9130..12c5a2e9f25 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -2864,7 +2864,7 @@ fn wrong_message_format_option() { assert_that(p.cargo("build").arg("--message-format").arg("XML"), execs().with_status(1) .with_stderr_contains( -r#"[ERROR] Could not match 'xml' with any of the allowed variants: ["Human", "Json"]"#)); +r#"[ERROR] Could not match 'xml' with any of the allowed variants: ["Human", "Json", "Short"]"#)); } #[test]