5
5
6
6
pub mod cc;
7
7
pub mod clang;
8
+ mod command;
8
9
pub mod diff;
9
10
pub mod llvm_readobj;
10
11
pub mod run;
@@ -16,7 +17,6 @@ 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;
@@ -27,7 +27,7 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
27
27
pub use clang:: { clang, Clang } ;
28
28
pub use diff:: { diff, Diff } ;
29
29
pub use llvm_readobj:: { llvm_readobj, LlvmReadobj } ;
30
- pub use run:: { run, run_fail} ;
30
+ pub use run:: { cmd , run, run_fail} ;
31
31
pub use rustc:: { aux_build, rustc, Rustc } ;
32
32
pub use rustdoc:: { bare_rustdoc, rustdoc, Rustdoc } ;
33
33
@@ -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
@@ -286,6 +285,7 @@ pub fn read_dir<F: Fn(&Path)>(dir: impl AsRef<Path>, callback: F) {
286
285
}
287
286
288
287
/// Check that `haystack` does not contain `needle`. Panic otherwise.
288
+ #[ track_caller]
289
289
pub fn assert_not_contains ( haystack : & str , needle : & str ) {
290
290
if haystack. contains ( needle) {
291
291
eprintln ! ( "=== HAYSTACK ===" ) ;
@@ -412,28 +412,14 @@ macro_rules! impl_common_helpers {
412
412
413
413
/// Run the constructed command and assert that it is successfully run.
414
414
#[ track_caller]
415
- pub fn run( & mut self ) -> :: std:: process:: Output {
416
- let caller_location = :: std:: panic:: Location :: caller( ) ;
417
- let caller_line_number = caller_location. line( ) ;
418
-
419
- let output = self . command_output( ) ;
420
- if !output. status. success( ) {
421
- handle_failed_output( & self . cmd, output, caller_line_number) ;
422
- }
423
- output
415
+ pub fn run( & mut self ) -> crate :: command:: CompletedProcess {
416
+ self . cmd. run( )
424
417
}
425
418
426
419
/// Run the constructed command and assert that it does not successfully run.
427
420
#[ track_caller]
428
- pub fn run_fail( & mut self ) -> :: std:: process:: Output {
429
- let caller_location = :: std:: panic:: Location :: caller( ) ;
430
- let caller_line_number = caller_location. line( ) ;
431
-
432
- let output = self . command_output( ) ;
433
- if output. status. success( ) {
434
- handle_failed_output( & self . cmd, output, caller_line_number) ;
435
- }
436
- output
421
+ pub fn run_fail( & mut self ) -> crate :: command:: CompletedProcess {
422
+ self . cmd. run_fail( )
437
423
}
438
424
439
425
/// Set the path where the command will be run.
@@ -445,4 +431,5 @@ macro_rules! impl_common_helpers {
445
431
} ;
446
432
}
447
433
434
+ use crate :: command:: { Command , CompletedProcess } ;
448
435
pub ( crate ) use impl_common_helpers;
0 commit comments