Skip to content

Remove output helper bootstrap #142459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = 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<String> = 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.
Expand Down
32 changes: 21 additions & 11 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:"))
Expand Down Expand Up @@ -941,9 +946,14 @@ impl Build {
fn rustc_snapshot_sysroot(&self) -> &Path {
static SYSROOT_CACHE: OnceLock<PathBuf> = 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()
})
}

Expand Down
19 changes: 0 additions & 19 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading