@@ -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:: io:: { stdout, Write } ;
@@ -148,13 +149,13 @@ pub fn initialize_build(
148149 let root_config_name = packages:: get_package_name ( & project_root) ;
149150 let rescript_version = helpers:: get_rescript_version ( & bsc_path) ;
150151
151- print ! ( "{}{}Building package tree..." , style( "[1/7]" ) . bold( ) . dim( ) , TREE ) ;
152+ log :: info !( "{}{}Building package tree..." , style( "[1/7]" ) . bold( ) . dim( ) , TREE ) ;
152153 let _ = stdout ( ) . flush ( ) ;
153154 let timing_package_tree = Instant :: now ( ) ;
154155 let packages = packages:: make ( filter, & project_root, & workspace_root) ;
155156 let timing_package_tree_elapsed = timing_package_tree. elapsed ( ) ;
156157
157- println ! (
158+ log :: info !(
158159 "{}{} {}Built package tree in {:.2}s" ,
159160 LINE_CLEAR ,
160161 style( "[1/7]" ) . bold( ) . dim( ) ,
@@ -170,7 +171,7 @@ pub fn initialize_build(
170171
171172 let timing_source_files = Instant :: now ( ) ;
172173
173- print ! (
174+ log :: info !(
174175 "{} {}Finding source files..." ,
175176 style( "[2/7]" ) . bold( ) . dim( ) ,
176177 LOOKING_GLASS
@@ -186,7 +187,7 @@ pub fn initialize_build(
186187 ) ;
187188 packages:: parse_packages ( & mut build_state) ;
188189 let timing_source_files_elapsed = timing_source_files. elapsed ( ) ;
189- println ! (
190+ log :: info !(
190191 "{}{} {}Found source files in {:.2}s" ,
191192 LINE_CLEAR ,
192193 style( "[2/7]" ) . bold( ) . dim( ) ,
@@ -196,7 +197,7 @@ pub fn initialize_build(
196197 . as_secs_f64( )
197198 ) ;
198199
199- print ! (
200+ log :: info !(
200201 "{} {}Reading compile state..." ,
201202 style( "[3/7]" ) . bold( ) . dim( ) ,
202203 COMPILE_STATE
@@ -205,7 +206,7 @@ pub fn initialize_build(
205206 let timing_compile_state = Instant :: now ( ) ;
206207 let compile_assets_state = read_compile_state:: read ( & mut build_state) ;
207208 let timing_compile_state_elapsed = timing_compile_state. elapsed ( ) ;
208- println ! (
209+ log :: info !(
209210 "{}{} {}Read compile state {:.2}s" ,
210211 LINE_CLEAR ,
211212 style( "[3/7]" ) . bold( ) . dim( ) ,
@@ -215,15 +216,15 @@ pub fn initialize_build(
215216 . as_secs_f64( )
216217 ) ;
217218
218- print ! (
219+ log :: info !(
219220 "{} {}Cleaning up previous build..." ,
220221 style( "[4/7]" ) . bold( ) . dim( ) ,
221222 SWEEP
222223 ) ;
223224 let timing_cleanup = Instant :: now ( ) ;
224225 let ( diff_cleanup, total_cleanup) = clean:: cleanup_previous_build ( & mut build_state, compile_assets_state) ;
225226 let timing_cleanup_elapsed = timing_cleanup. elapsed ( ) ;
226- println ! (
227+ log :: info !(
227228 "{}{} {}Cleaned {}/{} {:.2}s" ,
228229 LINE_CLEAR ,
229230 style( "[4/7]" ) . bold( ) . dim( ) ,
@@ -263,7 +264,11 @@ pub fn incremental_build(
263264) -> Result < ( ) , IncrementalBuildError > {
264265 logs:: initialize ( & build_state. packages ) ;
265266 let num_dirty_modules = build_state. modules . values ( ) . filter ( |m| is_dirty ( m) ) . count ( ) as u64 ;
266- let pb = ProgressBar :: new ( num_dirty_modules) ;
267+ let pb = if log_enabled ! ( Info ) {
268+ ProgressBar :: new ( num_dirty_modules)
269+ } else {
270+ ProgressBar :: hidden ( )
271+ } ;
267272 let mut current_step = if only_incremental { 1 } else { 5 } ;
268273 let total_steps = if only_incremental { 3 } else { 7 } ;
269274 pb. set_style (
@@ -281,26 +286,26 @@ pub fn incremental_build(
281286
282287 match result_asts {
283288 Ok ( err) => {
284- println ! (
289+ log :: info !(
285290 "{}{} {}Parsed {} source files in {:.2}s" ,
286291 LINE_CLEAR ,
287292 format_step( current_step, total_steps) ,
288293 CODE ,
289294 num_dirty_modules,
290295 default_timing. unwrap_or( timing_ast_elapsed) . as_secs_f64( )
291296 ) ;
292- print ! ( "{}" , & err) ;
297+ log :: warn !( "{}" , & err) ;
293298 }
294299 Err ( err) => {
295300 logs:: finalize ( & build_state. packages ) ;
296- println ! (
301+ log :: error !(
297302 "{}{} {}Error parsing source files in {:.2}s" ,
298303 LINE_CLEAR ,
299304 format_step( current_step, total_steps) ,
300305 CROSS ,
301306 default_timing. unwrap_or( timing_ast_elapsed) . as_secs_f64( )
302307 ) ;
303- print ! ( "{}" , & err) ;
308+ log :: error !( "{}" , & err) ;
304309 return Err ( IncrementalBuildError :: SourceFileParseError ) ;
305310 }
306311 }
@@ -309,7 +314,7 @@ pub fn incremental_build(
309314 let timing_deps_elapsed = timing_deps. elapsed ( ) ;
310315 current_step += 1 ;
311316
312- println ! (
317+ log :: info !(
313318 "{}{} {}Collected deps in {:.2}s" ,
314319 LINE_CLEAR ,
315320 format_step( current_step, total_steps) ,
@@ -339,15 +344,12 @@ pub fn incremental_build(
339344 // }
340345
341346 let start_compiling = Instant :: now ( ) ;
342- let pb = ProgressBar :: new ( build_state. modules . len ( ) . try_into ( ) . unwrap ( ) ) ;
343- pb. set_style (
344- ProgressStyle :: with_template ( & format ! (
345- "{} {}Compiling... {{spinner}} {{pos}}/{{len}} {{msg}}" ,
346- format_step( current_step, total_steps) ,
347- SWORDS
348- ) )
349- . unwrap ( ) ,
350- ) ;
347+ let pb = if log_enabled ! ( Info ) {
348+ ProgressBar :: new ( build_state. modules . len ( ) . try_into ( ) . unwrap ( ) )
349+ } else {
350+ ProgressBar :: hidden ( )
351+ } ;
352+
351353 let ( compile_errors, compile_warnings, num_compiled_modules) =
352354 compile:: compile ( build_state, || pb. inc ( 1 ) , |size| pb. set_length ( size) ) ;
353355 let compile_duration = start_compiling. elapsed ( ) ;
@@ -359,17 +361,17 @@ pub fn incremental_build(
359361 pb. finish ( ) ;
360362 if !compile_errors. is_empty ( ) {
361363 if helpers:: contains_ascii_characters ( & compile_warnings) {
362- println ! ( "{}" , & compile_warnings) ;
364+ log :: error !( "{}" , & compile_warnings) ;
363365 }
364- println ! (
366+ log :: info !(
365367 "{}{} {}Compiled {} modules in {:.2}s" ,
366368 LINE_CLEAR ,
367369 format_step( current_step, total_steps) ,
368370 CROSS ,
369371 num_compiled_modules,
370372 default_timing. unwrap_or( compile_duration) . as_secs_f64( )
371373 ) ;
372- print ! ( "{}" , & compile_errors) ;
374+ log :: error !( "{}" , & compile_errors) ;
373375 // mark the original files as dirty again, because we didn't complete a full build
374376 for ( module_name, module) in build_state. modules . iter_mut ( ) {
375377 if tracked_dirty_modules. contains ( module_name) {
@@ -378,7 +380,7 @@ pub fn incremental_build(
378380 }
379381 Err ( IncrementalBuildError :: CompileError )
380382 } else {
381- println ! (
383+ log :: info !(
382384 "{}{} {}Compiled {} modules in {:.2}s" ,
383385 LINE_CLEAR ,
384386 format_step( current_step, total_steps) ,
@@ -387,7 +389,7 @@ pub fn incremental_build(
387389 default_timing. unwrap_or( compile_duration) . as_secs_f64( )
388390 ) ;
389391 if helpers:: contains_ascii_characters ( & compile_warnings) {
390- print ! ( "{}" , & compile_warnings) ;
392+ log :: warn !( "{}" , & compile_warnings) ;
391393 }
392394 Ok ( ( ) )
393395 }
@@ -433,7 +435,7 @@ pub fn build(
433435 match incremental_build ( & mut build_state, default_timing, true , false , create_sourcedirs) {
434436 Ok ( _) => {
435437 let timing_total_elapsed = timing_total. elapsed ( ) ;
436- println ! (
438+ log :: info !(
437439 "\n {}{}Finished Compilation in {:.2}s" ,
438440 LINE_CLEAR ,
439441 SPARKLES ,
0 commit comments