Skip to content

Commit 4451e28

Browse files
authored
Rollup merge of #103969 - ferrocene:pa-download-rustc-ui-tests, r=jyn514
Partial support for running UI tests with `download-rustc` Right now trying to run UI tests with `download-rustc` results in a bunch of test failures, requiring someone who wants to only work on tests to also build the full compiler. This PR **partially** addresses the problem by solving a lot of the errors (but not all). * This installs the `rust-src` component on CI toolchains, since the test output depends on whether the standard library source code is installed; We can't just symlink the current source because the `rustc-dev` component already includes the compiler sources, but not the library sources, and mixing things is worse IMO. * This ensures the `$SRC_DIR` normalization done by compiletest correctly handles the source code added above. * This unconditionally sets `remap-prefix` to the prefix used in the downloaded toolchain, to ensure compiletest normalizes it.
2 parents 52cc0d5 + 470423c commit 4451e28

File tree

6 files changed

+45
-25
lines changed

6 files changed

+45
-25
lines changed

src/bootstrap/config.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -1511,19 +1511,25 @@ impl Config {
15111511

15121512
/// Return whether we will use a downloaded, pre-compiled version of rustc, or just build from source.
15131513
pub(crate) fn download_rustc(&self) -> bool {
1514-
static DOWNLOAD_RUSTC: OnceCell<bool> = OnceCell::new();
1514+
self.download_rustc_commit().is_some()
1515+
}
1516+
1517+
pub(crate) fn download_rustc_commit(&self) -> Option<&'static str> {
1518+
static DOWNLOAD_RUSTC: OnceCell<Option<String>> = OnceCell::new();
15151519
if self.dry_run() && DOWNLOAD_RUSTC.get().is_none() {
15161520
// avoid trying to actually download the commit
1517-
return false;
1521+
return None;
15181522
}
15191523

1520-
*DOWNLOAD_RUSTC.get_or_init(|| match &self.download_rustc_commit {
1521-
None => false,
1522-
Some(commit) => {
1523-
self.download_ci_rustc(commit);
1524-
true
1525-
}
1526-
})
1524+
DOWNLOAD_RUSTC
1525+
.get_or_init(|| match &self.download_rustc_commit {
1526+
None => None,
1527+
Some(commit) => {
1528+
self.download_ci_rustc(commit);
1529+
Some(commit.clone())
1530+
}
1531+
})
1532+
.as_deref()
15271533
}
15281534

15291535
pub(crate) fn initial_rustfmt(&self) -> Option<PathBuf> {

src/bootstrap/test.rs

+5
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);
@@ -1670,6 +1671,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the
16701671

16711672
cmd.arg("--channel").arg(&builder.config.channel);
16721673

1674+
if let Some(commit) = builder.config.download_rustc_commit() {
1675+
cmd.env("FAKE_DOWNLOAD_RUSTC_PREFIX", format!("/rustc/{commit}"));
1676+
}
1677+
16731678
builder.ci_env.force_coloring_in_ci(&mut cmd);
16741679

16751680
builder.info(&format!(

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

+19-16
Original file line numberDiff line numberDiff line change
@@ -3533,22 +3533,25 @@ impl<'test> TestCx<'test> {
35333533
let parent_dir = self.testpaths.file.parent().unwrap();
35343534
normalize_path(parent_dir, "$DIR");
35353535

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

35543557
// Paths into the build directory

0 commit comments

Comments
 (0)