@@ -9,7 +9,10 @@ use std::{
9
9
io:: { self , Read , Write } ,
10
10
path:: Path ,
11
11
process:: { Child , ChildStderr , Command , Stdio } ,
12
- sync:: Arc ,
12
+ sync:: {
13
+ atomic:: { AtomicBool , Ordering } ,
14
+ Arc ,
15
+ } ,
13
16
} ;
14
17
15
18
use crate :: { Error , ErrorKind , Object } ;
@@ -18,13 +21,17 @@ use crate::{Error, ErrorKind, Object};
18
21
pub ( crate ) struct CargoOutput {
19
22
pub ( crate ) metadata : bool ,
20
23
pub ( crate ) warnings : bool ,
24
+ pub ( crate ) debug : bool ,
25
+ checked_dbg_var : Arc < AtomicBool > ,
21
26
}
22
27
23
28
impl CargoOutput {
24
- pub ( crate ) const fn new ( ) -> Self {
29
+ pub ( crate ) fn new ( ) -> Self {
25
30
Self {
26
31
metadata : true ,
27
32
warnings : true ,
33
+ debug : std:: env:: var_os ( "CC_ENABLE_DEBUG_OUTPUT" ) . is_some ( ) ,
34
+ checked_dbg_var : Arc :: new ( AtomicBool :: new ( false ) ) ,
28
35
}
29
36
}
30
37
@@ -40,6 +47,16 @@ impl CargoOutput {
40
47
}
41
48
}
42
49
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
+
43
60
fn stdio_for_warnings ( & self ) -> Stdio {
44
61
if self . warnings {
45
62
Stdio :: piped ( )
@@ -217,7 +234,7 @@ fn wait_on_child(
217
234
}
218
235
} ;
219
236
220
- cargo_output. print_warning ( & status) ;
237
+ cargo_output. print_debug ( & status) ;
221
238
222
239
if status. success ( ) {
223
240
Ok ( ( ) )
@@ -326,7 +343,7 @@ pub(crate) fn spawn(
326
343
}
327
344
}
328
345
329
- cargo_output. print_warning ( & format_args ! ( "running: {:?}" , cmd) ) ;
346
+ cargo_output. print_debug ( & format_args ! ( "running: {:?}" , cmd) ) ;
330
347
331
348
let cmd = ResetStderr ( cmd) ;
332
349
let child = cmd. 0 . stderr ( cargo_output. stdio_for_warnings ( ) ) . spawn ( ) ;
0 commit comments