Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 94b54e4

Browse files
committedJun 29, 2024
Remove various usages of the output function
1 parent e4240bb commit 94b54e4

File tree

16 files changed

+120
-130
lines changed

16 files changed

+120
-130
lines changed
 

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

Lines changed: 7 additions & 6 deletions
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};
@@ -1498,10 +1498,10 @@ pub fn compiler_file(
14981498
if builder.config.dry_run() {
14991499
return PathBuf::new();
15001500
}
1501-
let mut cmd = Command::new(compiler);
1501+
let mut cmd = BootstrapCommand::new(compiler);
15021502
cmd.args(builder.cflags(target, GitRepo::Rustc, c));
15031503
cmd.arg(format!("-print-file-name={file}"));
1504-
let out = output(&mut cmd);
1504+
let out = builder.run(cmd.capture_stdout()).stdout();
15051505
PathBuf::from(out.trim())
15061506
}
15071507

@@ -1833,7 +1833,9 @@ impl Step for Assemble {
18331833
let llvm::LlvmResult { llvm_config, .. } =
18341834
builder.ensure(llvm::Llvm { target: target_compiler.host });
18351835
if !builder.config.dry_run() && builder.config.llvm_tools_enabled {
1836-
let llvm_bin_dir = output(Command::new(llvm_config).arg("--bindir"));
1836+
let llvm_bin_dir = builder
1837+
.run(BootstrapCommand::new(llvm_config).capture_stdout().arg("--bindir"))
1838+
.stdout();
18371839
let llvm_bin_dir = Path::new(llvm_bin_dir.trim());
18381840

18391841
// Since we've already built the LLVM tools, install them to the sysroot.
@@ -2158,8 +2160,7 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
21582160
}
21592161

21602162
let previous_mtime = FileTime::from_last_modification_time(&path.metadata().unwrap());
2161-
// NOTE: `output` will propagate any errors here.
2162-
output(Command::new("strip").arg("--strip-debug").arg(path));
2163+
builder.run(BootstrapCommand::new("strip").capture().arg("--strip-debug").arg(path));
21632164

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

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

Lines changed: 11 additions & 8 deletions
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

Lines changed: 17 additions & 16 deletions
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

Lines changed: 8 additions & 6 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 8 additions & 17 deletions
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

Lines changed: 4 additions & 10 deletions
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.

‎src/bootstrap/src/core/build_steps/test.rs

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ use crate::core::config::TargetSelection;
2929
use crate::utils::exec::BootstrapCommand;
3030
use crate::utils::helpers::{
3131
self, add_link_lib_path, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var,
32-
linker_args, linker_flags, output, t, target_supports_cranelift_backend, up_to_date,
33-
LldThreads,
32+
linker_args, linker_flags, t, target_supports_cranelift_backend, up_to_date, LldThreads,
3433
};
3534
use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
3635
use crate::{envify, CLang, DocTests, GitRepo, Mode};
@@ -470,19 +469,12 @@ impl Miri {
470469
// We re-use the `cargo` from above.
471470
cargo.arg("--print-sysroot");
472471

473-
// FIXME: Is there a way in which we can re-use the usual `run` helpers?
474472
if builder.config.dry_run() {
475473
String::new()
476474
} else {
477475
builder.verbose(|| println!("running: {cargo:?}"));
478-
let out = cargo
479-
.command
480-
.output()
481-
.expect("We already ran `cargo miri setup` before and that worked");
482-
assert!(out.status.success(), "`cargo miri setup` returned with non-0 exit code");
476+
let stdout = builder.run(cargo.capture_stdout()).stdout();
483477
// Output is "<sysroot>\n".
484-
let stdout = String::from_utf8(out.stdout)
485-
.expect("`cargo miri setup` stdout is not valid UTF-8");
486478
let sysroot = stdout.trim_end();
487479
builder.verbose(|| println!("`cargo miri setup --print-sysroot` said: {sysroot:?}"));
488480
sysroot.to_owned()
@@ -911,25 +903,26 @@ impl Step for RustdocJSNotStd {
911903
}
912904
}
913905

914-
fn get_browser_ui_test_version_inner(npm: &Path, global: bool) -> Option<String> {
915-
let mut command = Command::new(npm);
906+
fn get_browser_ui_test_version_inner(
907+
builder: &Builder<'_>,
908+
npm: &Path,
909+
global: bool,
910+
) -> Option<String> {
911+
let mut command = BootstrapCommand::new(npm).capture();
916912
command.arg("list").arg("--parseable").arg("--long").arg("--depth=0");
917913
if global {
918914
command.arg("--global");
919915
}
920-
let lines = command
921-
.output()
922-
.map(|output| String::from_utf8_lossy(&output.stdout).into_owned())
923-
.unwrap_or_default();
916+
let lines = builder.run(command.allow_failure()).stdout();
924917
lines
925918
.lines()
926919
.find_map(|l| l.split(':').nth(1)?.strip_prefix("browser-ui-test@"))
927920
.map(|v| v.to_owned())
928921
}
929922

930-
fn get_browser_ui_test_version(npm: &Path) -> Option<String> {
931-
get_browser_ui_test_version_inner(npm, false)
932-
.or_else(|| get_browser_ui_test_version_inner(npm, true))
923+
fn get_browser_ui_test_version(builder: &Builder<'_>, npm: &Path) -> Option<String> {
924+
get_browser_ui_test_version_inner(builder, npm, false)
925+
.or_else(|| get_browser_ui_test_version_inner(builder, npm, true))
933926
}
934927

935928
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -953,7 +946,7 @@ impl Step for RustdocGUI {
953946
.config
954947
.npm
955948
.as_ref()
956-
.map(|p| get_browser_ui_test_version(p).is_some())
949+
.map(|p| get_browser_ui_test_version(builder, p).is_some())
957950
.unwrap_or(false)
958951
}))
959952
}
@@ -1810,25 +1803,16 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18101803
cmd.arg("--gdb").arg(gdb);
18111804
}
18121805

1813-
let run = |cmd: &mut Command| {
1814-
cmd.output().map(|output| {
1815-
String::from_utf8_lossy(&output.stdout)
1816-
.lines()
1817-
.next()
1818-
.unwrap_or_else(|| panic!("{:?} failed {:?}", cmd, output))
1819-
.to_string()
1820-
})
1821-
};
1822-
18231806
let lldb_exe = builder.config.lldb.clone().unwrap_or_else(|| PathBuf::from("lldb"));
1824-
let lldb_version = Command::new(&lldb_exe)
1825-
.arg("--version")
1826-
.output()
1827-
.map(|output| String::from_utf8_lossy(&output.stdout).to_string())
1828-
.ok();
1807+
let lldb_version = builder
1808+
.run(BootstrapCommand::new(&lldb_exe).capture().allow_failure().arg("--version"))
1809+
.stdout_if_ok();
18291810
if let Some(ref vers) = lldb_version {
18301811
cmd.arg("--lldb-version").arg(vers);
1831-
let lldb_python_dir = run(Command::new(&lldb_exe).arg("-P")).ok();
1812+
let lldb_python_dir = builder
1813+
.run(BootstrapCommand::new(&lldb_exe).allow_failure().capture_stdout().arg("-P"))
1814+
.stdout_if_ok()
1815+
.map(|p| p.lines().next().expect("lldb Python dir not found").to_string());
18321816
if let Some(ref dir) = lldb_python_dir {
18331817
cmd.arg("--lldb-python-dir").arg(dir);
18341818
}
@@ -1884,8 +1868,12 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
18841868
let llvm::LlvmResult { llvm_config, .. } =
18851869
builder.ensure(llvm::Llvm { target: builder.config.build });
18861870
if !builder.config.dry_run() {
1887-
let llvm_version = output(Command::new(&llvm_config).arg("--version"));
1888-
let llvm_components = output(Command::new(&llvm_config).arg("--components"));
1871+
let llvm_version = builder
1872+
.run(BootstrapCommand::new(&llvm_config).capture_stdout().arg("--version"))
1873+
.stdout();
1874+
let llvm_components = builder
1875+
.run(BootstrapCommand::new(&llvm_config).capture_stdout().arg("--components"))
1876+
.stdout();
18891877
// Remove trailing newline from llvm-config output.
18901878
cmd.arg("--llvm-version")
18911879
.arg(llvm_version.trim())
@@ -1904,7 +1892,9 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
19041892
// separate compilations. We can add LLVM's library path to the
19051893
// platform-specific environment variable as a workaround.
19061894
if !builder.config.dry_run() && suite.ends_with("fulldeps") {
1907-
let llvm_libdir = output(Command::new(&llvm_config).arg("--libdir"));
1895+
let llvm_libdir = builder
1896+
.run(BootstrapCommand::new(&llvm_config).capture_stdout().arg("--libdir"))
1897+
.stdout();
19081898
add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd);
19091899
}
19101900

‎src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::env;
22
use std::fs;
33
use std::path::{Path, PathBuf};
4-
use std::process::Command;
54

65
use crate::core::build_steps::compile;
76
use crate::core::build_steps::toolstate::ToolState;
@@ -10,7 +9,6 @@ use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun,
109
use crate::core::config::TargetSelection;
1110
use crate::utils::channel::GitInfo;
1211
use crate::utils::exec::BootstrapCommand;
13-
use crate::utils::helpers::output;
1412
use crate::utils::helpers::{add_dylib_path, exe, t};
1513
use crate::Compiler;
1614
use crate::Mode;
@@ -925,7 +923,8 @@ impl Step for LibcxxVersionTool {
925923
}
926924
}
927925

928-
let version_output = output(&mut Command::new(executable));
926+
let version_output =
927+
builder.run(BootstrapCommand::new(executable).capture_stdout()).stdout();
929928

930929
let version_str = version_output.split_once("version:").unwrap().1;
931930
let version = version_str.trim().parse::<usize>().unwrap();

‎src/bootstrap/src/core/builder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::fs;
88
use std::hash::Hash;
99
use std::ops::Deref;
1010
use std::path::{Path, PathBuf};
11-
use std::process::Command;
1211
use std::time::{Duration, Instant};
1312

1413
use crate::core::build_steps::tool::{self, SourceType};
@@ -20,7 +19,7 @@ use crate::core::config::{DryRun, SplitDebuginfo, TargetSelection};
2019
use crate::prepare_behaviour_dump_dir;
2120
use crate::utils::cache::Cache;
2221
use crate::utils::helpers::{self, add_dylib_path, add_link_lib_path, exe, linker_args};
23-
use crate::utils::helpers::{check_cfg_arg, libdir, linker_flags, output, t, LldThreads};
22+
use crate::utils::helpers::{check_cfg_arg, libdir, linker_flags, t, LldThreads};
2423
use crate::EXTRA_CHECK_CFGS;
2524
use crate::{Build, CLang, Crate, DocTests, GitRepo, Mode};
2625

@@ -1919,7 +1918,9 @@ impl<'a> Builder<'a> {
19191918
// platform-specific environment variable as a workaround.
19201919
if mode == Mode::ToolRustc || mode == Mode::Codegen {
19211920
if let Some(llvm_config) = self.llvm_config(target) {
1922-
let llvm_libdir = output(Command::new(llvm_config).arg("--libdir"));
1921+
let llvm_libdir = self
1922+
.run(BootstrapCommand::new(llvm_config).capture_stdout().arg("--libdir"))
1923+
.stdout();
19231924
add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cargo);
19241925
}
19251926
}

‎src/bootstrap/src/core/metadata.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::path::PathBuf;
2-
use std::process::Command;
32

43
use serde_derive::Deserialize;
54

6-
use crate::utils::helpers::output;
5+
use crate::utils::exec::BootstrapCommand;
76
use crate::{t, Build, Crate};
87

98
/// For more information, see the output of
@@ -71,7 +70,7 @@ pub fn build(build: &mut Build) {
7170
/// particular crate (e.g., `x build sysroot` to build library/sysroot).
7271
fn workspace_members(build: &Build) -> Vec<Package> {
7372
let collect_metadata = |manifest_path| {
74-
let mut cargo = Command::new(&build.initial_cargo);
73+
let mut cargo = BootstrapCommand::new(&build.initial_cargo);
7574
cargo
7675
// Will read the libstd Cargo.toml
7776
// which uses the unstable `public-dependency` feature.
@@ -82,7 +81,8 @@ fn workspace_members(build: &Build) -> Vec<Package> {
8281
.arg("--no-deps")
8382
.arg("--manifest-path")
8483
.arg(build.src.join(manifest_path));
85-
let metadata_output = output(&mut cargo);
84+
// FIXME: fix stderr
85+
let metadata_output = build.run(cargo.capture()).stdout();
8686
let Output { packages, .. } = t!(serde_json::from_str(&metadata_output));
8787
packages
8888
};

‎src/bootstrap/src/core/sanity.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use std::collections::HashSet;
2424

2525
use crate::builder::Kind;
2626
use crate::core::config::Target;
27+
use crate::utils::exec::BootstrapCommand;
2728
use crate::utils::helpers::output;
2829
use crate::Build;
2930

@@ -352,7 +353,8 @@ than building it.
352353
// There are three builds of cmake on windows: MSVC, MinGW, and
353354
// Cygwin. The Cygwin build does not have generators for Visual
354355
// Studio, so detect that here and error.
355-
let out = output(Command::new("cmake").arg("--help"));
356+
let out =
357+
build.run(BootstrapCommand::new("cmake").capture_stdout().arg("--help")).stdout();
356358
if !out.contains("Visual Studio") {
357359
panic!(
358360
"

‎src/bootstrap/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,14 +889,16 @@ impl Build {
889889
if let Some(s) = target_config.and_then(|c| c.llvm_filecheck.as_ref()) {
890890
s.to_path_buf()
891891
} else if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
892-
let llvm_bindir = output(Command::new(s).arg("--bindir"));
892+
let llvm_bindir =
893+
self.run(BootstrapCommand::new(s).capture_stdout().arg("--bindir")).stdout();
893894
let filecheck = Path::new(llvm_bindir.trim()).join(exe("FileCheck", target));
894895
if filecheck.exists() {
895896
filecheck
896897
} else {
897898
// On Fedora the system LLVM installs FileCheck in the
898899
// llvm subdirectory of the libdir.
899-
let llvm_libdir = output(Command::new(s).arg("--libdir"));
900+
let llvm_libdir =
901+
self.run(BootstrapCommand::new(s).capture_stdout().arg("--libdir")).stdout();
900902
let lib_filecheck =
901903
Path::new(llvm_libdir.trim()).join("llvm").join(exe("FileCheck", target));
902904
if lib_filecheck.exists() {

‎src/bootstrap/src/utils/cc_detect.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
2424
use std::collections::HashSet;
2525
use std::path::{Path, PathBuf};
26-
use std::process::Command;
2726
use std::{env, iter};
2827

2928
use crate::core::config::TargetSelection;
30-
use crate::utils::helpers::output;
29+
use crate::utils::exec::BootstrapCommand;
3130
use crate::{Build, CLang, GitRepo};
3231

3332
// The `cc` crate doesn't provide a way to obtain a path to the detected archiver,
@@ -183,14 +182,15 @@ fn default_compiler(
183182
return None;
184183
}
185184

186-
let output = output(c.to_command().arg("--version"));
185+
let cmd = BootstrapCommand::from(c.to_command());
186+
let output = build.run(cmd.capture_stdout().arg("--version")).stdout();
187187
let i = output.find(" 4.")?;
188188
match output[i + 3..].chars().next().unwrap() {
189189
'0'..='6' => {}
190190
_ => return None,
191191
}
192192
let alternative = format!("e{gnu_compiler}");
193-
if Command::new(&alternative).output().is_ok() {
193+
if build.run(BootstrapCommand::new(&alternative).capture()).is_success() {
194194
Some(PathBuf::from(alternative))
195195
} else {
196196
None

‎src/bootstrap/src/utils/exec.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ pub struct BootstrapCommand {
5151

5252
impl BootstrapCommand {
5353
pub fn new<S: AsRef<OsStr>>(program: S) -> Self {
54-
Self {
55-
command: Command::new(program),
56-
failure_behavior: BehaviorOnFailure::Exit,
57-
output_mode: OutputMode::Print,
58-
}
54+
Command::new(program).into()
5955
}
6056

6157
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
@@ -130,6 +126,12 @@ impl AsMut<BootstrapCommand> for BootstrapCommand {
130126
}
131127
}
132128

129+
impl From<Command> for BootstrapCommand {
130+
fn from(command: Command) -> Self {
131+
Self { command, failure_behavior: BehaviorOnFailure::Exit, output_mode: OutputMode::Print }
132+
}
133+
}
134+
133135
/// Represents the output of an executed process.
134136
#[allow(unused)]
135137
pub struct CommandOutput(Output);

‎src/bootstrap/src/utils/helpers.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub fn get_clang_cl_resource_dir(clang_cl_path: &str) -> PathBuf {
360360
/// Returns a flag that configures LLD to use only a single thread.
361361
/// If we use an external LLD, we need to find out which version is it to know which flag should we
362362
/// pass to it (LLD older than version 10 had a different flag).
363-
fn lld_flag_no_threads(lld_mode: LldMode, is_windows: bool) -> &'static str {
363+
fn lld_flag_no_threads(builder: &Builder<'_>, lld_mode: LldMode, is_windows: bool) -> &'static str {
364364
static LLD_NO_THREADS: OnceLock<(&'static str, &'static str)> = OnceLock::new();
365365

366366
let new_flags = ("/threads:1", "--threads=1");
@@ -369,7 +369,9 @@ fn lld_flag_no_threads(lld_mode: LldMode, is_windows: bool) -> &'static str {
369369
let (windows_flag, other_flag) = LLD_NO_THREADS.get_or_init(|| {
370370
let newer_version = match lld_mode {
371371
LldMode::External => {
372-
let out = output(Command::new("lld").arg("-flavor").arg("ld").arg("--version"));
372+
let mut cmd = BootstrapCommand::new("lld").capture_stdout();
373+
cmd.arg("-flavor").arg("ld").arg("--version");
374+
let out = builder.run(cmd).stdout();
373375
match (out.find(char::is_numeric), out.find('.')) {
374376
(Some(b), Some(e)) => out.as_str()[b..e].parse::<i32>().ok().unwrap_or(14) > 10,
375377
_ => true,
@@ -431,7 +433,7 @@ pub fn linker_flags(
431433
if matches!(lld_threads, LldThreads::No) {
432434
args.push(format!(
433435
"-Clink-arg=-Wl,{}",
434-
lld_flag_no_threads(builder.config.lld_mode, target.is_windows())
436+
lld_flag_no_threads(builder, builder.config.lld_mode, target.is_windows())
435437
));
436438
}
437439
}

0 commit comments

Comments
 (0)
Please sign in to comment.