Skip to content

Commit

Permalink
set the correct rustc and cargo even for tests invoking parse_inner
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Jul 8, 2024
1 parent 198c809 commit aed27c5
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aed27c5

Please sign in to comment.