Skip to content

Commit b899204

Browse files
authored
Unrolled build for rust-lang#137522
Rollup merge of rust-lang#137522 - onur-ozkan:137215-follow-ups, r=Kobzol use stage 2 on cargo and clippy tests when possible Follow-up for rust-lang#137215. For more context, read the discussion starting from rust-lang#137215 (comment). r? Kobzol (Feel free to re-r if you are not available).
2 parents c51b9b6 + 9ad6011 commit b899204

File tree

3 files changed

+99
-6
lines changed

3 files changed

+99
-6
lines changed

src/bootstrap/src/core/build_steps/test.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,27 @@ impl Step for Cargo {
293293
}
294294

295295
fn make_run(run: RunConfig<'_>) {
296-
run.builder.ensure(Cargo { stage: run.builder.top_stage, host: run.target });
296+
// If stage is explicitly set or not lower than 2, keep it. Otherwise, make sure it's at least 2
297+
// as tests for this step don't work with a lower stage.
298+
let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 {
299+
run.builder.top_stage
300+
} else {
301+
2
302+
};
303+
304+
run.builder.ensure(Cargo { stage, host: run.target });
297305
}
298306

299307
/// Runs `cargo test` for `cargo` packaged with Rust.
300308
fn run(self, builder: &Builder<'_>) {
301-
if self.stage < 2 {
302-
eprintln!("WARNING: cargo tests on stage {} may not behave well.", self.stage);
309+
let stage = self.stage;
310+
311+
if stage < 2 {
312+
eprintln!("WARNING: cargo tests on stage {stage} may not behave well.");
303313
eprintln!("HELP: consider using stage 2");
304314
}
305315

306-
let compiler = builder.compiler(self.stage, self.host);
316+
let compiler = builder.compiler(stage, self.host);
307317

308318
let cargo = builder.ensure(tool::Cargo { compiler, target: self.host });
309319
let compiler = cargo.build_compiler;
@@ -340,7 +350,7 @@ impl Step for Cargo {
340350
crates: vec!["cargo".into()],
341351
target: self.host.triple.to_string(),
342352
host: self.host.triple.to_string(),
343-
stage: self.stage,
353+
stage,
344354
},
345355
builder,
346356
);
@@ -739,7 +749,15 @@ impl Step for Clippy {
739749
}
740750

741751
fn make_run(run: RunConfig<'_>) {
742-
run.builder.ensure(Clippy { stage: run.builder.top_stage, host: run.target });
752+
// If stage is explicitly set or not lower than 2, keep it. Otherwise, make sure it's at least 2
753+
// as tests for this step don't work with a lower stage.
754+
let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 {
755+
run.builder.top_stage
756+
} else {
757+
2
758+
};
759+
760+
run.builder.ensure(Clippy { stage, host: run.target });
743761
}
744762

745763
/// Runs `cargo test` for clippy.

src/bootstrap/src/core/config/config.rs

+14
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ pub struct Config {
218218
pub stderr_is_tty: bool,
219219

220220
pub on_fail: Option<String>,
221+
pub explicit_stage_from_cli: bool,
222+
pub explicit_stage_from_config: bool,
221223
pub stage: u32,
222224
pub keep_stage: Vec<u32>,
223225
pub keep_stage_std: Vec<u32>,
@@ -2323,6 +2325,14 @@ impl Config {
23232325
config.compiletest_diff_tool = compiletest_diff_tool;
23242326

23252327
let download_rustc = config.download_rustc_commit.is_some();
2328+
config.explicit_stage_from_cli = flags.stage.is_some();
2329+
config.explicit_stage_from_config = test_stage.is_some()
2330+
|| build_stage.is_some()
2331+
|| doc_stage.is_some()
2332+
|| dist_stage.is_some()
2333+
|| install_stage.is_some()
2334+
|| check_stage.is_some()
2335+
|| bench_stage.is_some();
23262336
// See https://github.com/rust-lang/compiler-team/issues/326
23272337
config.stage = match config.cmd {
23282338
Subcommand::Check { .. } => flags.stage.or(check_stage).unwrap_or(0),
@@ -2392,6 +2402,10 @@ impl Config {
23922402
}
23932403
}
23942404

2405+
pub fn is_explicit_stage(&self) -> bool {
2406+
self.explicit_stage_from_cli || self.explicit_stage_from_config
2407+
}
2408+
23952409
/// Runs a command, printing out nice contextual information if it fails.
23962410
/// Exits if the command failed to execute at all, otherwise returns its
23972411
/// `status.success()`.

src/bootstrap/src/core/config/tests.rs

+61
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,64 @@ fn check_rustc_if_unchanged_paths() {
454454
assert!(config.src.join(p).exists(), "{p} doesn't exist.");
455455
}
456456
}
457+
458+
#[test]
459+
fn test_explicit_stage() {
460+
let config = Config::parse_inner(
461+
Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]),
462+
|&_| {
463+
toml::from_str(
464+
r#"
465+
[build]
466+
test-stage = 1
467+
"#,
468+
)
469+
},
470+
);
471+
472+
assert!(!config.explicit_stage_from_cli);
473+
assert!(config.explicit_stage_from_config);
474+
assert!(config.is_explicit_stage());
475+
476+
let config = Config::parse_inner(
477+
Flags::parse(&[
478+
"check".to_owned(),
479+
"--stage=2".to_owned(),
480+
"--config=/does/not/exist".to_owned(),
481+
]),
482+
|&_| toml::from_str(""),
483+
);
484+
485+
assert!(config.explicit_stage_from_cli);
486+
assert!(!config.explicit_stage_from_config);
487+
assert!(config.is_explicit_stage());
488+
489+
let config = Config::parse_inner(
490+
Flags::parse(&[
491+
"check".to_owned(),
492+
"--stage=2".to_owned(),
493+
"--config=/does/not/exist".to_owned(),
494+
]),
495+
|&_| {
496+
toml::from_str(
497+
r#"
498+
[build]
499+
test-stage = 1
500+
"#,
501+
)
502+
},
503+
);
504+
505+
assert!(config.explicit_stage_from_cli);
506+
assert!(config.explicit_stage_from_config);
507+
assert!(config.is_explicit_stage());
508+
509+
let config = Config::parse_inner(
510+
Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]),
511+
|&_| toml::from_str(""),
512+
);
513+
514+
assert!(!config.explicit_stage_from_cli);
515+
assert!(!config.explicit_stage_from_config);
516+
assert!(!config.is_explicit_stage());
517+
}

0 commit comments

Comments
 (0)