Skip to content

Commit 346641f

Browse files
committed
move all commands to new execution context
1 parent aca8011 commit 346641f

File tree

6 files changed

+20
-172
lines changed

6 files changed

+20
-172
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 & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -932,131 +932,6 @@ impl Build {
932932
})
933933
}
934934

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