about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--build_system/src/prepare.rs12
-rw-r--r--build_system/src/utils.rs31
2 files changed, 35 insertions, 8 deletions
diff --git a/build_system/src/prepare.rs b/build_system/src/prepare.rs
index 74d0c2a2a06..8e6183be629 100644
--- a/build_system/src/prepare.rs
+++ b/build_system/src/prepare.rs
@@ -1,5 +1,5 @@
 use crate::rustc_info::get_rustc_path;
-use crate::utils::{cargo_install, git_clone, run_command, walk_dir};
+use crate::utils::{cargo_install, git_clone, run_command, run_command_with_output, walk_dir};
 
 use std::fs;
 use std::path::Path;
@@ -37,9 +37,9 @@ fn prepare_libcore() -> Result<(), String> {
     run_command(&[&"cp", &"-r", &rustlib_dir, &sysroot_library_dir], None)?;
 
     println!("[GIT] init (cwd): `{}`", sysroot_dir.display());
-    run_command(&[&"git", &"init"], Some(&sysroot_dir))?;
+    run_command_with_output(&[&"git", &"init"], Some(&sysroot_dir))?;
     println!("[GIT] add (cwd): `{}`", sysroot_dir.display());
-    run_command(&[&"git", &"add", &"."], Some(&sysroot_dir))?;
+    run_command_with_output(&[&"git", &"add", &"."], Some(&sysroot_dir))?;
     println!("[GIT] commit (cwd): `{}`", sysroot_dir.display());
 
     // This is needed on systems where nothing is configured.
@@ -54,9 +54,9 @@ fn prepare_libcore() -> Result<(), String> {
     walk_dir("patches", |_| Ok(()), |file_path: &Path| {
         println!("[GIT] apply `{}`", file_path.display());
         let path = Path::new("../..").join(file_path);
-        run_command(&[&"git", &"apply", &path], Some(&sysroot_dir))?;
-        run_command(&[&"git", &"add", &"-A"], Some(&sysroot_dir))?;
-        run_command(
+        run_command_with_output(&[&"git", &"apply", &path], Some(&sysroot_dir))?;
+        run_command_with_output(&[&"git", &"add", &"-A"], Some(&sysroot_dir))?;
+        run_command_with_output(
             &[&"git", &"commit", &"--no-gpg-sign", &"-m", &format!("Patch {}", path.display())],
             Some(&sysroot_dir),
         )?;
diff --git a/build_system/src/utils.rs b/build_system/src/utils.rs
index f3c2571c28f..145f40ec8ae 100644
--- a/build_system/src/utils.rs
+++ b/build_system/src/utils.rs
@@ -3,7 +3,7 @@ use std::fs;
 use std::path::Path;
 use std::process::{Command, Output};
 
-pub fn run_command(input: &[&dyn AsRef<OsStr>], cwd: Option<&Path>) -> Result<Output, String> {
+fn run_command_inner(input: &[&dyn AsRef<OsStr>], cwd: Option<&Path>) -> Command {
     let (cmd, args) = match input {
         [] => panic!("empty command"),
         [cmd, args @ ..] => (cmd, args),
@@ -13,7 +13,11 @@ pub fn run_command(input: &[&dyn AsRef<OsStr>], cwd: Option<&Path>) -> Result<Ou
     if let Some(cwd) = cwd {
         command.current_dir(cwd);
     }
-    command.output()
+    command
+}
+
+pub fn run_command(input: &[&dyn AsRef<OsStr>], cwd: Option<&Path>) -> Result<Output, String> {
+    run_command_inner(input, cwd).output()
         .map_err(|e| format!(
             "Command `{}` failed to run: {e:?}",
             input.iter()
@@ -23,6 +27,29 @@ pub fn run_command(input: &[&dyn AsRef<OsStr>], cwd: Option<&Path>) -> Result<Ou
         ))
 }
 
+pub fn run_command_with_output(
+    input: &[&dyn AsRef<OsStr>],
+    cwd: Option<&Path>,
+) -> Result<(), String> {
+    run_command_inner(input, cwd).spawn()
+        .map_err(|e| format!(
+            "Command `{}` failed to run: {e:?}",
+            input.iter()
+                .map(|s| s.as_ref().to_str().unwrap())
+                .collect::<Vec<_>>()
+                .join(" "),
+        ))?
+        .wait()
+        .map_err(|e| format!(
+            "Failed to wait for command `{}` to run: {e:?}",
+            input.iter()
+                .map(|s| s.as_ref().to_str().unwrap())
+                .collect::<Vec<_>>()
+                .join(" "),
+        ))?;
+    Ok(())
+}
+
 pub fn cargo_install(to_install: &str) -> Result<(), String> {
     let output = run_command(&[&"cargo", &"install", &"--list"], None)?;