@@ -94,14 +94,7 @@ impl ExecutionContext {
94
94
let executed_at = std:: panic:: Location :: caller ( ) ;
95
95
96
96
if self . dry_run ( ) && !command. run_always {
97
- return DeferredCommand {
98
- process : None ,
99
- stdout,
100
- stderr,
101
- command,
102
- exec_ctx : Arc :: new ( self . clone ( ) ) ,
103
- created_at,
104
- } ;
97
+ return DeferredCommand { process : None , stdout, stderr, command, created_at } ;
105
98
}
106
99
107
100
#[ cfg( feature = "tracing" ) ]
@@ -117,14 +110,7 @@ impl ExecutionContext {
117
110
118
111
let child = cmd. spawn ( ) . unwrap ( ) ;
119
112
120
- DeferredCommand {
121
- process : Some ( child) ,
122
- stdout,
123
- stderr,
124
- command,
125
- exec_ctx : Arc :: new ( self . clone ( ) ) ,
126
- created_at,
127
- }
113
+ DeferredCommand { process : Some ( child) , stdout, stderr, command, created_at }
128
114
}
129
115
130
116
/// Execute a command and return its output.
@@ -137,7 +123,7 @@ impl ExecutionContext {
137
123
stdout : OutputMode ,
138
124
stderr : OutputMode ,
139
125
) -> CommandOutput {
140
- self . start ( command, stdout, stderr) . wait_for_output ( )
126
+ self . start ( command, stdout, stderr) . wait_for_output ( self )
141
127
}
142
128
143
129
fn fail ( & self , message : & str , output : CommandOutput ) -> ! {
@@ -164,20 +150,28 @@ impl ExecutionContext {
164
150
}
165
151
}
166
152
153
+ impl AsRef < ExecutionContext > for ExecutionContext {
154
+ fn as_ref ( & self ) -> & ExecutionContext {
155
+ self
156
+ }
157
+ }
158
+
167
159
pub struct DeferredCommand < ' a > {
168
160
process : Option < Child > ,
169
161
command : & ' a mut BootstrapCommand ,
170
162
stdout : OutputMode ,
171
163
stderr : OutputMode ,
172
- exec_ctx : Arc < ExecutionContext > ,
173
164
created_at : Location < ' a > ,
174
165
}
175
166
176
167
impl < ' a > DeferredCommand < ' a > {
177
- pub fn wait_for_output ( mut self ) -> CommandOutput {
168
+ pub fn wait_for_output ( mut self , exec_ctx : impl AsRef < ExecutionContext > ) -> CommandOutput {
178
169
if self . process . is_none ( ) {
179
170
return CommandOutput :: default ( ) ;
180
171
}
172
+
173
+ let exec_ctx = exec_ctx. as_ref ( ) ;
174
+
181
175
let output = self . process . take ( ) . unwrap ( ) . wait_with_output ( ) ;
182
176
183
177
let created_at = self . created_at ;
@@ -234,14 +228,14 @@ Executed at: {executed_at}"#,
234
228
if !output. is_success ( ) {
235
229
match self . command . failure_behavior {
236
230
BehaviorOnFailure :: DelayFail => {
237
- if self . exec_ctx . fail_fast {
238
- self . exec_ctx . fail ( & message, output) ;
231
+ if exec_ctx. fail_fast {
232
+ exec_ctx. fail ( & message, output) ;
239
233
}
240
234
241
- self . exec_ctx . add_to_delay_failure ( message) ;
235
+ exec_ctx. add_to_delay_failure ( message) ;
242
236
}
243
237
BehaviorOnFailure :: Exit => {
244
- self . exec_ctx . fail ( & message, output) ;
238
+ exec_ctx. fail ( & message, output) ;
245
239
}
246
240
BehaviorOnFailure :: Ignore => {
247
241
// If failures are allowed, either the error has been printed already
0 commit comments