Skip to content

Commit

Permalink
Auto merge of #127321 - Kobzol:bootstrap-cmd-refactor-4, r=onur-ozkan
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed Jul 7, 2024
2 parents 9e27377 + 061edfe commit 35e6e4c
Show file tree
Hide file tree
Showing 23 changed files with 362 additions and 367 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ macro_rules! clean_crate_tree {

// NOTE: doesn't use `run_cargo` because we don't want to save a stamp file,
// and doesn't use `stream_cargo` to avoid passing `--message-format` which `clean` doesn't accept.
builder.run(cargo);
cargo.run(builder);
}
}
)+ }
Expand Down
30 changes: 14 additions & 16 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::core::builder::crate_description;
use crate::core::builder::Cargo;
use crate::core::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, TaskPath};
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
use crate::utils::exec::BootstrapCommand;
use crate::utils::exec::command;
use crate::utils::helpers::{
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
};
Expand Down Expand Up @@ -773,20 +773,19 @@ impl Step for StartupObjects {
let src_file = &src_dir.join(file.to_string() + ".rs");
let dst_file = &dst_dir.join(file.to_string() + ".o");
if !up_to_date(src_file, dst_file) {
let mut cmd = BootstrapCommand::new(&builder.initial_rustc);
let mut cmd = command(&builder.initial_rustc);
cmd.env("RUSTC_BOOTSTRAP", "1");
if !builder.local_rebuild {
// a local_rebuild compiler already has stage1 features
cmd.arg("--cfg").arg("bootstrap");
}
builder.run(
cmd.arg("--target")
.arg(target.rustc_target_arg())
.arg("--emit=obj")
.arg("-o")
.arg(dst_file)
.arg(src_file),
);
cmd.arg("--target")
.arg(target.rustc_target_arg())
.arg("--emit=obj")
.arg("-o")
.arg(dst_file)
.arg(src_file)
.run(builder);
}

let target = sysroot_dir.join((*file).to_string() + ".o");
Expand Down Expand Up @@ -1488,10 +1487,10 @@ pub fn compiler_file(
if builder.config.dry_run() {
return PathBuf::new();
}
let mut cmd = BootstrapCommand::new(compiler);
let mut cmd = command(compiler);
cmd.args(builder.cflags(target, GitRepo::Rustc, c));
cmd.arg(format!("-print-file-name={file}"));
let out = builder.run(cmd.capture_stdout()).stdout();
let out = cmd.capture_stdout().run(builder).stdout();
PathBuf::from(out.trim())
}

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

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

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

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

0 comments on commit 35e6e4c

Please sign in to comment.