Skip to content

Commit f933d78

Browse files
committed
Add a shortcut helper function command for creating commands
This is simply a quality-of-life improvement to make command creation in bootstrap a bit shorter and more discoverable.
1 parent 7366064 commit f933d78

18 files changed

+94
-111
lines changed

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +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;
30+
use crate::utils::exec::command;
3131
use crate::utils::helpers::{
3232
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
3333
};
@@ -773,7 +773,7 @@ impl Step for StartupObjects {
773773
let src_file = &src_dir.join(file.to_string() + ".rs");
774774
let dst_file = &dst_dir.join(file.to_string() + ".o");
775775
if !up_to_date(src_file, dst_file) {
776-
let mut cmd = BootstrapCommand::new(&builder.initial_rustc);
776+
let mut cmd = command(&builder.initial_rustc);
777777
cmd.env("RUSTC_BOOTSTRAP", "1");
778778
if !builder.local_rebuild {
779779
// a local_rebuild compiler already has stage1 features
@@ -1487,7 +1487,7 @@ pub fn compiler_file(
14871487
if builder.config.dry_run() {
14881488
return PathBuf::new();
14891489
}
1490-
let mut cmd = BootstrapCommand::new(compiler);
1490+
let mut cmd = command(compiler);
14911491
cmd.args(builder.cflags(target, GitRepo::Rustc, c));
14921492
cmd.arg(format!("-print-file-name={file}"));
14931493
let out = cmd.capture_stdout().run(builder).stdout();
@@ -1835,11 +1835,8 @@ impl Step for Assemble {
18351835
let llvm::LlvmResult { llvm_config, .. } =
18361836
builder.ensure(llvm::Llvm { target: target_compiler.host });
18371837
if !builder.config.dry_run() && builder.config.llvm_tools_enabled {
1838-
let llvm_bin_dir = BootstrapCommand::new(llvm_config)
1839-
.capture_stdout()
1840-
.arg("--bindir")
1841-
.run(builder)
1842-
.stdout();
1838+
let llvm_bin_dir =
1839+
command(llvm_config).capture_stdout().arg("--bindir").run(builder).stdout();
18431840
let llvm_bin_dir = Path::new(llvm_bin_dir.trim());
18441841

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

21662163
let previous_mtime = FileTime::from_last_modification_time(&path.metadata().unwrap());
2167-
BootstrapCommand::new("strip").capture().arg("--strip-debug").arg(path).run(builder);
2164+
command("strip").capture().arg("--strip-debug").arg(path).run(builder);
21682165

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

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

+17-17
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::core::build_steps::tool::{self, Tool};
2525
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2626
use crate::core::config::TargetSelection;
2727
use crate::utils::channel::{self, Info};
28-
use crate::utils::exec::BootstrapCommand;
28+
use crate::utils::exec::{command, BootstrapCommand};
2929
use crate::utils::helpers::{
3030
exe, is_dylib, move_file, t, target_supports_cranelift_backend, timeit,
3131
};
@@ -180,7 +180,7 @@ fn make_win_dist(
180180
}
181181

182182
//Ask gcc where it keeps its stuff
183-
let mut cmd = BootstrapCommand::new(builder.cc(target));
183+
let mut cmd = command(builder.cc(target));
184184
cmd.arg("-print-search-dirs");
185185
let gcc_out = cmd.capture_stdout().run(builder).stdout();
186186

@@ -1023,7 +1023,7 @@ impl Step for PlainSourceTarball {
10231023
}
10241024

10251025
// Vendor all Cargo dependencies
1026-
let mut cmd = BootstrapCommand::new(&builder.initial_cargo);
1026+
let mut cmd = command(&builder.initial_cargo);
10271027
cmd.arg("vendor")
10281028
.arg("--versioned-dirs")
10291029
.arg("--sync")
@@ -1599,7 +1599,7 @@ impl Step for Extended {
15991599
let _ = fs::remove_dir_all(&pkg);
16001600

16011601
let pkgbuild = |component: &str| {
1602-
let mut cmd = BootstrapCommand::new("pkgbuild");
1602+
let mut cmd = command("pkgbuild");
16031603
cmd.arg("--identifier")
16041604
.arg(format!("org.rust-lang.{}", component))
16051605
.arg("--scripts")
@@ -1636,7 +1636,7 @@ impl Step for Extended {
16361636
builder.create_dir(&pkg.join("res"));
16371637
builder.create(&pkg.join("res/LICENSE.txt"), &license);
16381638
builder.install(&etc.join("gfx/rust-logo.png"), &pkg.join("res"), 0o644);
1639-
let mut cmd = BootstrapCommand::new("productbuild");
1639+
let mut cmd = command("productbuild");
16401640
cmd.arg("--distribution")
16411641
.arg(xform(&etc.join("pkg/Distribution.xml")))
16421642
.arg("--resources")
@@ -1703,7 +1703,7 @@ impl Step for Extended {
17031703
let light = wix.join("bin/light.exe");
17041704

17051705
let heat_flags = ["-nologo", "-gg", "-sfrag", "-srd", "-sreg"];
1706-
BootstrapCommand::new(&heat)
1706+
command(&heat)
17071707
.current_dir(&exe)
17081708
.arg("dir")
17091709
.arg("rustc")
@@ -1718,7 +1718,7 @@ impl Step for Extended {
17181718
.arg(exe.join("RustcGroup.wxs"))
17191719
.run(builder);
17201720
if built_tools.contains("rust-docs") {
1721-
BootstrapCommand::new(&heat)
1721+
command(&heat)
17221722
.current_dir(&exe)
17231723
.arg("dir")
17241724
.arg("rust-docs")
@@ -1735,7 +1735,7 @@ impl Step for Extended {
17351735
.arg(etc.join("msi/squash-components.xsl"))
17361736
.run(builder);
17371737
}
1738-
BootstrapCommand::new(&heat)
1738+
command(&heat)
17391739
.current_dir(&exe)
17401740
.arg("dir")
17411741
.arg("cargo")
@@ -1751,7 +1751,7 @@ impl Step for Extended {
17511751
.arg("-t")
17521752
.arg(etc.join("msi/remove-duplicates.xsl"))
17531753
.run(builder);
1754-
BootstrapCommand::new(&heat)
1754+
command(&heat)
17551755
.current_dir(&exe)
17561756
.arg("dir")
17571757
.arg("rust-std")
@@ -1766,7 +1766,7 @@ impl Step for Extended {
17661766
.arg(exe.join("StdGroup.wxs"))
17671767
.run(builder);
17681768
if built_tools.contains("rust-analyzer") {
1769-
BootstrapCommand::new(&heat)
1769+
command(&heat)
17701770
.current_dir(&exe)
17711771
.arg("dir")
17721772
.arg("rust-analyzer")
@@ -1784,7 +1784,7 @@ impl Step for Extended {
17841784
.run(builder);
17851785
}
17861786
if built_tools.contains("clippy") {
1787-
BootstrapCommand::new(&heat)
1787+
command(&heat)
17881788
.current_dir(&exe)
17891789
.arg("dir")
17901790
.arg("clippy")
@@ -1802,7 +1802,7 @@ impl Step for Extended {
18021802
.run(builder);
18031803
}
18041804
if built_tools.contains("miri") {
1805-
BootstrapCommand::new(&heat)
1805+
command(&heat)
18061806
.current_dir(&exe)
18071807
.arg("dir")
18081808
.arg("miri")
@@ -1819,7 +1819,7 @@ impl Step for Extended {
18191819
.arg(etc.join("msi/remove-duplicates.xsl"))
18201820
.run(builder);
18211821
}
1822-
BootstrapCommand::new(&heat)
1822+
command(&heat)
18231823
.current_dir(&exe)
18241824
.arg("dir")
18251825
.arg("rust-analysis")
@@ -1836,7 +1836,7 @@ impl Step for Extended {
18361836
.arg(etc.join("msi/remove-duplicates.xsl"))
18371837
.run(builder);
18381838
if target.ends_with("windows-gnu") {
1839-
BootstrapCommand::new(&heat)
1839+
command(&heat)
18401840
.current_dir(&exe)
18411841
.arg("dir")
18421842
.arg("rust-mingw")
@@ -1855,7 +1855,7 @@ impl Step for Extended {
18551855
let candle = |input: &Path| {
18561856
let output = exe.join(input.file_stem().unwrap()).with_extension("wixobj");
18571857
let arch = if target.contains("x86_64") { "x64" } else { "x86" };
1858-
let mut cmd = BootstrapCommand::new(&candle);
1858+
let mut cmd = command(&candle);
18591859
cmd.current_dir(&exe)
18601860
.arg("-nologo")
18611861
.arg("-dRustcDir=rustc")
@@ -1916,7 +1916,7 @@ impl Step for Extended {
19161916

19171917
builder.info(&format!("building `msi` installer with {light:?}"));
19181918
let filename = format!("{}-{}.msi", pkgname(builder, "rust"), target.triple);
1919-
let mut cmd = BootstrapCommand::new(&light);
1919+
let mut cmd = command(&light);
19201920
cmd.arg("-nologo")
19211921
.arg("-ext")
19221922
.arg("WixUIExtension")
@@ -2069,7 +2069,7 @@ fn maybe_install_llvm(
20692069
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult { llvm_config, .. }) =
20702070
llvm::prebuilt_llvm_config(builder, target)
20712071
{
2072-
let mut cmd = BootstrapCommand::new(llvm_config);
2072+
let mut cmd = command(llvm_config);
20732073
cmd.arg("--libfiles");
20742074
builder.verbose(|| println!("running {cmd:?}"));
20752075
let files = if builder.config.dry_run() {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Runs rustfmt on the repository.
22
33
use crate::core::builder::Builder;
4-
use crate::utils::exec::BootstrapCommand;
4+
use crate::utils::exec::command;
55
use crate::utils::helpers::{self, program_out_of_date, t};
66
use build_helper::ci::CiEnv;
77
use build_helper::git::get_git_modified_files;
@@ -54,7 +54,7 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
5454
fn get_rustfmt_version(build: &Builder<'_>) -> Option<(String, PathBuf)> {
5555
let stamp_file = build.out.join("rustfmt.stamp");
5656

57-
let mut cmd = BootstrapCommand::new(match build.initial_rustfmt() {
57+
let mut cmd = command(match build.initial_rustfmt() {
5858
Some(p) => p,
5959
None => return None,
6060
});

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::path::{Component, Path, PathBuf};
1010
use crate::core::build_steps::dist;
1111
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
1212
use crate::core::config::{Config, TargetSelection};
13-
use crate::utils::exec::BootstrapCommand;
13+
use crate::utils::exec::command;
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 = BootstrapCommand::new(SHELL);
105+
let mut cmd = command(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)))

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

+6-13
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::utils::helpers::{
2424
};
2525
use crate::{generate_smart_stamp_hash, CLang, GitRepo, Kind};
2626

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

@@ -478,11 +478,8 @@ 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 = BootstrapCommand::new(&llvm_config)
482-
.capture_stdout()
483-
.arg("--bindir")
484-
.run(builder)
485-
.stdout();
481+
let llvm_bindir =
482+
command(&llvm_config).capture_stdout().arg("--bindir").run(builder).stdout();
486483
let host_bin = Path::new(llvm_bindir.trim());
487484
cfg.define(
488485
"LLVM_TABLEGEN",
@@ -532,11 +529,8 @@ impl Step for Llvm {
532529

533530
// Helper to find the name of LLVM's shared library on darwin and linux.
534531
let find_llvm_lib_name = |extension| {
535-
let version = BootstrapCommand::new(&res.llvm_config)
536-
.capture_stdout()
537-
.arg("--version")
538-
.run(builder)
539-
.stdout();
532+
let version =
533+
command(&res.llvm_config).capture_stdout().arg("--version").run(builder).stdout();
540534
let major = version.split('.').next().unwrap();
541535

542536
match &llvm_version_suffix {
@@ -592,8 +586,7 @@ fn check_llvm_version(builder: &Builder<'_>, llvm_config: &Path) {
592586
return;
593587
}
594588

595-
let version =
596-
BootstrapCommand::new(llvm_config).capture_stdout().arg("--version").run(builder).stdout();
589+
let version = command(llvm_config).capture_stdout().arg("--version").run(builder).stdout();
597590
let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok());
598591
if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) {
599592
if major >= 17 {

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::core::build_steps::tool::{self, SourceType, Tool};
1111
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
1212
use crate::core::config::flags::get_completion;
1313
use crate::core::config::TargetSelection;
14-
use crate::utils::exec::BootstrapCommand;
14+
use crate::utils::exec::command;
1515
use crate::Mode;
1616

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

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

4645
cmd.arg(sign);
4746
cmd.arg(distdir(builder));

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
use crate::core::builder::{Builder, ShouldRun, Step};
1111
use crate::core::config::TargetSelection;
12-
use crate::utils::exec::BootstrapCommand;
12+
use crate::utils::exec::command;
1313
use crate::Compiler;
1414

1515
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -56,7 +56,7 @@ fn create_synthetic_target(
5656
return TargetSelection::create_synthetic(&name, path.to_str().unwrap());
5757
}
5858

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

0 commit comments

Comments
 (0)