@@ -16,6 +16,7 @@ use ahash::AHashSet;
1616use build_types:: * ;
1717use console:: style;
1818use indicatif:: { ProgressBar , ProgressStyle } ;
19+ use log:: { log_enabled, Level :: Info } ;
1920use serde:: Serialize ;
2021use std:: fmt;
2122use std:: fs:: File ;
@@ -149,13 +150,13 @@ pub fn initialize_build(
149150 let root_config_name = packages:: get_package_name ( & project_root) ;
150151 let rescript_version = helpers:: get_rescript_version ( & bsc_path) ;
151152
152- print ! ( "{}{}Building package tree..." , style( "[1/7]" ) . bold( ) . dim( ) , TREE ) ;
153+ log :: info !( "{}{}Building package tree..." , style( "[1/7]" ) . bold( ) . dim( ) , TREE ) ;
153154 let _ = stdout ( ) . flush ( ) ;
154155 let timing_package_tree = Instant :: now ( ) ;
155156 let packages = packages:: make ( filter, & project_root, & workspace_root) ;
156157 let timing_package_tree_elapsed = timing_package_tree. elapsed ( ) ;
157158
158- println ! (
159+ log :: info !(
159160 "{}{} {}Built package tree in {:.2}s" ,
160161 LINE_CLEAR ,
161162 style( "[1/7]" ) . bold( ) . dim( ) ,
@@ -171,7 +172,7 @@ pub fn initialize_build(
171172
172173 let timing_source_files = Instant :: now ( ) ;
173174
174- print ! (
175+ log :: info !(
175176 "{} {}Finding source files..." ,
176177 style( "[2/7]" ) . bold( ) . dim( ) ,
177178 LOOKING_GLASS
@@ -187,7 +188,7 @@ pub fn initialize_build(
187188 ) ;
188189 packages:: parse_packages ( & mut build_state) ;
189190 let timing_source_files_elapsed = timing_source_files. elapsed ( ) ;
190- println ! (
191+ log :: info !(
191192 "{}{} {}Found source files in {:.2}s" ,
192193 LINE_CLEAR ,
193194 style( "[2/7]" ) . bold( ) . dim( ) ,
@@ -197,7 +198,7 @@ pub fn initialize_build(
197198 . as_secs_f64( )
198199 ) ;
199200
200- print ! (
201+ log :: info !(
201202 "{} {}Reading compile state..." ,
202203 style( "[3/7]" ) . bold( ) . dim( ) ,
203204 COMPILE_STATE
@@ -206,7 +207,7 @@ pub fn initialize_build(
206207 let timing_compile_state = Instant :: now ( ) ;
207208 let compile_assets_state = read_compile_state:: read ( & mut build_state) ;
208209 let timing_compile_state_elapsed = timing_compile_state. elapsed ( ) ;
209- println ! (
210+ log :: info !(
210211 "{}{} {}Read compile state {:.2}s" ,
211212 LINE_CLEAR ,
212213 style( "[3/7]" ) . bold( ) . dim( ) ,
@@ -216,15 +217,15 @@ pub fn initialize_build(
216217 . as_secs_f64( )
217218 ) ;
218219
219- print ! (
220+ log :: info !(
220221 "{} {}Cleaning up previous build..." ,
221222 style( "[4/7]" ) . bold( ) . dim( ) ,
222223 SWEEP
223224 ) ;
224225 let timing_cleanup = Instant :: now ( ) ;
225226 let ( diff_cleanup, total_cleanup) = clean:: cleanup_previous_build ( & mut build_state, compile_assets_state) ;
226227 let timing_cleanup_elapsed = timing_cleanup. elapsed ( ) ;
227- println ! (
228+ log :: info !(
228229 "{}{} {}Cleaned {}/{} {:.2}s" ,
229230 LINE_CLEAR ,
230231 style( "[4/7]" ) . bold( ) . dim( ) ,
@@ -264,7 +265,11 @@ pub fn incremental_build(
264265) -> Result < ( ) , IncrementalBuildError > {
265266 logs:: initialize ( & build_state. packages ) ;
266267 let num_dirty_modules = build_state. modules . values ( ) . filter ( |m| is_dirty ( m) ) . count ( ) as u64 ;
267- let pb = ProgressBar :: new ( num_dirty_modules) ;
268+ let pb = if log_enabled ! ( Info ) {
269+ ProgressBar :: new ( num_dirty_modules)
270+ } else {
271+ ProgressBar :: hidden ( )
272+ } ;
268273 let mut current_step = if only_incremental { 1 } else { 5 } ;
269274 let total_steps = if only_incremental { 3 } else { 7 } ;
270275 pb. set_style (
@@ -282,26 +287,26 @@ pub fn incremental_build(
282287
283288 match result_asts {
284289 Ok ( err) => {
285- println ! (
290+ log :: info !(
286291 "{}{} {}Parsed {} source files in {:.2}s" ,
287292 LINE_CLEAR ,
288293 format_step( current_step, total_steps) ,
289294 CODE ,
290295 num_dirty_modules,
291296 default_timing. unwrap_or( timing_ast_elapsed) . as_secs_f64( )
292297 ) ;
293- print ! ( "{}" , & err) ;
298+ log :: warn !( "{}" , & err) ;
294299 }
295300 Err ( err) => {
296301 logs:: finalize ( & build_state. packages ) ;
297- println ! (
302+ log :: error !(
298303 "{}{} {}Error parsing source files in {:.2}s" ,
299304 LINE_CLEAR ,
300305 format_step( current_step, total_steps) ,
301306 CROSS ,
302307 default_timing. unwrap_or( timing_ast_elapsed) . as_secs_f64( )
303308 ) ;
304- print ! ( "{}" , & err) ;
309+ log :: error !( "{}" , & err) ;
305310 return Err ( IncrementalBuildError :: SourceFileParseError ) ;
306311 }
307312 }
@@ -310,7 +315,7 @@ pub fn incremental_build(
310315 let timing_deps_elapsed = timing_deps. elapsed ( ) ;
311316 current_step += 1 ;
312317
313- println ! (
318+ log :: info !(
314319 "{}{} {}Collected deps in {:.2}s" ,
315320 LINE_CLEAR ,
316321 format_step( current_step, total_steps) ,
@@ -340,15 +345,12 @@ pub fn incremental_build(
340345 // }
341346
342347 let start_compiling = Instant :: now ( ) ;
343- let pb = ProgressBar :: new ( build_state. modules . len ( ) . try_into ( ) . unwrap ( ) ) ;
344- pb. set_style (
345- ProgressStyle :: with_template ( & format ! (
346- "{} {}Compiling... {{spinner}} {{pos}}/{{len}} {{msg}}" ,
347- format_step( current_step, total_steps) ,
348- SWORDS
349- ) )
350- . unwrap ( ) ,
351- ) ;
348+ let pb = if log_enabled ! ( Info ) {
349+ ProgressBar :: new ( build_state. modules . len ( ) . try_into ( ) . unwrap ( ) )
350+ } else {
351+ ProgressBar :: hidden ( )
352+ } ;
353+
352354 let ( compile_errors, compile_warnings, num_compiled_modules) =
353355 compile:: compile ( build_state, || pb. inc ( 1 ) , |size| pb. set_length ( size) ) ;
354356 let compile_duration = start_compiling. elapsed ( ) ;
@@ -360,17 +362,17 @@ pub fn incremental_build(
360362 pb. finish ( ) ;
361363 if !compile_errors. is_empty ( ) {
362364 if helpers:: contains_ascii_characters ( & compile_warnings) {
363- println ! ( "{}" , & compile_warnings) ;
365+ log :: error !( "{}" , & compile_warnings) ;
364366 }
365- println ! (
367+ log :: info !(
366368 "{}{} {}Compiled {} modules in {:.2}s" ,
367369 LINE_CLEAR ,
368370 format_step( current_step, total_steps) ,
369371 CROSS ,
370372 num_compiled_modules,
371373 default_timing. unwrap_or( compile_duration) . as_secs_f64( )
372374 ) ;
373- print ! ( "{}" , & compile_errors) ;
375+ log :: error !( "{}" , & compile_errors) ;
374376 // mark the original files as dirty again, because we didn't complete a full build
375377 for ( module_name, module) in build_state. modules . iter_mut ( ) {
376378 if tracked_dirty_modules. contains ( module_name) {
@@ -379,7 +381,7 @@ pub fn incremental_build(
379381 }
380382 Err ( IncrementalBuildError :: CompileError )
381383 } else {
382- println ! (
384+ log :: info !(
383385 "{}{} {}Compiled {} modules in {:.2}s" ,
384386 LINE_CLEAR ,
385387 format_step( current_step, total_steps) ,
@@ -388,7 +390,7 @@ pub fn incremental_build(
388390 default_timing. unwrap_or( compile_duration) . as_secs_f64( )
389391 ) ;
390392 if helpers:: contains_ascii_characters ( & compile_warnings) {
391- print ! ( "{}" , & compile_warnings) ;
393+ log :: warn !( "{}" , & compile_warnings) ;
392394 }
393395 Ok ( ( ) )
394396 }
@@ -448,7 +450,7 @@ pub fn build(
448450 match incremental_build ( & mut build_state, default_timing, true , false , create_sourcedirs) {
449451 Ok ( _) => {
450452 let timing_total_elapsed = timing_total. elapsed ( ) ;
451- println ! (
453+ log :: info !(
452454 "\n {}{}Finished Compilation in {:.2}s" ,
453455 LINE_CLEAR ,
454456 SPARKLES ,
0 commit comments