Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
Kobzol committed Jul 4, 2024
commit f933d789b7399f505525362b0527960966b62cdc
15 changes: 6 additions & 9 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,7 +773,7 @@ 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
Expand Down Expand Up @@ -1487,7 +1487,7 @@ 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 = cmd.capture_stdout().run(builder).stdout();
Expand Down Expand Up @@ -1835,11 +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 = BootstrapCommand::new(llvm_config)
.capture_stdout()
.arg("--bindir")
.run(builder)
.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 @@ -2164,7 +2161,7 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
}

let previous_mtime = FileTime::from_last_modification_time(&path.metadata().unwrap());
BootstrapCommand::new("strip").capture().arg("--strip-debug").arg(path).run(builder);
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
34 changes: 17 additions & 17 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::core::build_steps::tool::{self, Tool};
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::core::config::TargetSelection;
use crate::utils::channel::{self, Info};
use crate::utils::exec::BootstrapCommand;
use crate::utils::exec::{command, BootstrapCommand};
use crate::utils::helpers::{
exe, is_dylib, move_file, t, target_supports_cranelift_backend, timeit,
};
Expand Down Expand Up @@ -180,7 +180,7 @@ fn make_win_dist(
}

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

Expand Down Expand Up @@ -1023,7 +1023,7 @@ impl Step for PlainSourceTarball {
}

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

let pkgbuild = |component: &str| {
let mut cmd = BootstrapCommand::new("pkgbuild");
let mut cmd = command("pkgbuild");
cmd.arg("--identifier")
.arg(format!("org.rust-lang.{}", component))
.arg("--scripts")
Expand Down Expand Up @@ -1636,7 +1636,7 @@ impl Step for Extended {
builder.create_dir(&pkg.join("res"));
builder.create(&pkg.join("res/LICENSE.txt"), &license);
builder.install(&etc.join("gfx/rust-logo.png"), &pkg.join("res"), 0o644);
let mut cmd = BootstrapCommand::new("productbuild");
let mut cmd = command("productbuild");
cmd.arg("--distribution")
.arg(xform(&etc.join("pkg/Distribution.xml")))
.arg("--resources")
Expand Down Expand Up @@ -1703,7 +1703,7 @@ impl Step for Extended {
let light = wix.join("bin/light.exe");

let heat_flags = ["-nologo", "-gg", "-sfrag", "-srd", "-sreg"];
BootstrapCommand::new(&heat)
command(&heat)
.current_dir(&exe)
.arg("dir")
.arg("rustc")
Expand All @@ -1718,7 +1718,7 @@ impl Step for Extended {
.arg(exe.join("RustcGroup.wxs"))
.run(builder);
if built_tools.contains("rust-docs") {
BootstrapCommand::new(&heat)
command(&heat)
.current_dir(&exe)
.arg("dir")
.arg("rust-docs")
Expand All @@ -1735,7 +1735,7 @@ impl Step for Extended {
.arg(etc.join("msi/squash-components.xsl"))
.run(builder);
}
BootstrapCommand::new(&heat)
command(&heat)
.current_dir(&exe)
.arg("dir")
.arg("cargo")
Expand All @@ -1751,7 +1751,7 @@ impl Step for Extended {
.arg("-t")
.arg(etc.join("msi/remove-duplicates.xsl"))
.run(builder);
BootstrapCommand::new(&heat)
command(&heat)
.current_dir(&exe)
.arg("dir")
.arg("rust-std")
Expand All @@ -1766,7 +1766,7 @@ impl Step for Extended {
.arg(exe.join("StdGroup.wxs"))
.run(builder);
if built_tools.contains("rust-analyzer") {
BootstrapCommand::new(&heat)
command(&heat)
.current_dir(&exe)
.arg("dir")
.arg("rust-analyzer")
Expand All @@ -1784,7 +1784,7 @@ impl Step for Extended {
.run(builder);
}
if built_tools.contains("clippy") {
BootstrapCommand::new(&heat)
command(&heat)
.current_dir(&exe)
.arg("dir")
.arg("clippy")
Expand All @@ -1802,7 +1802,7 @@ impl Step for Extended {
.run(builder);
}
if built_tools.contains("miri") {
BootstrapCommand::new(&heat)
command(&heat)
.current_dir(&exe)
.arg("dir")
.arg("miri")
Expand All @@ -1819,7 +1819,7 @@ impl Step for Extended {
.arg(etc.join("msi/remove-duplicates.xsl"))
.run(builder);
}
BootstrapCommand::new(&heat)
command(&heat)
.current_dir(&exe)
.arg("dir")
.arg("rust-analysis")
Expand All @@ -1836,7 +1836,7 @@ impl Step for Extended {
.arg(etc.join("msi/remove-duplicates.xsl"))
.run(builder);
if target.ends_with("windows-gnu") {
BootstrapCommand::new(&heat)
command(&heat)
.current_dir(&exe)
.arg("dir")
.arg("rust-mingw")
Expand All @@ -1855,7 +1855,7 @@ impl Step for Extended {
let candle = |input: &Path| {
let output = exe.join(input.file_stem().unwrap()).with_extension("wixobj");
let arch = if target.contains("x86_64") { "x64" } else { "x86" };
let mut cmd = BootstrapCommand::new(&candle);
let mut cmd = command(&candle);
cmd.current_dir(&exe)
.arg("-nologo")
.arg("-dRustcDir=rustc")
Expand Down Expand Up @@ -1916,7 +1916,7 @@ impl Step for Extended {

builder.info(&format!("building `msi` installer with {light:?}"));
let filename = format!("{}-{}.msi", pkgname(builder, "rust"), target.triple);
let mut cmd = BootstrapCommand::new(&light);
let mut cmd = command(&light);
cmd.arg("-nologo")
.arg("-ext")
.arg("WixUIExtension")
Expand Down Expand Up @@ -2069,7 +2069,7 @@ fn maybe_install_llvm(
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult { llvm_config, .. }) =
llvm::prebuilt_llvm_config(builder, target)
{
let mut cmd = BootstrapCommand::new(llvm_config);
let mut cmd = command(llvm_config);
cmd.arg("--libfiles");
builder.verbose(|| println!("running {cmd:?}"));
let files = if builder.config.dry_run() {
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Runs rustfmt on the repository.

use crate::core::builder::Builder;
use crate::utils::exec::BootstrapCommand;
use crate::utils::exec::command;
use crate::utils::helpers::{self, program_out_of_date, t};
use build_helper::ci::CiEnv;
use build_helper::git::get_git_modified_files;
Expand Down Expand Up @@ -54,7 +54,7 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
fn get_rustfmt_version(build: &Builder<'_>) -> Option<(String, PathBuf)> {
let stamp_file = build.out.join("rustfmt.stamp");

let mut cmd = BootstrapCommand::new(match build.initial_rustfmt() {
let mut cmd = command(match build.initial_rustfmt() {
Some(p) => p,
None => return None,
});
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::{Component, Path, PathBuf};
use crate::core::build_steps::dist;
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::core::config::{Config, TargetSelection};
use crate::utils::exec::BootstrapCommand;
use crate::utils::exec::command;
use crate::utils::helpers::t;
use crate::utils::tarball::GeneratedTarball;
use crate::{Compiler, Kind};
Expand Down Expand Up @@ -102,7 +102,7 @@ fn install_sh(
let empty_dir = builder.out.join("tmp/empty_dir");
t!(fs::create_dir_all(&empty_dir));

let mut cmd = BootstrapCommand::new(SHELL);
let mut cmd = command(SHELL);
cmd.current_dir(&empty_dir)
.arg(sanitize_sh(&tarball.decompressed_output().join("install.sh")))
.arg(format!("--prefix={}", prepare_dir(&destdir_env, prefix)))
Expand Down
19 changes: 6 additions & 13 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::utils::helpers::{
};
use crate::{generate_smart_stamp_hash, CLang, GitRepo, Kind};

use crate::utils::exec::BootstrapCommand;
use crate::utils::exec::command;
use build_helper::ci::CiEnv;
use build_helper::git::get_git_merge_base;

Expand Down Expand Up @@ -478,11 +478,8 @@ impl Step for Llvm {
let LlvmResult { llvm_config, .. } =
builder.ensure(Llvm { target: builder.config.build });
if !builder.config.dry_run() {
let llvm_bindir = BootstrapCommand::new(&llvm_config)
.capture_stdout()
.arg("--bindir")
.run(builder)
.stdout();
let llvm_bindir =
command(&llvm_config).capture_stdout().arg("--bindir").run(builder).stdout();
let host_bin = Path::new(llvm_bindir.trim());
cfg.define(
"LLVM_TABLEGEN",
Expand Down Expand Up @@ -532,11 +529,8 @@ impl Step for Llvm {

// Helper to find the name of LLVM's shared library on darwin and linux.
let find_llvm_lib_name = |extension| {
let version = BootstrapCommand::new(&res.llvm_config)
.capture_stdout()
.arg("--version")
.run(builder)
.stdout();
let version =
command(&res.llvm_config).capture_stdout().arg("--version").run(builder).stdout();
let major = version.split('.').next().unwrap();

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

let version =
BootstrapCommand::new(llvm_config).capture_stdout().arg("--version").run(builder).stdout();
let version = command(llvm_config).capture_stdout().arg("--version").run(builder).stdout();
let mut parts = version.split('.').take(2).filter_map(|s| s.parse::<u32>().ok());
if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) {
if major >= 17 {
Expand Down
5 changes: 2 additions & 3 deletions src/bootstrap/src/core/build_steps/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::core::build_steps::tool::{self, SourceType, Tool};
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::core::config::flags::get_completion;
use crate::core::config::TargetSelection;
use crate::utils::exec::BootstrapCommand;
use crate::utils::exec::command;
use crate::Mode;

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

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

cmd.arg(sign);
cmd.arg(distdir(builder));
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/synthetic_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use crate::core::builder::{Builder, ShouldRun, Step};
use crate::core::config::TargetSelection;
use crate::utils::exec::BootstrapCommand;
use crate::utils::exec::command;
use crate::Compiler;

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

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

Expand Down
Loading