Skip to content

Commit

Permalink
Remove various usages of the output function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Jun 29, 2024
1 parent 2a9bcbb commit 96ed1d1
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 133 deletions.
13 changes: 7 additions & 6 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::core::builder::{Builder, Kind, PathSet, RunConfig, ShouldRun, Step, T
use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection};
use crate::utils::exec::BootstrapCommand;
use crate::utils::helpers::{
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, output, symlink_dir, t, up_to_date,
exe, get_clang_cl_resource_dir, is_debug_info, is_dylib, symlink_dir, t, up_to_date,
};
use crate::LLVM_TOOLS;
use crate::{CLang, Compiler, DependencyType, GitRepo, Mode};
Expand Down Expand Up @@ -1498,10 +1498,10 @@ pub fn compiler_file(
if builder.config.dry_run() {
return PathBuf::new();
}
let mut cmd = Command::new(compiler);
let mut cmd = BootstrapCommand::new(compiler);
cmd.args(builder.cflags(target, GitRepo::Rustc, c));
cmd.arg(format!("-print-file-name={file}"));
let out = output(&mut cmd);
let out = builder.run(cmd.capture_stdout()).stdout();
PathBuf::from(out.trim())
}

Expand Down Expand Up @@ -1833,7 +1833,9 @@ 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 = output(Command::new(llvm_config).arg("--bindir"));
let llvm_bin_dir = builder
.run(BootstrapCommand::new(llvm_config).capture_stdout().arg("--bindir"))
.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 @@ -2158,8 +2160,7 @@ pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path)
}

let previous_mtime = FileTime::from_last_modification_time(&path.metadata().unwrap());
// NOTE: `output` will propagate any errors here.
output(Command::new("strip").arg("--strip-debug").arg(path));
builder.run(BootstrapCommand::new("strip").capture().arg("--strip-debug").arg(path));

// 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
19 changes: 11 additions & 8 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::ffi::OsStr;
use std::fs;
use std::io::Write;
use std::path::{Path, PathBuf};
use std::process::Command;

use object::read::archive::ArchiveFile;
use object::BinaryFormat;
Expand All @@ -28,7 +27,7 @@ use crate::core::config::TargetSelection;
use crate::utils::channel::{self, Info};
use crate::utils::exec::BootstrapCommand;
use crate::utils::helpers::{
exe, is_dylib, move_file, output, t, target_supports_cranelift_backend, timeit,
exe, is_dylib, move_file, t, target_supports_cranelift_backend, timeit,
};
use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball};
use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS};
Expand Down Expand Up @@ -181,9 +180,9 @@ fn make_win_dist(
}

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

let mut bin_path: Vec<_> = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect();
let mut lib_path = Vec::new();
Expand Down Expand Up @@ -1024,7 +1023,7 @@ impl Step for PlainSourceTarball {
}

// Vendor all Cargo dependencies
let mut cmd = Command::new(&builder.initial_cargo);
let mut cmd = BootstrapCommand::new(&builder.initial_cargo);
cmd.arg("vendor")
.arg("--versioned-dirs")
.arg("--sync")
Expand Down Expand Up @@ -1062,7 +1061,7 @@ impl Step for PlainSourceTarball {
}

let config = if !builder.config.dry_run() {
t!(String::from_utf8(t!(cmd.output()).stdout))
builder.run(cmd.capture()).stdout()
} else {
String::new()
};
Expand Down Expand Up @@ -2079,10 +2078,14 @@ fn maybe_install_llvm(
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult { llvm_config, .. }) =
llvm::prebuilt_llvm_config(builder, target)
{
let mut cmd = Command::new(llvm_config);
let mut cmd = BootstrapCommand::new(llvm_config);
cmd.arg("--libfiles");
builder.verbose(|| println!("running {cmd:?}"));
let files = if builder.config.dry_run() { "".into() } else { output(&mut cmd) };
let files = if builder.config.dry_run() {
"".into()
} else {
builder.run(cmd.capture_stdout()).stdout()
};
let build_llvm_out = &builder.llvm_out(builder.config.build);
let target_llvm_out = &builder.llvm_out(target);
for file in files.trim_end().split(' ') {
Expand Down
33 changes: 17 additions & 16 deletions src/bootstrap/src/core/build_steps/format.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
//! Runs rustfmt on the repository.
use crate::core::builder::Builder;
use crate::utils::helpers::{self, output, program_out_of_date, t};
use crate::utils::exec::BootstrapCommand;
use crate::utils::helpers::{self, program_out_of_date, t};
use build_helper::ci::CiEnv;
use build_helper::git::get_git_modified_files;
use ignore::WalkBuilder;
Expand Down Expand Up @@ -53,19 +54,17 @@ 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 = Command::new(match build.initial_rustfmt() {
let mut cmd = BootstrapCommand::new(match build.initial_rustfmt() {
Some(p) => p,
None => return None,
});
cmd.arg("--version");
let output = match cmd.output() {
Ok(status) => status,
Err(_) => return None,
};
if !output.status.success() {

let output = build.run(cmd.capture().allow_failure());
if output.is_failure() {
return None;
}
Some((String::from_utf8(output.stdout).unwrap(), stamp_file))
Some((output.stdout(), stamp_file))
}

/// Return whether the format cache can be reused.
Expand Down Expand Up @@ -166,14 +165,16 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
if git_available {
let in_working_tree = build.run(helpers::git(Some(&build.src)).capture()).is_success();
if in_working_tree {
let untracked_paths_output = output(
&mut helpers::git(Some(&build.src))
.arg("status")
.arg("--porcelain")
.arg("-z")
.arg("--untracked-files=normal")
.command,
);
let untracked_paths_output = build
.run(
helpers::git(Some(&build.src))
.capture_stdout()
.arg("status")
.arg("--porcelain")
.arg("-z")
.arg("--untracked-files=normal"),
)
.stdout();
let untracked_paths: Vec<_> = untracked_paths_output
.split_terminator('\0')
.filter_map(
Expand Down
14 changes: 8 additions & 6 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::ffi::{OsStr, OsString};
use std::fs::{self, File};
use std::io;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::sync::OnceLock;

use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
Expand All @@ -25,6 +24,7 @@ use crate::utils::helpers::{
};
use crate::{generate_smart_stamp_hash, CLang, GitRepo, Kind};

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

Expand Down Expand Up @@ -478,7 +478,9 @@ impl Step for Llvm {
let LlvmResult { llvm_config, .. } =
builder.ensure(Llvm { target: builder.config.build });
if !builder.config.dry_run() {
let llvm_bindir = output(Command::new(&llvm_config).arg("--bindir"));
let llvm_bindir = builder
.run(BootstrapCommand::new(&llvm_config).capture_stdout().arg("--bindir"))
.stdout();
let host_bin = Path::new(llvm_bindir.trim());
cfg.define(
"LLVM_TABLEGEN",
Expand Down Expand Up @@ -528,8 +530,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 mut cmd = Command::new(&res.llvm_config);
let version = output(cmd.arg("--version"));
let cmd = BootstrapCommand::new(&res.llvm_config);
let version = builder.run(cmd.capture_stdout().arg("--version")).stdout();
let major = version.split('.').next().unwrap();

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

let mut cmd = Command::new(llvm_config);
let version = output(cmd.arg("--version"));
let cmd = BootstrapCommand::new(llvm_config);
let version = builder.run(cmd.capture_stdout().arg("--version")).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/perf.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::process::Command;

use crate::core::build_steps::compile::{Std, Sysroot};
use crate::core::build_steps::tool::RustcPerf;
use crate::core::builder::Builder;
use crate::core::config::DebuginfoLevel;
use crate::utils::exec::BootstrapCommand;

/// Performs profiling using `rustc-perf` on a built version of the compiler.
pub fn perf(builder: &Builder<'_>) {
Expand All @@ -24,7 +23,7 @@ Consider setting `rust.debuginfo-level = 1` in `config.toml`."#);

let results_dir = builder.build.tempdir().join("rustc-perf");

let mut cmd = Command::new(collector);
let mut cmd = BootstrapCommand::new(collector);
let cmd = cmd
.arg("profile_local")
.arg("eprintln")
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
//! If it can be reached from `./x.py run` it can go here.
use std::path::PathBuf;
use std::process::Command;

use crate::core::build_steps::dist::distdir;
use crate::core::build_steps::test;
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::helpers::output;
use crate::utils::exec::BootstrapCommand;
use crate::Mode;

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

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

cmd.arg(sign);
cmd.arg(distdir(builder));
Expand Down
25 changes: 8 additions & 17 deletions src/bootstrap/src/core/build_steps/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,15 @@ use crate::core::builder::Builder;
pub fn suggest(builder: &Builder<'_>, run: bool) {
let git_config = builder.config.git_config();
let suggestions = builder
.tool_cmd(Tool::SuggestTests)
.env("SUGGEST_TESTS_GIT_REPOSITORY", git_config.git_repository)
.env("SUGGEST_TESTS_NIGHTLY_BRANCH", git_config.nightly_branch)
.command
.output()
.expect("failed to run `suggest-tests` tool");
.run(
builder
.tool_cmd(Tool::SuggestTests)
.capture_stdout()
.env("SUGGEST_TESTS_GIT_REPOSITORY", git_config.git_repository)
.env("SUGGEST_TESTS_NIGHTLY_BRANCH", git_config.nightly_branch),
)
.stdout();

if !suggestions.status.success() {
println!("failed to run `suggest-tests` tool ({})", suggestions.status);
println!(
"`suggest_tests` stdout:\n{}`suggest_tests` stderr:\n{}",
String::from_utf8(suggestions.stdout).unwrap(),
String::from_utf8(suggestions.stderr).unwrap()
);
panic!("failed to run `suggest-tests`");
}

let suggestions = String::from_utf8(suggestions.stdout).unwrap();
let suggestions = suggestions
.lines()
.map(|line| {
Expand Down
14 changes: 4 additions & 10 deletions src/bootstrap/src/core/build_steps/synthetic_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use crate::core::builder::{Builder, ShouldRun, Step};
use crate::core::config::TargetSelection;
use crate::utils::exec::BootstrapCommand;
use crate::Compiler;
use std::process::{Command, Stdio};

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

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

// If `rust.channel` is set to either beta or stable, rustc will complain that
// we cannot use nightly features. So `RUSTC_BOOTSTRAP` is needed here.
cmd.env("RUSTC_BOOTSTRAP", "1");

cmd.stdout(Stdio::piped());

let output = cmd.spawn().unwrap().wait_with_output().unwrap();
if !output.status.success() {
panic!("failed to gather the target spec for {base}");
}

let mut spec: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
let output = builder.run(cmd.capture()).stdout();
let mut spec: serde_json::Value = serde_json::from_slice(output.as_bytes()).unwrap();
let spec_map = spec.as_object_mut().unwrap();

// The `is-builtin` attribute of a spec needs to be removed, otherwise rustc will complain.
Expand Down
Loading

0 comments on commit 96ed1d1

Please sign in to comment.