about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2025-01-01 23:49:09 +1100
committerZalathar <Zalathar@users.noreply.github.com>2025-01-02 18:43:33 +1100
commit725fccda2bda2ec931099e589bc1222c9d9e6cf3 (patch)
tree7f9d59898be8a159a4a2a19a3048ce8fa8c00728
parentbba24a2ffeb279dd09e4f93029569ae57c980cb0 (diff)
downloadrust-725fccda2bda2ec931099e589bc1222c9d9e6cf3.tar.gz
rust-725fccda2bda2ec931099e589bc1222c9d9e6cf3.zip
Move most of `Step::run` out of `tool_extended!`
-rw-r--r--src/bootstrap/src/core/build_steps/tool.rs78
1 files changed, 48 insertions, 30 deletions
diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs
index d276d5b6e62..9bf89e11155 100644
--- a/src/bootstrap/src/core/build_steps/tool.rs
+++ b/src/bootstrap/src/core/build_steps/tool.rs
@@ -1051,46 +1051,64 @@ macro_rules! tool_extended {
                 });
             }
 
-            #[allow(unused_mut)]
             fn run(self, builder: &Builder<'_>) -> PathBuf {
                 let Self { compiler, target } = self;
-                let tool = builder.ensure(ToolBuild {
+                run_tool_build_step(
+                    builder,
                     compiler,
                     target,
-                    tool: $tool_name,
-                    mode: Mode::ToolRustc,
-                    path: $path,
-                    extra_features: vec![],
-                    source_type: SourceType::InTree,
-                    allow_features: "",
-                    cargo_args: vec![]
-                });
-
-                if (false $(|| !$add_bins_to_sysroot.is_empty())?) && compiler.stage > 0 {
-                    let bindir = builder.sysroot(compiler).join("bin");
-                    t!(fs::create_dir_all(&bindir));
-
-                    #[allow(unused_variables)]
-                    let tools_out = builder
-                        .cargo_out(compiler, Mode::ToolRustc, target);
-
-                    $(for add_bin in $add_bins_to_sysroot {
-                        let bin_source = tools_out.join(exe(add_bin, target));
-                        let bin_destination = bindir.join(exe(add_bin, compiler.host));
-                        builder.copy_link(&bin_source, &bin_destination);
-                    })?
-
-                    let tool = bindir.join(exe($tool_name, compiler.host));
-                    tool
-                } else {
-                    tool
-                }
+                    $tool_name,
+                    $path,
+                    None $( .or(Some(&$add_bins_to_sysroot)) )?,
+                )
             }
         }
         )+
     }
 }
 
+fn run_tool_build_step(
+    builder: &Builder<'_>,
+    compiler: Compiler,
+    target: TargetSelection,
+    tool_name: &'static str,
+    path: &'static str,
+    add_bins_to_sysroot: Option<&[&str]>,
+) -> PathBuf {
+    let tool = builder.ensure(ToolBuild {
+        compiler,
+        target,
+        tool: tool_name,
+        mode: Mode::ToolRustc,
+        path,
+        extra_features: vec![],
+        source_type: SourceType::InTree,
+        allow_features: "",
+        cargo_args: vec![],
+    });
+
+    // FIXME: This should just be an if-let-chain, but those are unstable.
+    if let Some(add_bins_to_sysroot) =
+        add_bins_to_sysroot.filter(|bins| !bins.is_empty() && compiler.stage > 0)
+    {
+        let bindir = builder.sysroot(compiler).join("bin");
+        t!(fs::create_dir_all(&bindir));
+
+        let tools_out = builder.cargo_out(compiler, Mode::ToolRustc, target);
+
+        for add_bin in add_bins_to_sysroot {
+            let bin_source = tools_out.join(exe(add_bin, target));
+            let bin_destination = bindir.join(exe(add_bin, compiler.host));
+            builder.copy_link(&bin_source, &bin_destination);
+        }
+
+        // Return a path into the bin dir.
+        bindir.join(exe(tool_name, compiler.host))
+    } else {
+        tool
+    }
+}
+
 tool_extended!(
     Cargofmt, "src/tools/rustfmt", "cargo-fmt", stable=true;
     CargoClippy, "src/tools/clippy", "cargo-clippy", stable=true;