@@ -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 (
@@ -245,7 +279,7 @@ pub fn incremental_build(
245279 only_incremental : bool ,
246280 create_sourcedirs : bool ,
247281 plain_output : bool ,
248- ) -> Result < ( ) , IncrementalBuildError > {
282+ ) -> Result < IncrementalBuildResult , IncrementalBuildError > {
249283 let build_folder = build_state. root_folder . to_string_lossy ( ) . to_string ( ) ;
250284
251285 let _lock = get_lock_or_exit ( LockKind :: Build , & build_folder) ;
@@ -263,7 +297,7 @@ pub fn incremental_build(
263297 ProgressStyle :: with_template ( & format ! (
264298 "{} {}Parsing... {{spinner}} {{pos}}/{{len}} {{msg}}" ,
265299 format_step( current_step, total_steps) ,
266- CODE
300+ PARSE
267301 ) )
268302 . unwrap ( ) ,
269303 ) ;
@@ -313,13 +347,14 @@ pub fn incremental_build(
313347 "{}{} {}Parsed {} source files in {:.2}s" ,
314348 LINE_CLEAR ,
315349 format_step( current_step, total_steps) ,
316- CODE ,
350+ PARSE ,
317351 num_dirty_modules,
318352 default_timing. unwrap_or( timing_parse_total) . as_secs_f64( )
319353 ) ;
320354 }
321355 }
322- if helpers:: contains_ascii_characters ( & parse_warnings) {
356+ let has_parse_warnings = has_output ( & parse_warnings) ;
357+ if has_parse_warnings {
323358 eprintln ! ( "{}" , & parse_warnings) ;
324359 }
325360
@@ -388,13 +423,13 @@ pub fn incremental_build(
388423 ) ;
389424 }
390425 }
391- if helpers :: contains_ascii_characters ( & compile_warnings) {
426+ if has_output ( & compile_warnings) {
392427 eprintln ! ( "{}" , & compile_warnings) ;
393428 }
394429 if initial_build {
395430 log_config_warnings ( build_state) ;
396431 }
397- if helpers :: contains_ascii_characters ( & compile_errors) {
432+ if has_output ( & compile_errors) {
398433 eprintln ! ( "{}" , & compile_errors) ;
399434 }
400435
@@ -405,6 +440,10 @@ pub fn incremental_build(
405440 plain_output,
406441 } )
407442 } else {
443+ let has_compile_warnings = has_output ( & compile_warnings) ;
444+ let has_config_warning_output = initial_build && has_config_warnings ( build_state) ;
445+ let has_warnings = has_parse_warnings || has_compile_warnings || has_config_warning_output;
446+
408447 if show_progress {
409448 if plain_output {
410449 println ! ( "Compiled {num_compiled_modules} modules" )
@@ -420,7 +459,7 @@ pub fn incremental_build(
420459 }
421460 }
422461
423- if helpers :: contains_ascii_characters ( & compile_warnings ) {
462+ if has_compile_warnings {
424463 eprintln ! ( "{}" , & compile_warnings) ;
425464 }
426465 if initial_build {
@@ -431,7 +470,7 @@ pub fn incremental_build(
431470 write_compiler_info ( build_state) ;
432471
433472 let _lock = drop_lock ( LockKind :: Build , & build_folder) ;
434- Ok ( ( ) )
473+ Ok ( IncrementalBuildResult { has_warnings } )
435474 }
436475}
437476
@@ -518,14 +557,16 @@ pub fn build(
518557 create_sourcedirs,
519558 plain_output,
520559 ) {
521- Ok ( _ ) => {
560+ Ok ( result ) => {
522561 if !plain_output && show_progress {
523562 let timing_total_elapsed = timing_total. elapsed ( ) ;
524563 println ! (
525- "\n {}{}Finished Compilation in {:.2}s" ,
526- LINE_CLEAR ,
527- SPARKLES ,
528- default_timing. unwrap_or( timing_total_elapsed) . as_secs_f64( )
564+ "\n {}" ,
565+ format_finished_compilation_message(
566+ None ,
567+ result. has_warnings,
568+ default_timing. unwrap_or( timing_total_elapsed) ,
569+ )
529570 ) ;
530571 }
531572 clean:: cleanup_after_build ( & build_state) ;
@@ -539,3 +580,27 @@ pub fn build(
539580 }
540581 }
541582}
583+
584+ #[ cfg( test) ]
585+ mod tests {
586+ use super :: * ;
587+
588+ #[ test]
589+ fn formats_successful_completion_message ( ) {
590+ assert_eq ! (
591+ format_finished_compilation_message( None , false , Duration :: from_millis( 1500 ) ) ,
592+ format!( "{LINE_CLEAR}{}Finished compilation in 1.50s" , CHECKMARK )
593+ ) ;
594+ }
595+
596+ #[ test]
597+ fn formats_warning_completion_message ( ) {
598+ assert_eq ! (
599+ format_finished_compilation_message( Some ( "incremental" ) , true , Duration :: from_millis( 1500 ) ) ,
600+ format!(
601+ "{LINE_CLEAR}{}Finished incremental compilation with warnings in 1.50s" ,
602+ WARNING
603+ )
604+ ) ;
605+ }
606+ }
0 commit comments