Skip to content

Commit 35e6e4c

Browse files
committed
Auto merge of #127321 - Kobzol:bootstrap-cmd-refactor-4, r=onur-ozkan
Bootstrap command refactoring: quality-of-life improvements (step 4) Continuation of #127120. This PR simply introduce two new functions (`BootstrapCommand:run` and `command`) that make it a bit easier to use commands in bootstrap. It also adds several `#[must_use]` annotations. This shouldn't (hopefully) have any effect on behavior. Especially the first commit IMO makes any code that runs commands more readable, and allows using the API in a fluent way, without needing to jump back and forth between the command and the `Build(er)`. Tracking issue: #126819 r? `@onur-ozkan`
2 parents 9e27377 + 061edfe commit 35e6e4c

23 files changed

+362
-367
lines changed

Diff for: 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(cargo);
88+
cargo.run(builder);
8989
}
9090
}
9191
)+ }

Diff for: src/bootstrap/src/core/build_steps/compile.rs

+14-16
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,20 +773,19 @@ 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
780780
cmd.arg("--cfg").arg("bootstrap");
781781
}
782-
builder.run(
783-
cmd.arg("--target")
784-
.arg(target.rustc_target_arg())
785-
.arg("--emit=obj")
786-
.arg("-o")
787-
.arg(dst_file)
788-
.arg(src_file),
789-
);
782+
cmd.arg("--target")
783+
.arg(target.rustc_target_arg())
784+
.arg("--emit=obj")
785+
.arg("-o")
786+
.arg(dst_file)
787+
.arg(src_file)
788+
.run(builder);
790789
}
791790

792791
let target = sysroot_dir.join((*file).to_string() + ".o");
@@ -1488,10 +1487,10 @@ pub fn compiler_file(
14881487
if builder.config.dry_run() {
14891488
return PathBuf::new();
14901489
}
1491-
let mut cmd = BootstrapCommand::new(compiler);
1490+
let mut cmd = command(compiler);
14921491
cmd.args(builder.cflags(target, GitRepo::Rustc, c));
14931492
cmd.arg(format!("-print-file-name={file}"));
1494-
let out = builder.run(cmd.capture_stdout()).stdout();
1493+
let out = cmd.capture_stdout().run(builder).stdout();
14951494
PathBuf::from(out.trim())
14961495
}
14971496

@@ -1836,9 +1835,8 @@ impl Step for Assemble {
18361835
let llvm::LlvmResult { llvm_config, .. } =
18371836
builder.ensure(llvm::Llvm { target: target_compiler.host });
18381837
if !builder.config.dry_run() && builder.config.llvm_tools_enabled {
1839-
let llvm_bin_dir = builder
1840-
.run(BootstrapCommand::new(llvm_config).capture_stdout().arg("--bindir"))
1841-
.stdout();
1838+
let llvm_bin_dir =
1839+
command(llvm_config).capture_stdout().arg("--bindir").run(builder).stdout();
18421840
let llvm_bin_dir = Path::new(llvm_bin_dir.trim());
18431841

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

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

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

0 commit comments

Comments
 (0)