Skip to content

Commit a34d0a8

Browse files
committed
Make git helper return BootstrapCmd
1 parent 9192479 commit a34d0a8

File tree

11 files changed

+112
-80
lines changed

11 files changed

+112
-80
lines changed

src/bootstrap/src/core/build_steps/format.rs

+16-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use build_helper::git::get_git_modified_files;
77
use ignore::WalkBuilder;
88
use std::collections::VecDeque;
99
use std::path::{Path, PathBuf};
10-
use std::process::{Command, Stdio};
10+
use std::process::Command;
1111
use std::sync::mpsc::SyncSender;
1212
use std::sync::Mutex;
1313

@@ -160,35 +160,29 @@ pub fn format(build: &Builder<'_>, check: bool, all: bool, paths: &[PathBuf]) {
160160
override_builder.add(&format!("!{ignore}")).expect(&ignore);
161161
}
162162
}
163-
let git_available = match helpers::git(None)
164-
.arg("--version")
165-
.stdout(Stdio::null())
166-
.stderr(Stdio::null())
167-
.status()
168-
{
169-
Ok(status) => status.success(),
170-
Err(_) => false,
171-
};
163+
let git_available = build
164+
.run(helpers::git(None).print_on_failure().allow_failure().arg("--version"))
165+
.is_success();
172166

173167
let mut adjective = None;
174168
if git_available {
175-
let in_working_tree = match helpers::git(Some(&build.src))
176-
.arg("rev-parse")
177-
.arg("--is-inside-work-tree")
178-
.stdout(Stdio::null())
179-
.stderr(Stdio::null())
180-
.status()
181-
{
182-
Ok(status) => status.success(),
183-
Err(_) => false,
184-
};
169+
let in_working_tree = build
170+
.run(
171+
helpers::git(Some(&build.src))
172+
.print_on_failure()
173+
.allow_failure()
174+
.arg("rev-parse")
175+
.arg("--is-inside-work-tree"),
176+
)
177+
.is_success();
185178
if in_working_tree {
186179
let untracked_paths_output = output(
187-
helpers::git(Some(&build.src))
180+
&mut helpers::git(Some(&build.src))
188181
.arg("status")
189182
.arg("--porcelain")
190183
.arg("-z")
191-
.arg("--untracked-files=normal"),
184+
.arg("--untracked-files=normal")
185+
.command,
192186
);
193187
let untracked_paths: Vec<_> = untracked_paths_output
194188
.split_terminator('\0')

src/bootstrap/src/core/build_steps/llvm.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
172172
// the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
173173
config.src.join("src/version"),
174174
]);
175-
output(&mut rev_list).trim().to_owned()
175+
output(&mut rev_list.command).trim().to_owned()
176176
} else if let Some(info) = channel::read_commit_info_file(&config.src) {
177177
info.sha.trim().to_owned()
178178
} else {
@@ -253,7 +253,8 @@ pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool {
253253
// We assume we have access to git, so it's okay to unconditionally pass
254254
// `true` here.
255255
let llvm_sha = detect_llvm_sha(config, true);
256-
let head_sha = output(helpers::git(Some(&config.src)).arg("rev-parse").arg("HEAD"));
256+
let head_sha =
257+
output(&mut helpers::git(Some(&config.src)).arg("rev-parse").arg("HEAD").command);
257258
let head_sha = head_sha.trim();
258259
llvm_sha == head_sha
259260
}

src/bootstrap/src/core/build_steps/perf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::core::build_steps::compile::{Std, Sysroot};
22
use crate::core::build_steps::tool::{RustcPerf, Tool};
33
use crate::core::builder::Builder;
44
use crate::core::config::DebuginfoLevel;
5+
use crate::utils::exec::BootstrapCommand;
56

67
/// Performs profiling using `rustc-perf` on a built version of the compiler.
78
pub fn perf(builder: &Builder<'_>) {

src/bootstrap/src/core/build_steps/setup.rs

+1
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ impl Step for Hook {
484484
fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
485485
let git = helpers::git(Some(&config.src))
486486
.args(["rev-parse", "--git-common-dir"])
487+
.command
487488
.output()
488489
.map(|output| {
489490
assert!(output.status.success(), "failed to run `git`");

src/bootstrap/src/core/build_steps/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2349,7 +2349,7 @@ fn markdown_test(builder: &Builder<'_>, compiler: Compiler, markdown: &Path) ->
23492349

23502350
cmd = cmd.delay_failure();
23512351
if !builder.config.verbose_tests {
2352-
cmd = cmd.quiet();
2352+
cmd = cmd.print_on_failure();
23532353
}
23542354
builder.run(cmd).is_success()
23552355
}

src/bootstrap/src/core/build_steps/toolstate.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ fn print_error(tool: &str, submodule: &str) {
101101

102102
fn check_changed_files(toolstates: &HashMap<Box<str>, ToolState>) {
103103
// Changed files
104-
let output =
105-
helpers::git(None).arg("diff").arg("--name-status").arg("HEAD").arg("HEAD^").output();
104+
let output = helpers::git(None)
105+
.arg("diff")
106+
.arg("--name-status")
107+
.arg("HEAD")
108+
.arg("HEAD^")
109+
.command
110+
.output();
106111
let output = match output {
107112
Ok(o) => o,
108113
Err(e) => {
@@ -324,6 +329,7 @@ fn checkout_toolstate_repo() {
324329
.arg("--depth=1")
325330
.arg(toolstate_repo())
326331
.arg(TOOLSTATE_DIR)
332+
.command
327333
.status();
328334
let success = match status {
329335
Ok(s) => s.success(),
@@ -337,7 +343,8 @@ fn checkout_toolstate_repo() {
337343
/// Sets up config and authentication for modifying the toolstate repo.
338344
fn prepare_toolstate_config(token: &str) {
339345
fn git_config(key: &str, value: &str) {
340-
let status = helpers::git(None).arg("config").arg("--global").arg(key).arg(value).status();
346+
let status =
347+
helpers::git(None).arg("config").arg("--global").arg(key).arg(value).command.status();
341348
let success = match status {
342349
Ok(s) => s.success(),
343350
Err(_) => false,
@@ -406,6 +413,7 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) {
406413
.arg("-a")
407414
.arg("-m")
408415
.arg(&message)
416+
.command
409417
.status());
410418
if !status.success() {
411419
success = true;
@@ -416,6 +424,7 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) {
416424
.arg("push")
417425
.arg("origin")
418426
.arg("master")
427+
.command
419428
.status());
420429
// If we successfully push, exit.
421430
if status.success() {
@@ -428,12 +437,14 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) {
428437
.arg("fetch")
429438
.arg("origin")
430439
.arg("master")
440+
.command
431441
.status());
432442
assert!(status.success());
433443
let status = t!(helpers::git(Some(Path::new(TOOLSTATE_DIR)))
434444
.arg("reset")
435445
.arg("--hard")
436446
.arg("origin/master")
447+
.command
437448
.status());
438449
assert!(status.success());
439450
}
@@ -449,7 +460,7 @@ fn commit_toolstate_change(current_toolstate: &ToolstateData) {
449460
/// `publish_toolstate.py` script if the PR passes all tests and is merged to
450461
/// master.
451462
fn publish_test_results(current_toolstate: &ToolstateData) {
452-
let commit = t!(helpers::git(None).arg("rev-parse").arg("HEAD").output());
463+
let commit = t!(helpers::git(None).arg("rev-parse").arg("HEAD").command.output());
453464
let commit = t!(String::from_utf8(commit.stdout));
454465

455466
let toolstate_serialized = t!(serde_json::to_string(&current_toolstate));

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

+16-10
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ impl Config {
12591259
cmd.arg("rev-parse").arg("--show-cdup");
12601260
// Discard stderr because we expect this to fail when building from a tarball.
12611261
let output = cmd
1262+
.command
12621263
.stderr(std::process::Stdio::null())
12631264
.output()
12641265
.ok()
@@ -2141,7 +2142,7 @@ impl Config {
21412142

21422143
let mut git = helpers::git(Some(&self.src));
21432144
git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap()));
2144-
output(&mut git)
2145+
output(&mut git.command)
21452146
}
21462147

21472148
/// Bootstrap embeds a version number into the name of shared libraries it uploads in CI.
@@ -2445,19 +2446,21 @@ impl Config {
24452446
};
24462447

24472448
// Handle running from a directory other than the top level
2448-
let top_level =
2449-
output(helpers::git(Some(&self.src)).args(["rev-parse", "--show-toplevel"]));
2449+
let top_level = output(
2450+
&mut helpers::git(Some(&self.src)).args(["rev-parse", "--show-toplevel"]).command,
2451+
);
24502452
let top_level = top_level.trim_end();
24512453
let compiler = format!("{top_level}/compiler/");
24522454
let library = format!("{top_level}/library/");
24532455

24542456
// Look for a version to compare to based on the current commit.
24552457
// Only commits merged by bors will have CI artifacts.
24562458
let merge_base = output(
2457-
helpers::git(Some(&self.src))
2459+
&mut helpers::git(Some(&self.src))
24582460
.arg("rev-list")
24592461
.arg(format!("--author={}", self.stage0_metadata.config.git_merge_commit_email))
2460-
.args(["-n1", "--first-parent", "HEAD"]),
2462+
.args(["-n1", "--first-parent", "HEAD"])
2463+
.command,
24612464
);
24622465
let commit = merge_base.trim_end();
24632466
if commit.is_empty() {
@@ -2471,6 +2474,7 @@ impl Config {
24712474
// Warn if there were changes to the compiler or standard library since the ancestor commit.
24722475
let has_changes = !t!(helpers::git(Some(&self.src))
24732476
.args(["diff-index", "--quiet", commit, "--", &compiler, &library])
2477+
.command
24742478
.status())
24752479
.success();
24762480
if has_changes {
@@ -2542,17 +2546,19 @@ impl Config {
25422546
if_unchanged: bool,
25432547
) -> Option<String> {
25442548
// Handle running from a directory other than the top level
2545-
let top_level =
2546-
output(helpers::git(Some(&self.src)).args(["rev-parse", "--show-toplevel"]));
2549+
let top_level = output(
2550+
&mut helpers::git(Some(&self.src)).args(["rev-parse", "--show-toplevel"]).command,
2551+
);
25472552
let top_level = top_level.trim_end();
25482553

25492554
// Look for a version to compare to based on the current commit.
25502555
// Only commits merged by bors will have CI artifacts.
25512556
let merge_base = output(
2552-
helpers::git(Some(&self.src))
2557+
&mut helpers::git(Some(&self.src))
25532558
.arg("rev-list")
25542559
.arg(format!("--author={}", self.stage0_metadata.config.git_merge_commit_email))
2555-
.args(["-n1", "--first-parent", "HEAD"]),
2560+
.args(["-n1", "--first-parent", "HEAD"])
2561+
.command,
25562562
);
25572563
let commit = merge_base.trim_end();
25582564
if commit.is_empty() {
@@ -2571,7 +2577,7 @@ impl Config {
25712577
git.arg(format!("{top_level}/{path}"));
25722578
}
25732579

2574-
let has_changes = !t!(git.status()).success();
2580+
let has_changes = !t!(git.command.status()).success();
25752581
if has_changes {
25762582
if if_unchanged {
25772583
if self.verbose > 0 {

src/bootstrap/src/lib.rs

+30-16
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,12 @@ impl Build {
494494
let submodule_git = || helpers::git(Some(&absolute_path));
495495

496496
// Determine commit checked out in submodule.
497-
let checked_out_hash = output(submodule_git().args(["rev-parse", "HEAD"]));
497+
let checked_out_hash = output(&mut submodule_git().args(["rev-parse", "HEAD"]).command);
498498
let checked_out_hash = checked_out_hash.trim_end();
499499
// Determine commit that the submodule *should* have.
500-
let recorded =
501-
output(helpers::git(Some(&self.src)).args(["ls-tree", "HEAD"]).arg(relative_path));
500+
let recorded = output(
501+
&mut helpers::git(Some(&self.src)).args(["ls-tree", "HEAD"]).arg(relative_path).command,
502+
);
502503
let actual_hash = recorded
503504
.split_whitespace()
504505
.nth(2)
@@ -521,6 +522,7 @@ impl Build {
521522
let current_branch = {
522523
let output = helpers::git(Some(&self.src))
523524
.args(["symbolic-ref", "--short", "HEAD"])
525+
.command
524526
.stderr(Stdio::inherit())
525527
.output();
526528
let output = t!(output);
@@ -546,7 +548,7 @@ impl Build {
546548
git
547549
};
548550
// NOTE: doesn't use `try_run` because this shouldn't print an error if it fails.
549-
if !update(true).status().map_or(false, |status| status.success()) {
551+
if !update(true).command.status().map_or(false, |status| status.success()) {
550552
self.run(update(false));
551553
}
552554

@@ -577,12 +579,15 @@ impl Build {
577579
if !self.config.submodules(self.rust_info()) {
578580
return;
579581
}
580-
let output = output(
581-
helpers::git(Some(&self.src))
582-
.args(["config", "--file"])
583-
.arg(self.config.src.join(".gitmodules"))
584-
.args(["--get-regexp", "path"]),
585-
);
582+
let output = self
583+
.run(
584+
helpers::git(Some(&self.src))
585+
.quiet()
586+
.args(["config", "--file"])
587+
.arg(self.config.src.join(".gitmodules"))
588+
.args(["--get-regexp", "path"]),
589+
)
590+
.stdout();
586591
for line in output.lines() {
587592
// Look for `submodule.$name.path = $path`
588593
// Sample output: `submodule.src/rust-installer.path src/tools/rust-installer`
@@ -950,7 +955,10 @@ impl Build {
950955
command.command.status().map(|status| status.into()),
951956
matches!(mode, OutputMode::All),
952957
),
953-
OutputMode::OnlyOnFailure => (command.command.output().map(|o| o.into()), true),
958+
mode @ (OutputMode::OnlyOnFailure | OutputMode::Quiet) => (
959+
command.command.output().map(|o| o.into()),
960+
matches!(mode, OutputMode::OnlyOnFailure),
961+
),
954962
};
955963

956964
let output = match output {
@@ -1480,14 +1488,18 @@ impl Build {
14801488
// Figure out how many merge commits happened since we branched off master.
14811489
// That's our beta number!
14821490
// (Note that we use a `..` range, not the `...` symmetric difference.)
1483-
output(
1484-
helpers::git(Some(&self.src)).arg("rev-list").arg("--count").arg("--merges").arg(
1485-
format!(
1491+
self.run(
1492+
helpers::git(Some(&self.src))
1493+
.quiet()
1494+
.arg("rev-list")
1495+
.arg("--count")
1496+
.arg("--merges")
1497+
.arg(format!(
14861498
"refs/remotes/origin/{}..HEAD",
14871499
self.config.stage0_metadata.config.nightly_branch
1488-
),
1489-
),
1500+
)),
14901501
)
1502+
.stdout()
14911503
});
14921504
let n = count.trim().parse().unwrap();
14931505
self.prerelease_version.set(Some(n));
@@ -1914,6 +1926,7 @@ fn envify(s: &str) -> String {
19141926
pub fn generate_smart_stamp_hash(dir: &Path, additional_input: &str) -> String {
19151927
let diff = helpers::git(Some(dir))
19161928
.arg("diff")
1929+
.command
19171930
.output()
19181931
.map(|o| String::from_utf8(o.stdout).unwrap_or_default())
19191932
.unwrap_or_default();
@@ -1923,6 +1936,7 @@ pub fn generate_smart_stamp_hash(dir: &Path, additional_input: &str) -> String {
19231936
.arg("--porcelain")
19241937
.arg("-z")
19251938
.arg("--untracked-files=normal")
1939+
.command
19261940
.output()
19271941
.map(|o| String::from_utf8(o.stdout).unwrap_or_default())
19281942
.unwrap_or_default();

0 commit comments

Comments
 (0)