From c707193aae3a22735dac783b5acfe842816796b4 Mon Sep 17 00:00:00 2001 From: Debian Rust Maintainers Date: Tue, 27 Jun 2023 16:12:20 +0100 Subject: [PATCH] Fix get_toml() when cfg(test) Bug: https://github.com/rust-lang/rust/issues/105766 Last-Update: 2023-03-29 When cfg(test), Config::parse doesn't parse a config.toml but uses default values, failing when the initial rustc is needed. This is a workaround before upstream issue gets solved. Last-Update: 2023-03-29 Gbp-Pq: Name u-fix-get-toml-when-test.patch --- src/bootstrap/config.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index a8c403675d..73798d6df1 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -896,9 +896,9 @@ impl Config { config.stage0_metadata = t!(serde_json::from_slice::(&stage0_json)); - #[cfg(test)] + /*#[cfg(test)] let get_toml = |_| TomlConfig::default(); - #[cfg(not(test))] + #[cfg(not(test))]*/ let get_toml = |file: &Path| { let contents = t!(fs::read_to_string(file), format!("config file {} not found", file.display())); @@ -907,7 +907,22 @@ impl Config { match toml::from_str(&contents) .and_then(|table: toml::Value| TomlConfig::deserialize(table)) { - Ok(table) => table, + /// Debian: We use previous version as a custom rustc, which unfortunately won't be + /// picked up because config.toml isn't read when cfg!(test). Making tests use the + /// entirety of our config.toml isn't feasible either as it panicks on GitRepo::Llvm + /// (d-bootstrap-custom-debuginfo-path.patch), so only give paths of initial rustc + /// and cargo. + Ok(table) => if !cfg!(test) || table.build.is_none() { + table + } else { + let mut config = TomlConfig::default(); + let mut build = Build::default(); + let cbuild = table.build.unwrap(); + build.rustc = cbuild.rustc; + build.cargo = cbuild.cargo; + config.build = Some(build); + config + }, Err(err) => { eprintln!("failed to parse TOML configuration '{}': {}", file.display(), err); crate::detail_exit(2); -- 2.30.2