@@ -7560,9 +7560,11 @@ let bs_file_groups = ref []
7560
7560
7561
7561
let sourcedirs_meta = " .sourcedirs"
7562
7562
let merlin = " .merlin"
7563
- let merlin_header = " \n ####{BSB GENERATED: NO EDIT\n "
7564
- let merlin_trailer = " \n ####BSB GENERATED: NO EDIT}\n "
7563
+ let merlin_header = " ####{BSB GENERATED: NO EDIT"
7564
+ let merlin_trailer = " ####BSB GENERATED: NO EDIT}"
7565
7565
let merlin_trailer_length = String. length merlin_trailer
7566
+
7567
+ (* * [new_content] should start end finish with newline *)
7566
7568
let revise_merlin new_content =
7567
7569
if Sys. file_exists merlin then
7568
7570
let merlin_chan = open_in_bin merlin in
@@ -7572,27 +7574,33 @@ let revise_merlin new_content =
7572
7574
7573
7575
let header = Ext_string. find s ~sub: merlin_header in
7574
7576
let tail = Ext_string. find s ~sub: merlin_trailer in
7575
- if header < 0 && tail < 0 then
7577
+ if header < 0 && tail < 0 then (* locked region not added yet *)
7576
7578
let ochan = open_out_bin merlin in
7577
7579
output_string ochan s ;
7580
+ output_string ochan " \n " ;
7578
7581
output_string ochan merlin_header;
7579
7582
Buffer. output_buffer ochan new_content;
7580
7583
output_string ochan merlin_trailer ;
7584
+ output_string ochan " \n " ;
7581
7585
close_out ochan
7582
- else if header > = 0 && tail > = 0 then
7586
+ else if header > = 0 && tail > = 0 then
7587
+ (* there is one, hit it everytime,
7588
+ should be fixed point
7589
+ *)
7583
7590
let ochan = open_out_bin merlin in
7584
7591
output_string ochan (String. sub s 0 header) ;
7585
7592
output_string ochan merlin_header;
7586
7593
Buffer. output_buffer ochan new_content;
7587
7594
output_string ochan merlin_trailer ;
7588
7595
output_string ochan (Ext_string. tail_from s (tail + merlin_trailer_length));
7589
7596
close_out ochan
7590
- else assert false
7597
+ else failwith ( " the .merlin is corrupted, locked region by bsb is not consistent " )
7591
7598
else
7592
7599
let ochan = open_out_bin merlin in
7593
7600
output_string ochan merlin_header ;
7594
7601
Buffer. output_buffer ochan new_content;
7595
7602
output_string ochan merlin_trailer ;
7603
+ output_string ochan " \n " ;
7596
7604
close_out ochan
7597
7605
(* TODO: it is a little mess that [cwd] and [project dir] are shared*)
7598
7606
(* * *)
@@ -7616,11 +7624,12 @@ let write_ninja_file bsc_dir cwd =
7616
7624
let () =
7617
7625
Bsb_default. get_ppx_flags ()
7618
7626
|> List. iter (fun x ->
7619
- Buffer. add_string buffer (Printf. sprintf " FLG -ppx %s\n " x )
7627
+ Buffer. add_string buffer (Printf. sprintf " \n FLG -ppx %s" x )
7620
7628
)
7621
7629
in
7622
7630
let () = Buffer. add_string buffer
7623
- (Printf. sprintf " S %s\n \
7631
+ (Printf. sprintf " \n \
7632
+ S %s\n \
7624
7633
B %s\n \
7625
7634
FLG -ppx %s\n \
7626
7635
" lib_ocaml_dir lib_ocaml_dir bsppx
@@ -7630,7 +7639,7 @@ let write_ninja_file bsc_dir cwd =
7630
7639
| [] -> ()
7631
7640
| xs ->
7632
7641
Buffer. add_string buffer
7633
- (Printf. sprintf " FLG %s\n " (String. concat " " xs) ) in
7642
+ (Printf. sprintf " \n FLG %s" (String. concat " " xs) ) in
7634
7643
let () =
7635
7644
Bsb_default. get_bs_dependencies ()
7636
7645
|> List. iter (fun package ->
@@ -7646,7 +7655,7 @@ let write_ninja_file bsc_dir cwd =
7646
7655
in
7647
7656
res.files |> List. iter
7648
7657
(fun (x : Bsb_build_ui.file_group ) ->
7649
- output_string ochan x.dir;
7658
+ output_string ochan x.dir; (* to [.sourcedirs] *)
7650
7659
output_string ochan " \n " ;
7651
7660
Buffer. add_string buffer " \n S " ;
7652
7661
Buffer. add_string buffer x.dir ;
0 commit comments