1
+ use std:: ffi:: OsStr ;
1
2
use std:: fs;
2
3
use std:: path:: { Path , PathBuf } ;
4
+ use std:: process:: Output ;
3
5
4
6
use crate :: rustc_info:: get_rustc_path;
5
7
use crate :: utils:: {
6
8
cargo_install, create_dir, get_sysroot_dir, git_clone_root_dir, remove_file, run_command,
7
9
run_command_with_output, walk_dir,
8
10
} ;
9
11
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
+
10
47
fn prepare_libcore (
11
48
sysroot_path : & Path ,
12
49
libgccjit12_patches : bool ,
@@ -55,19 +92,12 @@ fn prepare_libcore(
55
92
run_command ( & [ & "cp" , & "-r" , & rustlib_dir. join ( "library" ) , & sysroot_dir] , None ) ?;
56
93
57
94
println ! ( "[GIT] init (cwd): `{}`" , sysroot_dir. display( ) ) ;
58
- run_command ( & [ & "git ", & "init" ] , Some ( & sysroot_dir) ) ?;
95
+ run_git_command ( & "init ", & [ ] , Some ( & sysroot_dir) ) ?;
59
96
println ! ( "[GIT] add (cwd): `{}`" , sysroot_dir. display( ) ) ;
60
- run_command ( & [ & "git" , & " add", & "." ] , Some ( & sysroot_dir) ) ?;
97
+ run_git_command ( & " add", & [ & "." ] , Some ( & sysroot_dir) ) ?;
61
98
println ! ( "[GIT] commit (cwd): `{}`" , sysroot_dir. display( ) ) ;
62
99
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) ) ?;
71
101
72
102
let mut patches = Vec :: new ( ) ;
73
103
walk_dir (
@@ -105,10 +135,11 @@ fn prepare_libcore(
105
135
for file_path in patches {
106
136
println ! ( "[GIT] apply `{}`" , file_path. display( ) ) ;
107
137
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( ) ) ] ,
112
143
Some ( & sysroot_dir) ,
113
144
) ?;
114
145
}
@@ -124,10 +155,11 @@ fn prepare_rand() -> Result<(), String> {
124
155
let rand_dir = Path :: new ( "build/rand" ) ;
125
156
println ! ( "[GIT] apply `{file_path}`" ) ;
126
157
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( ) ) ] ,
131
163
Some ( rand_dir) ,
132
164
) ?;
133
165
@@ -154,8 +186,8 @@ where
154
186
println ! ( "`{}` has already been cloned" , clone_result. repo_name) ;
155
187
}
156
188
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) ) ?;
159
191
if let Some ( extra) = extra {
160
192
extra ( & repo_path) ?;
161
193
}
0 commit comments