1
Fork 0

Don't capture output on git commands

This commit is contained in:
Guillaume Gomez 2023-08-19 18:24:01 +02:00
parent 6b588cc007
commit 18d22d5698
2 changed files with 35 additions and 8 deletions

View file

@ -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),
)?;

View file

@ -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)?;