@@ -4,7 +4,7 @@ use crate::utils::{cargo_install, git_clone, run_command, run_command_with_outpu
4
4
use std:: fs;
5
5
use std:: path:: Path ;
6
6
7
- fn prepare_libcore ( ) -> Result < ( ) , String > {
7
+ fn prepare_libcore ( sysroot_path : & Path ) -> Result < ( ) , String > {
8
8
let rustc_path = match get_rustc_path ( ) {
9
9
Some ( path) => path,
10
10
None => return Err ( "`rustc` path not found" . to_owned ( ) ) ,
@@ -15,14 +15,18 @@ fn prepare_libcore() -> Result<(), String> {
15
15
None => return Err ( format ! ( "No parent for `{}`" , rustc_path. display( ) ) ) ,
16
16
} ;
17
17
18
- let rustlib_dir = parent. join ( "../lib/rustlib/src/rust" ) ;
18
+ let rustlib_dir =
19
+ parent
20
+ . join ( "../lib/rustlib/src/rust" )
21
+ . canonicalize ( )
22
+ . map_err ( |e| format ! ( "Failed to canonicalize path: {e:?}" ) ) ?;
19
23
if !rustlib_dir. is_dir ( ) {
20
24
return Err ( "Please install `rust-src` component" . to_owned ( ) ) ;
21
25
}
22
26
23
- let sysroot_dir = Path :: new ( "build_sysroot/ sysroot_src") ;
27
+ let sysroot_dir = sysroot_path . join ( " sysroot_src") ;
24
28
if sysroot_dir. is_dir ( ) {
25
- if let Err ( e) = fs:: remove_dir_all ( sysroot_dir) {
29
+ if let Err ( e) = fs:: remove_dir_all ( & sysroot_dir) {
26
30
return Err ( format ! ( "Failed to remove `{}`: {:?}" , sysroot_dir. display( ) , e) ) ;
27
31
}
28
32
}
@@ -34,7 +38,7 @@ fn prepare_libcore() -> Result<(), String> {
34
38
sysroot_library_dir. display( ) ,
35
39
) ) ?;
36
40
37
- run_command ( & [ & "cp" , & "-r" , & rustlib_dir, & sysroot_library_dir ] , None ) ?;
41
+ run_command ( & [ & "cp" , & "-r" , & rustlib_dir. join ( "library" ) , & sysroot_dir ] , None ) ?;
38
42
39
43
println ! ( "[GIT] init (cwd): `{}`" , sysroot_dir. display( ) ) ;
40
44
run_command_with_output ( & [ & "git" , & "init" ] , Some ( & sysroot_dir) ) ?;
@@ -47,8 +51,8 @@ fn prepare_libcore() -> Result<(), String> {
47
51
// Even using --author is not enough.
48
52
run_command ( & [ & "git" , & "config" , & "user.email" , & "[email protected] " ] , Some ( & sysroot_dir
) ) ?
;
49
53
run_command ( & [ & "git" , & "config" , & "user.name" , & "None" ] , Some ( & sysroot_dir) ) ?;
50
- run_command ( & [ & "git" , & "config" , & "core.autocrlf= false" ] , Some ( & sysroot_dir) ) ?;
51
- run_command ( & [ & "git" , & "config" , & "commit.gpgSign= false" ] , Some ( & sysroot_dir) ) ?;
54
+ run_command ( & [ & "git" , & "config" , & "core.autocrlf" , & " false"] , Some ( & sysroot_dir) ) ?;
55
+ run_command ( & [ & "git" , & "config" , & "commit.gpgSign" , & " false"] , Some ( & sysroot_dir) ) ?;
52
56
run_command ( & [ & "git" , & "commit" , & "-m" , & "Initial commit" , & "-q" ] , Some ( & sysroot_dir) ) ?;
53
57
54
58
walk_dir ( "patches" , |_| Ok ( ( ) ) , |file_path : & Path | {
@@ -73,27 +77,30 @@ fn build_raytracer(repo_dir: &Path) -> Result<(), String> {
73
77
Ok ( ( ) )
74
78
}
75
79
76
- fn clone_and_setup < F > ( repo_url : & str , checkout_commit : & str , extra : Option < F > ) -> Result < ( ) , String >
80
+ fn clone_and_setup < F > ( sysroot_path : & Path , repo_url : & str , checkout_commit : & str , extra : Option < F > ) -> Result < ( ) , String >
77
81
where
78
82
F : Fn ( & Path ) -> Result < ( ) , String > ,
79
83
{
80
- let clone_result = git_clone ( repo_url, None ) ?;
84
+ let clone_result = git_clone ( repo_url, Some ( sysroot_path ) ) ?;
81
85
if !clone_result. ran_clone {
82
86
println ! ( "`{}` has already been cloned" , clone_result. repo_name) ;
83
87
}
84
- let repo_path = Path :: new ( & clone_result. repo_name ) ;
85
- run_command ( & [ & "git" , & "checkout" , & "--" , & "." ] , Some ( repo_path) ) ?;
86
- run_command ( & [ & "git" , & "checkout" , & checkout_commit] , Some ( repo_path) ) ?;
88
+ let repo_path = sysroot_path . join ( & clone_result. repo_name ) ;
89
+ run_command_with_output ( & [ & "git" , & "checkout" , & "--" , & "." ] , Some ( & repo_path) ) ?;
90
+ run_command_with_output ( & [ & "git" , & "checkout" , & checkout_commit] , Some ( & repo_path) ) ?;
87
91
let filter = format ! ( "-{}-" , clone_result. repo_name) ;
88
92
walk_dir ( "crate_patches" , |_| Ok ( ( ) ) , |file_path| {
89
93
let s = file_path. as_os_str ( ) . to_str ( ) . unwrap ( ) ;
90
94
if s. contains ( & filter) && s. ends_with ( ".patch" ) {
91
- run_command ( & [ & "git" , & "am" , & s] , Some ( repo_path) ) ?;
95
+ run_command_with_output (
96
+ & [ & "git" , & "am" , & file_path. canonicalize ( ) . unwrap ( ) ] ,
97
+ Some ( & repo_path) ,
98
+ ) ?;
92
99
}
93
100
Ok ( ( ) )
94
101
} ) ?;
95
102
if let Some ( extra) = extra {
96
- extra ( repo_path) ?;
103
+ extra ( & repo_path) ?;
97
104
}
98
105
Ok ( ( ) )
99
106
}
@@ -136,7 +143,8 @@ pub fn run() -> Result<(), String> {
136
143
Some ( a) => a,
137
144
None => return Ok ( ( ) ) ,
138
145
} ;
139
- prepare_libcore ( ) ?;
146
+ let sysroot_path = Path :: new ( "build_sysroot" ) ;
147
+ prepare_libcore ( sysroot_path) ?;
140
148
141
149
if !args. only_libcore {
142
150
cargo_install ( "hyperfine" ) ?;
@@ -148,7 +156,7 @@ pub fn run() -> Result<(), String> {
148
156
] ;
149
157
150
158
for ( repo_url, checkout_commit, cb) in to_clone {
151
- clone_and_setup ( repo_url, checkout_commit, * cb) ?;
159
+ clone_and_setup ( sysroot_path , repo_url, checkout_commit, * cb) ?;
152
160
}
153
161
}
154
162
0 commit comments