@@ -5,7 +5,7 @@ use std::fs;
55use std:: io;
66use std:: path:: Component ;
77use std:: path:: { Path , PathBuf } ;
8- use std:: process:: { Command , ExitStatus } ;
8+ use std:: process:: { Command , ExitStatus , Stdio } ;
99
1010use cargo_metadata:: { Metadata , MetadataCommand , Package , PackageId } ;
1111use statum_graph:: CodebaseDoc ;
@@ -69,6 +69,7 @@ pub enum Error {
6969 manifest_path : PathBuf ,
7070 status : ExitStatus ,
7171 details : Option < String > ,
72+ diagnostics_reported : bool ,
7273 } ,
7374}
7475
@@ -137,6 +138,7 @@ impl fmt::Display for Error {
137138 manifest_path,
138139 status,
139140 details,
141+ diagnostics_reported : _,
140142 } => match details {
141143 Some ( details) => write ! (
142144 formatter,
@@ -153,6 +155,18 @@ impl fmt::Display for Error {
153155 }
154156}
155157
158+ impl Error {
159+ pub fn diagnostics_reported ( & self ) -> bool {
160+ matches ! (
161+ self ,
162+ Self :: RunnerFailed {
163+ diagnostics_reported: true ,
164+ ..
165+ }
166+ )
167+ }
168+ }
169+
156170impl std:: error:: Error for Error {
157171 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
158172 match self {
@@ -191,6 +205,7 @@ pub fn run(options: Options) -> Result<Vec<PathBuf>, Error> {
191205 temp_dir. path ( ) . join ( "Cargo.toml" ) ,
192206 & prepared. input . manifest_path ,
193207 "codebase export" ,
208+ RunnerStdio :: Captured ,
194209 ) ?;
195210
196211 Ok ( bundle_paths ( & out_dir, & options. stem ) )
@@ -216,6 +231,7 @@ pub fn inspect(options: InspectOptions) -> Result<(), Error> {
216231 temp_dir. path ( ) . join ( "Cargo.toml" ) ,
217232 & prepared. input . manifest_path ,
218233 "inspect session" ,
234+ RunnerStdio :: Inherited ,
219235 )
220236}
221237
@@ -590,28 +606,59 @@ fn run_runner(
590606 runner_manifest_path : PathBuf ,
591607 target_manifest_path : & Path ,
592608 operation : & ' static str ,
609+ stdio : RunnerStdio ,
593610) -> Result < ( ) , Error > {
594- let output = Command :: new ( "cargo" )
611+ let mut command = Command :: new ( "cargo" ) ;
612+ command
595613 . arg ( "run" )
596614 . arg ( "--quiet" )
597615 . arg ( "--manifest-path" )
598- . arg ( & runner_manifest_path)
599- . output ( )
600- . map_err ( |source| Error :: Io {
601- action : "run generated cargo runner" ,
602- path : runner_manifest_path. clone ( ) ,
603- source,
604- } ) ?;
605-
606- if output. status . success ( ) {
607- Ok ( ( ) )
608- } else {
609- Err ( Error :: RunnerFailed {
610- operation,
611- manifest_path : target_manifest_path. to_path_buf ( ) ,
612- status : output. status ,
613- details : normalize_runner_failure_details ( & output. stderr , & output. stdout ) ,
614- } )
616+ . arg ( & runner_manifest_path) ;
617+
618+ match stdio {
619+ RunnerStdio :: Captured => {
620+ let output = command. output ( ) . map_err ( |source| Error :: Io {
621+ action : "run generated cargo runner" ,
622+ path : runner_manifest_path. clone ( ) ,
623+ source,
624+ } ) ?;
625+
626+ if output. status . success ( ) {
627+ Ok ( ( ) )
628+ } else {
629+ Err ( Error :: RunnerFailed {
630+ operation,
631+ manifest_path : target_manifest_path. to_path_buf ( ) ,
632+ status : output. status ,
633+ details : normalize_runner_failure_details ( & output. stderr , & output. stdout ) ,
634+ diagnostics_reported : false ,
635+ } )
636+ }
637+ }
638+ RunnerStdio :: Inherited => {
639+ let status = command
640+ . stdin ( Stdio :: inherit ( ) )
641+ . stdout ( Stdio :: inherit ( ) )
642+ . stderr ( Stdio :: inherit ( ) )
643+ . status ( )
644+ . map_err ( |source| Error :: Io {
645+ action : "run generated cargo runner" ,
646+ path : runner_manifest_path. clone ( ) ,
647+ source,
648+ } ) ?;
649+
650+ if status. success ( ) {
651+ Ok ( ( ) )
652+ } else {
653+ Err ( Error :: RunnerFailed {
654+ operation,
655+ manifest_path : target_manifest_path. to_path_buf ( ) ,
656+ status,
657+ details : None ,
658+ diagnostics_reported : true ,
659+ } )
660+ }
661+ }
615662 }
616663}
617664
@@ -784,6 +831,12 @@ struct PreparedRun {
784831 patch_root : Option < PathBuf > ,
785832}
786833
834+ #[ derive( Clone , Copy ) ]
835+ enum RunnerStdio {
836+ Captured ,
837+ Inherited ,
838+ }
839+
787840#[ derive( Clone , Copy ) ]
788841enum RunnerMode < ' a > {
789842 Export { out_dir : & ' a Path , stem : & ' a str } ,
0 commit comments