@@ -168,7 +168,12 @@ pub fn run_command(cmd: &mut Command) -> anyhow::Result<()> {
168168 Ok ( ( ) )
169169}
170170
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 > {
172177 use anyhow:: Context ;
173178 use utils:: read2;
174179 let mut child = cmd
@@ -187,7 +192,7 @@ fn run_command_with_output(cmd: &mut Command) -> anyhow::Result<process::Output>
187192 child. stderr . take ( ) . unwrap ( ) ,
188193 & mut |is_stdout, buffer, _is_done| {
189194 // 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 ) {
191196 use std:: io:: Write ;
192197 if is_stdout {
193198 stdout_writer. write_all ( & buffer[ stdout_written..] ) . unwrap ( ) ;
@@ -215,18 +220,28 @@ fn run_command_with_output(cmd: &mut Command) -> anyhow::Result<process::Output>
215220}
216221
217222pub 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+ }
219233
234+ fn check_command_output ( output : & process:: Output ) -> anyhow:: Result < ( ) > {
220235 if !output. status . success ( ) {
221- return Err ( anyhow:: anyhow!(
236+ Err ( anyhow:: anyhow!(
222237 "expected success, got {}\n \n stderr={}\n \n stdout={}\n " ,
223238 output. status,
224239 String :: from_utf8_lossy( & output. stderr) ,
225240 String :: from_utf8_lossy( & output. stdout)
226- ) ) ;
241+ ) )
242+ } else {
243+ Ok ( ( ) )
227244 }
228-
229- Ok ( output)
230245}
231246
232247pub async fn async_command_output (
0 commit comments