diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index ef776e2194365..493f73b21fe15 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -200,12 +200,14 @@ than building it. .map(|p| cmd_finder.must_have(p)) .or_else(|| cmd_finder.maybe_have("reuse")); - let stage0_supported_target_list: HashSet = crate::utils::helpers::output( - command(&build.config.initial_rustc).args(["--print", "target-list"]).as_command_mut(), - ) - .lines() - .map(|s| s.to_string()) - .collect(); + let stage0_supported_target_list: HashSet = command(&build.config.initial_rustc) + .args(["--print", "target-list"]) + .run_always() + .run_capture_stdout(&build) + .stdout() + .lines() + .map(|s| s.to_string()) + .collect(); // Compiler tools like `cc` and `ar` are not configured for cross-targets on certain subcommands // because they are not needed. diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 25e59bfe3a889..7254c653a2dba 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -21,7 +21,6 @@ use std::cell::{Cell, RefCell}; use std::collections::{BTreeSet, HashMap, HashSet}; use std::fmt::Display; use std::path::{Path, PathBuf}; -use std::process::Command; use std::sync::OnceLock; use std::time::SystemTime; use std::{env, fs, io, str}; @@ -39,7 +38,7 @@ use crate::core::builder::Kind; use crate::core::config::{DryRun, LldMode, LlvmLibunwind, TargetSelection, flags}; use crate::utils::exec::{BehaviorOnFailure, BootstrapCommand, CommandOutput, OutputMode, command}; use crate::utils::helpers::{ - self, dir_is_empty, exe, libdir, output, set_file_times, split_debuginfo, symlink_dir, + self, dir_is_empty, exe, libdir, set_file_times, split_debuginfo, symlink_dir, }; mod core; @@ -376,10 +375,13 @@ impl Build { let in_tree_llvm_info = config.in_tree_llvm_info.clone(); let in_tree_gcc_info = config.in_tree_gcc_info.clone(); - let initial_target_libdir = - output(Command::new(&config.initial_rustc).args(["--print", "target-libdir"])) - .trim() - .to_owned(); + let initial_target_libdir = command(&config.initial_rustc) + .run_always() + .args(["--print", "target-libdir"]) + .run_capture_stdout(&config) + .stdout() + .trim() + .to_owned(); let initial_target_dir = Path::new(&initial_target_libdir) .parent() @@ -479,8 +481,11 @@ impl Build { // If local-rust is the same major.minor as the current version, then force a // local-rebuild - let local_version_verbose = - output(Command::new(&build.initial_rustc).arg("--version").arg("--verbose")); + let local_version_verbose = command(&build.initial_rustc) + .run_always() + .args(["--version", "--verbose"]) + .run_capture_stdout(&build) + .stdout(); let local_release = local_version_verbose .lines() .filter_map(|x| x.strip_prefix("release:")) @@ -941,9 +946,14 @@ impl Build { fn rustc_snapshot_sysroot(&self) -> &Path { static SYSROOT_CACHE: OnceLock = OnceLock::new(); SYSROOT_CACHE.get_or_init(|| { - let mut rustc = Command::new(&self.initial_rustc); - rustc.args(["--print", "sysroot"]); - output(&mut rustc).trim().into() + command(&self.initial_rustc) + .run_always() + .args(["--print", "sysroot"]) + .run_capture_stdout(self) + .stdout() + .trim() + .to_owned() + .into() }) } diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index f2c3e8c0df464..3e04e04684466 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -300,25 +300,6 @@ pub fn make(host: &str) -> PathBuf { } } -#[track_caller] -pub fn output(cmd: &mut Command) -> String { - #[cfg(feature = "tracing")] - let _run_span = crate::trace_cmd!(cmd); - - let output = match cmd.stderr(Stdio::inherit()).output() { - Ok(status) => status, - Err(e) => fail(&format!("failed to execute command: {cmd:?}\nERROR: {e}")), - }; - if !output.status.success() { - panic!( - "command did not execute successfully: {:?}\n\ - expected success, got: {}", - cmd, output.status - ); - } - String::from_utf8(output.stdout).unwrap() -} - /// Spawn a process and return a closure that will wait for the process /// to finish and then return its output. This allows the spawned process /// to do work without immediately blocking bootstrap.