@@ -12387,6 +12387,7 @@ module Bsb_ninja_check : sig
12387
12387
12388
12388
type check_result =
12389
12389
| Good
12390
+ | Bsb_file_corrupted
12390
12391
| Bsb_file_not_exist (** We assume that it is a clean repo *)
12391
12392
| Bsb_source_directory_changed
12392
12393
| Bsb_bsc_version_mismatch
@@ -12449,23 +12450,69 @@ end = struct
12449
12450
* along with this program; if not, write to the Free Software
12450
12451
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
12451
12452
12453
+ [@@@warning "+9"]
12452
12454
12453
12455
type t =
12454
12456
{
12455
12457
dir_or_files : string array ;
12456
12458
st_mtimes : float array;
12457
12459
source_directory : string ;
12458
12460
}
12461
+ (* float_of_string_opt *)
12462
+ external hexstring_of_float : float -> int -> char -> string
12463
+ = "caml_hexstring_of_float"
12464
+
12465
+ let hex_of_float f = hexstring_of_float f (-1) '-'
12459
12466
12467
+ (* This should not lose any preicision *)
12468
+ (* let id (f : float) =
12469
+ float_of_string (hex_of_float f) = f
12470
+ *)
12471
+
12472
+ let encode ( {source_directory ; st_mtimes; dir_or_files} : t )
12473
+ (buf: Ext_buffer.t)=
12474
+ Ext_buffer.add_string_char buf Bs_version.version '\n';
12475
+ Ext_buffer.add_string_char buf source_directory '\n';
12476
+ let dir_or_files_len = Array.length dir_or_files in
12477
+ (if dir_or_files_len <> 0 then begin
12478
+ Ext_buffer.add_string buf dir_or_files.(0);
12479
+ for i = 1 to dir_or_files_len - 1 do
12480
+ Ext_buffer.add_char_string buf '\t' dir_or_files.(i)
12481
+ done
12482
+ end);
12483
+ Ext_buffer.add_char buf '\n';
12484
+ let st_mtimes_len = Array.length st_mtimes in
12485
+ (if st_mtimes_len <> 0 then begin
12486
+ Ext_buffer.add_string buf (hex_of_float st_mtimes.(0));
12487
+ for i = 1 to st_mtimes_len - 1 do
12488
+ Ext_buffer.add_char_string buf '\t' (hex_of_float st_mtimes.(i))
12489
+ done
12490
+ end);
12491
+ Ext_buffer.add_char buf '\n'
12492
+
12493
+ let decode_exn ic =
12494
+ let source_directory = input_line ic in
12495
+ let dir_or_files = input_line ic in
12496
+ let dir_or_files =
12497
+ Array.of_list
12498
+ (Ext_string.split dir_or_files '\t') in
12499
+ let st_mtimes_line =
12500
+ input_line ic in
12501
+ let st_mtimes =
12502
+ Ext_array.of_list_map
12503
+ (Ext_string.split st_mtimes_line '\t')
12504
+ (fun x -> float_of_string x) in
12505
+ close_in ic ;
12506
+ {dir_or_files; st_mtimes; source_directory}
12460
12507
12461
- let magic_number = Bs_version.version
12462
12508
12463
12509
(* TODO: for such small data structure, maybe text format is better *)
12464
12510
12465
12511
let write (fname : string) (x : t) =
12512
+ let buf = Ext_buffer.create 1_000 in
12513
+ encode x buf;
12466
12514
let oc = open_out_bin fname in
12467
- output_string oc magic_number ;
12468
- output_value oc x ;
12515
+ Ext_buffer.output_buffer oc buf ;
12469
12516
close_out oc
12470
12517
12471
12518
@@ -12474,6 +12521,7 @@ let write (fname : string) (x : t) =
12474
12521
12475
12522
type check_result =
12476
12523
| Good
12524
+ | Bsb_file_corrupted
12477
12525
| Bsb_file_not_exist (** We assume that it is a clean repo *)
12478
12526
| Bsb_source_directory_changed
12479
12527
| Bsb_bsc_version_mismatch
@@ -12483,6 +12531,7 @@ type check_result =
12483
12531
let pp_check_result fmt (check_resoult : check_result) =
12484
12532
Format.pp_print_string fmt (match check_resoult with
12485
12533
| Good -> "OK"
12534
+ | Bsb_file_corrupted -> "Stored data corrupted"
12486
12535
| Bsb_file_not_exist -> "Dependencies information missing"
12487
12536
| Bsb_source_directory_changed ->
12488
12537
"Bsb source directory changed"
@@ -12502,17 +12551,10 @@ let rec check_aux cwd (xs : string array) (ys: float array) i finish =
12502
12551
check_aux cwd xs ys (i + 1 ) finish
12503
12552
else Other current_file
12504
12553
12554
+
12555
+
12556
+
12505
12557
12506
- let read (fname : string) (cont : t -> check_result) =
12507
- match open_in_bin fname with (* Windows binary mode*)
12508
- | ic ->
12509
- let buffer = really_input_string ic (String.length magic_number) in
12510
- if (buffer <> magic_number) then Bsb_bsc_version_mismatch
12511
- else
12512
- let res : t = input_value ic in
12513
- close_in ic ;
12514
- cont res
12515
- | exception _ -> Bsb_file_not_exist
12516
12558
12517
12559
let record ~per_proj_dir ~file (file_or_dirs : string list) : unit =
12518
12560
let dir_or_files = Array.of_list file_or_dirs in
@@ -12522,8 +12564,9 @@ let record ~per_proj_dir ~file (file_or_dirs : string list) : unit =
12522
12564
(Unix.stat (Filename.concat per_proj_dir x )).st_mtime
12523
12565
)
12524
12566
in
12525
- write (file ^ "_js" )
12526
- { st_mtimes ;
12567
+ write file
12568
+ {
12569
+ st_mtimes ;
12527
12570
dir_or_files;
12528
12571
source_directory = per_proj_dir ;
12529
12572
}
@@ -12535,21 +12578,28 @@ let record ~per_proj_dir ~file (file_or_dirs : string list) : unit =
12535
12578
bit in case we found a different version of compiler
12536
12579
*)
12537
12580
let check ~(per_proj_dir:string) ~forced ~file : check_result =
12538
- read ( file ^ "_js" ) (fun {
12539
- dir_or_files ; source_directory; st_mtimes
12540
- } ->
12541
- if per_proj_dir <> source_directory then Bsb_source_directory_changed else
12542
- if forced then Bsb_forced (* No need walk through *)
12543
- else
12544
- try
12545
- check_aux per_proj_dir dir_or_files st_mtimes 0 (Array.length dir_or_files)
12546
- with e ->
12547
- begin
12548
- Bsb_log.info
12549
- "@{<info>Stat miss %s@}@."
12550
- (Printexc.to_string e);
12551
- Bsb_file_not_exist
12552
- end)
12581
+ match open_in_bin file with (* Windows binary mode*)
12582
+ | exception _ -> Bsb_file_not_exist
12583
+ | ic ->
12584
+ if input_line ic <> Bs_version.version then Bsb_bsc_version_mismatch
12585
+ else
12586
+ match decode_exn ic with
12587
+ | exception _ -> Bsb_file_corrupted (* corrupted file *)
12588
+ | {
12589
+ dir_or_files ; source_directory; st_mtimes
12590
+ } ->
12591
+ if per_proj_dir <> source_directory then Bsb_source_directory_changed else
12592
+ if forced then Bsb_forced (* No need walk through *)
12593
+ else
12594
+ try
12595
+ check_aux per_proj_dir dir_or_files st_mtimes 0 (Array.length dir_or_files)
12596
+ with e ->
12597
+ begin
12598
+ Bsb_log.info
12599
+ "@{<info>Stat miss %s@}@."
12600
+ (Printexc.to_string e);
12601
+ Bsb_file_not_exist
12602
+ end
12553
12603
12554
12604
12555
12605
end
@@ -14490,7 +14540,8 @@ let regenerate_ninja
14490
14540
| Good ->
14491
14541
None (* Fast path, no need regenerate ninja *)
14492
14542
| Bsb_forced
14493
- | Bsb_bsc_version_mismatch
14543
+ | Bsb_bsc_version_mismatch
14544
+ | Bsb_file_corrupted
14494
14545
| Bsb_file_not_exist
14495
14546
| Bsb_source_directory_changed
14496
14547
| Other _ ->
0 commit comments