@@ -5,6 +5,7 @@ use std::ffi;
55use std:: fmt:: Debug ;
66use std:: path:: { Path , PathBuf } ;
77use std:: process:: { ExitStatus , Stdio } ;
8+ use tap:: Pipe ;
89use tokio:: fs;
910use tokio:: io:: AsyncWriteExt ;
1011use tokio:: process:: Command ;
@@ -18,29 +19,43 @@ where
1819 S : AsRef < ffi:: OsStr > ,
1920{
2021 tracing:: info!( "Building {:?}" , root) ;
21- let output = Command :: new ( "/usr/bin/xcodebuild" )
22+ let mut result = Command :: new ( "/usr/bin/xcodebuild" )
2223 . arg ( "build" )
2324 . args ( args)
2425 . stdout ( Stdio :: piped ( ) )
25- . stderr ( Stdio :: null ( ) )
26+ . stderr ( Stdio :: piped ( ) )
2627 . current_dir ( root)
2728 . spawn ( ) ?
2829 . wait_with_output ( )
29- . await
30- . map ( |o| String :: from_utf8 ( o. stdout ) ) ??
31- . split ( "\n " )
32- . map ( |s| s. to_string ( ) )
33- . collect ( ) ;
30+ . await ?;
31+
32+ let is_successful = result. status . success ( ) ;
33+ let output = if is_successful {
34+ result. stdout
35+ } else {
36+ result. stdout . extend ( result. stderr ) ;
37+ result. stdout
38+ }
39+ . pipe ( String :: from_utf8) ?
40+ . split ( "\n " )
41+ . map ( |s| s. to_string ( ) )
42+ . collect ( ) ;
43+
44+ if is_successful {
45+ return Ok ( output) ;
46+ }
47+
48+ output. iter ( ) . for_each ( |s| {
49+ tracing:: error!( "{s}" ) ;
50+ } ) ;
51+ let output = output
52+ . into_iter ( )
53+ . filter ( |s| s. starts_with ( "error:" ) )
54+ . map ( |s| s. strip_prefix ( "error:" ) . map ( |s| s. to_string ( ) ) )
55+ . flatten ( )
56+ . collect :: < Vec < _ > > ( ) ;
3457
35- // TODO: Check xcodebuild build output if it contains failure
36- //
37- // Command succeed (return 0 status) but the output contains failure! need to be handled
38- // somehow as errror
39- tracing:: trace!(
40- "xcodebuild output: \n {:#?}\n \n \n ---------------------------------- end" ,
41- output
42- ) ;
43- Ok ( output)
58+ anyhow:: bail!( "{}" , output. join( "\n " ) ) ;
4459}
4560
4661/// run xcodebuild clean with extra arguments
0 commit comments