Skip to content

Commit bce234d

Browse files
Don't capture output on git commands
1 parent 2a87b26 commit bce234d

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

build_system/src/prepare.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::rustc_info::get_rustc_path;
2-
use crate::utils::{cargo_install, git_clone, run_command, walk_dir};
2+
use crate::utils::{cargo_install, git_clone, run_command, run_command_with_output, walk_dir};
33

44
use std::fs;
55
use std::path::Path;
@@ -37,9 +37,9 @@ fn prepare_libcore() -> Result<(), String> {
3737
run_command(&[&"cp", &"-r", &rustlib_dir, &sysroot_library_dir], None)?;
3838

3939
println!("[GIT] init (cwd): `{}`", sysroot_dir.display());
40-
run_command(&[&"git", &"init"], Some(&sysroot_dir))?;
40+
run_command_with_output(&[&"git", &"init"], Some(&sysroot_dir))?;
4141
println!("[GIT] add (cwd): `{}`", sysroot_dir.display());
42-
run_command(&[&"git", &"add", &"."], Some(&sysroot_dir))?;
42+
run_command_with_output(&[&"git", &"add", &"."], Some(&sysroot_dir))?;
4343
println!("[GIT] commit (cwd): `{}`", sysroot_dir.display());
4444

4545
// This is needed on systems where nothing is configured.
@@ -54,9 +54,9 @@ fn prepare_libcore() -> Result<(), String> {
5454
walk_dir("patches", |_| Ok(()), |file_path: &Path| {
5555
println!("[GIT] apply `{}`", file_path.display());
5656
let path = Path::new("../..").join(file_path);
57-
run_command(&[&"git", &"apply", &path], Some(&sysroot_dir))?;
58-
run_command(&[&"git", &"add", &"-A"], Some(&sysroot_dir))?;
59-
run_command(
57+
run_command_with_output(&[&"git", &"apply", &path], Some(&sysroot_dir))?;
58+
run_command_with_output(&[&"git", &"add", &"-A"], Some(&sysroot_dir))?;
59+
run_command_with_output(
6060
&[&"git", &"commit", &"--no-gpg-sign", &"-m", &format!("Patch {}", path.display())],
6161
Some(&sysroot_dir),
6262
)?;

build_system/src/utils.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fs;
33
use std::path::Path;
44
use std::process::{Command, Output};
55

6-
pub fn run_command(input: &[&dyn AsRef<OsStr>], cwd: Option<&Path>) -> Result<Output, String> {
6+
fn run_command_inner(input: &[&dyn AsRef<OsStr>], cwd: Option<&Path>) -> Command {
77
let (cmd, args) = match input {
88
[] => panic!("empty command"),
99
[cmd, args @ ..] => (cmd, args),
@@ -13,7 +13,11 @@ pub fn run_command(input: &[&dyn AsRef<OsStr>], cwd: Option<&Path>) -> Result<Ou
1313
if let Some(cwd) = cwd {
1414
command.current_dir(cwd);
1515
}
16-
command.output()
16+
command
17+
}
18+
19+
pub fn run_command(input: &[&dyn AsRef<OsStr>], cwd: Option<&Path>) -> Result<Output, String> {
20+
run_command_inner(input, cwd).output()
1721
.map_err(|e| format!(
1822
"Command `{}` failed to run: {e:?}",
1923
input.iter()
@@ -23,6 +27,29 @@ pub fn run_command(input: &[&dyn AsRef<OsStr>], cwd: Option<&Path>) -> Result<Ou
2327
))
2428
}
2529

30+
pub fn run_command_with_output(
31+
input: &[&dyn AsRef<OsStr>],
32+
cwd: Option<&Path>,
33+
) -> Result<(), String> {
34+
run_command_inner(input, cwd).spawn()
35+
.map_err(|e| format!(
36+
"Command `{}` failed to run: {e:?}",
37+
input.iter()
38+
.map(|s| s.as_ref().to_str().unwrap())
39+
.collect::<Vec<_>>()
40+
.join(" "),
41+
))?
42+
.wait()
43+
.map_err(|e| format!(
44+
"Failed to wait for command `{}` to run: {e:?}",
45+
input.iter()
46+
.map(|s| s.as_ref().to_str().unwrap())
47+
.collect::<Vec<_>>()
48+
.join(" "),
49+
))?;
50+
Ok(())
51+
}
52+
2653
pub fn cargo_install(to_install: &str) -> Result<(), String> {
2754
let output = run_command(&[&"cargo", &"install", &"--list"], None)?;
2855

0 commit comments

Comments
 (0)