Skip to content

Commit dc4d32d

Browse files
committed
remove try_run and change vanilla command execution to bootstrapCommand monitored lifecycle run methods
1 parent 921c358 commit dc4d32d

File tree

1 file changed

+72
-58
lines changed

1 file changed

+72
-58
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 72 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ use std::fmt::{self, Display};
99
use std::hash::Hash;
1010
use std::io::IsTerminal;
1111
use std::path::{Path, PathBuf, absolute};
12-
use std::process::Command;
1312
use std::str::FromStr;
1413
use std::sync::{Arc, Mutex, OnceLock};
1514
use std::{cmp, env, fs};
1615

1716
use build_helper::ci::CiEnv;
1817
use build_helper::exit;
19-
use build_helper::git::{GitConfig, PathFreshness, check_path_modifications, output_result};
18+
use build_helper::git::{GitConfig, PathFreshness, check_path_modifications};
2019
use serde::{Deserialize, Deserializer};
2120
use serde_derive::Deserialize;
2221
#[cfg(feature = "tracing")]
2322
use tracing::{instrument, span};
2423

24+
use crate::command;
2525
use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX;
2626
use crate::core::build_steps::llvm;
2727
use crate::core::build_steps::llvm::LLVM_INVALIDATION_PATHS;
@@ -1530,14 +1530,10 @@ impl Config {
15301530
// has already been (kinda-cross-)compiled to Windows land, we require a normal Windows path.
15311531
cmd.arg("rev-parse").arg("--show-cdup");
15321532
// Discard stderr because we expect this to fail when building from a tarball.
1533-
let output = cmd
1534-
.as_command_mut()
1535-
.stderr(std::process::Stdio::null())
1536-
.output()
1537-
.ok()
1538-
.and_then(|output| if output.status.success() { Some(output) } else { None });
1539-
if let Some(output) = output {
1540-
let git_root_relative = String::from_utf8(output.stdout).unwrap();
1533+
let output = cmd.run_capture_stdout(&config.context());
1534+
1535+
if output.is_success() {
1536+
let git_root_relative = output.stdout();
15411537
// We need to canonicalize this path to make sure it uses backslashes instead of forward slashes,
15421538
// and to resolve any relative components.
15431539
let git_root = env::current_dir()
@@ -1632,7 +1628,9 @@ impl Config {
16321628
build.cargo = build.cargo.take().or(std::env::var_os("CARGO").map(|p| p.into()));
16331629
}
16341630

1635-
if GitInfo::new(false, &config.src).is_from_tarball() && toml.profile.is_none() {
1631+
if GitInfo::new(false, &config.src, config.context()).is_from_tarball()
1632+
&& toml.profile.is_none()
1633+
{
16361634
toml.profile = Some("dist".into());
16371635
}
16381636

@@ -1839,7 +1837,11 @@ impl Config {
18391837
};
18401838

18411839
config.initial_sysroot = t!(PathBuf::from_str(
1842-
output(Command::new(&config.initial_rustc).args(["--print", "sysroot"])).trim()
1840+
command(&config.initial_rustc)
1841+
.args(["--print", "sysroot"])
1842+
.run_capture_stdout(&config.context())
1843+
.stdout()
1844+
.trim()
18431845
));
18441846

18451847
config.initial_cargo_clippy = cargo_clippy;
@@ -1966,19 +1968,41 @@ impl Config {
19661968
let default = config.channel == "dev";
19671969
config.omit_git_hash = toml.rust.as_ref().and_then(|r| r.omit_git_hash).unwrap_or(default);
19681970

1969-
config.rust_info = GitInfo::new(config.omit_git_hash, &config.src);
1970-
config.cargo_info = GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/cargo"));
1971-
config.rust_analyzer_info =
1972-
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/rust-analyzer"));
1973-
config.clippy_info =
1974-
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/clippy"));
1975-
config.miri_info = GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/miri"));
1976-
config.rustfmt_info =
1977-
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/rustfmt"));
1978-
config.enzyme_info =
1979-
GitInfo::new(config.omit_git_hash, &config.src.join("src/tools/enzyme"));
1980-
config.in_tree_llvm_info = GitInfo::new(false, &config.src.join("src/llvm-project"));
1981-
config.in_tree_gcc_info = GitInfo::new(false, &config.src.join("src/gcc"));
1971+
config.rust_info = GitInfo::new(config.omit_git_hash, &config.src, &config.context());
1972+
config.cargo_info = GitInfo::new(
1973+
config.omit_git_hash,
1974+
&config.src.join("src/tools/cargo"),
1975+
config.context(),
1976+
);
1977+
config.rust_analyzer_info = GitInfo::new(
1978+
config.omit_git_hash,
1979+
&config.src.join("src/tools/rust-analyzer"),
1980+
config.context(),
1981+
);
1982+
config.clippy_info = GitInfo::new(
1983+
config.omit_git_hash,
1984+
&config.src.join("src/tools/clippy"),
1985+
config.context(),
1986+
);
1987+
config.miri_info = GitInfo::new(
1988+
config.omit_git_hash,
1989+
&config.src.join("src/tools/miri"),
1990+
config.context(),
1991+
);
1992+
config.rustfmt_info = GitInfo::new(
1993+
config.omit_git_hash,
1994+
&config.src.join("src/tools/rustfmt"),
1995+
config.context(),
1996+
);
1997+
config.enzyme_info = GitInfo::new(
1998+
config.omit_git_hash,
1999+
&config.src.join("src/tools/enzyme"),
2000+
config.context(),
2001+
);
2002+
config.in_tree_llvm_info =
2003+
GitInfo::new(false, &config.src.join("src/llvm-project"), config.context());
2004+
config.in_tree_gcc_info =
2005+
GitInfo::new(false, &config.src.join("src/gcc"), config.context());
19822006

19832007
config.vendor = vendor.unwrap_or(
19842008
config.rust_info.is_from_tarball()
@@ -2610,18 +2634,6 @@ impl Config {
26102634
self.explicit_stage_from_cli || self.explicit_stage_from_config
26112635
}
26122636

2613-
/// Runs a command, printing out nice contextual information if it fails.
2614-
/// Exits if the command failed to execute at all, otherwise returns its
2615-
/// `status.success()`.
2616-
#[deprecated = "use `Builder::try_run` instead where possible"]
2617-
pub(crate) fn try_run(&self, cmd: &mut Command) -> Result<(), ()> {
2618-
if self.dry_run() {
2619-
return Ok(());
2620-
}
2621-
self.verbose(|| println!("running: {cmd:?}"));
2622-
build_helper::util::try_run(cmd, self.is_verbose())
2623-
}
2624-
26252637
pub(crate) fn test_args(&self) -> Vec<&str> {
26262638
let mut test_args = match self.cmd {
26272639
Subcommand::Test { ref test_args, .. }
@@ -2655,7 +2667,7 @@ impl Config {
26552667

26562668
let mut git = helpers::git(Some(&self.src));
26572669
git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap()));
2658-
output(git.as_command_mut())
2670+
git.run_capture_stdout(self.context()).stdout()
26592671
}
26602672

26612673
/// Bootstrap embeds a version number into the name of shared libraries it uploads in CI.
@@ -2980,7 +2992,7 @@ impl Config {
29802992

29812993
// NOTE: The check for the empty directory is here because when running x.py the first time,
29822994
// the submodule won't be checked out. Check it out now so we can build it.
2983-
if !GitInfo::new(false, &absolute_path).is_managed_git_subrepository()
2995+
if !GitInfo::new(false, &absolute_path, &self.context()).is_managed_git_subrepository()
29842996
&& !helpers::dir_is_empty(&absolute_path)
29852997
{
29862998
return;
@@ -2999,16 +3011,20 @@ impl Config {
29993011
};
30003012

30013013
// Determine commit checked out in submodule.
3002-
let checked_out_hash = output(submodule_git().args(["rev-parse", "HEAD"]).as_command_mut());
3014+
// let checked_out_hash = output(submodule_git().args(["rev-parse", "HEAD"]).as_command_mut());
3015+
let checked_out_hash = submodule_git()
3016+
.args(["rev-parse", "HEAD"])
3017+
.run_capture_stdout(&self.context())
3018+
.stdout();
30033019
let checked_out_hash = checked_out_hash.trim_end();
30043020
// Determine commit that the submodule *should* have.
3005-
let recorded = output(
3006-
helpers::git(Some(&self.src))
3007-
.run_always()
3008-
.args(["ls-tree", "HEAD"])
3009-
.arg(relative_path)
3010-
.as_command_mut(),
3011-
);
3021+
3022+
let recorded = helpers::git(Some(&self.src))
3023+
.run_always()
3024+
.args(["ls-tree", "HEAD"])
3025+
.arg(relative_path)
3026+
.run_capture_stdout(&self.context())
3027+
.stdout();
30123028

30133029
let actual_hash = recorded
30143030
.split_whitespace()
@@ -3032,20 +3048,17 @@ impl Config {
30323048
let update = |progress: bool| {
30333049
// Git is buggy and will try to fetch submodules from the tracking branch for *this* repository,
30343050
// even though that has no relation to the upstream for the submodule.
3035-
let current_branch = output_result(
3036-
helpers::git(Some(&self.src))
3037-
.allow_failure()
3038-
.run_always()
3039-
.args(["symbolic-ref", "--short", "HEAD"])
3040-
.as_command_mut(),
3041-
)
3042-
.map(|b| b.trim().to_owned());
3043-
3051+
let current_branch = helpers::git(Some(&self.src))
3052+
.allow_failure()
3053+
.run_always()
3054+
.args(["symbolic-ref", "--short", "HEAD"])
3055+
.run_capture_stdout(&self.context());
30443056
let mut git = helpers::git(Some(&self.src)).allow_failure();
30453057
git.run_always();
3046-
if let Ok(branch) = current_branch {
3058+
if current_branch.is_success() {
30473059
// If there is a tag named after the current branch, git will try to disambiguate by prepending `heads/` to the branch name.
30483060
// This syntax isn't accepted by `branch.{branch}`. Strip it.
3061+
let branch = current_branch.stdout();
30493062
let branch = branch.strip_prefix("heads/").unwrap_or(&branch);
30503063
git.arg("-c").arg(format!("branch.{branch}.remote=origin"));
30513064
}
@@ -3091,7 +3104,8 @@ impl Config {
30913104
return;
30923105
}
30933106

3094-
let stage0_output = output(Command::new(program_path).arg("--version"));
3107+
let stage0_output =
3108+
command(program_path).arg("--version").run_capture_stdout(self.context()).stdout();
30953109
let mut stage0_output = stage0_output.lines().next().unwrap().split(' ');
30963110

30973111
let stage0_name = stage0_output.next().unwrap();

0 commit comments

Comments
 (0)