Skip to content

Commit 80d5359

Browse files
committed
normalize source paths from sysroot in compiletest
1 parent 357f660 commit 80d5359

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

src/bootstrap/test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
14011401

14021402
cmd.arg("--src-base").arg(builder.src.join("src/test").join(suite));
14031403
cmd.arg("--build-base").arg(testdir(builder, compiler.host).join(suite));
1404+
cmd.arg("--sysroot-base").arg(builder.sysroot(compiler));
14041405
cmd.arg("--stage-id").arg(format!("stage{}-{}", compiler.stage, target));
14051406
cmd.arg("--suite").arg(suite);
14061407
cmd.arg("--mode").arg(mode);

src/tools/compiletest/src/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ pub struct Config {
230230
/// The directory where programs should be built
231231
pub build_base: PathBuf,
232232

233+
/// The directory containing the compiler sysroot
234+
pub sysroot_base: PathBuf,
235+
233236
/// The name of the stage being built (stage1, etc)
234237
pub stage_id: String,
235238

src/tools/compiletest/src/header/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fn config() -> Config {
4646
"--jsondocck-path=",
4747
"--src-base=",
4848
"--build-base=",
49+
"--sysroot-base=",
4950
"--stage-id=stage2",
5051
"--cc=c",
5152
"--cxx=c++",

src/tools/compiletest/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
6969
.optopt("", "llvm-filecheck", "path to LLVM's FileCheck binary", "DIR")
7070
.reqopt("", "src-base", "directory to scan for test files", "PATH")
7171
.reqopt("", "build-base", "directory to deposit test outputs", "PATH")
72+
.reqopt("", "sysroot-base", "directory containing the compiler sysroot", "PATH")
7273
.reqopt("", "stage-id", "the target-stage identifier", "stageN-TARGET")
7374
.reqopt(
7475
"",
@@ -234,6 +235,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
234235
llvm_bin_dir: matches.opt_str("llvm-bin-dir").map(PathBuf::from),
235236
src_base,
236237
build_base: opt_path(matches, "build-base"),
238+
sysroot_base: opt_path(matches, "sysroot-base"),
237239
stage_id: matches.opt_str("stage-id").unwrap(),
238240
mode,
239241
suite: matches.opt_str("suite").unwrap(),

src/tools/compiletest/src/runtest.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -3529,22 +3529,23 @@ impl<'test> TestCx<'test> {
35293529
let parent_dir = self.testpaths.file.parent().unwrap();
35303530
normalize_path(parent_dir, "$DIR");
35313531

3532-
// Paths into the libstd/libcore
3533-
let base_dir = self.config.src_base.parent().unwrap().parent().unwrap().parent().unwrap();
3534-
let src_dir = base_dir.join("library");
3535-
normalize_path(&src_dir, "$SRC_DIR");
3536-
3537-
// `ui-fulldeps` tests can show paths to the compiler source when testing macros from
3538-
// `rustc_macros`
3539-
// eg. /home/user/rust/compiler
3540-
let compiler_src_dir = base_dir.join("compiler");
3541-
normalize_path(&compiler_src_dir, "$COMPILER_DIR");
3542-
3543-
if let Some(virtual_rust_source_base_dir) =
3544-
option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(PathBuf::from)
3545-
{
3546-
normalize_path(&virtual_rust_source_base_dir.join("library"), "$SRC_DIR");
3547-
normalize_path(&virtual_rust_source_base_dir.join("compiler"), "$COMPILER_DIR");
3532+
let source_bases = &[
3533+
// Source base on the current filesystem (calculated as parent of `src/test/$suite`):
3534+
Some(self.config.src_base.parent().unwrap().parent().unwrap().parent().unwrap().into()),
3535+
// Source base on the sysroot (from the src components downloaded by `download-rustc`):
3536+
Some(self.config.sysroot_base.join("lib").join("rustlib").join("src").join("rust")),
3537+
// Virtual `/rustc/$sha` remapped paths (if `remap-debuginfo` is enabled):
3538+
option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(PathBuf::from),
3539+
];
3540+
for base_dir in source_bases {
3541+
if let Some(base_dir) = base_dir {
3542+
// Paths into the libstd/libcore
3543+
normalize_path(&base_dir.join("library"), "$SRC_DIR");
3544+
// `ui-fulldeps` tests can show paths to the compiler source when testing macros from
3545+
// `rustc_macros`
3546+
// eg. /home/user/rust/compiler
3547+
normalize_path(&base_dir.join("compiler"), "$COMPILER_DIR");
3548+
}
35483549
}
35493550

35503551
// Paths into the build directory

0 commit comments

Comments
 (0)