Skip to content

Commit a7dfed9

Browse files
committed
Migrate some usage of Command to BootstrapCmd
1 parent 3beb59f commit a7dfed9

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
};
@@ -1595,14 +1596,14 @@ impl Step for Extended {
15951596
let _ = fs::remove_dir_all(&pkg);
15961597

15971598
let pkgbuild = |component: &str| {
1598-
let mut cmd = Command::new("pkgbuild");
1599+
let mut cmd = BootstrapCommand::new("pkgbuild");
15991600
cmd.arg("--identifier")
16001601
.arg(format!("org.rust-lang.{}", component))
16011602
.arg("--scripts")
16021603
.arg(pkg.join(component))
16031604
.arg("--nopayload")
16041605
.arg(pkg.join(component).with_extension("pkg"));
1605-
builder.run(&mut cmd);
1606+
builder.run(cmd);
16061607
};
16071608

16081609
let prepare = |name: &str| {
@@ -1632,7 +1633,7 @@ impl Step for Extended {
16321633
builder.create_dir(&pkg.join("res"));
16331634
builder.create(&pkg.join("res/LICENSE.txt"), &license);
16341635
builder.install(&etc.join("gfx/rust-logo.png"), &pkg.join("res"), 0o644);
1635-
let mut cmd = Command::new("productbuild");
1636+
let mut cmd = BootstrapCommand::new("productbuild");
16361637
cmd.arg("--distribution")
16371638
.arg(xform(&etc.join("pkg/Distribution.xml")))
16381639
.arg("--resources")
@@ -1645,7 +1646,7 @@ impl Step for Extended {
16451646
.arg("--package-path")
16461647
.arg(&pkg);
16471648
let _time = timeit(builder);
1648-
builder.run(&mut cmd);
1649+
builder.run(cmd);
16491650
}
16501651

16511652
if target.is_windows() {
@@ -1860,7 +1861,7 @@ impl Step for Extended {
18601861
let candle = |input: &Path| {
18611862
let output = exe.join(input.file_stem().unwrap()).with_extension("wixobj");
18621863
let arch = if target.contains("x86_64") { "x64" } else { "x86" };
1863-
let mut cmd = Command::new(&candle);
1864+
let mut cmd = BootstrapCommand::new(&candle);
18641865
cmd.current_dir(&exe)
18651866
.arg("-nologo")
18661867
.arg("-dRustcDir=rustc")
@@ -1889,7 +1890,7 @@ impl Step for Extended {
18891890
if target.ends_with("windows-gnu") {
18901891
cmd.arg("-dGccDir=rust-mingw");
18911892
}
1892-
builder.run(&mut cmd);
1893+
builder.run(cmd);
18931894
};
18941895
candle(&xform(&etc.join("msi/rust.wxs")));
18951896
candle(&etc.join("msi/ui.wxs"));
@@ -1921,7 +1922,7 @@ impl Step for Extended {
19211922

19221923
builder.info(&format!("building `msi` installer with {light:?}"));
19231924
let filename = format!("{}-{}.msi", pkgname(builder, "rust"), target.triple);
1924-
let mut cmd = Command::new(&light);
1925+
let mut cmd = BootstrapCommand::new(&light);
19251926
cmd.arg("-nologo")
19261927
.arg("-ext")
19271928
.arg("WixUIExtension")
@@ -1958,7 +1959,7 @@ impl Step for Extended {
19581959
cmd.arg("-sice:ICE57");
19591960

19601961
let _time = timeit(builder);
1961-
builder.run(&mut cmd);
1962+
builder.run(cmd);
19621963

19631964
if !builder.config.dry_run() {
19641965
t!(move_file(exe.join(&filename), distdir(builder).join(&filename)));
@@ -1967,7 +1968,7 @@ impl Step for Extended {
19671968
}
19681969
}
19691970

1970-
fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
1971+
fn add_env(builder: &Builder<'_>, cmd: &mut BootstrapCommand, target: TargetSelection) {
19711972
let mut parts = builder.version.split('.');
19721973
cmd.env("CFG_RELEASE_INFO", builder.rust_version())
19731974
.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
@@ -2345,7 +2345,7 @@ fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) ->
23452345
let test_args = builder.config.test_args().join(" ");
23462346
cmd.arg("--test-args").arg(test_args);
23472347

2348-
let mut cmd = BootstrapCommand::from(&mut cmd).delay_failure();
2348+
cmd = cmd.delay_failure();
23492349
if !builder.config.verbose_tests {
23502350
cmd = cmd.quiet();
23512351
}
@@ -2943,12 +2943,12 @@ impl Step for Distcheck {
29432943
let _ = fs::remove_dir_all(&dir);
29442944
t!(fs::create_dir_all(&dir));
29452945

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

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

src/bootstrap/src/core/builder.rs

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

29-
pub use crate::Compiler;
3029
use crate::utils::exec::BootstrapCommand;
30+
pub use crate::Compiler;
3131

3232
use clap::ValueEnum;
3333
// FIXME: replace with std::lazy after it gets stabilized and reaches beta
@@ -1291,8 +1291,8 @@ impl<'a> Builder<'a> {
12911291
cmd
12921292
}
12931293

1294-
pub fn rustdoc_cmd(&self, compiler: Compiler) -> Command {
1295-
let mut cmd = Command::new(self.bootstrap_out.join("rustdoc"));
1294+
pub fn rustdoc_cmd(&self, compiler: Compiler) -> BootstrapCommand {
1295+
let mut cmd = BootstrapCommand::new(self.bootstrap_out.join("rustdoc"));
12961296
cmd.env("RUSTC_STAGE", compiler.stage.to_string())
12971297
.env("RUSTC_SYSROOT", self.sysroot(compiler))
12981298
// 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)