about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbit-aloo <sshourya17@gmail.com>2025-06-17 18:52:39 +0530
committerbit-aloo <sshourya17@gmail.com>2025-06-17 20:49:20 +0530
commit05e1ae7bd4d3982a33431912d24623f6c46cd34c (patch)
treedb63996d97e023ae342bb44a3f27a00749e1d9f0
parentdca9fe0d940c61b16d1a8d4a13b9639a7d035458 (diff)
downloadrust-05e1ae7bd4d3982a33431912d24623f6c46cd34c.tar.gz
rust-05e1ae7bd4d3982a33431912d24623f6c46cd34c.zip
move execution context out of deferred command, add as_ref implementation and update wait_for_output usage
-rw-r--r--src/bootstrap/src/utils/channel.rs6
-rw-r--r--src/bootstrap/src/utils/execution_context.rs40
2 files changed, 20 insertions, 26 deletions
diff --git a/src/bootstrap/src/utils/channel.rs b/src/bootstrap/src/utils/channel.rs
index 3303e0b7715..9a9100a820b 100644
--- a/src/bootstrap/src/utils/channel.rs
+++ b/src/bootstrap/src/utils/channel.rs
@@ -79,9 +79,9 @@ impl GitInfo {
             .start_capture_stdout(&exec_ctx);
 
         GitInfo::Present(Some(Info {
-            commit_date: ver_date.wait_for_output().stdout().trim().to_string(),
-            sha: ver_hash.wait_for_output().stdout().trim().to_string(),
-            short_sha: short_ver_hash.wait_for_output().stdout().trim().to_string(),
+            commit_date: ver_date.wait_for_output(&exec_ctx).stdout().trim().to_string(),
+            sha: ver_hash.wait_for_output(&exec_ctx).stdout().trim().to_string(),
+            short_sha: short_ver_hash.wait_for_output(&exec_ctx).stdout().trim().to_string(),
         }))
     }
 
diff --git a/src/bootstrap/src/utils/execution_context.rs b/src/bootstrap/src/utils/execution_context.rs
index 15b92f93b04..5417307e54f 100644
--- a/src/bootstrap/src/utils/execution_context.rs
+++ b/src/bootstrap/src/utils/execution_context.rs
@@ -94,14 +94,7 @@ impl ExecutionContext {
         let executed_at = std::panic::Location::caller();
 
         if self.dry_run() && !command.run_always {
-            return DeferredCommand {
-                process: None,
-                stdout,
-                stderr,
-                command,
-                exec_ctx: Arc::new(self.clone()),
-                created_at,
-            };
+            return DeferredCommand { process: None, stdout, stderr, command, created_at };
         }
 
         #[cfg(feature = "tracing")]
@@ -117,14 +110,7 @@ impl ExecutionContext {
 
         let child = cmd.spawn().unwrap();
 
-        DeferredCommand {
-            process: Some(child),
-            stdout,
-            stderr,
-            command,
-            exec_ctx: Arc::new(self.clone()),
-            created_at,
-        }
+        DeferredCommand { process: Some(child), stdout, stderr, command, created_at }
     }
 
     /// Execute a command and return its output.
@@ -137,7 +123,7 @@ impl ExecutionContext {
         stdout: OutputMode,
         stderr: OutputMode,
     ) -> CommandOutput {
-        self.start(command, stdout, stderr).wait_for_output()
+        self.start(command, stdout, stderr).wait_for_output(self)
     }
 
     fn fail(&self, message: &str, output: CommandOutput) -> ! {
@@ -164,20 +150,28 @@ impl ExecutionContext {
     }
 }
 
+impl AsRef<ExecutionContext> for ExecutionContext {
+    fn as_ref(&self) -> &ExecutionContext {
+        self
+    }
+}
+
 pub struct DeferredCommand<'a> {
     process: Option<Child>,
     command: &'a mut BootstrapCommand,
     stdout: OutputMode,
     stderr: OutputMode,
-    exec_ctx: Arc<ExecutionContext>,
     created_at: Location<'a>,
 }
 
 impl<'a> DeferredCommand<'a> {
-    pub fn wait_for_output(mut self) -> CommandOutput {
+    pub fn wait_for_output(mut self, exec_ctx: impl AsRef<ExecutionContext>) -> CommandOutput {
         if self.process.is_none() {
             return CommandOutput::default();
         }
+
+        let exec_ctx = exec_ctx.as_ref();
+
         let output = self.process.take().unwrap().wait_with_output();
 
         let created_at = self.created_at;
@@ -234,14 +228,14 @@ Executed at: {executed_at}"#,
         if !output.is_success() {
             match self.command.failure_behavior {
                 BehaviorOnFailure::DelayFail => {
-                    if self.exec_ctx.fail_fast {
-                        self.exec_ctx.fail(&message, output);
+                    if exec_ctx.fail_fast {
+                        exec_ctx.fail(&message, output);
                     }
 
-                    self.exec_ctx.add_to_delay_failure(message);
+                    exec_ctx.add_to_delay_failure(message);
                 }
                 BehaviorOnFailure::Exit => {
-                    self.exec_ctx.fail(&message, output);
+                    exec_ctx.fail(&message, output);
                 }
                 BehaviorOnFailure::Ignore => {
                     // If failures are allowed, either the error has been printed already