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
+ 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
+
10
64
fn prepare_libcore (
11
65
sysroot_path : & Path ,
12
66
libgccjit12_patches : bool ,
@@ -55,19 +109,12 @@ fn prepare_libcore(
55
109
run_command ( & [ & "cp" , & "-r" , & rustlib_dir. join ( "library" ) , & sysroot_dir] , None ) ?;
56
110
57
111
println ! ( "[GIT] init (cwd): `{}`" , sysroot_dir. display( ) ) ;
58
- run_command ( & [ & "git ", & "init" ] , Some ( & sysroot_dir) ) ?;
112
+ run_git_command ( & "init ", & [ ] , Some ( & sysroot_dir) ) ?;
59
113
println ! ( "[GIT] add (cwd): `{}`" , sysroot_dir. display( ) ) ;
60
- run_command ( & [ & "git" , & " add", & "." ] , Some ( & sysroot_dir) ) ?;
114
+ run_git_command ( & " add", & [ & "." ] , Some ( & sysroot_dir) ) ?;
61
115
println ! ( "[GIT] commit (cwd): `{}`" , sysroot_dir. display( ) ) ;
62
116
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) ) ?;
71
118
72
119
let mut patches = Vec :: new ( ) ;
73
120
walk_dir (
@@ -105,10 +152,11 @@ fn prepare_libcore(
105
152
for file_path in patches {
106
153
println ! ( "[GIT] apply `{}`" , file_path. display( ) ) ;
107
154
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( ) ) ] ,
112
160
Some ( & sysroot_dir) ,
113
161
) ?;
114
162
}
@@ -124,10 +172,11 @@ fn prepare_rand() -> Result<(), String> {
124
172
let rand_dir = Path :: new ( "build/rand" ) ;
125
173
println ! ( "[GIT] apply `{file_path}`" ) ;
126
174
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( ) ) ] ,
131
180
Some ( rand_dir) ,
132
181
) ?;
133
182
@@ -154,8 +203,8 @@ where
154
203
println ! ( "`{}` has already been cloned" , clone_result. repo_name) ;
155
204
}
156
205
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) ) ?;
159
208
if let Some ( extra) = extra {
160
209
extra ( & repo_path) ?;
161
210
}
0 commit comments