diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 825e5452f0e6a..b0181410be124 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -1648,16 +1648,17 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the // bootstrap compiler. // NOTE: Only stage 1 is special cased because we need the rustc_private artifacts to match the // running compiler in stage 2 when plugins run. - let stage_id = if suite == "ui-fulldeps" && compiler.stage == 1 { - // At stage 0 (stage - 1) we are using the beta compiler. Using `self.target` can lead finding - // an incorrect compiler path on cross-targets, as the stage 0 beta compiler is always equal - // to `build.build` in the configuration. + let (stage, stage_id) = if suite == "ui-fulldeps" && compiler.stage == 1 { + // At stage 0 (stage - 1) we are using the beta compiler. Using `self.target` can lead + // finding an incorrect compiler path on cross-targets, as the stage 0 beta compiler is + // always equal to `build.build` in the configuration. let build = builder.build.build; - compiler = builder.compiler(compiler.stage - 1, build); - format!("stage{}-{}", compiler.stage + 1, build) + let test_stage = compiler.stage + 1; + (test_stage, format!("stage{}-{}", test_stage, build)) } else { - format!("stage{}-{}", compiler.stage, target) + let stage = compiler.stage; + (stage, format!("stage{}-{}", stage, target)) }; if suite.ends_with("fulldeps") { @@ -1699,6 +1700,9 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the // compiletest currently has... a lot of arguments, so let's just pass all // of them! + cmd.arg("--stage").arg(stage.to_string()); + cmd.arg("--stage-id").arg(stage_id); + cmd.arg("--compile-lib-path").arg(builder.rustc_libdir(compiler)); cmd.arg("--run-lib-path").arg(builder.sysroot_target_libdir(compiler, target)); cmd.arg("--rustc-path").arg(builder.rustc(compiler)); @@ -1767,8 +1771,9 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the } else { builder.sysroot(compiler).to_path_buf() }; + cmd.arg("--sysroot-base").arg(sysroot); - cmd.arg("--stage-id").arg(stage_id); + cmd.arg("--suite").arg(suite); cmd.arg("--mode").arg(mode); cmd.arg("--target").arg(target.rustc_target_arg()); diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 00821fc9f9db2..cde4f7a665cbf 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -224,7 +224,9 @@ pub struct Config { /// The directory containing the compiler sysroot pub sysroot_base: PathBuf, - /// The name of the stage being built (stage1, etc) + /// The number of the stage under test. + pub stage: u32, + /// The id of the stage under test (stage1-xxx, etc). pub stage_id: String, /// The test mode, e.g. ui or debuginfo. diff --git a/src/tools/compiletest/src/header/cfg.rs b/src/tools/compiletest/src/header/cfg.rs index 6e5ced17c2084..cfe51b5655f82 100644 --- a/src/tools/compiletest/src/header/cfg.rs +++ b/src/tools/compiletest/src/header/cfg.rs @@ -192,7 +192,7 @@ fn parse_cfg_name_directive<'a>( message: "on big-endian targets", } condition! { - name: config.stage_id.split('-').next().unwrap(), + name: format!("stage{}", config.stage).as_str(), allowed_names: &["stage0", "stage1", "stage2"], message: "when the bootstrapping stage is {name}", } diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index ebba16d41f9e8..a9a07ff49564f 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -72,6 +72,7 @@ struct ConfigBuilder { channel: Option, host: Option, target: Option, + stage: Option, stage_id: Option, llvm_version: Option, git_hash: bool, @@ -102,6 +103,11 @@ impl ConfigBuilder { self } + fn stage(&mut self, n: u32) -> &mut Self { + self.stage = Some(n); + self + } + fn stage_id(&mut self, s: &str) -> &mut Self { self.stage_id = Some(s.to_owned()); self @@ -156,6 +162,8 @@ impl ConfigBuilder { "--cxxflags=", "--llvm-components=", "--android-cross-path=", + "--stage", + &self.stage.unwrap_or(2).to_string(), "--stage-id", self.stage_id.as_deref().unwrap_or("stage2-x86_64-unknown-linux-gnu"), "--channel", @@ -387,7 +395,7 @@ fn std_debug_assertions() { #[test] fn stage() { - let config: Config = cfg().stage_id("stage1-x86_64-unknown-linux-gnu").build(); + let config: Config = cfg().stage(1).stage_id("stage1-x86_64-unknown-linux-gnu").build(); assert!(check_ignore(&config, "//@ ignore-stage1")); assert!(!check_ignore(&config, "//@ ignore-stage2")); diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs index 27a046ba5bc4a..d0a83cab9cd99 100644 --- a/src/tools/compiletest/src/lib.rs +++ b/src/tools/compiletest/src/lib.rs @@ -64,6 +64,7 @@ pub fn parse_config(args: Vec) -> Config { .reqopt("", "src-base", "directory to scan for test files", "PATH") .reqopt("", "build-base", "directory to deposit test outputs", "PATH") .reqopt("", "sysroot-base", "directory containing the compiler sysroot", "PATH") + .reqopt("", "stage", "stage number under test", "N") .reqopt("", "stage-id", "the target-stage identifier", "stageN-TARGET") .reqopt( "", @@ -294,6 +295,11 @@ pub fn parse_config(args: Vec) -> Config { panic!("`--nocapture` is deprecated; please use `--no-capture`"); } + let stage = match matches.opt_str("stage") { + Some(stage) => stage.parse::().expect("expected `--stage` to be an unsigned integer"), + None => panic!("`--stage` is required"), + }; + Config { bless: matches.opt_present("bless"), compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")), @@ -311,7 +317,10 @@ pub fn parse_config(args: Vec) -> Config { src_base, build_base: opt_path(matches, "build-base"), sysroot_base: opt_path(matches, "sysroot-base"), + + stage, stage_id: matches.opt_str("stage-id").unwrap(), + mode, suite: matches.opt_str("suite").unwrap(), debugger: matches.opt_str("debugger").map(|debugger| { @@ -415,6 +424,7 @@ pub fn log_config(config: &Config) { logv(c, format!("rustdoc_path: {:?}", config.rustdoc_path)); logv(c, format!("src_base: {:?}", config.src_base.display())); logv(c, format!("build_base: {:?}", config.build_base.display())); + logv(c, format!("stage: {}", config.stage)); logv(c, format!("stage_id: {}", config.stage_id)); logv(c, format!("mode: {}", config.mode)); logv(c, format!("run_ignored: {}", config.run_ignored)); diff --git a/src/tools/compiletest/src/runtest/run_make.rs b/src/tools/compiletest/src/runtest/run_make.rs index 7ef16e4a9667b..16c46fc13390f 100644 --- a/src/tools/compiletest/src/runtest/run_make.rs +++ b/src/tools/compiletest/src/runtest/run_make.rs @@ -239,30 +239,6 @@ impl TestCx<'_> { } } - // `self.config.stage_id` looks like `stage1-`, but we only want - // the `stage1` part as that is what the output directories of bootstrap are prefixed with. - // Note that this *assumes* build layout from bootstrap is produced as: - // - // ``` - // build// // <- this is `build_root` - // ├── stage0 - // ├── stage0-bootstrap-tools - // ├── stage0-codegen - // ├── stage0-rustc - // ├── stage0-std - // ├── stage0-sysroot - // ├── stage0-tools - // ├── stage0-tools-bin - // ├── stage1 - // ├── stage1-std - // ├── stage1-tools - // ├── stage1-tools-bin - // └── test - // ``` - // FIXME(jieyouxu): improve the communication between bootstrap and compiletest here so - // we don't have to hack out a `stageN`. - let stage = self.config.stage_id.split('-').next().unwrap(); - // In order to link in the support library as a rlib when compiling recipes, we need three // paths: // 1. Path of the built support library rlib itself. @@ -284,10 +260,12 @@ impl TestCx<'_> { // support lib and its deps are organized, can't we copy them to the tools-bin dir as // well?), but this seems to work for now. - let stage_tools_bin = build_root.join(format!("{stage}-tools-bin")); + let stage_number = self.config.stage; + + let stage_tools_bin = build_root.join(format!("stage{stage_number}-tools-bin")); let support_lib_path = stage_tools_bin.join("librun_make_support.rlib"); - let stage_tools = build_root.join(format!("{stage}-tools")); + let stage_tools = build_root.join(format!("stage{stage_number}-tools")); let support_lib_deps = stage_tools.join(&self.config.host).join("release").join("deps"); let support_lib_deps_deps = stage_tools.join("release").join("deps"); @@ -368,7 +346,7 @@ impl TestCx<'_> { // provided through env vars. // Compute stage-specific standard library paths. - let stage_std_path = build_root.join(&stage).join("lib"); + let stage_std_path = build_root.join(format!("stage{stage_number}")).join("lib"); // Compute dynamic library search paths for recipes. let recipe_dylib_search_paths = {