Skip to content

Commit 13b4c10

Browse files
committed
Always pass git options to run_command
Signed-off-by: dvermd <[email protected]>
1 parent 03aa02f commit 13b4c10

File tree

1 file changed

+69
-20
lines changed

1 file changed

+69
-20
lines changed

build_system/src/prepare.rs

Lines changed: 69 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,66 @@
1+
use std::ffi::OsStr;
12
use std::fs;
23
use std::path::{Path, PathBuf};
4+
use std::process::Output;
35

46
use crate::rustc_info::get_rustc_path;
57
use crate::utils::{
68
cargo_install, create_dir, get_sysroot_dir, git_clone_root_dir, remove_file, run_command,
79
run_command_with_output, walk_dir,
810
};
911

12+
fn run_git_command(
13+
command: &dyn AsRef<OsStr>,
14+
input: &[&dyn AsRef<OsStr>],
15+
cwd: Option<&Path>,
16+
) -> Result<Output, String> {
17+
// This is needed on systems where nothing is configured.
18+
// git really needs something here, or it will fail.
19+
// Even using --author is not enough.
20+
let git_cmd = &[
21+
&"git" as &dyn AsRef<OsStr>,
22+
&"-c" as &dyn AsRef<OsStr>,
23+
&"user.name=None" as &dyn AsRef<OsStr>,
24+
&"-c" as &dyn AsRef<OsStr>,
25+
&"[email protected]" as &dyn AsRef<OsStr>,
26+
&"-c" as &dyn AsRef<OsStr>,
27+
&"core.autocrlf=false" as &dyn AsRef<OsStr>,
28+
&"-c" as &dyn AsRef<OsStr>,
29+
&"commit.gpgSign=false" as &dyn AsRef<OsStr>,
30+
]
31+
.into_iter()
32+
.chain([command])
33+
.chain(input.iter().cloned())
34+
.collect::<Vec<_>>()[..];
35+
run_command(git_cmd, cwd)
36+
}
37+
38+
fn run_git_command_with_output(
39+
command: &dyn AsRef<OsStr>,
40+
input: &[&dyn AsRef<OsStr>],
41+
cwd: Option<&Path>,
42+
) -> Result<(), String> {
43+
// This is needed on systems where nothing is configured.
44+
// git really needs something here, or it will fail.
45+
// Even using --author is not enough.
46+
let git_cmd = &[
47+
&"git" as &dyn AsRef<OsStr>,
48+
&"-c" as &dyn AsRef<OsStr>,
49+
&"user.name=None" as &dyn AsRef<OsStr>,
50+
&"-c" as &dyn AsRef<OsStr>,
51+
&"[email protected]" as &dyn AsRef<OsStr>,
52+
&"-c" as &dyn AsRef<OsStr>,
53+
&"core.autocrlf=false" as &dyn AsRef<OsStr>,
54+
&"-c" as &dyn AsRef<OsStr>,
55+
&"commit.gpgSign=false" as &dyn AsRef<OsStr>,
56+
]
57+
.into_iter()
58+
.chain([command])
59+
.chain(input.iter().cloned())
60+
.collect::<Vec<_>>()[..];
61+
run_command_with_output(git_cmd, cwd)
62+
}
63+
1064
fn prepare_libcore(
1165
sysroot_path: &Path,
1266
libgccjit12_patches: bool,
@@ -55,19 +109,12 @@ fn prepare_libcore(
55109
run_command(&[&"cp", &"-r", &rustlib_dir.join("library"), &sysroot_dir], None)?;
56110

57111
println!("[GIT] init (cwd): `{}`", sysroot_dir.display());
58-
run_command(&[&"git", &"init"], Some(&sysroot_dir))?;
112+
run_git_command(&"init", &[], Some(&sysroot_dir))?;
59113
println!("[GIT] add (cwd): `{}`", sysroot_dir.display());
60-
run_command(&[&"git", &"add", &"."], Some(&sysroot_dir))?;
114+
run_git_command(&"add", &[&"."], Some(&sysroot_dir))?;
61115
println!("[GIT] commit (cwd): `{}`", sysroot_dir.display());
62116

63-
// This is needed on systems where nothing is configured.
64-
// git really needs something here, or it will fail.
65-
// Even using --author is not enough.
66-
run_command(&[&"git", &"config", &"user.email", &"[email protected]"], Some(&sysroot_dir))?;
67-
run_command(&[&"git", &"config", &"user.name", &"None"], Some(&sysroot_dir))?;
68-
run_command(&[&"git", &"config", &"core.autocrlf", &"false"], Some(&sysroot_dir))?;
69-
run_command(&[&"git", &"config", &"commit.gpgSign", &"false"], Some(&sysroot_dir))?;
70-
run_command(&[&"git", &"commit", &"-m", &"Initial commit", &"-q"], Some(&sysroot_dir))?;
117+
run_git_command(&"commit", &[&"-m", &"Initial commit", &"-q"], Some(&sysroot_dir))?;
71118

72119
let mut patches = Vec::new();
73120
walk_dir(
@@ -105,10 +152,11 @@ fn prepare_libcore(
105152
for file_path in patches {
106153
println!("[GIT] apply `{}`", file_path.display());
107154
let path = Path::new("../../..").join(file_path);
108-
run_command_with_output(&[&"git", &"apply", &path], Some(&sysroot_dir))?;
109-
run_command_with_output(&[&"git", &"add", &"-A"], Some(&sysroot_dir))?;
110-
run_command_with_output(
111-
&[&"git", &"commit", &"--no-gpg-sign", &"-m", &format!("Patch {}", path.display())],
155+
run_git_command_with_output(&"apply", &[&path], Some(&sysroot_dir))?;
156+
run_git_command_with_output(&"add", &[&"-A"], Some(&sysroot_dir))?;
157+
run_git_command_with_output(
158+
&"commit",
159+
&[&"-m", &format!("Patch {}", path.display())],
112160
Some(&sysroot_dir),
113161
)?;
114162
}
@@ -124,10 +172,11 @@ fn prepare_rand() -> Result<(), String> {
124172
let rand_dir = Path::new("build/rand");
125173
println!("[GIT] apply `{file_path}`");
126174
let path = Path::new("../..").join(file_path);
127-
run_command_with_output(&[&"git", &"apply", &path], Some(rand_dir))?;
128-
run_command_with_output(&[&"git", &"add", &"-A"], Some(rand_dir))?;
129-
run_command_with_output(
130-
&[&"git", &"commit", &"--no-gpg-sign", &"-m", &format!("Patch {}", path.display())],
175+
run_git_command_with_output(&"apply", &[&path], Some(rand_dir))?;
176+
run_git_command_with_output(&"add", &[&"-A"], Some(rand_dir))?;
177+
run_git_command_with_output(
178+
&"commit",
179+
&[&"-m", &format!("Patch {}", path.display())],
131180
Some(rand_dir),
132181
)?;
133182

@@ -154,8 +203,8 @@ where
154203
println!("`{}` has already been cloned", clone_result.repo_name);
155204
}
156205
let repo_path = Path::new(crate::BUILD_DIR).join(&clone_result.repo_name);
157-
run_command(&[&"git", &"checkout", &"--", &"."], Some(&repo_path))?;
158-
run_command(&[&"git", &"checkout", &checkout_commit], Some(&repo_path))?;
206+
run_git_command(&"checkout", &[&"--", &"."], Some(&repo_path))?;
207+
run_git_command(&"checkout", &[&checkout_commit], Some(&repo_path))?;
159208
if let Some(extra) = extra {
160209
extra(&repo_path)?;
161210
}

0 commit comments

Comments
 (0)