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

add support for rustc's --error-format short #4720

Closed
Closed
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
2 changes: 1 addition & 1 deletion src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bin/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bin/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/ops/cargo_rustc/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down