diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 4cabc77f2be..11a7a404535 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -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, }; @@ -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 @@ -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(); @@ -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. @@ -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 diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index 0a7f3ec6b79..7bc5405e92f 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -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, }; @@ -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(); @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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") @@ -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() { diff --git a/src/bootstrap/src/core/build_steps/format.rs b/src/bootstrap/src/core/build_steps/format.rs index 04b3ec770d2..d3ac2bae1e8 100644 --- a/src/bootstrap/src/core/build_steps/format.rs +++ b/src/bootstrap/src/core/build_steps/format.rs @@ -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; @@ -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, }); diff --git a/src/bootstrap/src/core/build_steps/install.rs b/src/bootstrap/src/core/build_steps/install.rs index 2cb745deff6..d3e9d6d7875 100644 --- a/src/bootstrap/src/core/build_steps/install.rs +++ b/src/bootstrap/src/core/build_steps/install.rs @@ -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}; @@ -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))) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 32414e4e397..bff731e13b0 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -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; @@ -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", @@ -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 { @@ -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::().ok()); if let (Some(major), Some(_minor)) = (parts.next(), parts.next()) { if major >= 17 { diff --git a/src/bootstrap/src/core/build_steps/run.rs b/src/bootstrap/src/core/build_steps/run.rs index 7088cd0d4c2..3a2d3f67522 100644 --- a/src/bootstrap/src/core/build_steps/run.rs +++ b/src/bootstrap/src/core/build_steps/run.rs @@ -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)] @@ -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)); diff --git a/src/bootstrap/src/core/build_steps/synthetic_targets.rs b/src/bootstrap/src/core/build_steps/synthetic_targets.rs index 0f3963ac663..021680302cd 100644 --- a/src/bootstrap/src/core/build_steps/synthetic_targets.rs +++ b/src/bootstrap/src/core/build_steps/synthetic_targets.rs @@ -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)] @@ -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"]); diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index e48ef58eb0c..7f4c4bd53df 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -26,7 +26,7 @@ use crate::core::builder::{Builder, Compiler, Kind, RunConfig, ShouldRun, Step}; use crate::core::config::flags::get_completion; use crate::core::config::flags::Subcommand; use crate::core::config::TargetSelection; -use crate::utils::exec::BootstrapCommand; +use crate::utils::exec::{command, BootstrapCommand}; use crate::utils::helpers::{ self, add_link_lib_path, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var, linker_args, linker_flags, t, target_supports_cranelift_backend, up_to_date, LldThreads, @@ -834,7 +834,7 @@ impl Step for RustdocJSStd { fn run(self, builder: &Builder<'_>) { let nodejs = builder.config.nodejs.as_ref().expect("need nodejs to run rustdoc-js-std tests"); - let mut command = BootstrapCommand::new(nodejs); + let mut command = command(nodejs); command .arg(builder.src.join("src/tools/rustdoc-js/tester.js")) .arg("--crate-name") @@ -910,7 +910,7 @@ fn get_browser_ui_test_version_inner( npm: &Path, global: bool, ) -> Option { - let mut command = BootstrapCommand::new(npm).capture(); + let mut command = command(npm).capture(); command.arg("list").arg("--parseable").arg("--long").arg("--depth=0"); if global { command.arg("--global"); @@ -1806,7 +1806,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the } let lldb_exe = builder.config.lldb.clone().unwrap_or_else(|| PathBuf::from("lldb")); - let lldb_version = BootstrapCommand::new(&lldb_exe) + let lldb_version = command(&lldb_exe) .capture() .allow_failure() .arg("--version") @@ -1815,7 +1815,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the .and_then(|v| if v.trim().is_empty() { None } else { Some(v) }); if let Some(ref vers) = lldb_version { cmd.arg("--lldb-version").arg(vers); - let lldb_python_dir = BootstrapCommand::new(&lldb_exe) + let lldb_python_dir = command(&lldb_exe) .allow_failure() .capture_stdout() .arg("-P") @@ -1877,11 +1877,10 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the let llvm::LlvmResult { llvm_config, .. } = builder.ensure(llvm::Llvm { target: builder.config.build }); if !builder.config.dry_run() { - let llvm_version = builder - .run(BootstrapCommand::new(&llvm_config).capture_stdout().arg("--version")) - .stdout(); + let llvm_version = + builder.run(command(&llvm_config).capture_stdout().arg("--version")).stdout(); let llvm_components = builder - .run(BootstrapCommand::new(&llvm_config).capture_stdout().arg("--components")) + .run(command(&llvm_config).capture_stdout().arg("--components")) .stdout(); // Remove trailing newline from llvm-config output. cmd.arg("--llvm-version") @@ -1901,9 +1900,8 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the // separate compilations. We can add LLVM's library path to the // platform-specific environment variable as a workaround. if !builder.config.dry_run() && suite.ends_with("fulldeps") { - let llvm_libdir = builder - .run(BootstrapCommand::new(&llvm_config).capture_stdout().arg("--libdir")) - .stdout(); + let llvm_libdir = + builder.run(command(&llvm_config).capture_stdout().arg("--libdir")).stdout(); add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cmd); } @@ -2873,7 +2871,7 @@ impl Step for RemoteCopyLibs { // Spawn the emulator and wait for it to come online let tool = builder.tool_exe(Tool::RemoteTestClient); - let mut cmd = BootstrapCommand::new(&tool); + let mut cmd = command(&tool); cmd.arg("spawn-emulator").arg(target.triple).arg(&server).arg(builder.tempdir()); if let Some(rootfs) = builder.qemu_rootfs(target) { cmd.arg(rootfs); @@ -2885,7 +2883,7 @@ impl Step for RemoteCopyLibs { let f = t!(f); let name = f.file_name().into_string().unwrap(); if helpers::is_dylib(&name) { - builder.run(BootstrapCommand::new(&tool).arg("push").arg(f.path())); + builder.run(command(&tool).arg("push").arg(f.path())); } } } @@ -2916,22 +2914,20 @@ impl Step for Distcheck { builder.ensure(dist::PlainSourceTarball); builder.ensure(dist::Src); - let mut cmd = BootstrapCommand::new("tar"); + let mut cmd = command("tar"); cmd.arg("-xf") .arg(builder.ensure(dist::PlainSourceTarball).tarball()) .arg("--strip-components=1") .current_dir(&dir); cmd.run(builder); builder.run( - BootstrapCommand::new("./configure") + command("./configure") .args(&builder.config.configure_args) .arg("--enable-vendor") .current_dir(&dir), ); builder.run( - BootstrapCommand::new(helpers::make(&builder.config.build.triple)) - .arg("check") - .current_dir(&dir), + command(helpers::make(&builder.config.build.triple)).arg("check").current_dir(&dir), ); // Now make sure that rust-src has all of libstd's dependencies @@ -2940,7 +2936,7 @@ impl Step for Distcheck { let _ = fs::remove_dir_all(&dir); t!(fs::create_dir_all(&dir)); - let mut cmd = BootstrapCommand::new("tar"); + let mut cmd = command("tar"); cmd.arg("-xf") .arg(builder.ensure(dist::Src).tarball()) .arg("--strip-components=1") @@ -2949,7 +2945,7 @@ impl Step for Distcheck { let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml"); builder.run( - BootstrapCommand::new(&builder.initial_cargo) + command(&builder.initial_cargo) // Will read the libstd Cargo.toml // which uses the unstable `public-dependency` feature. .env("RUSTC_BOOTSTRAP", "1") @@ -2978,7 +2974,7 @@ impl Step for Bootstrap { // Some tests require cargo submodule to be present. builder.build.update_submodule(Path::new("src/tools/cargo")); - let mut check_bootstrap = BootstrapCommand::new(builder.python()); + let mut check_bootstrap = command(builder.python()); check_bootstrap .args(["-m", "unittest", "bootstrap_test.py"]) .env("BUILD_DIR", &builder.out) @@ -2988,7 +2984,7 @@ impl Step for Bootstrap { // Use `python -m unittest` manually if you want to pass arguments. check_bootstrap.delay_failure().run(builder); - let mut cmd = BootstrapCommand::new(&builder.initial_cargo); + let mut cmd = command(&builder.initial_cargo); cmd.arg("test") .args(["--features", "bootstrap-self-test"]) .current_dir(builder.src.join("src/bootstrap")) @@ -3139,7 +3135,7 @@ impl Step for RustInstaller { return; } - let mut cmd = BootstrapCommand::new(builder.src.join("src/tools/rust-installer/test.sh")); + let mut cmd = command(builder.src.join("src/tools/rust-installer/test.sh")); let tmpdir = testdir(builder, compiler.host).join("rust-installer"); let _ = std::fs::remove_dir_all(&tmpdir); let _ = std::fs::create_dir_all(&tmpdir); diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 7b4b5ff5a8c..ad92a01bce7 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -8,7 +8,7 @@ use crate::core::builder; use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step}; use crate::core::config::TargetSelection; use crate::utils::channel::GitInfo; -use crate::utils::exec::BootstrapCommand; +use crate::utils::exec::{command, BootstrapCommand}; use crate::utils::helpers::{add_dylib_path, exe, t}; use crate::Compiler; use crate::Mode; @@ -438,7 +438,7 @@ impl ErrorIndex { // for rustc_private and libLLVM.so, and `sysroot_lib` for libstd, etc. let host = builder.config.build; let compiler = builder.compiler_for(builder.top_stage, host, host); - let mut cmd = BootstrapCommand::new(builder.ensure(ErrorIndex { compiler })); + let mut cmd = command(builder.ensure(ErrorIndex { compiler })); let mut dylib_paths = builder.rustc_lib_paths(compiler); dylib_paths.push(PathBuf::from(&builder.sysroot_libdir(compiler, compiler.host))); add_dylib_path(dylib_paths, &mut cmd); @@ -912,7 +912,7 @@ impl Step for LibcxxVersionTool { } let compiler = builder.cxx(self.target).unwrap(); - let mut cmd = BootstrapCommand::new(compiler); + let mut cmd = command(compiler); cmd.arg("-o") .arg(&executable) @@ -925,8 +925,7 @@ impl Step for LibcxxVersionTool { } } - let version_output = - BootstrapCommand::new(executable).capture_stdout().run(builder).stdout(); + let version_output = command(executable).capture_stdout().run(builder).stdout(); let version_str = version_output.split_once("version:").unwrap().1; let version = version_str.trim().parse::().unwrap(); @@ -1050,7 +1049,7 @@ impl<'a> Builder<'a> { /// Gets a `BootstrapCommand` which is ready to run `tool` in `stage` built for /// `host`. pub fn tool_cmd(&self, tool: Tool) -> BootstrapCommand { - let mut cmd = BootstrapCommand::new(self.tool_exe(tool)); + let mut cmd = command(self.tool_exe(tool)); let compiler = self.compiler(0, self.config.build); let host = &compiler.host; // Prepares the `cmd` provided to be able to run the `compiler` provided. diff --git a/src/bootstrap/src/core/build_steps/vendor.rs b/src/bootstrap/src/core/build_steps/vendor.rs index 82cd95489d0..62342ee4792 100644 --- a/src/bootstrap/src/core/build_steps/vendor.rs +++ b/src/bootstrap/src/core/build_steps/vendor.rs @@ -1,5 +1,5 @@ use crate::core::builder::{Builder, RunConfig, ShouldRun, Step}; -use crate::utils::exec::BootstrapCommand; +use crate::utils::exec::command; use std::path::{Path, PathBuf}; #[derive(Debug, Clone, Hash, PartialEq, Eq)] @@ -27,7 +27,7 @@ impl Step for Vendor { } fn run(self, builder: &Builder<'_>) -> Self::Output { - let mut cmd = BootstrapCommand::new(&builder.initial_cargo); + let mut cmd = command(&builder.initial_cargo); cmd.arg("vendor"); if self.versioned_dirs { diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 91dfffdaf7e..24bb96c6b88 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -23,7 +23,7 @@ use crate::utils::helpers::{check_cfg_arg, libdir, linker_flags, t, LldThreads}; use crate::EXTRA_CHECK_CFGS; use crate::{Build, CLang, Crate, DocTests, GitRepo, Mode}; -use crate::utils::exec::BootstrapCommand; +use crate::utils::exec::{command, BootstrapCommand}; pub use crate::Compiler; use clap::ValueEnum; @@ -1254,7 +1254,7 @@ impl<'a> Builder<'a> { if run_compiler.stage == 0 { // `ensure(Clippy { stage: 0 })` *builds* clippy with stage0, it doesn't use the beta clippy. let cargo_clippy = self.build.config.download_clippy(); - let mut cmd = BootstrapCommand::new(cargo_clippy); + let mut cmd = command(cargo_clippy); cmd.env("CARGO", &self.initial_cargo); return cmd; } @@ -1273,7 +1273,7 @@ impl<'a> Builder<'a> { let mut dylib_path = helpers::dylib_path(); dylib_path.insert(0, self.sysroot(run_compiler).join("lib")); - let mut cmd = BootstrapCommand::new(cargo_clippy); + let mut cmd = command(cargo_clippy); cmd.env(helpers::dylib_path_var(), env::join_paths(&dylib_path).unwrap()); cmd.env("CARGO", &self.initial_cargo); cmd @@ -1295,7 +1295,7 @@ impl<'a> Builder<'a> { extra_features: Vec::new(), }); // Invoke cargo-miri, make sure it can find miri and cargo. - let mut cmd = BootstrapCommand::new(cargo_miri); + let mut cmd = command(cargo_miri); cmd.env("MIRI", &miri); cmd.env("CARGO", &self.initial_cargo); // Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler`, @@ -1311,7 +1311,7 @@ impl<'a> Builder<'a> { } pub fn rustdoc_cmd(&self, compiler: Compiler) -> BootstrapCommand { - let mut cmd = BootstrapCommand::new(self.bootstrap_out.join("rustdoc")); + let mut cmd = command(self.bootstrap_out.join("rustdoc")); cmd.env("RUSTC_STAGE", compiler.stage.to_string()) .env("RUSTC_SYSROOT", self.sysroot(compiler)) // Note that this is *not* the sysroot_libdir because rustdoc must be linked @@ -1365,7 +1365,7 @@ impl<'a> Builder<'a> { cargo = self.cargo_miri_cmd(compiler); cargo.arg("miri").arg(subcmd); } else { - cargo = BootstrapCommand::new(&self.initial_cargo); + cargo = command(&self.initial_cargo); cargo.arg(cmd); } @@ -1918,11 +1918,8 @@ impl<'a> Builder<'a> { // platform-specific environment variable as a workaround. if mode == Mode::ToolRustc || mode == Mode::Codegen { if let Some(llvm_config) = self.llvm_config(target) { - let llvm_libdir = BootstrapCommand::new(llvm_config) - .capture_stdout() - .arg("--libdir") - .run(self) - .stdout(); + let llvm_libdir = + command(llvm_config).capture_stdout().arg("--libdir").run(self).stdout(); add_link_lib_path(vec![llvm_libdir.trim().into()], &mut cargo); } } diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs index c35398e2eb7..a7f4bb0cf14 100644 --- a/src/bootstrap/src/core/download.rs +++ b/src/bootstrap/src/core/download.rs @@ -11,7 +11,7 @@ use std::{ use build_helper::ci::CiEnv; use xz2::bufread::XzDecoder; -use crate::utils::exec::BootstrapCommand; +use crate::utils::exec::{command, BootstrapCommand}; use crate::utils::helpers::hex_encode; use crate::utils::helpers::{check_run, exe, move_file, program_out_of_date}; use crate::{t, Config}; @@ -212,7 +212,7 @@ impl Config { fn download_http_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) { println!("downloading {url}"); // Try curl. If that fails and we are on windows, fallback to PowerShell. - let mut curl = BootstrapCommand::new("curl"); + let mut curl = command("curl"); curl.args([ "-y", "30", diff --git a/src/bootstrap/src/core/metadata.rs b/src/bootstrap/src/core/metadata.rs index 83c22b06099..b18da844014 100644 --- a/src/bootstrap/src/core/metadata.rs +++ b/src/bootstrap/src/core/metadata.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use serde_derive::Deserialize; -use crate::utils::exec::BootstrapCommand; +use crate::utils::exec::command; use crate::{t, Build, Crate}; /// For more information, see the output of @@ -70,7 +70,7 @@ pub fn build(build: &mut Build) { /// particular crate (e.g., `x build sysroot` to build library/sysroot). fn workspace_members(build: &Build) -> Vec { let collect_metadata = |manifest_path| { - let mut cargo = BootstrapCommand::new(&build.initial_cargo); + let mut cargo = command(&build.initial_cargo); cargo // Will read the libstd Cargo.toml // which uses the unstable `public-dependency` feature. diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index e393d3df01f..9995da3a1e5 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -23,7 +23,7 @@ use std::collections::HashSet; use crate::builder::Kind; use crate::core::config::Target; -use crate::utils::exec::BootstrapCommand; +use crate::utils::exec::command; use crate::Build; pub struct Finder { @@ -209,9 +209,7 @@ than building it. #[cfg(not(feature = "bootstrap-self-test"))] let stage0_supported_target_list: HashSet = crate::utils::helpers::output( - &mut BootstrapCommand::new(&build.config.initial_rustc) - .args(["--print", "target-list"]) - .command, + &mut command(&build.config.initial_rustc).args(["--print", "target-list"]).command, ) .lines() .map(|s| s.to_string()) @@ -354,8 +352,7 @@ than building it. // There are three builds of cmake on windows: MSVC, MinGW, and // Cygwin. The Cygwin build does not have generators for Visual // Studio, so detect that here and error. - let out = - BootstrapCommand::new("cmake").capture_stdout().arg("--help").run(build).stdout(); + let out = command("cmake").capture_stdout().arg("--help").run(build).stdout(); if !out.contains("Visual Studio") { panic!( " diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 6604b8efa1d..f16afb29796 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -41,7 +41,7 @@ use crate::core::builder::Kind; use crate::core::config::{flags, LldMode}; use crate::core::config::{DryRun, Target}; use crate::core::config::{LlvmLibunwind, TargetSelection}; -use crate::utils::exec::{BehaviorOnFailure, BootstrapCommand, CommandOutput}; +use crate::utils::exec::{command, BehaviorOnFailure, BootstrapCommand, CommandOutput}; use crate::utils::helpers::{self, dir_is_empty, exe, libdir, mtime, output, symlink_dir}; mod core; @@ -861,16 +861,14 @@ impl Build { if let Some(s) = target_config.and_then(|c| c.llvm_filecheck.as_ref()) { s.to_path_buf() } else if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) { - let llvm_bindir = - BootstrapCommand::new(s).capture_stdout().arg("--bindir").run(self).stdout(); + let llvm_bindir = command(s).capture_stdout().arg("--bindir").run(self).stdout(); let filecheck = Path::new(llvm_bindir.trim()).join(exe("FileCheck", target)); if filecheck.exists() { filecheck } else { // On Fedora the system LLVM installs FileCheck in the // llvm subdirectory of the libdir. - let llvm_libdir = - BootstrapCommand::new(s).capture_stdout().arg("--libdir").run(self).stdout(); + let llvm_libdir = command(s).capture_stdout().arg("--libdir").run(self).stdout(); let lib_filecheck = Path::new(llvm_libdir.trim()).join("llvm").join(exe("FileCheck", target)); if lib_filecheck.exists() { diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index 5d8a5223a2d..d6fa7fc0bbe 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -26,7 +26,7 @@ use std::path::{Path, PathBuf}; use std::{env, iter}; use crate::core::config::TargetSelection; -use crate::utils::exec::BootstrapCommand; +use crate::utils::exec::{command, BootstrapCommand}; use crate::{Build, CLang, GitRepo}; // The `cc` crate doesn't provide a way to obtain a path to the detected archiver, @@ -190,7 +190,7 @@ fn default_compiler( _ => return None, } let alternative = format!("e{gnu_compiler}"); - if BootstrapCommand::new(&alternative).capture().run(build).is_success() { + if command(&alternative).capture().run(build).is_success() { Some(PathBuf::from(alternative)) } else { None diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index 8940ea24385..b6872d1c99f 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -162,6 +162,13 @@ enum CommandStatus { DidNotStart, } +/// Create a new BootstrapCommand. This is a helper function to make command creation +/// shorter than `BootstrapCommand::new`. +#[must_use] +pub fn command>(program: S) -> BootstrapCommand { + BootstrapCommand::new(program) +} + /// Represents the output of an executed process. #[allow(unused)] pub struct CommandOutput { diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index 0a81db3cd8e..8ce0f59399f 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -47,7 +47,7 @@ macro_rules! t { } }; } -use crate::utils::exec::BootstrapCommand; +use crate::utils::exec::{command, BootstrapCommand}; pub use t; pub fn exe(name: &str, target: TargetSelection) -> String { @@ -369,7 +369,7 @@ fn lld_flag_no_threads(builder: &Builder<'_>, lld_mode: LldMode, is_windows: boo let (windows_flag, other_flag) = LLD_NO_THREADS.get_or_init(|| { let newer_version = match lld_mode { LldMode::External => { - let mut cmd = BootstrapCommand::new("lld").capture_stdout(); + let mut cmd = command("lld").capture_stdout(); cmd.arg("-flavor").arg("ld").arg("--version"); let out = cmd.run(builder).stdout(); match (out.find(char::is_numeric), out.find('.')) { @@ -502,7 +502,7 @@ pub fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String { /// `BootstrapCommand::new("git")`, which is painful to ensure that the required change is applied /// on each one of them correctly. pub fn git(source_dir: Option<&Path>) -> BootstrapCommand { - let mut git = BootstrapCommand::new("git"); + let mut git = command("git"); if let Some(source_dir) = source_dir { git.current_dir(source_dir);