Skip to content

Commit 86b2191

Browse files
committed
Migrate some usage of Command to BootstrapCmd
1 parent 2a9d5ab commit 86b2191

File tree

6 files changed

+73
-19
lines changed

6 files changed

+73
-19
lines changed

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

Lines changed: 2 additions & 1 deletion
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

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

Lines changed: 10 additions & 9 deletions
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() {
@@ -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

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,7 @@ fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) ->
23432343
let test_args = builder.config.test_args().join(" ");
23442344
cmd.arg("--test-args").arg(test_args);
23452345

2346-
let mut cmd = BootstrapCommand::from(&mut cmd).delay_failure();
2346+
cmd = cmd.delay_failure();
23472347
if !builder.config.verbose_tests {
23482348
cmd = cmd.quiet();
23492349
}
@@ -2941,12 +2941,12 @@ impl Step for Distcheck {
29412941
let _ = fs::remove_dir_all(&dir);
29422942
t!(fs::create_dir_all(&dir));
29432943

2944-
let mut cmd = Command::new("tar");
2944+
let mut cmd = BootstrapCommand::new("tar");
29452945
cmd.arg("-xf")
29462946
.arg(builder.ensure(dist::Src).tarball())
29472947
.arg("--strip-components=1")
29482948
.current_dir(&dir);
2949-
builder.run(&mut cmd);
2949+
builder.run(cmd);
29502950

29512951
let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
29522952
builder.run(

src/bootstrap/src/core/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use crate::utils::helpers::{check_cfg_arg, libdir, linker_flags, output, t, LldT
2424
use crate::EXTRA_CHECK_CFGS;
2525
use crate::{Build, CLang, Crate, DocTests, GitRepo, Mode};
2626

27-
pub use crate::Compiler;
2827
use crate::utils::exec::BootstrapCommand;
28+
pub use crate::Compiler;
2929

3030
use clap::ValueEnum;
3131
// FIXME: replace with std::lazy after it gets stabilized and reaches beta
@@ -1311,8 +1311,8 @@ impl<'a> Builder<'a> {
13111311
cmd
13121312
}
13131313

1314-
pub fn rustdoc_cmd(&self, compiler: Compiler) -> Command {
1315-
let mut cmd = Command::new(self.bootstrap_out.join("rustdoc"));
1314+
pub fn rustdoc_cmd(&self, compiler: Compiler) -> BootstrapCommand {
1315+
let mut cmd = BootstrapCommand::new(self.bootstrap_out.join("rustdoc"));
13161316
cmd.env("RUSTC_STAGE", compiler.stage.to_string())
13171317
.env("RUSTC_SYSROOT", self.sysroot(compiler))
13181318
// Note that this is *not* the sysroot_libdir because rustdoc must be linked

src/bootstrap/src/utils/exec.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::ffi::OsStr;
2+
use std::ops::{Deref, DerefMut};
23
use std::path::Path;
34
use std::process::{Command, ExitStatus, Output};
45

@@ -46,6 +47,38 @@ pub struct BootstrapCommand {
4647
}
4748

4849
impl BootstrapCommand {
50+
pub fn new<S: AsRef<OsStr>>(program: S) -> Self {
51+
Command::new(program).into()
52+
}
53+
54+
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self {
55+
self.command.arg(arg.as_ref());
56+
self
57+
}
58+
59+
pub fn args<I, S>(&mut self, args: I) -> &mut Self
60+
where
61+
I: IntoIterator<Item = S>,
62+
S: AsRef<OsStr>,
63+
{
64+
self.command.args(args);
65+
self
66+
}
67+
68+
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Self
69+
where
70+
K: AsRef<OsStr>,
71+
V: AsRef<OsStr>,
72+
{
73+
self.command.env(key, val);
74+
self
75+
}
76+
77+
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Self {
78+
self.command.current_dir(dir);
79+
self
80+
}
81+
4982
pub fn delay_failure(self) -> Self {
5083
Self { failure_behavior: BehaviorOnFailure::DelayFail, ..self }
5184
}
@@ -101,6 +134,24 @@ impl<'a> From<&'a mut BootstrapCommand> for BootstrapCommand {
101134
}
102135
}
103136

137+
/// This implementation is temporary, until all `Command` invocations are migrated to
138+
/// `BootstrapCommand`.
139+
impl Deref for BootstrapCommand {
140+
type Target = Command;
141+
142+
fn deref(&self) -> &Self::Target {
143+
&self.command
144+
}
145+
}
146+
147+
/// This implementation is temporary, until all `Command` invocations are migrated to
148+
/// `BootstrapCommand`.
149+
impl DerefMut for BootstrapCommand {
150+
fn deref_mut(&mut self) -> &mut Self::Target {
151+
&mut self.command
152+
}
153+
}
154+
104155
impl From<Command> for BootstrapCommand {
105156
fn from(command: Command) -> Self {
106157
Self { command, failure_behavior: BehaviorOnFailure::Exit, output_mode: None }

0 commit comments

Comments
 (0)