Skip to content

Commit 2c38eff

Browse files
committed
Don't patch in place in apply_patches
This will make it easier to skip patching if unnecessary in the future
1 parent 75327f8 commit 2c38eff

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

build_system/prepare.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use super::build_sysroot::{BUILD_SYSROOT, ORIG_BUILD_SYSROOT, SYSROOT_RUSTC_VERS
77
use super::path::{Dirs, RelPath};
88
use super::rustc_info::{get_default_sysroot, get_rustc_version};
99
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+
};
1113

1214
pub(crate) fn prepare(dirs: &Dirs, rustc: &Path) {
1315
RelPath::DOWNLOAD.ensure_exists(dirs);
@@ -35,31 +37,24 @@ fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
3537
copy_dir_recursively(&ORIG_BUILD_SYSROOT.to_path(dirs), &BUILD_SYSROOT.to_path(dirs));
3638

3739
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));
4242

4343
let rustc_version = get_rustc_version(rustc);
4444
fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap();
45-
46-
apply_patches(dirs, "stdlib", &SYSROOT_SRC.to_path(dirs));
4745
}
4846

4947
fn prepare_coretests(dirs: &Dirs, rustc: &Path) {
5048
let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust");
5149
assert!(sysroot_src_orig.exists());
5250

53-
eprintln!("[COPY] coretests src");
54-
5551
// 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",
5855
&sysroot_src_orig.join("library/core/tests"),
5956
&LIBCORE_TESTS_SRC.to_path(dirs),
6057
);
61-
62-
apply_patches(dirs, "coretests", &LIBCORE_TESTS_SRC.to_path(dirs));
6358
}
6459

6560
pub(crate) struct GitRepo {
@@ -159,11 +154,12 @@ impl GitRepo {
159154
}
160155

161156
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+
);
167163
}
168164
}
169165

@@ -267,8 +263,14 @@ fn get_patches(dirs: &Dirs, crate_name: &str) -> Vec<PathBuf> {
267263
patches
268264
}
269265

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);
272274

273275
if crate_name == "<none>" {
274276
return;

0 commit comments

Comments
 (0)