@@ -7,7 +7,9 @@ use super::build_sysroot::{BUILD_SYSROOT, ORIG_BUILD_SYSROOT, SYSROOT_RUSTC_VERS
7
7
use super :: path:: { Dirs , RelPath } ;
8
8
use super :: rustc_info:: { get_default_sysroot, get_rustc_version} ;
9
9
use super :: tests:: LIBCORE_TESTS_SRC ;
10
- use super :: utils:: { copy_dir_recursively, git_command, retry_spawn_and_wait, spawn_and_wait} ;
10
+ use super :: utils:: {
11
+ copy_dir_recursively, git_command, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait,
12
+ } ;
11
13
12
14
pub ( crate ) fn prepare ( dirs : & Dirs , rustc : & Path ) {
13
15
RelPath :: DOWNLOAD . ensure_exists ( dirs) ;
@@ -35,31 +37,24 @@ fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
35
37
copy_dir_recursively ( & ORIG_BUILD_SYSROOT . to_path ( dirs) , & BUILD_SYSROOT . to_path ( dirs) ) ;
36
38
37
39
fs:: create_dir_all ( SYSROOT_SRC . to_path ( dirs) . join ( "library" ) ) . unwrap ( ) ;
38
- copy_dir_recursively (
39
- & sysroot_src_orig. join ( "library" ) ,
40
- & SYSROOT_SRC . to_path ( dirs) . join ( "library" ) ,
41
- ) ;
40
+
41
+ apply_patches ( dirs, "stdlib" , & sysroot_src_orig, & SYSROOT_SRC . to_path ( dirs) ) ;
42
42
43
43
let rustc_version = get_rustc_version ( rustc) ;
44
44
fs:: write ( SYSROOT_RUSTC_VERSION . to_path ( dirs) , & rustc_version) . unwrap ( ) ;
45
-
46
- apply_patches ( dirs, "stdlib" , & SYSROOT_SRC . to_path ( dirs) ) ;
47
45
}
48
46
49
47
fn prepare_coretests ( dirs : & Dirs , rustc : & Path ) {
50
48
let sysroot_src_orig = get_default_sysroot ( rustc) . join ( "lib/rustlib/src/rust" ) ;
51
49
assert ! ( sysroot_src_orig. exists( ) ) ;
52
50
53
- eprintln ! ( "[COPY] coretests src" ) ;
54
-
55
51
// FIXME ensure builds error out or update the copy if any of the files copied here change
56
- LIBCORE_TESTS_SRC . ensure_fresh ( dirs) ;
57
- copy_dir_recursively (
52
+ apply_patches (
53
+ dirs,
54
+ "coretests" ,
58
55
& sysroot_src_orig. join ( "library/core/tests" ) ,
59
56
& LIBCORE_TESTS_SRC . to_path ( dirs) ,
60
57
) ;
61
-
62
- apply_patches ( dirs, "coretests" , & LIBCORE_TESTS_SRC . to_path ( dirs) ) ;
63
58
}
64
59
65
60
pub ( crate ) struct GitRepo {
@@ -159,11 +154,12 @@ impl GitRepo {
159
154
}
160
155
161
156
pub ( crate ) fn patch ( & self , dirs : & Dirs ) {
162
- let download_dir = self . download_dir ( dirs) ;
163
- let source_dir = self . source_dir ( ) ;
164
- source_dir. ensure_fresh ( dirs) ;
165
- copy_dir_recursively ( & download_dir, & source_dir. to_path ( dirs) ) ;
166
- apply_patches ( dirs, self . patch_name , & source_dir. to_path ( dirs) ) ;
157
+ apply_patches (
158
+ dirs,
159
+ self . patch_name ,
160
+ & self . download_dir ( dirs) ,
161
+ & self . source_dir ( ) . to_path ( dirs) ,
162
+ ) ;
167
163
}
168
164
}
169
165
@@ -267,8 +263,14 @@ fn get_patches(dirs: &Dirs, crate_name: &str) -> Vec<PathBuf> {
267
263
patches
268
264
}
269
265
270
- fn apply_patches ( dirs : & Dirs , crate_name : & str , target_dir : & Path ) {
271
- init_git_repo ( & target_dir) ;
266
+ fn apply_patches ( dirs : & Dirs , crate_name : & str , source_dir : & Path , target_dir : & Path ) {
267
+ // FIXME avoid copy and patch if src, patches and target are unchanged
268
+
269
+ remove_dir_if_exists ( target_dir) ;
270
+ fs:: create_dir_all ( target_dir) . unwrap ( ) ;
271
+ copy_dir_recursively ( source_dir, target_dir) ;
272
+
273
+ init_git_repo ( target_dir) ;
272
274
273
275
if crate_name == "<none>" {
274
276
return ;
0 commit comments