Skip to content

Commit 50725f3

Browse files
committed
move all commands to new execution context
1 parent 98be2a0 commit 50725f3

File tree

6 files changed

+20
-174
lines changed

6 files changed

+20
-174
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl Config {
446446
// has already been (kinda-cross-)compiled to Windows land, we require a normal Windows path.
447447
cmd.arg("rev-parse").arg("--show-cdup");
448448
// Discard stderr because we expect this to fail when building from a tarball.
449-
let output = cmd.allow_failure().run_capture_stdout_exec_ctx(&config);
449+
let output = cmd.allow_failure().run_capture_stdout(&config);
450450
if output.is_success() {
451451
let git_root_relative = output.stdout();
452452
// We need to canonicalize this path to make sure it uses backslashes instead of forward slashes,
@@ -753,7 +753,7 @@ impl Config {
753753
command(&config.initial_rustc)
754754
.args(["--print", "sysroot"])
755755
.run_always()
756-
.run_capture_stdout_exec_ctx(&config)
756+
.run_capture_stdout(&config)
757757
.stdout()
758758
.trim()
759759
));
@@ -1068,7 +1068,7 @@ impl Config {
10681068

10691069
let mut git = helpers::git(Some(&self.src));
10701070
git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap()));
1071-
git.allow_failure().run_capture_stdout_exec_ctx(self).stdout()
1071+
git.allow_failure().run_capture_stdout(self).stdout()
10721072
}
10731073

10741074
/// Bootstrap embeds a version number into the name of shared libraries it uploads in CI.
@@ -1342,7 +1342,7 @@ impl Config {
13421342
let checked_out_hash = submodule_git()
13431343
.allow_failure()
13441344
.args(["rev-parse", "HEAD"])
1345-
.run_capture_stdout_exec_ctx(self)
1345+
.run_capture_stdout(self)
13461346
.stdout();
13471347
let checked_out_hash = checked_out_hash.trim_end();
13481348
// Determine commit that the submodule *should* have.
@@ -1351,7 +1351,7 @@ impl Config {
13511351
.run_always()
13521352
.args(["ls-tree", "HEAD"])
13531353
.arg(relative_path)
1354-
.run_capture_stdout_exec_ctx(self)
1354+
.run_capture_stdout(self)
13551355
.stdout();
13561356

13571357
let actual_hash = recorded
@@ -1380,7 +1380,7 @@ impl Config {
13801380
.allow_failure()
13811381
.run_always()
13821382
.args(["symbolic-ref", "--short", "HEAD"])
1383-
.run_capture_exec_ctx(self);
1383+
.run_capture(self);
13841384

13851385
let mut git = helpers::git(Some(&self.src)).allow_failure();
13861386
git.run_always();
@@ -1434,7 +1434,7 @@ impl Config {
14341434
}
14351435

14361436
let stage0_output =
1437-
command(program_path).arg("--version").run_capture_stdout_exec_ctx(self).stdout();
1437+
command(program_path).arg("--version").run_capture_stdout(self).stdout();
14381438
let mut stage0_output = stage0_output.lines().next().unwrap().split(' ');
14391439

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

src/bootstrap/src/core/download.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn extract_curl_version(out: String) -> semver::Version {
2727
fn curl_version(config: &Config) -> semver::Version {
2828
let mut curl = command("curl");
2929
curl.arg("-V");
30-
let curl = curl.run_capture_stdout_exec_ctx(config);
30+
let curl = curl.run_capture_stdout(config);
3131
if curl.is_failure() {
3232
return semver::Version::new(1, 0, 0);
3333
}
@@ -80,7 +80,7 @@ impl Config {
8080
/// on NixOS
8181
fn should_fix_bins_and_dylibs(&self) -> bool {
8282
let val = *SHOULD_FIX_BINS_AND_DYLIBS.get_or_init(|| {
83-
let uname = command("uname").arg("-s").run_capture_stdout_exec_ctx(self);
83+
let uname = command("uname").arg("-s").run_capture_stdout(self);
8484
if uname.is_failure() {
8585
return false;
8686
}
@@ -165,7 +165,7 @@ impl Config {
165165
nix_build_succeeded = command("nix-build")
166166
.allow_failure()
167167
.args([Path::new("-E"), Path::new(NIX_EXPR), Path::new("-o"), &nix_deps_dir])
168-
.run_capture_stdout_exec_ctx(self)
168+
.run_capture_stdout(self)
169169
.is_success();
170170
nix_deps_dir
171171
});
@@ -185,7 +185,7 @@ impl Config {
185185
patchelf.args(["--set-interpreter", dynamic_linker.trim_end()]);
186186
}
187187
patchelf.arg(fname);
188-
let _ = patchelf.run_capture_stdout_exec_ctx(self);
188+
let _ = patchelf.run_capture_stdout(self);
189189
}
190190

191191
fn download_file(&self, url: &str, dest_path: &Path, help_on_error: &str) {
@@ -267,7 +267,7 @@ impl Config {
267267
"(New-Object System.Net.WebClient).DownloadFile('{}', '{}')",
268268
url, tempfile.to_str().expect("invalid UTF-8 not supported with powershell downloads"),
269269
),
270-
]).run_capture_stdout_exec_ctx(self);
270+
]).run_capture_stdout(self);
271271

272272
if powershell.is_failure() {
273273
return;

src/bootstrap/src/core/sanity.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,8 @@ than building it.
361361
// There are three builds of cmake on windows: MSVC, MinGW, and
362362
// Cygwin. The Cygwin build does not have generators for Visual
363363
// Studio, so detect that here and error.
364-
let out = command("cmake")
365-
.arg("--help")
366-
.run_always()
367-
.run_capture_stdout_exec_ctx(&build)
368-
.stdout();
364+
let out =
365+
command("cmake").arg("--help").run_always().run_capture_stdout(&build).stdout();
369366
if !out.contains("Visual Studio") {
370367
panic!(
371368
"

src/bootstrap/src/lib.rs

Lines changed: 0 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -941,133 +941,6 @@ impl Build {
941941
})
942942
}
943943

944-
/// Execute a command and return its output.
945-
/// Note: Ideally, you should use one of the BootstrapCommand::run* functions to
946-
/// execute commands. They internally call this method.
947-
#[track_caller]
948-
fn run(
949-
&self,
950-
command: &mut BootstrapCommand,
951-
stdout: OutputMode,
952-
stderr: OutputMode,
953-
) -> CommandOutput {
954-
command.mark_as_executed();
955-
if self.config.dry_run() && !command.run_always {
956-
return CommandOutput::default();
957-
}
958-
959-
#[cfg(feature = "tracing")]
960-
let _run_span = trace_cmd!(command);
961-
962-
let created_at = command.get_created_location();
963-
let executed_at = std::panic::Location::caller();
964-
965-
self.verbose(|| {
966-
println!("running: {command:?} (created at {created_at}, executed at {executed_at})")
967-
});
968-
969-
let cmd = command.as_command_mut();
970-
cmd.stdout(stdout.stdio());
971-
cmd.stderr(stderr.stdio());
972-
973-
let output = cmd.output();
974-
975-
use std::fmt::Write;
976-
977-
let mut message = String::new();
978-
let output: CommandOutput = match output {
979-
// Command has succeeded
980-
Ok(output) if output.status.success() => {
981-
CommandOutput::from_output(output, stdout, stderr)
982-
}
983-
// Command has started, but then it failed
984-
Ok(output) => {
985-
writeln!(
986-
message,
987-
r#"
988-
Command {command:?} did not execute successfully.
989-
Expected success, got {}
990-
Created at: {created_at}
991-
Executed at: {executed_at}"#,
992-
output.status,
993-
)
994-
.unwrap();
995-
996-
let output: CommandOutput = CommandOutput::from_output(output, stdout, stderr);
997-
998-
// If the output mode is OutputMode::Capture, we can now print the output.
999-
// If it is OutputMode::Print, then the output has already been printed to
1000-
// stdout/stderr, and we thus don't have anything captured to print anyway.
1001-
if stdout.captures() {
1002-
writeln!(message, "\nSTDOUT ----\n{}", output.stdout().trim()).unwrap();
1003-
}
1004-
if stderr.captures() {
1005-
writeln!(message, "\nSTDERR ----\n{}", output.stderr().trim()).unwrap();
1006-
}
1007-
output
1008-
}
1009-
// The command did not even start
1010-
Err(e) => {
1011-
writeln!(
1012-
message,
1013-
"\n\nCommand {command:?} did not execute successfully.\
1014-
\nIt was not possible to execute the command: {e:?}"
1015-
)
1016-
.unwrap();
1017-
CommandOutput::did_not_start(stdout, stderr)
1018-
}
1019-
};
1020-
1021-
let fail = |message: &str, output: CommandOutput| -> ! {
1022-
if self.is_verbose() {
1023-
println!("{message}");
1024-
} else {
1025-
let (stdout, stderr) = (output.stdout_if_present(), output.stderr_if_present());
1026-
// If the command captures output, the user would not see any indication that
1027-
// it has failed. In this case, print a more verbose error, since to provide more
1028-
// context.
1029-
if stdout.is_some() || stderr.is_some() {
1030-
if let Some(stdout) =
1031-
output.stdout_if_present().take_if(|s| !s.trim().is_empty())
1032-
{
1033-
println!("STDOUT:\n{stdout}\n");
1034-
}
1035-
if let Some(stderr) =
1036-
output.stderr_if_present().take_if(|s| !s.trim().is_empty())
1037-
{
1038-
println!("STDERR:\n{stderr}\n");
1039-
}
1040-
println!("Command {command:?} has failed. Rerun with -v to see more details.");
1041-
} else {
1042-
println!("Command has failed. Rerun with -v to see more details.");
1043-
}
1044-
}
1045-
exit!(1);
1046-
};
1047-
1048-
if !output.is_success() {
1049-
match command.failure_behavior {
1050-
BehaviorOnFailure::DelayFail => {
1051-
if self.fail_fast {
1052-
fail(&message, output);
1053-
}
1054-
1055-
let mut failures = self.delayed_failures.borrow_mut();
1056-
failures.push(message);
1057-
}
1058-
BehaviorOnFailure::Exit => {
1059-
fail(&message, output);
1060-
}
1061-
BehaviorOnFailure::Ignore => {
1062-
// If failures are allowed, either the error has been printed already
1063-
// (OutputMode::Print) or the user used a capture output mode and wants to
1064-
// handle the error output on their own.
1065-
}
1066-
}
1067-
}
1068-
output
1069-
}
1070-
1071944
/// Check if verbosity is greater than the `level`
1072945
pub fn is_verbose_than(&self, level: usize) -> bool {
1073946
self.verbosity > level

src/bootstrap/src/utils/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl GitInfo {
4646

4747
let mut git_command = helpers::git(Some(dir));
4848
git_command.arg("rev-parse");
49-
let output = git_command.allow_failure().run_capture_stdout_exec_ctx(exec_ctx);
49+
let output = git_command.allow_failure().run_capture_stdout(exec_ctx);
5050

5151
if output.is_failure() {
5252
return GitInfo::Absent;

src/bootstrap/src/utils/exec.rs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use build_helper::ci::CiEnv;
1212
use build_helper::drop_bomb::DropBomb;
1313

1414
use super::execution_context::ExecutionContext;
15-
use crate::Build;
1615

1716
/// What should be done when the command fails.
1817
#[derive(Debug, Copy, Clone)]
@@ -140,48 +139,25 @@ impl BootstrapCommand {
140139
self
141140
}
142141

142+
/// Run the command, while printing stdout and stderr.
143+
/// Returns true if the command has succeeded.
143144
#[track_caller]
144-
pub fn run_exec_ctx(&mut self, exec_ctx: impl AsRef<ExecutionContext>) -> bool {
145+
pub fn run(&mut self, exec_ctx: impl AsRef<ExecutionContext>) -> bool {
145146
exec_ctx.as_ref().run(self, OutputMode::Print, OutputMode::Print).is_success()
146147
}
147148

148149
/// Run the command, while capturing and returning all its output.
149150
#[track_caller]
150-
pub fn run_capture_exec_ctx(
151-
&mut self,
152-
exec_ctx: impl AsRef<ExecutionContext>,
153-
) -> CommandOutput {
151+
pub fn run_capture(&mut self, exec_ctx: impl AsRef<ExecutionContext>) -> CommandOutput {
154152
exec_ctx.as_ref().run(self, OutputMode::Capture, OutputMode::Capture)
155153
}
156154

157155
/// Run the command, while capturing and returning stdout, and printing stderr.
158156
#[track_caller]
159-
pub fn run_capture_stdout_exec_ctx(
160-
&mut self,
161-
exec_ctx: impl AsRef<ExecutionContext>,
162-
) -> CommandOutput {
157+
pub fn run_capture_stdout(&mut self, exec_ctx: impl AsRef<ExecutionContext>) -> CommandOutput {
163158
exec_ctx.as_ref().run(self, OutputMode::Capture, OutputMode::Print)
164159
}
165160

166-
/// Run the command, while printing stdout and stderr.
167-
/// Returns true if the command has succeeded.
168-
#[track_caller]
169-
pub fn run(&mut self, builder: &Build) -> bool {
170-
builder.run(self, OutputMode::Print, OutputMode::Print).is_success()
171-
}
172-
173-
/// Run the command, while capturing and returning all its output.
174-
#[track_caller]
175-
pub fn run_capture(&mut self, builder: &Build) -> CommandOutput {
176-
builder.run(self, OutputMode::Capture, OutputMode::Capture)
177-
}
178-
179-
/// Run the command, while capturing and returning stdout, and printing stderr.
180-
#[track_caller]
181-
pub fn run_capture_stdout(&mut self, builder: &Build) -> CommandOutput {
182-
builder.run(self, OutputMode::Capture, OutputMode::Print)
183-
}
184-
185161
/// Provides access to the stdlib Command inside.
186162
/// FIXME: This function should be eventually removed from bootstrap.
187163
pub fn as_command_mut(&mut self) -> &mut Command {

0 commit comments

Comments
 (0)