Skip to content

Commit fc23a8a

Browse files
committed
Lazily patch coretests
1 parent 2c38eff commit fc23a8a

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

build_system/prepare.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::process::Command;
66
use super::build_sysroot::{BUILD_SYSROOT, ORIG_BUILD_SYSROOT, SYSROOT_RUSTC_VERSION, SYSROOT_SRC};
77
use super::path::{Dirs, RelPath};
88
use super::rustc_info::{get_default_sysroot, get_rustc_version};
9-
use super::tests::LIBCORE_TESTS_SRC;
109
use super::utils::{
1110
copy_dir_recursively, git_command, remove_dir_if_exists, retry_spawn_and_wait, spawn_and_wait,
1211
};
@@ -19,7 +18,6 @@ pub(crate) fn prepare(dirs: &Dirs, rustc: &Path) {
1918

2019
// FIXME do this on the fly?
2120
prepare_stdlib(dirs, rustc);
22-
prepare_coretests(dirs, rustc);
2321

2422
super::tests::RAND_REPO.patch(dirs);
2523
super::tests::REGEX_REPO.patch(dirs);
@@ -44,19 +42,6 @@ fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
4442
fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap();
4543
}
4644

47-
fn prepare_coretests(dirs: &Dirs, rustc: &Path) {
48-
let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust");
49-
assert!(sysroot_src_orig.exists());
50-
51-
// FIXME ensure builds error out or update the copy if any of the files copied here change
52-
apply_patches(
53-
dirs,
54-
"coretests",
55-
&sysroot_src_orig.join("library/core/tests"),
56-
&LIBCORE_TESTS_SRC.to_path(dirs),
57-
);
58-
}
59-
6045
pub(crate) struct GitRepo {
6146
url: GitRepoUrl,
6247
rev: &'static str,
@@ -263,7 +248,7 @@ fn get_patches(dirs: &Dirs, crate_name: &str) -> Vec<PathBuf> {
263248
patches
264249
}
265250

266-
fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, target_dir: &Path) {
251+
pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, target_dir: &Path) {
267252
// FIXME avoid copy and patch if src, patches and target are unchanged
268253

269254
remove_dir_if_exists(target_dir);

build_system/tests.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
use super::build_sysroot;
22
use super::config;
33
use super::path::{Dirs, RelPath};
4-
use super::prepare::GitRepo;
4+
use super::prepare::{apply_patches, GitRepo};
5+
use super::rustc_info::get_default_sysroot;
56
use super::utils::{spawn_and_wait, spawn_and_wait_with_input, CargoProject, Compiler};
67
use super::{CodegenBackend, SysrootKind};
78
use std::env;
89
use std::ffi::OsStr;
910
use std::fs;
11+
use std::path::PathBuf;
1012
use std::process::Command;
1113

1214
static BUILD_EXAMPLE_OUT_DIR: RelPath = RelPath::BUILD.join("example");
@@ -125,9 +127,9 @@ pub(crate) static PORTABLE_SIMD_REPO: GitRepo = GitRepo::github(
125127
pub(crate) static PORTABLE_SIMD: CargoProject =
126128
CargoProject::new(&PORTABLE_SIMD_REPO.source_dir(), "portable_simd_target");
127129

128-
pub(crate) static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests_src");
130+
static LIBCORE_TESTS_SRC: RelPath = RelPath::BUILD.join("coretests_src");
129131

130-
pub(crate) static LIBCORE_TESTS: CargoProject = CargoProject::new(&LIBCORE_TESTS_SRC, "core_tests");
132+
static LIBCORE_TESTS: CargoProject = CargoProject::new(&LIBCORE_TESTS_SRC, "core_tests");
131133

132134
const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
133135
TestCase::custom("test.rust-random/rand", &|runner| {
@@ -145,6 +147,13 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
145147
}
146148
}),
147149
TestCase::custom("test.libcore", &|runner| {
150+
apply_patches(
151+
&runner.dirs,
152+
"coretests",
153+
&runner.stdlib_source.join("library/core/tests"),
154+
&LIBCORE_TESTS_SRC.to_path(&runner.dirs),
155+
);
156+
148157
LIBCORE_TESTS.clean(&runner.dirs);
149158

150159
if runner.is_native {
@@ -231,6 +240,10 @@ pub(crate) fn run_tests(
231240
rustup_toolchain_name: Option<&str>,
232241
target_triple: String,
233242
) {
243+
let stdlib_source =
244+
get_default_sysroot(&bootstrap_host_compiler.rustc).join("lib/rustlib/src/rust");
245+
assert!(stdlib_source.exists());
246+
234247
if config::get_bool("testsuite.no_sysroot") {
235248
let target_compiler = build_sysroot::build_sysroot(
236249
dirs,
@@ -247,6 +260,7 @@ pub(crate) fn run_tests(
247260
target_compiler,
248261
use_unstable_features,
249262
bootstrap_host_compiler.triple == target_triple,
263+
stdlib_source.clone(),
250264
);
251265

252266
BUILD_EXAMPLE_OUT_DIR.ensure_fresh(dirs);
@@ -277,6 +291,7 @@ pub(crate) fn run_tests(
277291
target_compiler,
278292
use_unstable_features,
279293
bootstrap_host_compiler.triple == target_triple,
294+
stdlib_source,
280295
);
281296

282297
if run_base_sysroot {
@@ -299,6 +314,7 @@ struct TestRunner {
299314
use_unstable_features: bool,
300315
dirs: Dirs,
301316
target_compiler: Compiler,
317+
stdlib_source: PathBuf,
302318
}
303319

304320
impl TestRunner {
@@ -307,6 +323,7 @@ impl TestRunner {
307323
mut target_compiler: Compiler,
308324
use_unstable_features: bool,
309325
is_native: bool,
326+
stdlib_source: PathBuf,
310327
) -> Self {
311328
if let Ok(rustflags) = env::var("RUSTFLAGS") {
312329
target_compiler.rustflags.push(' ');
@@ -327,7 +344,14 @@ impl TestRunner {
327344
&& target_compiler.triple.contains("x86_64")
328345
&& !target_compiler.triple.contains("windows");
329346

330-
Self { is_native, jit_supported, use_unstable_features, dirs, target_compiler }
347+
Self {
348+
is_native,
349+
jit_supported,
350+
use_unstable_features,
351+
dirs,
352+
target_compiler,
353+
stdlib_source,
354+
}
331355
}
332356

333357
fn run_testsuite(&self, tests: &[TestCase]) {

0 commit comments

Comments
 (0)