@@ -56,6 +56,40 @@ pub struct CompilerArgs {
5656 pub parser_args : Vec < String > ,
5757}
5858
59+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
60+ pub struct IncrementalBuildResult {
61+ pub has_warnings : bool ,
62+ }
63+
64+ fn has_output ( output : & str ) -> bool {
65+ helpers:: contains_ascii_characters ( output)
66+ }
67+
68+ fn has_config_warnings ( build_state : & BuildCommandState ) -> bool {
69+ build_state. packages . iter ( ) . any ( |( _, package) | {
70+ package. is_local_dep
71+ && ( !package. config . get_unsupported_fields ( ) . is_empty ( )
72+ || !package. config . get_unknown_fields ( ) . is_empty ( ) )
73+ } )
74+ }
75+
76+ pub fn format_finished_compilation_message (
77+ compilation_kind : Option < & str > ,
78+ has_warnings : bool ,
79+ duration : Duration ,
80+ ) -> String {
81+ let compilation_kind = compilation_kind
82+ . map ( |kind| format ! ( "{kind} " ) )
83+ . unwrap_or_default ( ) ;
84+ let status = if has_warnings { WARNING } else { CHECKMARK } ;
85+ let warning_suffix = if has_warnings { " with warnings" } else { "" } ;
86+
87+ format ! (
88+ "{LINE_CLEAR}{status}Finished {compilation_kind}compilation{warning_suffix} in {:.2}s" ,
89+ duration. as_secs_f64( )
90+ )
91+ }
92+
5993pub fn get_compiler_args ( rescript_file_path : & Path ) -> Result < String > {
6094 let filename = & helpers:: get_abs_path ( rescript_file_path) ;
6195 let current_package = helpers:: get_abs_path (
@@ -246,7 +280,7 @@ pub fn incremental_build(
246280 only_incremental : bool ,
247281 create_sourcedirs : bool ,
248282 plain_output : bool ,
249- ) -> Result < ( ) , IncrementalBuildError > {
283+ ) -> Result < IncrementalBuildResult , IncrementalBuildError > {
250284 let build_folder = build_state. root_folder . to_string_lossy ( ) . to_string ( ) ;
251285
252286 let _lock = get_lock_or_exit ( LockKind :: Build , & build_folder) ;
@@ -264,7 +298,7 @@ pub fn incremental_build(
264298 ProgressStyle :: with_template ( & format ! (
265299 "{} {}Parsing... {{spinner}} {{pos}}/{{len}} {{msg}}" ,
266300 format_step( current_step, total_steps) ,
267- CODE
301+ PARSE
268302 ) )
269303 . unwrap ( ) ,
270304 ) ;
@@ -314,13 +348,14 @@ pub fn incremental_build(
314348 "{}{} {}Parsed {} source files in {:.2}s" ,
315349 LINE_CLEAR ,
316350 format_step( current_step, total_steps) ,
317- CODE ,
351+ PARSE ,
318352 num_dirty_modules,
319353 default_timing. unwrap_or( timing_parse_total) . as_secs_f64( )
320354 ) ;
321355 }
322356 }
323- if helpers:: contains_ascii_characters ( & parse_warnings) {
357+ let has_parse_warnings = has_output ( & parse_warnings) ;
358+ if has_parse_warnings {
324359 eprintln ! ( "{}" , & parse_warnings) ;
325360 }
326361
@@ -389,13 +424,13 @@ pub fn incremental_build(
389424 ) ;
390425 }
391426 }
392- if helpers :: contains_ascii_characters ( & compile_warnings) {
427+ if has_output ( & compile_warnings) {
393428 eprintln ! ( "{}" , & compile_warnings) ;
394429 }
395430 if initial_build {
396431 log_config_warnings ( build_state) ;
397432 }
398- if helpers :: contains_ascii_characters ( & compile_errors) {
433+ if has_output ( & compile_errors) {
399434 eprintln ! ( "{}" , & compile_errors) ;
400435 }
401436
@@ -406,6 +441,10 @@ pub fn incremental_build(
406441 plain_output,
407442 } )
408443 } else {
444+ let has_compile_warnings = has_output ( & compile_warnings) ;
445+ let has_config_warning_output = initial_build && has_config_warnings ( build_state) ;
446+ let has_warnings = has_parse_warnings || has_compile_warnings || has_config_warning_output;
447+
409448 if show_progress {
410449 if plain_output {
411450 println ! ( "Compiled {num_compiled_modules} modules" )
@@ -421,7 +460,7 @@ pub fn incremental_build(
421460 }
422461 }
423462
424- if helpers :: contains_ascii_characters ( & compile_warnings ) {
463+ if has_compile_warnings {
425464 eprintln ! ( "{}" , & compile_warnings) ;
426465 }
427466 if initial_build {
@@ -432,7 +471,7 @@ pub fn incremental_build(
432471 write_compiler_info ( build_state) ;
433472
434473 let _lock = drop_lock ( LockKind :: Build , & build_folder) ;
435- Ok ( ( ) )
474+ Ok ( IncrementalBuildResult { has_warnings } )
436475 }
437476}
438477
@@ -519,14 +558,16 @@ pub fn build(
519558 create_sourcedirs,
520559 plain_output,
521560 ) {
522- Ok ( _ ) => {
561+ Ok ( result ) => {
523562 if !plain_output && show_progress {
524563 let timing_total_elapsed = timing_total. elapsed ( ) ;
525564 println ! (
526- "\n {}{}Finished Compilation in {:.2}s" ,
527- LINE_CLEAR ,
528- SPARKLES ,
529- default_timing. unwrap_or( timing_total_elapsed) . as_secs_f64( )
565+ "\n {}" ,
566+ format_finished_compilation_message(
567+ None ,
568+ result. has_warnings,
569+ default_timing. unwrap_or( timing_total_elapsed) ,
570+ )
530571 ) ;
531572 }
532573 clean:: cleanup_after_build ( & build_state) ;
@@ -540,3 +581,27 @@ pub fn build(
540581 }
541582 }
542583}
584+
585+ #[ cfg( test) ]
586+ mod tests {
587+ use super :: * ;
588+
589+ #[ test]
590+ fn formats_successful_completion_message ( ) {
591+ assert_eq ! (
592+ format_finished_compilation_message( None , false , Duration :: from_millis( 1500 ) ) ,
593+ format!( "{LINE_CLEAR}{}Finished compilation in 1.50s" , CHECKMARK )
594+ ) ;
595+ }
596+
597+ #[ test]
598+ fn formats_warning_completion_message ( ) {
599+ assert_eq ! (
600+ format_finished_compilation_message( Some ( "incremental" ) , true , Duration :: from_millis( 1500 ) ) ,
601+ format!(
602+ "{LINE_CLEAR}{}Finished incremental compilation with warnings in 1.50s" ,
603+ WARNING
604+ )
605+ ) ;
606+ }
607+ }
0 commit comments