@@ -10,13 +10,13 @@ pub mod llvm_readobj;
10
10
pub mod run;
11
11
pub mod rustc;
12
12
pub mod rustdoc;
13
+ mod command;
13
14
14
15
use std:: env;
15
16
use std:: ffi:: OsString ;
16
17
use std:: fs;
17
18
use std:: io;
18
19
use std:: path:: { Path , PathBuf } ;
19
- use std:: process:: { Command , Output } ;
20
20
21
21
pub use gimli;
22
22
pub use object;
@@ -167,13 +167,12 @@ pub fn cygpath_windows<P: AsRef<Path>>(path: P) -> String {
167
167
let mut cygpath = Command :: new ( "cygpath" ) ;
168
168
cygpath. arg ( "-w" ) ;
169
169
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 ( ) {
172
172
handle_failed_output ( & cygpath, output, caller_line_number) ;
173
173
}
174
- let s = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
175
174
// cygpath -w can attach a newline
176
- s . trim ( ) . to_string ( )
175
+ output . stdout_utf8 ( ) . trim ( ) . to_string ( )
177
176
}
178
177
179
178
/// Run `uname`. This assumes that `uname` is available on the platform!
@@ -183,23 +182,23 @@ pub fn uname() -> String {
183
182
let caller_line_number = caller_location. line ( ) ;
184
183
185
184
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 ( ) {
188
187
handle_failed_output ( & uname, output, caller_line_number) ;
189
188
}
190
- String :: from_utf8 ( output. stdout ) . unwrap ( )
189
+ output. stdout_utf8 ( )
191
190
}
192
191
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 ( ) {
195
194
eprintln ! ( "command unexpectedly succeeded at line {caller_line_number}" ) ;
196
195
} else {
197
196
eprintln ! ( "command failed at line {caller_line_number}" ) ;
198
197
}
199
198
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 ( ) ) ;
203
202
std:: process:: exit ( 1 )
204
203
}
205
204
@@ -412,25 +411,25 @@ macro_rules! impl_common_helpers {
412
411
413
412
/// Run the constructed command and assert that it is successfully run.
414
413
#[ track_caller]
415
- pub fn run( & mut self ) -> :: std :: process :: Output {
414
+ pub fn run( & mut self ) -> crate :: command :: CompletedProcess {
416
415
let caller_location = :: std:: panic:: Location :: caller( ) ;
417
416
let caller_line_number = caller_location. line( ) ;
418
417
419
- let output = self . command_output( ) ;
420
- if !output. status. success( ) {
418
+ let output = self . cmd . command_output( ) ;
419
+ if !output. status( ) . success( ) {
421
420
handle_failed_output( & self . cmd, output, caller_line_number) ;
422
421
}
423
422
output
424
423
}
425
424
426
425
/// Run the constructed command and assert that it does not successfully run.
427
426
#[ track_caller]
428
- pub fn run_fail( & mut self ) -> :: std :: process :: Output {
427
+ pub fn run_fail( & mut self ) -> crate :: command :: CompletedProcess {
429
428
let caller_location = :: std:: panic:: Location :: caller( ) ;
430
429
let caller_line_number = caller_location. line( ) ;
431
430
432
- let output = self . command_output( ) ;
433
- if output. status. success( ) {
431
+ let output = self . cmd . command_output( ) ;
432
+ if output. status( ) . success( ) {
434
433
handle_failed_output( & self . cmd, output, caller_line_number) ;
435
434
}
436
435
output
@@ -446,3 +445,4 @@ macro_rules! impl_common_helpers {
446
445
}
447
446
448
447
pub ( crate ) use impl_common_helpers;
448
+ use crate :: command:: { Command , CompletedProcess } ;
0 commit comments