Skip to content

Commit 8b22fcb

Browse files
Rollup merge of #142459 - Shourya742:2025-06-11-remove-output-helper, r=Kobzol
Remove output helper bootstrap This PR removes output utility helper method. r? `@Kobzol`
2 parents 63631fb + 2f7cc5a commit 8b22fcb

File tree

3 files changed

+29
-36
lines changed

3 files changed

+29
-36
lines changed

src/bootstrap/src/core/sanity.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,14 @@ than building it.
200200
.map(|p| cmd_finder.must_have(p))
201201
.or_else(|| cmd_finder.maybe_have("reuse"));
202202

203-
let stage0_supported_target_list: HashSet<String> = crate::utils::helpers::output(
204-
command(&build.config.initial_rustc).args(["--print", "target-list"]).as_command_mut(),
205-
)
206-
.lines()
207-
.map(|s| s.to_string())
208-
.collect();
203+
let stage0_supported_target_list: HashSet<String> = command(&build.config.initial_rustc)
204+
.args(["--print", "target-list"])
205+
.run_always()
206+
.run_capture_stdout(&build)
207+
.stdout()
208+
.lines()
209+
.map(|s| s.to_string())
210+
.collect();
209211

210212
// Compiler tools like `cc` and `ar` are not configured for cross-targets on certain subcommands
211213
// because they are not needed.

src/bootstrap/src/lib.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use std::cell::{Cell, RefCell};
2121
use std::collections::{BTreeSet, HashMap, HashSet};
2222
use std::fmt::Display;
2323
use std::path::{Path, PathBuf};
24-
use std::process::Command;
2524
use std::sync::OnceLock;
2625
use std::time::SystemTime;
2726
use std::{env, fs, io, str};
@@ -39,7 +38,7 @@ use crate::core::builder::Kind;
3938
use crate::core::config::{DryRun, LldMode, LlvmLibunwind, TargetSelection, flags};
4039
use crate::utils::exec::{BehaviorOnFailure, BootstrapCommand, CommandOutput, OutputMode, command};
4140
use crate::utils::helpers::{
42-
self, dir_is_empty, exe, libdir, output, set_file_times, split_debuginfo, symlink_dir,
41+
self, dir_is_empty, exe, libdir, set_file_times, split_debuginfo, symlink_dir,
4342
};
4443

4544
mod core;
@@ -376,10 +375,13 @@ impl Build {
376375
let in_tree_llvm_info = config.in_tree_llvm_info.clone();
377376
let in_tree_gcc_info = config.in_tree_gcc_info.clone();
378377

379-
let initial_target_libdir =
380-
output(Command::new(&config.initial_rustc).args(["--print", "target-libdir"]))
381-
.trim()
382-
.to_owned();
378+
let initial_target_libdir = command(&config.initial_rustc)
379+
.run_always()
380+
.args(["--print", "target-libdir"])
381+
.run_capture_stdout(&config)
382+
.stdout()
383+
.trim()
384+
.to_owned();
383385

384386
let initial_target_dir = Path::new(&initial_target_libdir)
385387
.parent()
@@ -479,8 +481,11 @@ impl Build {
479481

480482
// If local-rust is the same major.minor as the current version, then force a
481483
// local-rebuild
482-
let local_version_verbose =
483-
output(Command::new(&build.initial_rustc).arg("--version").arg("--verbose"));
484+
let local_version_verbose = command(&build.initial_rustc)
485+
.run_always()
486+
.args(["--version", "--verbose"])
487+
.run_capture_stdout(&build)
488+
.stdout();
484489
let local_release = local_version_verbose
485490
.lines()
486491
.filter_map(|x| x.strip_prefix("release:"))
@@ -941,9 +946,14 @@ impl Build {
941946
fn rustc_snapshot_sysroot(&self) -> &Path {
942947
static SYSROOT_CACHE: OnceLock<PathBuf> = OnceLock::new();
943948
SYSROOT_CACHE.get_or_init(|| {
944-
let mut rustc = Command::new(&self.initial_rustc);
945-
rustc.args(["--print", "sysroot"]);
946-
output(&mut rustc).trim().into()
949+
command(&self.initial_rustc)
950+
.run_always()
951+
.args(["--print", "sysroot"])
952+
.run_capture_stdout(self)
953+
.stdout()
954+
.trim()
955+
.to_owned()
956+
.into()
947957
})
948958
}
949959

src/bootstrap/src/utils/helpers.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -300,25 +300,6 @@ pub fn make(host: &str) -> PathBuf {
300300
}
301301
}
302302

303-
#[track_caller]
304-
pub fn output(cmd: &mut Command) -> String {
305-
#[cfg(feature = "tracing")]
306-
let _run_span = crate::trace_cmd!(cmd);
307-
308-
let output = match cmd.stderr(Stdio::inherit()).output() {
309-
Ok(status) => status,
310-
Err(e) => fail(&format!("failed to execute command: {cmd:?}\nERROR: {e}")),
311-
};
312-
if !output.status.success() {
313-
panic!(
314-
"command did not execute successfully: {:?}\n\
315-
expected success, got: {}",
316-
cmd, output.status
317-
);
318-
}
319-
String::from_utf8(output.stdout).unwrap()
320-
}
321-
322303
/// Spawn a process and return a closure that will wait for the process
323304
/// to finish and then return its output. This allows the spawned process
324305
/// to do work without immediately blocking bootstrap.

0 commit comments

Comments
 (0)