Skip to content

Commit

Permalink
Don't show cargo command errors
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 29, 2023
1 parent ec94074 commit c122376
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions build_system/src/cargo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::config::ConfigInfo;
use crate::utils::{
get_toolchain, run_command_with_output_and_env, rustc_toolchain_version_info,
get_toolchain, run_command_with_output_and_env_no_err, rustc_toolchain_version_info,
rustc_version_info,
};

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

Ok(())
}
25 changes: 21 additions & 4 deletions build_system/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn check_exit_status(
cwd: Option<&Path>,
exit_status: ExitStatus,
output: Option<&Output>,
show_err: bool,
) -> Result<(), String> {
if exit_status.success() {
return Ok(());
Expand All @@ -46,7 +47,9 @@ fn check_exit_status(
exit_status.code()
);
let input = input.iter().map(|i| i.as_ref()).collect::<Vec<&OsStr>>();
eprintln!("Command `{:?}` failed", input);
if show_err {
eprintln!("Command `{:?}` failed", input);
}
if let Some(output) = output {
let stdout = String::from_utf8_lossy(&output.stdout);
if !stdout.is_empty() {
Expand Down Expand Up @@ -88,7 +91,7 @@ pub fn run_command_with_env(
let output = get_command_inner(input, cwd, env)
.output()
.map_err(|e| command_error(input, &cwd, e))?;
check_exit_status(input, cwd, output.status, Some(&output))?;
check_exit_status(input, cwd, output.status, Some(&output), true)?;
Ok(output)
}

Expand All @@ -101,7 +104,7 @@ pub fn run_command_with_output(
.map_err(|e| command_error(input, &cwd, e))?
.wait()
.map_err(|e| command_error(input, &cwd, e))?;
check_exit_status(input, cwd, exit_status, None)?;
check_exit_status(input, cwd, exit_status, None, true)?;
Ok(())
}

Expand All @@ -115,7 +118,21 @@ pub fn run_command_with_output_and_env(
.map_err(|e| command_error(input, &cwd, e))?
.wait()
.map_err(|e| command_error(input, &cwd, e))?;
check_exit_status(input, cwd, exit_status, None)?;
check_exit_status(input, cwd, exit_status, None, true)?;
Ok(())
}

pub fn run_command_with_output_and_env_no_err(
input: &[&dyn AsRef<OsStr>],
cwd: Option<&Path>,
env: Option<&HashMap<String, String>>,
) -> Result<(), String> {
let exit_status = get_command_inner(input, cwd, env)
.spawn()
.map_err(|e| command_error(input, &cwd, e))?
.wait()
.map_err(|e| command_error(input, &cwd, e))?;
check_exit_status(input, cwd, exit_status, None, false)?;
Ok(())
}

Expand Down

0 comments on commit c122376

Please sign in to comment.