@@ -18,6 +18,7 @@ use console::style;
1818use indicatif:: { ProgressBar , ProgressStyle } ;
1919use serde:: Serialize ;
2020use std:: fmt;
21+ use std:: fs:: File ;
2122use std:: io:: { stdout, Write } ;
2223use std:: path:: PathBuf ;
2324use std:: time:: { Duration , Instant } ;
@@ -52,7 +53,7 @@ pub struct CompilerArgs {
5253 pub parser_args : Vec < String > ,
5354}
5455
55- pub fn get_compiler_args ( path : & str , rescript_version : Option < String > ) -> String {
56+ pub fn get_compiler_args ( path : & str , rescript_version : Option < String > , bsc_path : Option < String > ) -> String {
5657 let filename = & helpers:: get_abs_path ( path) ;
5758 let package_root = helpers:: get_abs_path (
5859 & helpers:: get_nearest_bsconfig ( & std:: path:: PathBuf :: from ( path) ) . expect ( "Couldn't find package root" ) ,
@@ -64,7 +65,10 @@ pub fn get_compiler_args(path: &str, rescript_version: Option<String>) -> String
6465 let rescript_version = if let Some ( rescript_version) = rescript_version {
6566 rescript_version
6667 } else {
67- let bsc_path = helpers:: get_bsc ( & package_root, workspace_root. to_owned ( ) ) ;
68+ let bsc_path = match bsc_path {
69+ Some ( bsc_path) => bsc_path,
70+ None => helpers:: get_bsc ( & package_root, workspace_root. to_owned ( ) ) ,
71+ } ;
6872 helpers:: get_rescript_version ( & bsc_path)
6973 } ;
7074 // make PathBuf from package root and get the relative path for filename
@@ -134,10 +138,14 @@ pub fn initialize_build(
134138 default_timing : Option < Duration > ,
135139 filter : & Option < regex:: Regex > ,
136140 path : & str ,
141+ bsc_path : Option < String > ,
137142) -> Result < BuildState , InitializeBuildError > {
138143 let project_root = helpers:: get_abs_path ( path) ;
139144 let workspace_root = helpers:: get_workspace_root ( & project_root) ;
140- let bsc_path = helpers:: get_bsc ( & project_root, workspace_root. to_owned ( ) ) ;
145+ let bsc_path = match bsc_path {
146+ Some ( bsc_path) => bsc_path,
147+ None => helpers:: get_bsc ( & project_root, workspace_root. to_owned ( ) ) ,
148+ } ;
141149 let root_config_name = packages:: get_package_name ( & project_root) ;
142150 let rescript_version = helpers:: get_rescript_version ( & bsc_path) ;
143151
@@ -407,11 +415,26 @@ impl fmt::Display for BuildError {
407415 }
408416}
409417
418+ pub fn write_build_ninja ( build_state : & BuildState ) {
419+ // write build.ninja files in the packages after a non-incremental build
420+ // this is necessary to bust the editor tooling cache. The editor tooling
421+ // is watching this file.
422+ // we don't need to do this in an incremental build because there are no file
423+ // changes (deletes / additions)
424+ for package in build_state. packages . values ( ) {
425+ // write empty file:
426+ let mut f = File :: create ( std:: path:: Path :: new ( & package. get_bs_build_path ( ) ) . join ( "build.ninja" ) )
427+ . expect ( "Unable to write file" ) ;
428+ f. write_all ( b"" ) . expect ( "unable to write to ninja file" ) ;
429+ }
430+ }
431+
410432pub fn build (
411433 filter : & Option < regex:: Regex > ,
412434 path : & str ,
413435 no_timing : bool ,
414436 create_sourcedirs : bool ,
437+ bsc_path : Option < String > ,
415438) -> Result < BuildState , BuildError > {
416439 let default_timing: Option < std:: time:: Duration > = if no_timing {
417440 Some ( std:: time:: Duration :: new ( 0.0 as u64 , 0.0 as u32 ) )
@@ -420,7 +443,7 @@ pub fn build(
420443 } ;
421444 let timing_total = Instant :: now ( ) ;
422445 let mut build_state =
423- initialize_build ( default_timing, filter, path) . map_err ( BuildError :: InitializeBuild ) ?;
446+ initialize_build ( default_timing, filter, path, bsc_path ) . map_err ( BuildError :: InitializeBuild ) ?;
424447
425448 match incremental_build ( & mut build_state, default_timing, true , false , create_sourcedirs) {
426449 Ok ( _) => {
@@ -432,10 +455,12 @@ pub fn build(
432455 default_timing. unwrap_or( timing_total_elapsed) . as_secs_f64( )
433456 ) ;
434457 clean:: cleanup_after_build ( & build_state) ;
458+ write_build_ninja ( & build_state) ;
435459 Ok ( build_state)
436460 }
437461 Err ( e) => {
438462 clean:: cleanup_after_build ( & build_state) ;
463+ write_build_ninja ( & build_state) ;
439464 Err ( BuildError :: IncrementalBuild ( e) )
440465 }
441466 }
0 commit comments