@@ -18,6 +18,7 @@ use console::style;
18
18
use indicatif:: { ProgressBar , ProgressStyle } ;
19
19
use serde:: Serialize ;
20
20
use std:: fmt;
21
+ use std:: fs:: File ;
21
22
use std:: io:: { stdout, Write } ;
22
23
use std:: path:: PathBuf ;
23
24
use std:: time:: { Duration , Instant } ;
@@ -52,7 +53,7 @@ pub struct CompilerArgs {
52
53
pub parser_args : Vec < String > ,
53
54
}
54
55
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 {
56
57
let filename = & helpers:: get_abs_path ( path) ;
57
58
let package_root = helpers:: get_abs_path (
58
59
& 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
64
65
let rescript_version = if let Some ( rescript_version) = rescript_version {
65
66
rescript_version
66
67
} 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
+ } ;
68
72
helpers:: get_rescript_version ( & bsc_path)
69
73
} ;
70
74
// make PathBuf from package root and get the relative path for filename
@@ -134,10 +138,14 @@ pub fn initialize_build(
134
138
default_timing : Option < Duration > ,
135
139
filter : & Option < regex:: Regex > ,
136
140
path : & str ,
141
+ bsc_path : Option < String > ,
137
142
) -> Result < BuildState , InitializeBuildError > {
138
143
let project_root = helpers:: get_abs_path ( path) ;
139
144
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
+ } ;
141
149
let root_config_name = packages:: get_package_name ( & project_root) ;
142
150
let rescript_version = helpers:: get_rescript_version ( & bsc_path) ;
143
151
@@ -407,11 +415,26 @@ impl fmt::Display for BuildError {
407
415
}
408
416
}
409
417
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
+
410
432
pub fn build (
411
433
filter : & Option < regex:: Regex > ,
412
434
path : & str ,
413
435
no_timing : bool ,
414
436
create_sourcedirs : bool ,
437
+ bsc_path : Option < String > ,
415
438
) -> Result < BuildState , BuildError > {
416
439
let default_timing: Option < std:: time:: Duration > = if no_timing {
417
440
Some ( std:: time:: Duration :: new ( 0.0 as u64 , 0.0 as u32 ) )
@@ -420,7 +443,7 @@ pub fn build(
420
443
} ;
421
444
let timing_total = Instant :: now ( ) ;
422
445
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 ) ?;
424
447
425
448
match incremental_build ( & mut build_state, default_timing, true , false , create_sourcedirs) {
426
449
Ok ( _) => {
@@ -432,10 +455,12 @@ pub fn build(
432
455
default_timing. unwrap_or( timing_total_elapsed) . as_secs_f64( )
433
456
) ;
434
457
clean:: cleanup_after_build ( & build_state) ;
458
+ write_build_ninja ( & build_state) ;
435
459
Ok ( build_state)
436
460
}
437
461
Err ( e) => {
438
462
clean:: cleanup_after_build ( & build_state) ;
463
+ write_build_ninja ( & build_state) ;
439
464
Err ( BuildError :: IncrementalBuild ( e) )
440
465
}
441
466
}
0 commit comments