Fix get_toml() when cfg(test)
authorDebian Rust Maintainers <pkg-rust-maintainers@alioth-lists.debian.net>
Mon, 15 Jan 2024 07:16:35 +0000 (08:16 +0100)
committerFabian Grünbichler <debian@fabian.gruenbichler.email>
Mon, 15 Jan 2024 07:16:35 +0000 (08:16 +0100)
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

index cc3b3bc25f3d53bfba0c14fb57909972e70b0ed6..3c740de8a7639dcf4b75832d5e948a28dd864a6f 100644 (file)
@@ -848,9 +848,9 @@ impl Config {
     }
 
     pub fn parse(args: &[String]) -> Config {
-        #[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()));
@@ -859,7 +859,23 @@ 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);