diff --git a/src/main.rs b/src/main.rs index db0c6613f3fc..75cc507740a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -128,9 +128,13 @@ pub fn main() { let args = std::env::args().skip(2); if let Some(first) = target.kind.get(0) { if target.kind.len() > 1 || first.ends_with("lib") { - process(std::iter::once("--lib".to_owned()).chain(args), &dep_path, &sys_root); + if let Err(code) = process(std::iter::once("--lib".to_owned()).chain(args), &dep_path, &sys_root) { + std::process::exit(code); + } } else if first == "bin" { - process(vec!["--bin".to_owned(), target.name].into_iter().chain(args), &dep_path, &sys_root); + if let Err(code) = process(vec!["--bin".to_owned(), target.name].into_iter().chain(args), &dep_path, &sys_root) { + std::process::exit(code); + } } } else { panic!("badly formatted cargo metadata: target::kind is an empty array"); @@ -152,7 +156,7 @@ pub fn main() { } } -fn process
(old_args: I, dep_path: P, sysroot: &str) +fn process
(old_args: I, dep_path: P, sysroot: &str) -> Result<(), i32>
where P: AsRef (old_args: I, dep_path: P, sysroot: &str)
.spawn().expect("could not run cargo")
.wait().expect("failed to wait for cargo?");
- if let Some(code) = exit_status.code() {
- std::process::exit(code);
+ if exit_status.success() {
+ Ok(())
+ } else {
+ use std::os::unix::process::ExitStatusExt;
+ Err(exit_status.code().or(exit_status.signal()).unwrap_or(-1))
}
}