1+ use std:: ffi:: OsStr ;
12use std:: fs;
23use std:: path:: { Path , PathBuf } ;
4+ use std:: process:: Output ;
35
46use crate :: rustc_info:: get_rustc_path;
57use 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+ // This is needed on systems where nothing is configured.
13+ // git really needs something here, or it will fail.
14+ // Even using --author is not enough.
15+ const GIT_CMD : [ & dyn AsRef < OsStr > ; 9 ] = [
16+ & "git" ,
17+ & "-c" ,
18+ & "user.name=None" ,
19+ & "-c" ,
20+ 21+ & "-c" ,
22+ & "core.autocrlf=false" ,
23+ & "-c" ,
24+ & "commit.gpgSign=false" ,
25+ ] ;
26+
27+ fn run_git_command (
28+ command : & dyn AsRef < OsStr > ,
29+ input : & [ & dyn AsRef < OsStr > ] ,
30+ cwd : Option < & Path > ,
31+ ) -> Result < Output , String > {
32+ let git_cmd =
33+ & GIT_CMD . into_iter ( ) . chain ( [ command] ) . chain ( input. iter ( ) . cloned ( ) ) . collect :: < Vec < _ > > ( ) [ ..] ;
34+ run_command ( git_cmd, cwd)
35+ }
36+
37+ fn run_git_command_with_output (
38+ command : & dyn AsRef < OsStr > ,
39+ input : & [ & dyn AsRef < OsStr > ] ,
40+ cwd : Option < & Path > ,
41+ ) -> Result < ( ) , String > {
42+ let git_cmd =
43+ & GIT_CMD . into_iter ( ) . chain ( [ command] ) . chain ( input. iter ( ) . cloned ( ) ) . collect :: < Vec < _ > > ( ) [ ..] ;
44+ run_command_with_output ( git_cmd, cwd)
45+ }
46+
1047fn prepare_libcore (
1148 sysroot_path : & Path ,
1249 libgccjit12_patches : bool ,
@@ -55,19 +92,12 @@ fn prepare_libcore(
5592 run_command ( & [ & "cp" , & "-r" , & rustlib_dir. join ( "library" ) , & sysroot_dir] , None ) ?;
5693
5794 println ! ( "[GIT] init (cwd): `{}`" , sysroot_dir. display( ) ) ;
58- run_command ( & [ & "git ", & "init" ] , Some ( & sysroot_dir) ) ?;
95+ run_git_command ( & "init ", & [ ] , Some ( & sysroot_dir) ) ?;
5996 println ! ( "[GIT] add (cwd): `{}`" , sysroot_dir. display( ) ) ;
60- run_command ( & [ & "git" , & " add", & "." ] , Some ( & sysroot_dir) ) ?;
97+ run_git_command ( & " add", & [ & "." ] , Some ( & sysroot_dir) ) ?;
6198 println ! ( "[GIT] commit (cwd): `{}`" , sysroot_dir. display( ) ) ;
6299
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) ) ?;
100+ run_git_command ( & "commit" , & [ & "-m" , & "Initial commit" , & "-q" ] , Some ( & sysroot_dir) ) ?;
71101
72102 let mut patches = Vec :: new ( ) ;
73103 walk_dir (
@@ -105,10 +135,11 @@ fn prepare_libcore(
105135 for file_path in patches {
106136 println ! ( "[GIT] apply `{}`" , file_path. display( ) ) ;
107137 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( ) ) ] ,
138+ run_git_command_with_output ( & "apply" , & [ & path] , Some ( & sysroot_dir) ) ?;
139+ run_git_command_with_output ( & "add" , & [ & "-A" ] , Some ( & sysroot_dir) ) ?;
140+ run_git_command_with_output (
141+ & "commit" ,
142+ & [ & "-m" , & format ! ( "Patch {}" , path. display( ) ) ] ,
112143 Some ( & sysroot_dir) ,
113144 ) ?;
114145 }
@@ -124,10 +155,11 @@ fn prepare_rand() -> Result<(), String> {
124155 let rand_dir = Path :: new ( "build/rand" ) ;
125156 println ! ( "[GIT] apply `{file_path}`" ) ;
126157 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( ) ) ] ,
158+ run_git_command_with_output ( & "apply" , & [ & path] , Some ( rand_dir) ) ?;
159+ run_git_command_with_output ( & "add" , & [ & "-A" ] , Some ( rand_dir) ) ?;
160+ run_git_command_with_output (
161+ & "commit" ,
162+ & [ & "-m" , & format ! ( "Patch {}" , path. display( ) ) ] ,
131163 Some ( rand_dir) ,
132164 ) ?;
133165
@@ -154,8 +186,8 @@ where
154186 println ! ( "`{}` has already been cloned" , clone_result. repo_name) ;
155187 }
156188 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) ) ?;
189+ run_git_command ( & " checkout", & [ & "--" , & "." ] , Some ( & repo_path) ) ?;
190+ run_git_command ( & " checkout", & [ & checkout_commit] , Some ( & repo_path) ) ?;
159191 if let Some ( extra) = extra {
160192 extra ( & repo_path) ?;
161193 }
0 commit comments