From 948bed2f0ca9e3a0ae718303149d8082ed513654 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Mon, 3 Nov 2025 21:00:40 +1100 Subject: [PATCH] Split out a separate `./x test bootstrap-py` step When working on the Rust parts of bootstrap, it's unhelpful for `./x test bootstrap` to also run Python unit tests. --- src/bootstrap/src/core/build_steps/test.rs | 44 +++++++++++++++++----- src/bootstrap/src/core/builder/mod.rs | 1 + 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 57dedcccf98c8..b66f965cd555b 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -3337,33 +3337,57 @@ fn distcheck_rustc_dev(builder: &Builder<'_>, dir: &Path) { builder.remove_dir(dir); } +/// Runs unit tests in `bootstrap_test.py`, which test the Python parts of bootstrap. #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct Bootstrap; +pub(crate) struct BootstrapPy; -impl Step for Bootstrap { +impl Step for BootstrapPy { type Output = (); const DEFAULT: bool = true; const IS_HOST: bool = true; - /// Tests the build system itself. - fn run(self, builder: &Builder<'_>) { - let host = builder.config.host_target; - let build_compiler = builder.compiler(0, host); + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + // Bootstrap tests might not be perfectly self-contained and can depend + // on the environment, so only run them by default in CI, not locally. + // See `test::Bootstrap::should_run`. + let is_ci = run.builder.config.is_running_on_ci; + run.alias("bootstrap-py").default_condition(is_ci) + } - // Some tests require cargo submodule to be present. - builder.build.require_submodule("src/tools/cargo", None); + fn make_run(run: RunConfig<'_>) { + run.builder.ensure(BootstrapPy) + } + fn run(self, builder: &Builder<'_>) -> Self::Output { let mut check_bootstrap = command(builder.python()); check_bootstrap .args(["-m", "unittest", "bootstrap_test.py"]) + // Forward command-line args after `--` to unittest, for filtering etc. + .args(builder.config.test_args()) .env("BUILD_DIR", &builder.out) .env("BUILD_PLATFORM", builder.build.host_target.triple) .env("BOOTSTRAP_TEST_RUSTC_BIN", &builder.initial_rustc) .env("BOOTSTRAP_TEST_CARGO_BIN", &builder.initial_cargo) .current_dir(builder.src.join("src/bootstrap/")); - // NOTE: we intentionally don't pass test_args here because the args for unittest and cargo test are mutually incompatible. - // Use `python -m unittest` manually if you want to pass arguments. check_bootstrap.delay_failure().run(builder); + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Bootstrap; + +impl Step for Bootstrap { + type Output = (); + const DEFAULT: bool = true; + const IS_HOST: bool = true; + + /// Tests the build system itself. + fn run(self, builder: &Builder<'_>) { + let host = builder.config.host_target; + let build_compiler = builder.compiler(0, host); + + // Some tests require cargo submodule to be present. + builder.build.require_submodule("src/tools/cargo", None); let mut cargo = tool::prepare_tool_cargo( builder, diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index c7490c7072bda..43faf92fe6d9b 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -869,6 +869,7 @@ impl<'a> Builder<'a> { Kind::Test => describe!( crate::core::build_steps::toolstate::ToolStateCheck, test::Tidy, + test::BootstrapPy, test::Bootstrap, test::Ui, test::Crashes,