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 #5879

Merged
merged 4 commits into from
Aug 12, 2018
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
4 changes: 3 additions & 1 deletion src/bin/cargo/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub trait AppExt: Sized {
opt("message-format", "Error format")
.value_name("FMT")
.case_insensitive(true)
.possible_values(&["human", "json"])
.possible_values(&["human", "json", "short"])
.default_value("human"),
)
}
Expand Down Expand Up @@ -270,6 +270,8 @@ pub trait ArgMatchesExt {
MessageFormat::Json
} else if f.eq_ignore_ascii_case("human") {
MessageFormat::Human
} else if f.eq_ignore_ascii_case("short") {
MessageFormat::Short
} else {
panic!("Impossible message format: {:?}", f)
}
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl BuildConfig {
pub enum MessageFormat {
Human,
Json,
Short,
}

/// The general "mode" of what to do.
Expand Down
17 changes: 10 additions & 7 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,7 @@ fn rustdoc<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoResult
rustdoc.arg("--cfg").arg(&format!("feature=\"{}\"", feat));
}

if bcx.build_config.json_messages() {
rustdoc.arg("--error-format").arg("json");
}
add_error_format(bcx, &mut rustdoc);

if let Some(ref args) = bcx.extra_args_for(unit) {
rustdoc.args(args);
Expand Down Expand Up @@ -706,6 +704,14 @@ fn add_color(bcx: &BuildContext, cmd: &mut ProcessBuilder) {
}
}

fn add_error_format(bcx: &BuildContext, cmd: &mut ProcessBuilder) {
match bcx.build_config.message_format {
MessageFormat::Human => (),
MessageFormat::Json => { cmd.arg("--error-format").arg("json"); },
MessageFormat::Short => { cmd.arg("--error-format").arg("short"); },
}
}

fn build_base_args<'a, 'cfg>(
cx: &mut Context<'a, 'cfg>,
cmd: &mut ProcessBuilder,
Expand All @@ -732,10 +738,7 @@ fn build_base_args<'a, 'cfg>(

add_path_args(bcx, unit, cmd);
add_color(bcx, cmd);

if bcx.build_config.json_messages() {
cmd.arg("--error-format").arg("json");
}
add_error_format(bcx, cmd);

if !test {
for crate_type in crate_types.iter() {
Expand Down
2 changes: 1 addition & 1 deletion src/etc/_cargo
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ case $state in
'(--lib --doc --bin --test --bench)--example=[example name]' \
'(--lib --doc --bin --example --bench)--test=[test name]' \
'(--lib --doc --bin --example --test)--bench=[benchmark name]' \
'--message-format:error format:(human json)' \
'--message-format:error format:(human json short)' \
'--frozen[require lock and cache up to date]' \
'--locked[require lock up to date]'
;;
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3571,7 +3571,7 @@ fn wrong_message_format_option() {
execs().with_status(1).with_stderr_contains(
"\
error: 'XML' isn't a valid value for '--message-format <FMT>'
<tab>[possible values: human, json]
<tab>[possible values: human, json, short]
",
),
);
Expand Down
17 changes: 17 additions & 0 deletions tests/testsuite/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,23 @@ fn check_artifacts() {
);
}

#[test]
fn short_message_format() {
let foo = project()
.file("src/lib.rs", "fn foo() { let _x: bool = 'a'; }")
.build();
assert_that(
foo.cargo("check --message-format=short"),
execs().with_status(101).with_stderr_contains(
"\
src/lib.rs:1:27: error[E0308]: mismatched types
error: aborting due to previous error
error: Could not compile `foo`.
",
),
);
}

#[test]
fn proc_macro() {
let p = project()
Expand Down
18 changes: 18 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1450,3 +1450,21 @@ fn doc_message_format() {
),
);
}

#[test]
fn short_message_format() {
if !is_nightly() {
// This can be removed once 1.30 is stable (rustdoc --error-format stabilized).
return;
}
let p = project().file("src/lib.rs", BAD_INTRA_LINK_LIB).build();
assert_that(
p.cargo("doc --message-format=short"),
execs().with_status(101).with_stderr_contains(
"\
src/lib.rs:4:6: error: `[bad_link]` cannot be resolved, ignoring it...
error: Could not document `foo`.
",
),
);
}