55
66pub mod cc;
77pub mod clang;
8+ mod command;
89pub mod diff;
910pub mod llvm_readobj;
1011pub mod run;
@@ -16,7 +17,6 @@ use 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;
@@ -27,7 +27,7 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
2727pub use clang:: { clang, Clang } ;
2828pub use diff:: { diff, Diff } ;
2929pub use llvm_readobj:: { llvm_readobj, LlvmReadobj } ;
30- pub use run:: { run, run_fail} ;
30+ pub use run:: { cmd , run, run_fail} ;
3131pub use rustc:: { aux_build, rustc, Rustc } ;
3232pub use rustdoc:: { bare_rustdoc, rustdoc, Rustdoc } ;
3333
@@ -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
@@ -286,6 +285,7 @@ pub fn read_dir<F: Fn(&Path)>(dir: impl AsRef<Path>, callback: F) {
286285}
287286
288287/// Check that `haystack` does not contain `needle`. Panic otherwise.
288+ #[ track_caller]
289289pub fn assert_not_contains ( haystack : & str , needle : & str ) {
290290 if haystack. contains ( needle) {
291291 eprintln ! ( "=== HAYSTACK ===" ) ;
@@ -412,28 +412,14 @@ macro_rules! impl_common_helpers {
412412
413413 /// Run the constructed command and assert that it is successfully run.
414414 #[ 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( )
424417 }
425418
426419 /// Run the constructed command and assert that it does not successfully run.
427420 #[ 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( )
437423 }
438424
439425 /// Set the path where the command will be run.
@@ -445,4 +431,5 @@ macro_rules! impl_common_helpers {
445431 } ;
446432}
447433
434+ use crate :: command:: { Command , CompletedProcess } ;
448435pub ( crate ) use impl_common_helpers;
0 commit comments