Skip to content

Commit 8aae939

Browse files
committed
compiletest: use --stage number directly instead of deriving from --stage-id
Notably, this avoids having to do hacky string splitting based on `--stage-id`.
1 parent 506bccb commit 8aae939

File tree

5 files changed

+28
-30
lines changed

5 files changed

+28
-30
lines changed

src/tools/compiletest/src/common.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ pub struct Config {
224224
/// The directory containing the compiler sysroot
225225
pub sysroot_base: PathBuf,
226226

227-
/// The name of the stage being built (stage1, etc)
227+
/// The number of the stage under test.
228+
pub stage: u32,
229+
/// The id of the stage under test (stage1-xxx, etc).
228230
pub stage_id: String,
229231

230232
/// The test mode, e.g. ui or debuginfo.

src/tools/compiletest/src/header/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fn parse_cfg_name_directive<'a>(
192192
message: "on big-endian targets",
193193
}
194194
condition! {
195-
name: config.stage_id.split('-').next().unwrap(),
195+
name: format!("stage{}", config.stage).as_str(),
196196
allowed_names: &["stage0", "stage1", "stage2"],
197197
message: "when the bootstrapping stage is {name}",
198198
}

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct ConfigBuilder {
7272
channel: Option<String>,
7373
host: Option<String>,
7474
target: Option<String>,
75+
stage: Option<u32>,
7576
stage_id: Option<String>,
7677
llvm_version: Option<String>,
7778
git_hash: bool,
@@ -102,6 +103,11 @@ impl ConfigBuilder {
102103
self
103104
}
104105

106+
fn stage(&mut self, n: u32) -> &mut Self {
107+
self.stage = Some(n);
108+
self
109+
}
110+
105111
fn stage_id(&mut self, s: &str) -> &mut Self {
106112
self.stage_id = Some(s.to_owned());
107113
self
@@ -156,6 +162,8 @@ impl ConfigBuilder {
156162
"--cxxflags=",
157163
"--llvm-components=",
158164
"--android-cross-path=",
165+
"--stage",
166+
&self.stage.unwrap_or(2).to_string(),
159167
"--stage-id",
160168
self.stage_id.as_deref().unwrap_or("stage2-x86_64-unknown-linux-gnu"),
161169
"--channel",
@@ -387,7 +395,7 @@ fn std_debug_assertions() {
387395

388396
#[test]
389397
fn stage() {
390-
let config: Config = cfg().stage_id("stage1-x86_64-unknown-linux-gnu").build();
398+
let config: Config = cfg().stage(1).stage_id("stage1-x86_64-unknown-linux-gnu").build();
391399

392400
assert!(check_ignore(&config, "//@ ignore-stage1"));
393401
assert!(!check_ignore(&config, "//@ ignore-stage2"));

src/tools/compiletest/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
6464
.reqopt("", "src-base", "directory to scan for test files", "PATH")
6565
.reqopt("", "build-base", "directory to deposit test outputs", "PATH")
6666
.reqopt("", "sysroot-base", "directory containing the compiler sysroot", "PATH")
67+
.reqopt("", "stage", "stage number under test", "N")
6768
.reqopt("", "stage-id", "the target-stage identifier", "stageN-TARGET")
6869
.reqopt(
6970
"",
@@ -294,6 +295,11 @@ pub fn parse_config(args: Vec<String>) -> Config {
294295
panic!("`--nocapture` is deprecated; please use `--no-capture`");
295296
}
296297

298+
let stage = match matches.opt_str("stage") {
299+
Some(stage) => stage.parse::<u32>().expect("expected `--stage` to be an unsigned integer"),
300+
None => panic!("`--stage` is required"),
301+
};
302+
297303
Config {
298304
bless: matches.opt_present("bless"),
299305
compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")),
@@ -311,7 +317,10 @@ pub fn parse_config(args: Vec<String>) -> Config {
311317
src_base,
312318
build_base: opt_path(matches, "build-base"),
313319
sysroot_base: opt_path(matches, "sysroot-base"),
320+
321+
stage,
314322
stage_id: matches.opt_str("stage-id").unwrap(),
323+
315324
mode,
316325
suite: matches.opt_str("suite").unwrap(),
317326
debugger: matches.opt_str("debugger").map(|debugger| {
@@ -415,6 +424,7 @@ pub fn log_config(config: &Config) {
415424
logv(c, format!("rustdoc_path: {:?}", config.rustdoc_path));
416425
logv(c, format!("src_base: {:?}", config.src_base.display()));
417426
logv(c, format!("build_base: {:?}", config.build_base.display()));
427+
logv(c, format!("stage: {}", config.stage));
418428
logv(c, format!("stage_id: {}", config.stage_id));
419429
logv(c, format!("mode: {}", config.mode));
420430
logv(c, format!("run_ignored: {}", config.run_ignored));

src/tools/compiletest/src/runtest/run_make.rs

+5-27
Original file line numberDiff line numberDiff line change
@@ -239,30 +239,6 @@ impl TestCx<'_> {
239239
}
240240
}
241241

242-
// `self.config.stage_id` looks like `stage1-<target_triple>`, but we only want
243-
// the `stage1` part as that is what the output directories of bootstrap are prefixed with.
244-
// Note that this *assumes* build layout from bootstrap is produced as:
245-
//
246-
// ```
247-
// build/<target_triple>/ // <- this is `build_root`
248-
// ├── stage0
249-
// ├── stage0-bootstrap-tools
250-
// ├── stage0-codegen
251-
// ├── stage0-rustc
252-
// ├── stage0-std
253-
// ├── stage0-sysroot
254-
// ├── stage0-tools
255-
// ├── stage0-tools-bin
256-
// ├── stage1
257-
// ├── stage1-std
258-
// ├── stage1-tools
259-
// ├── stage1-tools-bin
260-
// └── test
261-
// ```
262-
// FIXME(jieyouxu): improve the communication between bootstrap and compiletest here so
263-
// we don't have to hack out a `stageN`.
264-
let stage = self.config.stage_id.split('-').next().unwrap();
265-
266242
// In order to link in the support library as a rlib when compiling recipes, we need three
267243
// paths:
268244
// 1. Path of the built support library rlib itself.
@@ -284,10 +260,12 @@ impl TestCx<'_> {
284260
// support lib and its deps are organized, can't we copy them to the tools-bin dir as
285261
// well?), but this seems to work for now.
286262

287-
let stage_tools_bin = build_root.join(format!("{stage}-tools-bin"));
263+
let stage_number = self.config.stage;
264+
265+
let stage_tools_bin = build_root.join(format!("stage{stage_number}-tools-bin"));
288266
let support_lib_path = stage_tools_bin.join("librun_make_support.rlib");
289267

290-
let stage_tools = build_root.join(format!("{stage}-tools"));
268+
let stage_tools = build_root.join(format!("stage{stage_number}-tools"));
291269
let support_lib_deps = stage_tools.join(&self.config.host).join("release").join("deps");
292270
let support_lib_deps_deps = stage_tools.join("release").join("deps");
293271

@@ -368,7 +346,7 @@ impl TestCx<'_> {
368346
// provided through env vars.
369347

370348
// Compute stage-specific standard library paths.
371-
let stage_std_path = build_root.join(&stage).join("lib");
349+
let stage_std_path = build_root.join(format!("stage{stage_number}")).join("lib");
372350

373351
// Compute dynamic library search paths for recipes.
374352
let recipe_dylib_search_paths = {

0 commit comments

Comments
 (0)