diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-07-10 17:54:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-10 17:54:25 +0200 |
| commit | d17e0cfc5d690181ae60f92e4d1b0f0dd1fc2582 (patch) | |
| tree | 305bec4e525330fcbea581efbf8e67dd572a8369 | |
| parent | b215beb567857000fdaa868cbb78702bc5ee0ee9 (diff) | |
| parent | 9cd1d253a60aca27086da57b68c24b0924277d58 (diff) | |
| download | rust-d17e0cfc5d690181ae60f92e4d1b0f0dd1fc2582.tar.gz rust-d17e0cfc5d690181ae60f92e4d1b0f0dd1fc2582.zip | |
Rollup merge of #126476 - ferrocene:pa-bootstrap-test-local-rustc, r=onur-ozkan
Fix running bootstrap tests with a local Rust toolchain as the stage0 When configuring a local Rust toolchain as the stage0 (with `build.rustc` and `build.cargo` in `config.toml`) we noticed there were test failures (both on the Python and the Rust side) due to bootstrap not being able to find rustc and Cargo. This was due to those two `config.toml` settings not being propagated in the tests. This PR fixes the issue by ensuring rustc and cargo are always configured in tests, using the parent bootstrap's `initial_rustc` and `initial_cargo`. try-job: x86_64-msvc Fixes https://github.com/rust-lang/rust/issues/105766
| -rw-r--r-- | src/bootstrap/bootstrap_test.py | 19 | ||||
| -rw-r--r-- | src/bootstrap/src/core/build_steps/test.rs | 2 | ||||
| -rw-r--r-- | src/bootstrap/src/core/config/config.rs | 25 |
3 files changed, 44 insertions, 2 deletions
diff --git a/src/bootstrap/bootstrap_test.py b/src/bootstrap/bootstrap_test.py index 6da410ed2f2..706f2c5bf07 100644 --- a/src/bootstrap/bootstrap_test.py +++ b/src/bootstrap/bootstrap_test.py @@ -138,6 +138,25 @@ class BuildBootstrap(unittest.TestCase): if env is None: env = {} + # This test ends up invoking build_bootstrap_cmd, which searches for + # the Cargo binary and errors out if it cannot be found. This is not a + # problem in most cases, but there is a scenario where it would cause + # the test to fail. + # + # When a custom local Cargo is configured in config.toml (with the + # build.cargo setting), no Cargo is downloaded to any location known by + # bootstrap, and bootstrap relies on that setting to find it. + # + # In this test though we are not using the config.toml of the caller: + # we are generating a blank one instead. If we don't set build.cargo in + # it, the test will have no way to find Cargo, failing the test. + cargo_bin = os.environ.get("BOOTSTRAP_TEST_CARGO_BIN") + if cargo_bin is not None: + configure_args += ["--set", "build.cargo=" + cargo_bin] + rustc_bin = os.environ.get("BOOTSTRAP_TEST_RUSTC_BIN") + if rustc_bin is not None: + configure_args += ["--set", "build.rustc=" + rustc_bin] + env = env.copy() env["PATH"] = os.environ["PATH"] diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 7f4c4bd53df..0b60587bb79 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -2979,6 +2979,8 @@ impl Step for Bootstrap { .args(["-m", "unittest", "bootstrap_test.py"]) .env("BUILD_DIR", &builder.out) .env("BUILD_PLATFORM", builder.build.build.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. diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 10ac6c93e9a..2d54a84331f 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -1330,6 +1330,17 @@ impl Config { TomlConfig::default() }; + if cfg!(test) { + // When configuring bootstrap for tests, make sure to set the rustc and Cargo to the + // same ones used to call the tests (if custom ones are not defined in the toml). If we + // don't do that, bootstrap will use its own detection logic to find a suitable rustc + // and Cargo, which doesn't work when the caller is specìfying a custom local rustc or + // Cargo in their config.toml. + let build = toml.build.get_or_insert_with(Default::default); + build.rustc = build.rustc.take().or(std::env::var_os("RUSTC").map(|p| p.into())); + build.cargo = build.cargo.take().or(std::env::var_os("CARGO").map(|p| p.into())); + } + if let Some(include) = &toml.profile { // Allows creating alias for profile names, allowing // profiles to be renamed while maintaining back compatibility @@ -1448,7 +1459,12 @@ impl Config { rustc } else { config.download_beta_toolchain(); - config.out.join(config.build.triple).join("stage0/bin/rustc") + config + .out + .join(config.build.triple) + .join("stage0") + .join("bin") + .join(exe("rustc", config.build)) }; config.initial_cargo = if let Some(cargo) = cargo { @@ -1458,7 +1474,12 @@ impl Config { cargo } else { config.download_beta_toolchain(); - config.out.join(config.build.triple).join("stage0/bin/cargo") + config + .out + .join(config.build.triple) + .join("stage0") + .join("bin") + .join(exe("cargo", config.build)) }; // NOTE: it's important this comes *after* we set `initial_rustc` just above. |
