Skip to content

Commit dfa68f1

Browse files
authored
Rollup merge of #126822 - Kobzol:bootstrap-cmd-refactor-2, r=onur-ozkan
Bootstrap command refactoring: port more `Command` usages to `BootstrapCmd` (step 2) This PR moves more of bootstrap to use `BooststrapCmd`, and also refactors the struct to allow it to serve as a proper command wrapper. Tracking issue: #126819 Best reviewed commit-by-commit, I have been adding some helper impls along the way to ease the migration, and then later I remove some of them since they were no longer needed. r? `@onur-ozkan`
2 parents d38cd22 + 2ebfcce commit dfa68f1

17 files changed

+262
-173
lines changed

src/bootstrap/src/core/build_steps/clean.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ macro_rules! clean_crate_tree {
8585

8686
// NOTE: doesn't use `run_cargo` because we don't want to save a stamp file,
8787
// and doesn't use `stream_cargo` to avoid passing `--message-format` which `clean` doesn't accept.
88-
builder.run(&mut cargo);
88+
builder.run(cargo);
8989
}
9090
}
9191
)+ }

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::core::builder::crate_description;
2727
use crate::core::builder::Cargo;
2828
use crate::core::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath};
2929
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
30+
use crate::utils::exec::BootstrapCommand;
3031
use crate::utils::helpers::{
3132
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, output, symlink_dir, t, up_to_date,
3233
};
@@ -771,7 +772,7 @@ impl Step for StartupObjects {
771772
let src_file = &src_dir.join(file.to_string() + ".rs");
772773
let dst_file = &dst_dir.join(file.to_string() + ".o");
773774
if !up_to_date(src_file, dst_file) {
774-
let mut cmd = Command::new(&builder.initial_rustc);
775+
let mut cmd = BootstrapCommand::new(&builder.initial_rustc);
775776
cmd.env("RUSTC_BOOTSTRAP", "1");
776777
if !builder.local_rebuild {
777778
// a local_rebuild compiler already has stage1 features
@@ -2076,7 +2077,7 @@ pub fn stream_cargo(
20762077
tail_args: Vec<String>,
20772078
cb: &mut dyn FnMut(CargoMessage<'_>),
20782079
) -> bool {
2079-
let mut cargo = Command::from(cargo);
2080+
let mut cargo = BootstrapCommand::from(cargo).command;
20802081
// Instruct Cargo to give us json messages on stdout, critically leaving
20812082
// stderr as piped so we can get those pretty colors.
20822083
let mut message_format = if builder.config.json_output {

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

+19-18
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::core::build_steps::tool::{self, Tool};
2626
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2727
use crate::core::config::TargetSelection;
2828
use crate::utils::channel::{self, Info};
29+
use crate::utils::exec::BootstrapCommand;
2930
use crate::utils::helpers::{
3031
exe, is_dylib, move_file, output, t, target_supports_cranelift_backend, timeit,
3132
};
@@ -1599,14 +1600,14 @@ impl Step for Extended {
15991600
let _ = fs::remove_dir_all(&pkg);
16001601

16011602
let pkgbuild = |component: &str| {
1602-
let mut cmd = Command::new("pkgbuild");
1603+
let mut cmd = BootstrapCommand::new("pkgbuild");
16031604
cmd.arg("--identifier")
16041605
.arg(format!("org.rust-lang.{}", component))
16051606
.arg("--scripts")
16061607
.arg(pkg.join(component))
16071608
.arg("--nopayload")
16081609
.arg(pkg.join(component).with_extension("pkg"));
1609-
builder.run(&mut cmd);
1610+
builder.run(cmd);
16101611
};
16111612

16121613
let prepare = |name: &str| {
@@ -1636,7 +1637,7 @@ impl Step for Extended {
16361637
builder.create_dir(&pkg.join("res"));
16371638
builder.create(&pkg.join("res/LICENSE.txt"), &license);
16381639
builder.install(&etc.join("gfx/rust-logo.png"), &pkg.join("res"), 0o644);
1639-
let mut cmd = Command::new("productbuild");
1640+
let mut cmd = BootstrapCommand::new("productbuild");
16401641
cmd.arg("--distribution")
16411642
.arg(xform(&etc.join("pkg/Distribution.xml")))
16421643
.arg("--resources")
@@ -1649,7 +1650,7 @@ impl Step for Extended {
16491650
.arg("--package-path")
16501651
.arg(&pkg);
16511652
let _time = timeit(builder);
1652-
builder.run(&mut cmd);
1653+
builder.run(cmd);
16531654
}
16541655

16551656
if target.is_windows() {
@@ -1704,7 +1705,7 @@ impl Step for Extended {
17041705

17051706
let heat_flags = ["-nologo", "-gg", "-sfrag", "-srd", "-sreg"];
17061707
builder.run(
1707-
Command::new(&heat)
1708+
BootstrapCommand::new(&heat)
17081709
.current_dir(&exe)
17091710
.arg("dir")
17101711
.arg("rustc")
@@ -1720,7 +1721,7 @@ impl Step for Extended {
17201721
);
17211722
if built_tools.contains("rust-docs") {
17221723
builder.run(
1723-
Command::new(&heat)
1724+
BootstrapCommand::new(&heat)
17241725
.current_dir(&exe)
17251726
.arg("dir")
17261727
.arg("rust-docs")
@@ -1738,7 +1739,7 @@ impl Step for Extended {
17381739
);
17391740
}
17401741
builder.run(
1741-
Command::new(&heat)
1742+
BootstrapCommand::new(&heat)
17421743
.current_dir(&exe)
17431744
.arg("dir")
17441745
.arg("cargo")
@@ -1755,7 +1756,7 @@ impl Step for Extended {
17551756
.arg(etc.join("msi/remove-duplicates.xsl")),
17561757
);
17571758
builder.run(
1758-
Command::new(&heat)
1759+
BootstrapCommand::new(&heat)
17591760
.current_dir(&exe)
17601761
.arg("dir")
17611762
.arg("rust-std")
@@ -1771,7 +1772,7 @@ impl Step for Extended {
17711772
);
17721773
if built_tools.contains("rust-analyzer") {
17731774
builder.run(
1774-
Command::new(&heat)
1775+
BootstrapCommand::new(&heat)
17751776
.current_dir(&exe)
17761777
.arg("dir")
17771778
.arg("rust-analyzer")
@@ -1790,7 +1791,7 @@ impl Step for Extended {
17901791
}
17911792
if built_tools.contains("clippy") {
17921793
builder.run(
1793-
Command::new(&heat)
1794+
BootstrapCommand::new(&heat)
17941795
.current_dir(&exe)
17951796
.arg("dir")
17961797
.arg("clippy")
@@ -1809,7 +1810,7 @@ impl Step for Extended {
18091810
}
18101811
if built_tools.contains("miri") {
18111812
builder.run(
1812-
Command::new(&heat)
1813+
BootstrapCommand::new(&heat)
18131814
.current_dir(&exe)
18141815
.arg("dir")
18151816
.arg("miri")
@@ -1827,7 +1828,7 @@ impl Step for Extended {
18271828
);
18281829
}
18291830
builder.run(
1830-
Command::new(&heat)
1831+
BootstrapCommand::new(&heat)
18311832
.current_dir(&exe)
18321833
.arg("dir")
18331834
.arg("rust-analysis")
@@ -1845,7 +1846,7 @@ impl Step for Extended {
18451846
);
18461847
if target.ends_with("windows-gnu") {
18471848
builder.run(
1848-
Command::new(&heat)
1849+
BootstrapCommand::new(&heat)
18491850
.current_dir(&exe)
18501851
.arg("dir")
18511852
.arg("rust-mingw")
@@ -1864,7 +1865,7 @@ impl Step for Extended {
18641865
let candle = |input: &Path| {
18651866
let output = exe.join(input.file_stem().unwrap()).with_extension("wixobj");
18661867
let arch = if target.contains("x86_64") { "x64" } else { "x86" };
1867-
let mut cmd = Command::new(&candle);
1868+
let mut cmd = BootstrapCommand::new(&candle);
18681869
cmd.current_dir(&exe)
18691870
.arg("-nologo")
18701871
.arg("-dRustcDir=rustc")
@@ -1893,7 +1894,7 @@ impl Step for Extended {
18931894
if target.ends_with("windows-gnu") {
18941895
cmd.arg("-dGccDir=rust-mingw");
18951896
}
1896-
builder.run(&mut cmd);
1897+
builder.run(cmd);
18971898
};
18981899
candle(&xform(&etc.join("msi/rust.wxs")));
18991900
candle(&etc.join("msi/ui.wxs"));
@@ -1925,7 +1926,7 @@ impl Step for Extended {
19251926

19261927
builder.info(&format!("building `msi` installer with {light:?}"));
19271928
let filename = format!("{}-{}.msi", pkgname(builder, "rust"), target.triple);
1928-
let mut cmd = Command::new(&light);
1929+
let mut cmd = BootstrapCommand::new(&light);
19291930
cmd.arg("-nologo")
19301931
.arg("-ext")
19311932
.arg("WixUIExtension")
@@ -1962,7 +1963,7 @@ impl Step for Extended {
19621963
cmd.arg("-sice:ICE57");
19631964

19641965
let _time = timeit(builder);
1965-
builder.run(&mut cmd);
1966+
builder.run(cmd);
19661967

19671968
if !builder.config.dry_run() {
19681969
t!(move_file(exe.join(&filename), distdir(builder).join(&filename)));
@@ -1971,7 +1972,7 @@ impl Step for Extended {
19711972
}
19721973
}
19731974

1974-
fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
1975+
fn add_env(builder: &Builder<'_>, cmd: &mut BootstrapCommand, target: TargetSelection) {
19751976
let mut parts = builder.version.split('.');
19761977
cmd.env("CFG_RELEASE_INFO", builder.rust_version())
19771978
.env("CFG_RELEASE_NUM", &builder.version)

src/bootstrap/src/core/build_steps/doc.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ impl Step for TheBook {
249249
let shared_assets = builder.ensure(SharedAssets { target });
250250

251251
// build the command first so we don't nest GHA groups
252+
// FIXME: this doesn't do anything!
252253
builder.rustdoc_cmd(compiler);
253254

254255
// build the redirect pages
@@ -300,7 +301,7 @@ fn invoke_rustdoc(
300301
cmd.arg("-Z").arg("unstable-options").arg("--disable-minification");
301302
}
302303

303-
builder.run(&mut cmd);
304+
builder.run(cmd);
304305
}
305306

306307
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -394,7 +395,7 @@ impl Step for Standalone {
394395
} else {
395396
cmd.arg("--markdown-css").arg("rust.css");
396397
}
397-
builder.run(&mut cmd);
398+
builder.run(cmd);
398399
}
399400

400401
// We open doc/index.html as the default if invoked as `x.py doc --open`
@@ -493,7 +494,7 @@ impl Step for Releases {
493494
cmd.arg("--disable-minification");
494495
}
495496

496-
builder.run(&mut cmd);
497+
builder.run(cmd);
497498
}
498499

499500
// We open doc/RELEASES.html as the default if invoked as `x.py doc --open RELEASES.md`
@@ -737,7 +738,7 @@ fn doc_std(
737738
format!("library{} in {} format", crate_description(requested_crates), format.as_str());
738739
let _guard = builder.msg_doc(compiler, description, target);
739740

740-
builder.run(&mut cargo.into());
741+
builder.run(cargo);
741742
builder.cp_link_r(&out_dir, out);
742743
}
743744

@@ -862,7 +863,7 @@ impl Step for Rustc {
862863
let proc_macro_out_dir = builder.stage_out(compiler, Mode::Rustc).join("doc");
863864
symlink_dir_force(&builder.config, &out, &proc_macro_out_dir);
864865

865-
builder.run(&mut cargo.into());
866+
builder.run(cargo);
866867

867868
if !builder.config.dry_run() {
868869
// Sanity check on linked compiler crates
@@ -995,7 +996,7 @@ macro_rules! tool_doc {
995996
symlink_dir_force(&builder.config, &out, &proc_macro_out_dir);
996997

997998
let _guard = builder.msg_doc(compiler, stringify!($tool).to_lowercase(), target);
998-
builder.run(&mut cargo.into());
999+
builder.run(cargo);
9991000

10001001
if !builder.config.dry_run() {
10011002
// Sanity check on linked doc directories
@@ -1079,7 +1080,7 @@ impl Step for ErrorIndex {
10791080
index.arg(out);
10801081
index.arg(&builder.version);
10811082

1082-
builder.run(&mut index);
1083+
builder.run(index);
10831084
}
10841085
}
10851086

@@ -1115,7 +1116,7 @@ impl Step for UnstableBookGen {
11151116
cmd.arg(builder.src.join("src"));
11161117
cmd.arg(out);
11171118

1118-
builder.run(&mut cmd);
1119+
builder.run(cmd);
11191120
}
11201121
}
11211122

@@ -1210,7 +1211,7 @@ impl Step for RustcBook {
12101211
self.compiler.host,
12111212
self.target,
12121213
);
1213-
builder.run(&mut cmd);
1214+
builder.run(cmd);
12141215
drop(doc_generator_guard);
12151216

12161217
// Run rustbook/mdbook to generate the HTML pages.

src/bootstrap/src/core/build_steps/install.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
use std::env;
77
use std::fs;
88
use std::path::{Component, Path, PathBuf};
9-
use std::process::Command;
109

1110
use crate::core::build_steps::dist;
1211
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
1312
use crate::core::config::{Config, TargetSelection};
13+
use crate::utils::exec::BootstrapCommand;
1414
use crate::utils::helpers::t;
1515
use crate::utils::tarball::GeneratedTarball;
1616
use crate::{Compiler, Kind};
@@ -102,7 +102,7 @@ fn install_sh(
102102
let empty_dir = builder.out.join("tmp/empty_dir");
103103
t!(fs::create_dir_all(&empty_dir));
104104

105-
let mut cmd = Command::new(SHELL);
105+
let mut cmd = BootstrapCommand::new(SHELL);
106106
cmd.current_dir(&empty_dir)
107107
.arg(sanitize_sh(&tarball.decompressed_output().join("install.sh")))
108108
.arg(format!("--prefix={}", prepare_dir(&destdir_env, prefix)))
@@ -113,7 +113,7 @@ fn install_sh(
113113
.arg(format!("--libdir={}", prepare_dir(&destdir_env, libdir)))
114114
.arg(format!("--mandir={}", prepare_dir(&destdir_env, mandir)))
115115
.arg("--disable-ldconfig");
116-
builder.run(&mut cmd);
116+
builder.run(cmd);
117117
t!(fs::remove_dir_all(&empty_dir));
118118
}
119119

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Step for BuildManifest {
5050
cmd.arg(&builder.config.channel);
5151

5252
builder.create_dir(&distdir(builder));
53-
builder.run(&mut cmd);
53+
builder.run(cmd);
5454
}
5555
}
5656

@@ -72,7 +72,7 @@ impl Step for BumpStage0 {
7272
fn run(self, builder: &Builder<'_>) -> Self::Output {
7373
let mut cmd = builder.tool_cmd(Tool::BumpStage0);
7474
cmd.args(builder.config.args());
75-
builder.run(&mut cmd);
75+
builder.run(cmd);
7676
}
7777
}
7878

@@ -94,7 +94,7 @@ impl Step for ReplaceVersionPlaceholder {
9494
fn run(self, builder: &Builder<'_>) -> Self::Output {
9595
let mut cmd = builder.tool_cmd(Tool::ReplaceVersionPlaceholder);
9696
cmd.arg(&builder.src);
97-
builder.run(&mut cmd);
97+
builder.run(cmd);
9898
}
9999
}
100100

@@ -158,8 +158,7 @@ impl Step for Miri {
158158
// after another --, so this must be at the end.
159159
miri.args(builder.config.args());
160160

161-
let mut miri = Command::from(miri);
162-
builder.run(&mut miri);
161+
builder.run(miri);
163162
}
164163
}
165164

@@ -189,7 +188,7 @@ impl Step for CollectLicenseMetadata {
189188
let mut cmd = builder.tool_cmd(Tool::CollectLicenseMetadata);
190189
cmd.env("REUSE_EXE", reuse);
191190
cmd.env("DEST", &dest);
192-
builder.run(&mut cmd);
191+
builder.run(cmd);
193192

194193
dest
195194
}
@@ -219,7 +218,7 @@ impl Step for GenerateCopyright {
219218
let mut cmd = builder.tool_cmd(Tool::GenerateCopyright);
220219
cmd.env("LICENSE_METADATA", &license_metadata);
221220
cmd.env("DEST", &dest);
222-
builder.run(&mut cmd);
221+
builder.run(cmd);
223222

224223
dest
225224
}
@@ -243,7 +242,7 @@ impl Step for GenerateWindowsSys {
243242
fn run(self, builder: &Builder<'_>) {
244243
let mut cmd = builder.tool_cmd(Tool::GenerateWindowsSys);
245244
cmd.arg(&builder.src);
246-
builder.run(&mut cmd);
245+
builder.run(cmd);
247246
}
248247
}
249248

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

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub fn suggest(builder: &Builder<'_>, run: bool) {
1616
.tool_cmd(Tool::SuggestTests)
1717
.env("SUGGEST_TESTS_GIT_REPOSITORY", git_config.git_repository)
1818
.env("SUGGEST_TESTS_NIGHTLY_BRANCH", git_config.nightly_branch)
19+
.command
1920
.output()
2021
.expect("failed to run `suggest-tests` tool");
2122

0 commit comments

Comments
 (0)