@@ -9,7 +9,10 @@ use std::{
99 io:: { self , Read , Write } ,
1010 path:: Path ,
1111 process:: { Child , ChildStderr , Command , Stdio } ,
12- sync:: Arc ,
12+ sync:: {
13+ atomic:: { AtomicBool , Ordering } ,
14+ Arc ,
15+ } ,
1316} ;
1417
1518use crate :: { Error , ErrorKind , Object } ;
@@ -18,13 +21,17 @@ use crate::{Error, ErrorKind, Object};
1821pub ( crate ) struct CargoOutput {
1922 pub ( crate ) metadata : bool ,
2023 pub ( crate ) warnings : bool ,
24+ pub ( crate ) debug : bool ,
25+ checked_dbg_var : Arc < AtomicBool > ,
2126}
2227
2328impl CargoOutput {
24- pub ( crate ) const fn new ( ) -> Self {
29+ pub ( crate ) fn new ( ) -> Self {
2530 Self {
2631 metadata : true ,
2732 warnings : true ,
33+ debug : std:: env:: var_os ( "CC_ENABLE_DEBUG_OUTPUT" ) . is_some ( ) ,
34+ checked_dbg_var : Arc :: new ( AtomicBool :: new ( false ) ) ,
2835 }
2936 }
3037
@@ -40,6 +47,16 @@ impl CargoOutput {
4047 }
4148 }
4249
50+ pub ( crate ) fn print_debug ( & self , arg : & dyn Display ) {
51+ if self . metadata && !self . checked_dbg_var . load ( Ordering :: Relaxed ) {
52+ self . checked_dbg_var . store ( true , Ordering :: Relaxed ) ;
53+ println ! ( "cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT" ) ;
54+ }
55+ if self . debug {
56+ println ! ( "{}" , arg) ;
57+ }
58+ }
59+
4360 fn stdio_for_warnings ( & self ) -> Stdio {
4461 if self . warnings {
4562 Stdio :: piped ( )
@@ -217,7 +234,7 @@ fn wait_on_child(
217234 }
218235 } ;
219236
220- cargo_output. print_warning ( & status) ;
237+ cargo_output. print_debug ( & status) ;
221238
222239 if status. success ( ) {
223240 Ok ( ( ) )
@@ -326,7 +343,7 @@ pub(crate) fn spawn(
326343 }
327344 }
328345
329- cargo_output. print_warning ( & format_args ! ( "running: {:?}" , cmd) ) ;
346+ cargo_output. print_debug ( & format_args ! ( "running: {:?}" , cmd) ) ;
330347
331348 let cmd = ResetStderr ( cmd) ;
332349 let child = cmd. 0 . stderr ( cargo_output. stdio_for_warnings ( ) ) . spawn ( ) ;
0 commit comments