Skip to content

Commit c122376

Browse files
Don't show cargo command errors
1 parent ec94074 commit c122376

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

build_system/src/cargo.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::config::ConfigInfo;
22
use crate::utils::{
3-
get_toolchain, run_command_with_output_and_env, rustc_toolchain_version_info,
3+
get_toolchain, run_command_with_output_and_env_no_err, rustc_toolchain_version_info,
44
rustc_version_info,
55
};
66

@@ -106,7 +106,9 @@ pub fn run() -> Result<(), String> {
106106
for arg in &args {
107107
command.push(arg);
108108
}
109-
run_command_with_output_and_env(&command, None, Some(&env))?;
109+
if run_command_with_output_and_env_no_err(&command, None, Some(&env)).is_err() {
110+
std::process::exit(1);
111+
}
110112

111113
Ok(())
112114
}

build_system/src/utils.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ fn check_exit_status(
3030
cwd: Option<&Path>,
3131
exit_status: ExitStatus,
3232
output: Option<&Output>,
33+
show_err: bool,
3334
) -> Result<(), String> {
3435
if exit_status.success() {
3536
return Ok(());
@@ -46,7 +47,9 @@ fn check_exit_status(
4647
exit_status.code()
4748
);
4849
let input = input.iter().map(|i| i.as_ref()).collect::<Vec<&OsStr>>();
49-
eprintln!("Command `{:?}` failed", input);
50+
if show_err {
51+
eprintln!("Command `{:?}` failed", input);
52+
}
5053
if let Some(output) = output {
5154
let stdout = String::from_utf8_lossy(&output.stdout);
5255
if !stdout.is_empty() {
@@ -88,7 +91,7 @@ pub fn run_command_with_env(
8891
let output = get_command_inner(input, cwd, env)
8992
.output()
9093
.map_err(|e| command_error(input, &cwd, e))?;
91-
check_exit_status(input, cwd, output.status, Some(&output))?;
94+
check_exit_status(input, cwd, output.status, Some(&output), true)?;
9295
Ok(output)
9396
}
9497

@@ -101,7 +104,7 @@ pub fn run_command_with_output(
101104
.map_err(|e| command_error(input, &cwd, e))?
102105
.wait()
103106
.map_err(|e| command_error(input, &cwd, e))?;
104-
check_exit_status(input, cwd, exit_status, None)?;
107+
check_exit_status(input, cwd, exit_status, None, true)?;
105108
Ok(())
106109
}
107110

@@ -115,7 +118,21 @@ pub fn run_command_with_output_and_env(
115118
.map_err(|e| command_error(input, &cwd, e))?
116119
.wait()
117120
.map_err(|e| command_error(input, &cwd, e))?;
118-
check_exit_status(input, cwd, exit_status, None)?;
121+
check_exit_status(input, cwd, exit_status, None, true)?;
122+
Ok(())
123+
}
124+
125+
pub fn run_command_with_output_and_env_no_err(
126+
input: &[&dyn AsRef<OsStr>],
127+
cwd: Option<&Path>,
128+
env: Option<&HashMap<String, String>>,
129+
) -> Result<(), String> {
130+
let exit_status = get_command_inner(input, cwd, env)
131+
.spawn()
132+
.map_err(|e| command_error(input, &cwd, e))?
133+
.wait()
134+
.map_err(|e| command_error(input, &cwd, e))?;
135+
check_exit_status(input, cwd, exit_status, None, false)?;
119136
Ok(())
120137
}
121138

0 commit comments

Comments
 (0)