Skip to content

Commit 3ef77cc

Browse files
committed
Remove various usages of the output function
1 parent b14ff77 commit 3ef77cc

16 files changed

+120
-132
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::core::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, T
2929
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
3030
use crate::utils::exec::BootstrapCommand;
3131
use crate::utils::helpers::{
32-
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, output, symlink_dir, t, up_to_date,
32+
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
3333
};
3434
use crate::LLVM_TOOLS;
3535
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode};
@@ -1488,10 +1488,10 @@ pub fn compiler_file(
14881488
if builder.config.dry_run() {
14891489
return PathBuf::new();
14901490
}
1491-
let mut cmd = Command::new(compiler);
1491+
let mut cmd = BootstrapCommand::new(compiler);
14921492
cmd.args(builder.cflags(target, GitRepo::Rustc, c));
14931493
cmd.arg(format!("-print-file-name={file}"));
1494-
let out = output(&mut cmd);
1494+
let out = builder.run(cmd.capture_stdout()).stdout();
14951495
PathBuf::from(out.trim())
14961496
}
14971497

@@ -1836,7 +1836,9 @@ impl Step for Assemble {
18361836
let llvm::LlvmResult { llvm_config, .. } =
18371837
builder.ensure(llvm::Llvm { target: target_compiler.host });
18381838
if !builder.config.dry_run() && builder.config.llvm_tools_enabled {
1839-
let llvm_bin_dir = output(Command::new(llvm_config).arg("--bindir"));
1839+
let llvm_bin_dir = builder
1840+
.run(BootstrapCommand::new(llvm_config).capture_stdout().arg("--bindir"))
1841+
.stdout();
18401842
let llvm_bin_dir = Path::new(llvm_bin_dir.trim());
18411843

18421844
// Since we've already built the LLVM tools, install them to the sysroot.
@@ -2161,8 +2163,7 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
21612163
}
21622164

21632165
let previous_mtime = FileTime::from_last_modification_time(&path.metadata().unwrap());
2164-
// NOTE: `output` will propagate any errors here.
2165-
output(Command::new("strip").arg("--strip-debug").arg(path));
2166+
builder.run(BootstrapCommand::new("strip").capture().arg("--strip-debug").arg(path));
21662167

21672168
// After running `strip`, we have to set the file modification time to what it was before,
21682169
// otherwise we risk Cargo invalidating its fingerprint and rebuilding the world next time

src/bootstrap/src/core/build_steps/dist.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::ffi::OsStr;
1414
use std::fs;
1515
use std::io::Write;
1616
use std::path::{Path, PathBuf};
17-
use std::process::Command;
1817

1918
use object::read::archive::ArchiveFile;
2019
use object::BinaryFormat;
@@ -28,7 +27,7 @@ use crate::core::config::TargetSelection;
2827
use crate::utils::channel::{self, Info};
2928
use crate::utils::exec::BootstrapCommand;
3029
use crate::utils::helpers::{
31-
exe, is_dylib, move_file, output, t, target_supports_cranelift_backend, timeit,
30+
exe, is_dylib, move_file, t, target_supports_cranelift_backend, timeit,
3231
};
3332
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
3433
use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
@@ -181,9 +180,9 @@ fn make_win_dist(
181180
}
182181

183182
//Ask gcc where it keeps its stuff
184-
let mut cmd = Command::new(builder.cc(target));
183+
let mut cmd = BootstrapCommand::new(builder.cc(target));
185184
cmd.arg("-print-search-dirs");
186-
let gcc_out = output(&mut cmd);
185+
let gcc_out = builder.run(cmd.capture_stdout()).stdout();
187186

188187
let mut bin_path: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
189188
let mut lib_path = Vec::new();
@@ -1024,7 +1023,7 @@ impl Step for PlainSourceTarball {
10241023
}
10251024

10261025
// Vendor all Cargo dependencies
1027-
let mut cmd = Command::new(&builder.initial_cargo);
1026+
let mut cmd = BootstrapCommand::new(&builder.initial_cargo);
10281027
cmd.arg("vendor")
10291028
.arg("--versioned-dirs")
10301029
.arg("--sync")
@@ -1062,7 +1061,7 @@ impl Step for PlainSourceTarball {
10621061
}
10631062

10641063
let config = if !builder.config.dry_run() {
1065-
t!(String::from_utf8(t!(cmd.output()).stdout))
1064+
builder.run(cmd.capture()).stdout()
10661065
} else {
10671066
String::new()
10681067
};
@@ -2079,10 +2078,14 @@ fn maybe_install_llvm(
20792078
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult { llvm_config, .. }) =
20802079
llvm::prebuilt_llvm_config(builder, target)
20812080
{
2082-
let mut cmd = Command::new(llvm_config);
2081+
let mut cmd = BootstrapCommand::new(llvm_config);
20832082
cmd.arg("--libfiles");
20842083
builder.verbose(|| println!("running {cmd:?}"));
2085-
let files = if builder.config.dry_run() { "".into() } else { output(&mut cmd) };
2084+
let files = if builder.config.dry_run() {
2085+
"".into()
2086+
} else {
2087+
builder.run(cmd.capture_stdout()).stdout()
2088+
};
20862089
let build_llvm_out = &builder.llvm_out(builder.config.build);
20872090
let target_llvm_out = &builder.llvm_out(target);
20882091
for file in files.trim_end().split(' ') {

src/bootstrap/src/core/build_steps/format.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Runs rustfmt on the repository.
22
33
use crate::core::builder::Builder;
4-
use crate::utils::helpers::{self, output, program_out_of_date, t};
4+
use crate::utils::exec::BootstrapCommand;
5+
use crate::utils::helpers::{self, program_out_of_date, t};
56
use build_helper::ci::CiEnv;
67
use build_helper::git::get_git_modified_files;
78
use ignore::WalkBuilder;
@@ -53,19 +54,17 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
5354
fn get_rustfmt_version(build: &Builder<'_>) -> Option<(String, PathBuf)> {
5455
let stamp_file = build.out.join("rustfmt.stamp");
5556

56-
let mut cmd = Command::new(match build.initial_rustfmt() {
57+
let mut cmd = BootstrapCommand::new(match build.initial_rustfmt() {
5758
Some(p) => p,
5859
None => return None,
5960
});
6061
cmd.arg("--version");
61-
let output = match cmd.output() {
62-
Ok(status) => status,
63-
Err(_) => return None,
64-
};
65-
if !output.status.success() {
62+
63+
let output = build.run(cmd.capture().allow_failure());
64+
if output.is_failure() {
6665
return None;
6766
}
68-
Some((String::from_utf8(output.stdout).unwrap(), stamp_file))
67+
Some((output.stdout(), stamp_file))
6968
}
7069

7170
/// Return whether the format cache can be reused.
@@ -175,14 +174,16 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
175174
)
176175
.is_success();
177176
if in_working_tree {
178-
let untracked_paths_output = output(
179-
&mut helpers::git(Some(&build.src))
180-
.arg("status")
181-
.arg("--porcelain")
182-
.arg("-z")
183-
.arg("--untracked-files=normal")
184-
.command,
185-
);
177+
let untracked_paths_output = build
178+
.run(
179+
helpers::git(Some(&build.src))
180+
.capture_stdout()
181+
.arg("status")
182+
.arg("--porcelain")
183+
.arg("-z")
184+
.arg("--untracked-files=normal"),
185+
)
186+
.stdout();
186187
let untracked_paths: Vec<_> = untracked_paths_output
187188
.split_terminator('\0')
188189
.filter_map(

src/bootstrap/src/core/build_steps/llvm.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::ffi::{OsStr, OsString};
1414
use std::fs::{self, File};
1515
use std::io;
1616
use std::path::{Path, PathBuf};
17-
use std::process::Command;
1817
use std::sync::OnceLock;
1918

2019
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
@@ -25,6 +24,7 @@ use crate::utils::helpers::{
2524
};
2625
use crate::{generate_smart_stamp_hash, CLang, GitRepo, Kind};
2726

27+
use crate::utils::exec::BootstrapCommand;
2828
use build_helper::ci::CiEnv;
2929
use build_helper::git::get_git_merge_base;
3030

@@ -478,7 +478,9 @@ impl Step for Llvm {
478478
let LlvmResult { llvm_config, .. } =
479479
builder.ensure(Llvm { target: builder.config.build });
480480
if !builder.config.dry_run() {
481-
let llvm_bindir = output(Command::new(&llvm_config).arg("--bindir"));
481+
let llvm_bindir = builder
482+
.run(BootstrapCommand::new(&llvm_config).capture_stdout().arg("--bindir"))
483+
.stdout();
482484
let host_bin = Path::new(llvm_bindir.trim());
483485
cfg.define(
484486
"LLVM_TABLEGEN",
@@ -528,8 +530,8 @@ impl Step for Llvm {
528530

529531
// Helper to find the name of LLVM's shared library on darwin and linux.
530532
let find_llvm_lib_name = |extension| {
531-
let mut cmd = Command::new(&res.llvm_config);
532-
let version = output(cmd.arg("--version"));
533+
let cmd = BootstrapCommand::new(&res.llvm_config);
534+
let version = builder.run(cmd.capture_stdout().arg("--version")).stdout();
533535
let major = version.split('.').next().unwrap();
534536

535537
match &llvm_version_suffix {
@@ -585,8 +587,8 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
585587
return;
586588
}
587589

588-
let mut cmd = Command::new(llvm_config);
589-
let version = output(cmd.arg("--version"));
590+
let cmd = BootstrapCommand::new(llvm_config);
591+
let version = builder.run(cmd.capture_stdout().arg("--version")).stdout();
590592
let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok());
591593
if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) {
592594
if major >= 17 {

src/bootstrap/src/core/build_steps/run.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
//! If it can be reached from `./x.py run` it can go here.
55
66
use std::path::PathBuf;
7-
use std::process::Command;
87

98
use crate::core::build_steps::dist::distdir;
109
use crate::core::build_steps::test;
1110
use crate::core::build_steps::tool::{self, SourceType, Tool};
1211
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
1312
use crate::core::config::flags::get_completion;
1413
use crate::core::config::TargetSelection;
15-
use crate::utils::helpers::output;
14+
use crate::utils::exec::BootstrapCommand;
1615
use crate::Mode;
1716

1817
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
@@ -41,7 +40,8 @@ impl Step for BuildManifest {
4140
panic!("\n\nfailed to specify `dist.upload-addr` in `config.toml`\n\n")
4241
});
4342

44-
let today = output(Command::new("date").arg("+%Y-%m-%d"));
43+
let today =
44+
builder.run(BootstrapCommand::new("date").capture_stdout().arg("+%Y-%m-%d")).stdout();
4545

4646
cmd.arg(sign);
4747
cmd.arg(distdir(builder));

src/bootstrap/src/core/build_steps/suggest.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,15 @@ use crate::core::builder::Builder;
1313
pub fn suggest(builder: &Builder<'_>, run: bool) {
1414
let git_config = builder.config.git_config();
1515
let suggestions = builder
16-
.tool_cmd(Tool::SuggestTests)
17-
.env("SUGGEST_TESTS_GIT_REPOSITORY", git_config.git_repository)
18-
.env("SUGGEST_TESTS_NIGHTLY_BRANCH", git_config.nightly_branch)
19-
.command
20-
.output()
21-
.expect("failed to run `suggest-tests` tool");
16+
.run(
17+
builder
18+
.tool_cmd(Tool::SuggestTests)
19+
.capture_stdout()
20+
.env("SUGGEST_TESTS_GIT_REPOSITORY", git_config.git_repository)
21+
.env("SUGGEST_TESTS_NIGHTLY_BRANCH", git_config.nightly_branch),
22+
)
23+
.stdout();
2224

23-
if !suggestions.status.success() {
24-
println!("failed to run `suggest-tests` tool ({})", suggestions.status);
25-
println!(
26-
"`suggest_tests` stdout:\n{}`suggest_tests` stderr:\n{}",
27-
String::from_utf8(suggestions.stdout).unwrap(),
28-
String::from_utf8(suggestions.stderr).unwrap()
29-
);
30-
panic!("failed to run `suggest-tests`");
31-
}
32-
33-
let suggestions = String::from_utf8(suggestions.stdout).unwrap();
3425
let suggestions = suggestions
3526
.lines()
3627
.map(|line| {

src/bootstrap/src/core/build_steps/synthetic_targets.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
1010
use crate::core::builder::{Builder, ShouldRun, Step};
1111
use crate::core::config::TargetSelection;
12+
use crate::utils::exec::BootstrapCommand;
1213
use crate::Compiler;
13-
use std::process::{Command, Stdio};
1414

1515
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1616
pub(crate) struct MirOptPanicAbortSyntheticTarget {
@@ -56,22 +56,16 @@ fn create_synthetic_target(
5656
return TargetSelection::create_synthetic(&name, path.to_str().unwrap());
5757
}
5858

59-
let mut cmd = Command::new(builder.rustc(compiler));
59+
let mut cmd = BootstrapCommand::new(builder.rustc(compiler));
6060
cmd.arg("--target").arg(base.rustc_target_arg());
6161
cmd.args(["-Zunstable-options", "--print", "target-spec-json"]);
6262

6363
// If `rust.channel` is set to either beta or stable, rustc will complain that
6464
// we cannot use nightly features. So `RUSTC_BOOTSTRAP` is needed here.
6565
cmd.env("RUSTC_BOOTSTRAP", "1");
6666

67-
cmd.stdout(Stdio::piped());
68-
69-
let output = cmd.spawn().unwrap().wait_with_output().unwrap();
70-
if !output.status.success() {
71-
panic!("failed to gather the target spec for {base}");
72-
}
73-
74-
let mut spec: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
67+
let output = builder.run(cmd.capture()).stdout();
68+
let mut spec: serde_json::Value = serde_json::from_slice(output.as_bytes()).unwrap();
7569
let spec_map = spec.as_object_mut().unwrap();
7670

7771
// The `is-builtin` attribute of a spec needs to be removed, otherwise rustc will complain.

0 commit comments

Comments
 (0)