about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorbit-aloo <sshourya17@gmail.com>2025-06-07 15:05:04 +0530
committerbit-aloo <sshourya17@gmail.com>2025-06-09 20:39:15 +0530
commit50725f325b32d3de2a0f159c7b90b21cfc91a2d3 (patch)
tree1e43e93213db842b88693421b9aad87be5071eb0 /src/bootstrap
parent98be2a0498529db0f40628bf9ecef0ae833d937d (diff)
downloadrust-50725f325b32d3de2a0f159c7b90b21cfc91a2d3.tar.gz
rust-50725f325b32d3de2a0f159c7b90b21cfc91a2d3.zip
move all commands to new execution context
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/src/core/config/config.rs14
-rw-r--r--src/bootstrap/src/core/download.rs10
-rw-r--r--src/bootstrap/src/core/sanity.rs7
-rw-r--r--src/bootstrap/src/lib.rs127
-rw-r--r--src/bootstrap/src/utils/channel.rs2
-rw-r--r--src/bootstrap/src/utils/exec.rs34
6 files changed, 20 insertions, 174 deletions
diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
index e37101381dd..8b5e252d1d7 100644
--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -446,7 +446,7 @@ impl Config {
             // has already been (kinda-cross-)compiled to Windows land, we require a normal Windows path.
             cmd.arg("rev-parse").arg("--show-cdup");
             // Discard stderr because we expect this to fail when building from a tarball.
-            let output = cmd.allow_failure().run_capture_stdout_exec_ctx(&config);
+            let output = cmd.allow_failure().run_capture_stdout(&config);
             if output.is_success() {
                 let git_root_relative = output.stdout();
                 // We need to canonicalize this path to make sure it uses backslashes instead of forward slashes,
@@ -753,7 +753,7 @@ impl Config {
             command(&config.initial_rustc)
                 .args(["--print", "sysroot"])
                 .run_always()
-                .run_capture_stdout_exec_ctx(&config)
+                .run_capture_stdout(&config)
                 .stdout()
                 .trim()
         ));
@@ -1068,7 +1068,7 @@ impl Config {
 
         let mut git = helpers::git(Some(&self.src));
         git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap()));
-        git.allow_failure().run_capture_stdout_exec_ctx(self).stdout()
+        git.allow_failure().run_capture_stdout(self).stdout()
     }
 
     /// Bootstrap embeds a version number into the name of shared libraries it uploads in CI.
@@ -1342,7 +1342,7 @@ impl Config {
         let checked_out_hash = submodule_git()
             .allow_failure()
             .args(["rev-parse", "HEAD"])
-            .run_capture_stdout_exec_ctx(self)
+            .run_capture_stdout(self)
             .stdout();
         let checked_out_hash = checked_out_hash.trim_end();
         // Determine commit that the submodule *should* have.
@@ -1351,7 +1351,7 @@ impl Config {
             .run_always()
             .args(["ls-tree", "HEAD"])
             .arg(relative_path)
-            .run_capture_stdout_exec_ctx(self)
+            .run_capture_stdout(self)
             .stdout();
 
         let actual_hash = recorded
@@ -1380,7 +1380,7 @@ impl Config {
                 .allow_failure()
                 .run_always()
                 .args(["symbolic-ref", "--short", "HEAD"])
-                .run_capture_exec_ctx(self);
+                .run_capture(self);
 
             let mut git = helpers::git(Some(&self.src)).allow_failure();
             git.run_always();
@@ -1434,7 +1434,7 @@ impl Config {
         }
 
         let stage0_output =
-            command(program_path).arg("--version").run_capture_stdout_exec_ctx(self).stdout();
+            command(program_path).arg("--version").run_capture_stdout(self).stdout();
         let mut stage0_output = stage0_output.lines().next().unwrap().split(' ');
 
         let stage0_name = stage0_output.next().unwrap();
diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs
index 48604023c97..c518cc8bcd4 100644
--- a/src/bootstrap/src/core/download.rs
+++ b/src/bootstrap/src/core/download.rs
@@ -27,7 +27,7 @@ fn extract_curl_version(out: String) -> semver::Version {
 fn curl_version(config: &Config) -> semver::Version {
     let mut curl = command("curl");
     curl.arg("-V");
-    let curl = curl.run_capture_stdout_exec_ctx(config);
+    let curl = curl.run_capture_stdout(config);
     if curl.is_failure() {
         return semver::Version::new(1, 0, 0);
     }
@@ -80,7 +80,7 @@ impl Config {
     /// on NixOS
     fn should_fix_bins_and_dylibs(&self) -> bool {
         let val = *SHOULD_FIX_BINS_AND_DYLIBS.get_or_init(|| {
-            let uname = command("uname").arg("-s").run_capture_stdout_exec_ctx(self);
+            let uname = command("uname").arg("-s").run_capture_stdout(self);
             if uname.is_failure() {
                 return false;
             }
@@ -165,7 +165,7 @@ impl Config {
             nix_build_succeeded = command("nix-build")
                 .allow_failure()
                 .args([Path::new("-E"), Path::new(NIX_EXPR), Path::new("-o"), &nix_deps_dir])
-                .run_capture_stdout_exec_ctx(self)
+                .run_capture_stdout(self)
                 .is_success();
             nix_deps_dir
         });
@@ -185,7 +185,7 @@ impl Config {
             patchelf.args(["--set-interpreter", dynamic_linker.trim_end()]);
         }
         patchelf.arg(fname);
-        let _ = patchelf.run_capture_stdout_exec_ctx(self);
+        let _ = patchelf.run_capture_stdout(self);
     }
 
     fn download_file(&self, url: &str, dest_path: &Path, help_on_error: &str) {
@@ -267,7 +267,7 @@ impl Config {
                             "(New-Object System.Net.WebClient).DownloadFile('{}', '{}')",
                             url, tempfile.to_str().expect("invalid UTF-8 not supported with powershell downloads"),
                         ),
-                    ]).run_capture_stdout_exec_ctx(self);
+                    ]).run_capture_stdout(self);
 
                     if powershell.is_failure() {
                         return;
diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs
index 4ef9316d00b..f55d924fdd8 100644
--- a/src/bootstrap/src/core/sanity.rs
+++ b/src/bootstrap/src/core/sanity.rs
@@ -361,11 +361,8 @@ than building it.
             // There are three builds of cmake on windows: MSVC, MinGW, and
             // Cygwin. The Cygwin build does not have generators for Visual
             // Studio, so detect that here and error.
-            let out = command("cmake")
-                .arg("--help")
-                .run_always()
-                .run_capture_stdout_exec_ctx(&build)
-                .stdout();
+            let out =
+                command("cmake").arg("--help").run_always().run_capture_stdout(&build).stdout();
             if !out.contains("Visual Studio") {
                 panic!(
                     "
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs
index 9bace4eb77c..c8b6d59f38f 100644
--- a/src/bootstrap/src/lib.rs
+++ b/src/bootstrap/src/lib.rs
@@ -941,133 +941,6 @@ impl Build {
         })
     }
 
-    /// Execute a command and return its output.
-    /// Note: Ideally, you should use one of the BootstrapCommand::run* functions to
-    /// execute commands. They internally call this method.
-    #[track_caller]
-    fn run(
-        &self,
-        command: &mut BootstrapCommand,
-        stdout: OutputMode,
-        stderr: OutputMode,
-    ) -> CommandOutput {
-        command.mark_as_executed();
-        if self.config.dry_run() && !command.run_always {
-            return CommandOutput::default();
-        }
-
-        #[cfg(feature = "tracing")]
-        let _run_span = trace_cmd!(command);
-
-        let created_at = command.get_created_location();
-        let executed_at = std::panic::Location::caller();
-
-        self.verbose(|| {
-            println!("running: {command:?} (created at {created_at}, executed at {executed_at})")
-        });
-
-        let cmd = command.as_command_mut();
-        cmd.stdout(stdout.stdio());
-        cmd.stderr(stderr.stdio());
-
-        let output = cmd.output();
-
-        use std::fmt::Write;
-
-        let mut message = String::new();
-        let output: CommandOutput = match output {
-            // Command has succeeded
-            Ok(output) if output.status.success() => {
-                CommandOutput::from_output(output, stdout, stderr)
-            }
-            // Command has started, but then it failed
-            Ok(output) => {
-                writeln!(
-                    message,
-                    r#"
-Command {command:?} did not execute successfully.
-Expected success, got {}
-Created at: {created_at}
-Executed at: {executed_at}"#,
-                    output.status,
-                )
-                .unwrap();
-
-                let output: CommandOutput = CommandOutput::from_output(output, stdout, stderr);
-
-                // If the output mode is OutputMode::Capture, we can now print the output.
-                // If it is OutputMode::Print, then the output has already been printed to
-                // stdout/stderr, and we thus don't have anything captured to print anyway.
-                if stdout.captures() {
-                    writeln!(message, "\nSTDOUT ----\n{}", output.stdout().trim()).unwrap();
-                }
-                if stderr.captures() {
-                    writeln!(message, "\nSTDERR ----\n{}", output.stderr().trim()).unwrap();
-                }
-                output
-            }
-            // The command did not even start
-            Err(e) => {
-                writeln!(
-                    message,
-                    "\n\nCommand {command:?} did not execute successfully.\
-            \nIt was not possible to execute the command: {e:?}"
-                )
-                .unwrap();
-                CommandOutput::did_not_start(stdout, stderr)
-            }
-        };
-
-        let fail = |message: &str, output: CommandOutput| -> ! {
-            if self.is_verbose() {
-                println!("{message}");
-            } else {
-                let (stdout, stderr) = (output.stdout_if_present(), output.stderr_if_present());
-                // If the command captures output, the user would not see any indication that
-                // it has failed. In this case, print a more verbose error, since to provide more
-                // context.
-                if stdout.is_some() || stderr.is_some() {
-                    if let Some(stdout) =
-                        output.stdout_if_present().take_if(|s| !s.trim().is_empty())
-                    {
-                        println!("STDOUT:\n{stdout}\n");
-                    }
-                    if let Some(stderr) =
-                        output.stderr_if_present().take_if(|s| !s.trim().is_empty())
-                    {
-                        println!("STDERR:\n{stderr}\n");
-                    }
-                    println!("Command {command:?} has failed. Rerun with -v to see more details.");
-                } else {
-                    println!("Command has failed. Rerun with -v to see more details.");
-                }
-            }
-            exit!(1);
-        };
-
-        if !output.is_success() {
-            match command.failure_behavior {
-                BehaviorOnFailure::DelayFail => {
-                    if self.fail_fast {
-                        fail(&message, output);
-                    }
-
-                    let mut failures = self.delayed_failures.borrow_mut();
-                    failures.push(message);
-                }
-                BehaviorOnFailure::Exit => {
-                    fail(&message, output);
-                }
-                BehaviorOnFailure::Ignore => {
-                    // If failures are allowed, either the error has been printed already
-                    // (OutputMode::Print) or the user used a capture output mode and wants to
-                    // handle the error output on their own.
-                }
-            }
-        }
-        output
-    }
-
     /// Check if verbosity is greater than the `level`
     pub fn is_verbose_than(&self, level: usize) -> bool {
         self.verbosity > level
diff --git a/src/bootstrap/src/utils/channel.rs b/src/bootstrap/src/utils/channel.rs
index 333c04c3c26..fec9f068f6d 100644
--- a/src/bootstrap/src/utils/channel.rs
+++ b/src/bootstrap/src/utils/channel.rs
@@ -46,7 +46,7 @@ impl GitInfo {
 
         let mut git_command = helpers::git(Some(dir));
         git_command.arg("rev-parse");
-        let output = git_command.allow_failure().run_capture_stdout_exec_ctx(exec_ctx);
+        let output = git_command.allow_failure().run_capture_stdout(exec_ctx);
 
         if output.is_failure() {
             return GitInfo::Absent;
diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs
index c03fd2772ad..f297300e34a 100644
--- a/src/bootstrap/src/utils/exec.rs
+++ b/src/bootstrap/src/utils/exec.rs
@@ -12,7 +12,6 @@ use build_helper::ci::CiEnv;
 use build_helper::drop_bomb::DropBomb;
 
 use super::execution_context::ExecutionContext;
-use crate::Build;
 
 /// What should be done when the command fails.
 #[derive(Debug, Copy, Clone)]
@@ -140,48 +139,25 @@ impl BootstrapCommand {
         self
     }
 
+    /// Run the command, while printing stdout and stderr.
+    /// Returns true if the command has succeeded.
     #[track_caller]
-    pub fn run_exec_ctx(&mut self, exec_ctx: impl AsRef<ExecutionContext>) -> bool {
+    pub fn run(&mut self, exec_ctx: impl AsRef<ExecutionContext>) -> bool {
         exec_ctx.as_ref().run(self, OutputMode::Print, OutputMode::Print).is_success()
     }
 
     /// Run the command, while capturing and returning all its output.
     #[track_caller]
-    pub fn run_capture_exec_ctx(
-        &mut self,
-        exec_ctx: impl AsRef<ExecutionContext>,
-    ) -> CommandOutput {
+    pub fn run_capture(&mut self, exec_ctx: impl AsRef<ExecutionContext>) -> CommandOutput {
         exec_ctx.as_ref().run(self, OutputMode::Capture, OutputMode::Capture)
     }
 
     /// Run the command, while capturing and returning stdout, and printing stderr.
     #[track_caller]
-    pub fn run_capture_stdout_exec_ctx(
-        &mut self,
-        exec_ctx: impl AsRef<ExecutionContext>,
-    ) -> CommandOutput {
+    pub fn run_capture_stdout(&mut self, exec_ctx: impl AsRef<ExecutionContext>) -> CommandOutput {
         exec_ctx.as_ref().run(self, OutputMode::Capture, OutputMode::Print)
     }
 
-    /// Run the command, while printing stdout and stderr.
-    /// Returns true if the command has succeeded.
-    #[track_caller]
-    pub fn run(&mut self, builder: &Build) -> bool {
-        builder.run(self, OutputMode::Print, OutputMode::Print).is_success()
-    }
-
-    /// Run the command, while capturing and returning all its output.
-    #[track_caller]
-    pub fn run_capture(&mut self, builder: &Build) -> CommandOutput {
-        builder.run(self, OutputMode::Capture, OutputMode::Capture)
-    }
-
-    /// Run the command, while capturing and returning stdout, and printing stderr.
-    #[track_caller]
-    pub fn run_capture_stdout(&mut self, builder: &Build) -> CommandOutput {
-        builder.run(self, OutputMode::Capture, OutputMode::Print)
-    }
-
     /// Provides access to the stdlib Command inside.
     /// FIXME: This function should be eventually removed from bootstrap.
     pub fn as_command_mut(&mut self) -> &mut Command {