Skip to content

Commit 9ad6011

Browse files
committed
use stage 2 on cargo and clippy tests when possible
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent cf6dc74 commit 9ad6011

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-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

+4
Original file line numberDiff line numberDiff line change
@@ -2402,6 +2402,10 @@ impl Config {
24022402
}
24032403
}
24042404

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

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

+4
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ fn test_explicit_stage() {
471471

472472
assert!(!config.explicit_stage_from_cli);
473473
assert!(config.explicit_stage_from_config);
474+
assert!(config.is_explicit_stage());
474475

475476
let config = Config::parse_inner(
476477
Flags::parse(&[
@@ -483,6 +484,7 @@ fn test_explicit_stage() {
483484

484485
assert!(config.explicit_stage_from_cli);
485486
assert!(!config.explicit_stage_from_config);
487+
assert!(config.is_explicit_stage());
486488

487489
let config = Config::parse_inner(
488490
Flags::parse(&[
@@ -502,6 +504,7 @@ fn test_explicit_stage() {
502504

503505
assert!(config.explicit_stage_from_cli);
504506
assert!(config.explicit_stage_from_config);
507+
assert!(config.is_explicit_stage());
505508

506509
let config = Config::parse_inner(
507510
Flags::parse(&["check".to_owned(), "--config=/does/not/exist".to_owned()]),
@@ -510,4 +513,5 @@ fn test_explicit_stage() {
510513

511514
assert!(!config.explicit_stage_from_cli);
512515
assert!(!config.explicit_stage_from_config);
516+
assert!(!config.is_explicit_stage());
513517
}

0 commit comments

Comments
 (0)