@@ -168,7 +168,12 @@ pub fn run_command(cmd: &mut Command) -> anyhow::Result<()> {
168
168
Ok ( ( ) )
169
169
}
170
170
171
- fn run_command_with_output ( cmd : & mut Command ) -> anyhow:: Result < process:: Output > {
171
+ /// If `stream_output` is true, stdout/stderr of `cmd` should be streamed to stdout/stderr of the
172
+ /// current process, in addition to being captured.
173
+ fn run_command_with_output (
174
+ cmd : & mut Command ,
175
+ stream_output : bool ,
176
+ ) -> anyhow:: Result < process:: Output > {
172
177
use anyhow:: Context ;
173
178
use utils:: read2;
174
179
let mut child = cmd
@@ -187,7 +192,7 @@ fn run_command_with_output(cmd: &mut Command) -> anyhow::Result<process::Output>
187
192
child. stderr . take ( ) . unwrap ( ) ,
188
193
& mut |is_stdout, buffer, _is_done| {
189
194
// Send output if trace logging is enabled
190
- if log:: log_enabled!( target: "raw_cargo_messages" , log:: Level :: Trace ) {
195
+ if stream_output || log:: log_enabled!( target: "raw_cargo_messages" , log:: Level :: Trace ) {
191
196
use std:: io:: Write ;
192
197
if is_stdout {
193
198
stdout_writer. write_all ( & buffer[ stdout_written..] ) . unwrap ( ) ;
@@ -215,18 +220,28 @@ fn run_command_with_output(cmd: &mut Command) -> anyhow::Result<process::Output>
215
220
}
216
221
217
222
pub fn command_output ( cmd : & mut Command ) -> anyhow:: Result < process:: Output > {
218
- let output = run_command_with_output ( cmd) ?;
223
+ let output = run_command_with_output ( cmd, false ) ?;
224
+ check_command_output ( & output) ?;
225
+ Ok ( output)
226
+ }
227
+
228
+ pub fn command_output_stream ( cmd : & mut Command ) -> anyhow:: Result < process:: Output > {
229
+ let output = run_command_with_output ( cmd, true ) ?;
230
+ check_command_output ( & output) ?;
231
+ Ok ( output)
232
+ }
219
233
234
+ fn check_command_output ( output : & process:: Output ) -> anyhow:: Result < ( ) > {
220
235
if !output. status . success ( ) {
221
- return Err ( anyhow:: anyhow!(
236
+ Err ( anyhow:: anyhow!(
222
237
"expected success, got {}\n \n stderr={}\n \n stdout={}\n " ,
223
238
output. status,
224
239
String :: from_utf8_lossy( & output. stderr) ,
225
240
String :: from_utf8_lossy( & output. stdout)
226
- ) ) ;
241
+ ) )
242
+ } else {
243
+ Ok ( ( ) )
227
244
}
228
-
229
- Ok ( output)
230
245
}
231
246
232
247
pub async fn async_command_output (
0 commit comments