diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 882bae8aeb6a1..b8f26c3263460 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -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,18 @@ impl Config { TomlConfig::default() }; + #[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_default(); + build.rustc = build.rustc.or(std::env::var_os("RUSTC").into()); + build.cargo = build.cargo.or(std::env::var_os("CARGO").into()); + } + if let Some(include) = &toml.profile { // Allows creating alias for profile names, allowing // profiles to be renamed while maintaining back compatibility