Skip to content

Commit a83cd61

Browse files
committed
Auto merge of #6270 - ehuss:no-internal-signal, r=alexcrichton
Don't treat rustc exit on signal as internal error. If rustc exits with a signal, previously all you saw was: ``` Compiling foo ... error: Could not compile `foo`. To learn more, run the command again with --verbose. ``` Now it shows the complete error by default: ``` Compiling foo ... error: Could not compile `foo`. Caused by: process didn't exit successfully: `rustc ...` (signal: 6, SIGABRT: process abort signal) ```
2 parents 787bee6 + 6bc5e71 commit a83cd61

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ use std::io::{self, Write};
55
use std::path::{self, Path, PathBuf};
66
use std::sync::Arc;
77

8+
use failure::Error;
89
use same_file::is_same_file;
910
use serde_json;
1011

1112
use core::manifest::TargetSourcePath;
1213
use core::profiles::{Lto, Profile};
1314
use core::{PackageId, Target};
14-
use util::errors::{CargoResult, CargoResultExt, Internal};
15+
use util::errors::{CargoResult, CargoResultExt, Internal, ProcessError};
1516
use util::paths;
1617
use util::{self, machine_message, Freshness, ProcessBuilder, process};
1718
use util::{internal, join_paths, profile};
@@ -275,6 +276,19 @@ fn rustc<'a, 'cfg>(
275276
}
276277
}
277278

279+
fn internal_if_simple_exit_code(err: Error) -> Error {
280+
// If a signal on unix (code == None) or an abnormal termination
281+
// on Windows (codes like 0xC0000409), don't hide the error details.
282+
match err
283+
.downcast_ref::<ProcessError>()
284+
.as_ref()
285+
.and_then(|perr| perr.exit.and_then(|e| e.code()))
286+
{
287+
Some(n) if n < 128 => Internal::new(err).into(),
288+
_ => err,
289+
}
290+
}
291+
278292
state.running(&rustc);
279293
if json_messages {
280294
exec.exec_json(
@@ -284,13 +298,14 @@ fn rustc<'a, 'cfg>(
284298
mode,
285299
&mut assert_is_empty,
286300
&mut |line| json_stderr(line, &package_id, &target),
287-
).map_err(Internal::new)
301+
)
302+
.map_err(internal_if_simple_exit_code)
288303
.chain_err(|| format!("Could not compile `{}`.", name))?;
289304
} else if build_plan {
290305
state.build_plan(buildkey, rustc.clone(), outputs.clone());
291306
} else {
292307
exec.exec_and_capture_output(rustc, &package_id, &target, mode, state)
293-
.map_err(Internal::new)
308+
.map_err(internal_if_simple_exit_code)
294309
.chain_err(|| format!("Could not compile `{}`.", name))?;
295310
}
296311

tests/testsuite/build.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4373,3 +4373,65 @@ fn target_filters_workspace_not_found() {
43734373
.with_stderr("[ERROR] no library targets found in packages: a, b")
43744374
.run();
43754375
}
4376+
4377+
#[cfg(unix)]
4378+
#[test]
4379+
fn signal_display() {
4380+
// Cause the compiler to crash with a signal.
4381+
let foo = project()
4382+
.file(
4383+
"Cargo.toml",
4384+
r#"
4385+
[package]
4386+
name = "foo"
4387+
version = "0.1.0"
4388+
[dependencies]
4389+
pm = { path = "pm" }
4390+
"#,
4391+
)
4392+
.file(
4393+
"src/lib.rs",
4394+
r#"
4395+
#[macro_use]
4396+
extern crate pm;
4397+
4398+
#[derive(Foo)]
4399+
pub struct S;
4400+
"#,
4401+
)
4402+
.file(
4403+
"pm/Cargo.toml",
4404+
r#"
4405+
[package]
4406+
name = "pm"
4407+
version = "0.1.0"
4408+
[lib]
4409+
proc-macro = true
4410+
"#,
4411+
)
4412+
.file(
4413+
"pm/src/lib.rs",
4414+
r#"
4415+
extern crate proc_macro;
4416+
use proc_macro::TokenStream;
4417+
4418+
#[proc_macro_derive(Foo)]
4419+
pub fn derive(_input: TokenStream) -> TokenStream {
4420+
std::process::abort()
4421+
}
4422+
"#,
4423+
)
4424+
.build();
4425+
4426+
foo.cargo("build")
4427+
.with_stderr("\
4428+
[COMPILING] pm [..]
4429+
[COMPILING] foo [..]
4430+
[ERROR] Could not compile `foo`.
4431+
4432+
Caused by:
4433+
process didn't exit successfully: `rustc [..]` (signal: 6, SIGABRT: process abort signal)
4434+
")
4435+
.with_status(101)
4436+
.run();
4437+
}

0 commit comments

Comments
 (0)