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
This commit is contained in:
Matthias Krüger 2024-07-10 17:54:25 +02:00 committed by GitHub
commit d17e0cfc5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 2 deletions

View File

@ -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"]

View File

@ -2979,6 +2979,8 @@ fn run(self, builder: &Builder<'_>) {
.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.

View File

@ -1330,6 +1330,17 @@ pub(crate) fn parse_inner(args: &[String], get_toml: impl Fn(&Path) -> TomlConfi
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 @@ fn get_table(option: &str) -> Result<TomlConfig, toml::de::Error> {
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 @@ fn get_table(option: &str) -> Result<TomlConfig, toml::de::Error> {
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.