set the correct rustc and cargo even for tests invoking parse_inner

This commit is contained in:
Pietro Albini 2024-07-08 17:24:28 +02:00
parent 198c809dd1
commit b4b2643c11
No known key found for this signature in database
GPG Key ID: CD76B35F7734769E

View File

@ -1189,19 +1189,7 @@ impl Config {
pub fn parse(args: &[String]) -> Config {
#[cfg(test)]
fn get_toml(_: &Path) -> TomlConfig {
let mut default = TomlConfig::default();
// When configuring bootstrap for tests, make sure to set the rustc and Cargo to the
// same ones used to call the tests. 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.
default.build = Some(Build {
rustc: std::env::var_os("RUSTC").map(|v| v.into()),
cargo: std::env::var_os("CARGO").map(|v| v.into()),
..Build::default()
});
default
TomlConfig::default()
}
#[cfg(not(test))]
@ -1341,6 +1329,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