@@ -10,13 +10,13 @@ pub mod llvm_readobj;
1010pub mod run;
1111pub mod rustc;
1212pub mod rustdoc;
13+ mod command;
1314
1415use std:: env;
1516use std:: ffi:: OsString ;
1617use std:: fs;
1718use std:: io;
1819use std:: path:: { Path , PathBuf } ;
19- use std:: process:: { Command , Output } ;
2020
2121pub use gimli;
2222pub use object;
@@ -167,13 +167,12 @@ pub fn cygpath_windows<P: AsRef<Path>>(path: P) -> String {
167167 let mut cygpath = Command :: new ( "cygpath" ) ;
168168 cygpath. arg ( "-w" ) ;
169169 cygpath. arg ( path. as_ref ( ) ) ;
170- let output = cygpath. output ( ) . unwrap ( ) ;
171- if !output. status . success ( ) {
170+ let output = cygpath. command_output ( ) ;
171+ if !output. status ( ) . success ( ) {
172172 handle_failed_output ( & cygpath, output, caller_line_number) ;
173173 }
174- let s = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
175174 // cygpath -w can attach a newline
176- s . trim ( ) . to_string ( )
175+ output . stdout_utf8 ( ) . trim ( ) . to_string ( )
177176}
178177
179178/// Run `uname`. This assumes that `uname` is available on the platform!
@@ -183,23 +182,23 @@ pub fn uname() -> String {
183182 let caller_line_number = caller_location. line ( ) ;
184183
185184 let mut uname = Command :: new ( "uname" ) ;
186- let output = uname. output ( ) . unwrap ( ) ;
187- if !output. status . success ( ) {
185+ let output = uname. command_output ( ) ;
186+ if !output. status ( ) . success ( ) {
188187 handle_failed_output ( & uname, output, caller_line_number) ;
189188 }
190- String :: from_utf8 ( output. stdout ) . unwrap ( )
189+ output. stdout_utf8 ( )
191190}
192191
193- fn handle_failed_output ( cmd : & Command , output : Output , caller_line_number : u32 ) -> ! {
194- if output. status . success ( ) {
192+ fn handle_failed_output ( cmd : & Command , output : CompletedProcess , caller_line_number : u32 ) -> ! {
193+ if output. status ( ) . success ( ) {
195194 eprintln ! ( "command unexpectedly succeeded at line {caller_line_number}" ) ;
196195 } else {
197196 eprintln ! ( "command failed at line {caller_line_number}" ) ;
198197 }
199198 eprintln ! ( "{cmd:?}" ) ;
200- eprintln ! ( "output status: `{}`" , output. status) ;
201- eprintln ! ( "=== STDOUT ===\n {}\n \n " , String :: from_utf8 ( output. stdout ) . unwrap ( ) ) ;
202- eprintln ! ( "=== STDERR ===\n {}\n \n " , String :: from_utf8 ( output. stderr ) . unwrap ( ) ) ;
199+ eprintln ! ( "output status: `{}`" , output. status( ) ) ;
200+ eprintln ! ( "=== STDOUT ===\n {}\n \n " , output. stdout_utf8 ( ) ) ;
201+ eprintln ! ( "=== STDERR ===\n {}\n \n " , output. stderr_utf8 ( ) ) ;
203202 std:: process:: exit ( 1 )
204203}
205204
@@ -412,25 +411,25 @@ macro_rules! impl_common_helpers {
412411
413412 /// Run the constructed command and assert that it is successfully run.
414413 #[ track_caller]
415- pub fn run( & mut self ) -> :: std :: process :: Output {
414+ pub fn run( & mut self ) -> crate :: command :: CompletedProcess {
416415 let caller_location = :: std:: panic:: Location :: caller( ) ;
417416 let caller_line_number = caller_location. line( ) ;
418417
419- let output = self . command_output( ) ;
420- if !output. status. success( ) {
418+ let output = self . cmd . command_output( ) ;
419+ if !output. status( ) . success( ) {
421420 handle_failed_output( & self . cmd, output, caller_line_number) ;
422421 }
423422 output
424423 }
425424
426425 /// Run the constructed command and assert that it does not successfully run.
427426 #[ track_caller]
428- pub fn run_fail( & mut self ) -> :: std :: process :: Output {
427+ pub fn run_fail( & mut self ) -> crate :: command :: CompletedProcess {
429428 let caller_location = :: std:: panic:: Location :: caller( ) ;
430429 let caller_line_number = caller_location. line( ) ;
431430
432- let output = self . command_output( ) ;
433- if output. status. success( ) {
431+ let output = self . cmd . command_output( ) ;
432+ if output. status( ) . success( ) {
434433 handle_failed_output( & self . cmd, output, caller_line_number) ;
435434 }
436435 output
@@ -446,3 +445,4 @@ macro_rules! impl_common_helpers {
446445}
447446
448447pub ( crate ) use impl_common_helpers;
448+ use crate :: command:: { Command , CompletedProcess } ;
0 commit comments