about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2023-12-29 21:27:36 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2023-12-29 21:27:36 +0100
commitc122376493e40dd494dac45614205c340141f005 (patch)
tree6cf80448ac4b2bac7be62f2d82210d18612fe1d0
parentec940748175eca4e476ed29fa537319eb090356a (diff)
downloadrust-c122376493e40dd494dac45614205c340141f005.tar.gz
rust-c122376493e40dd494dac45614205c340141f005.zip
Don't show `cargo` command errors
-rw-r--r--build_system/src/cargo.rs6
-rw-r--r--build_system/src/utils.rs25
2 files changed, 25 insertions, 6 deletions
diff --git a/build_system/src/cargo.rs b/build_system/src/cargo.rs
index 5f9de5e2eb6..67b301d9aa6 100644
--- a/build_system/src/cargo.rs
+++ b/build_system/src/cargo.rs
@@ -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,
 };
 
@@ -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(())
 }
diff --git a/build_system/src/utils.rs b/build_system/src/utils.rs
index fdd8bd8f4c4..f0a07b597a0 100644
--- a/build_system/src/utils.rs
+++ b/build_system/src/utils.rs
@@ -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(());
@@ -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() {
@@ -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)
 }
 
@@ -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(())
 }
 
@@ -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(())
 }