Skip to content

Commit 0719287

Browse files
authored
Rollup merge of #148459 - Zalathar:bootstrap-py, r=Kobzol
bootstrap: Split out a separate `./x test bootstrap-py` step While testing changes to bootstrap, I was annoyed by the fact that `./x test bootstrap` spams a bunch of mysterious output to the console. That output turns out to come from `bootstrap_test.py`, which runs unit tests for the Python parts of bootstrap. Those tests are (presumably) useful, but they don't add value when working on the Rust parts of bootstrap. This PR therefore pulls them out into a separate test step that can be run with `./x test bootstrap-py`.
2 parents b40a20f + 948bed2 commit 0719287

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

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

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,33 +3337,57 @@ fn distcheck_rustc_dev(builder: &Builder<'_>, dir: &Path) {
33373337
builder.remove_dir(dir);
33383338
}
33393339

3340+
/// Runs unit tests in `bootstrap_test.py`, which test the Python parts of bootstrap.
33403341
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3341-
pub struct Bootstrap;
3342+
pub(crate) struct BootstrapPy;
33423343

3343-
impl Step for Bootstrap {
3344+
impl Step for BootstrapPy {
33443345
type Output = ();
33453346
const DEFAULT: bool = true;
33463347
const IS_HOST: bool = true;
33473348

3348-
/// Tests the build system itself.
3349-
fn run(self, builder: &Builder<'_>) {
3350-
let host = builder.config.host_target;
3351-
let build_compiler = builder.compiler(0, host);
3349+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
3350+
// Bootstrap tests might not be perfectly self-contained and can depend
3351+
// on the environment, so only run them by default in CI, not locally.
3352+
// See `test::Bootstrap::should_run`.
3353+
let is_ci = run.builder.config.is_running_on_ci;
3354+
run.alias("bootstrap-py").default_condition(is_ci)
3355+
}
33523356

3353-
// Some tests require cargo submodule to be present.
3354-
builder.build.require_submodule("src/tools/cargo", None);
3357+
fn make_run(run: RunConfig<'_>) {
3358+
run.builder.ensure(BootstrapPy)
3359+
}
33553360

3361+
fn run(self, builder: &Builder<'_>) -> Self::Output {
33563362
let mut check_bootstrap = command(builder.python());
33573363
check_bootstrap
33583364
.args(["-m", "unittest", "bootstrap_test.py"])
3365+
// Forward command-line args after `--` to unittest, for filtering etc.
3366+
.args(builder.config.test_args())
33593367
.env("BUILD_DIR", &builder.out)
33603368
.env("BUILD_PLATFORM", builder.build.host_target.triple)
33613369
.env("BOOTSTRAP_TEST_RUSTC_BIN", &builder.initial_rustc)
33623370
.env("BOOTSTRAP_TEST_CARGO_BIN", &builder.initial_cargo)
33633371
.current_dir(builder.src.join("src/bootstrap/"));
3364-
// NOTE: we intentionally don't pass test_args here because the args for unittest and cargo test are mutually incompatible.
3365-
// Use `python -m unittest` manually if you want to pass arguments.
33663372
check_bootstrap.delay_failure().run(builder);
3373+
}
3374+
}
3375+
3376+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3377+
pub struct Bootstrap;
3378+
3379+
impl Step for Bootstrap {
3380+
type Output = ();
3381+
const DEFAULT: bool = true;
3382+
const IS_HOST: bool = true;
3383+
3384+
/// Tests the build system itself.
3385+
fn run(self, builder: &Builder<'_>) {
3386+
let host = builder.config.host_target;
3387+
let build_compiler = builder.compiler(0, host);
3388+
3389+
// Some tests require cargo submodule to be present.
3390+
builder.build.require_submodule("src/tools/cargo", None);
33673391

33683392
let mut cargo = tool::prepare_tool_cargo(
33693393
builder,

src/bootstrap/src/core/builder/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ impl<'a> Builder<'a> {
869869
Kind::Test => describe!(
870870
crate::core::build_steps::toolstate::ToolStateCheck,
871871
test::Tidy,
872+
test::BootstrapPy,
872873
test::Bootstrap,
873874
test::Ui,
874875
test::Crashes,

0 commit comments

Comments
 (0)