@@ -458,6 +458,8 @@ external id : 'a -> 'a = "%identity"
458
458
val hash_variant : string -> int
459
459
460
460
val todo : string -> 'a
461
+
462
+ val digest_length : int
461
463
end = struct
462
464
#1 "ext_pervasives.ml"
463
465
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -546,6 +548,8 @@ let hash_variant s =
546
548
547
549
let todo loc =
548
550
failwith (loc ^ " Not supported yet")
551
+
552
+ let digest_length = 16
549
553
end
550
554
module Ext_string : sig
551
555
#1 "ext_string.mli"
@@ -12853,20 +12857,47 @@ let (//) = Ext_path.combine
12853
12857
12854
12858
12855
12859
12856
-
12857
- let output ~dir namespace
12860
+ let write_file fname digest contents =
12861
+ let oc = open_out_bin fname in
12862
+ Digest.output oc digest;
12863
+ output_char oc '\n';
12864
+ output_string oc contents;
12865
+ close_out oc
12866
+ (**
12867
+ TODO:
12868
+ sort filegroupts to ensure deterministic behavior
12869
+
12870
+ if [.bsbuild] is not changed
12871
+ [.mlmap] does not need to be changed too
12872
+
12873
+ *)
12874
+ let output
12875
+ ~dir
12876
+ (namespace : string)
12858
12877
(file_groups : Bsb_file_groups.file_groups )
12859
12878
=
12860
12879
let fname = namespace ^ Literals.suffix_mlmap in
12861
- let oc = open_out_bin (dir// fname ) in
12862
- List.iter
12863
- (fun (x : Bsb_file_groups.file_group) ->
12864
- String_map.iter x.sources (fun k _ ->
12865
- output_string oc k ;
12866
- output_string oc "\n"
12867
- )
12868
- ) file_groups ;
12869
- close_out oc
12880
+ let buf = Buffer.create 10000 in
12881
+ Ext_list.iter file_groups
12882
+ (fun x ->
12883
+ String_map.iter x.sources (fun k _ ->
12884
+ Buffer.add_string buf k ;
12885
+ Buffer.add_char buf '\n'
12886
+ )
12887
+ );
12888
+ let contents = Buffer.contents buf in
12889
+ let digest = Digest.string contents in
12890
+ let fname = (dir// fname ) in
12891
+ if Sys.file_exists fname then
12892
+ let ic = open_in_bin fname in
12893
+ let old_digest = really_input_string ic Ext_pervasives.digest_length in
12894
+ close_in ic ;
12895
+ (if old_digest <> digest then
12896
+ write_file fname digest contents)
12897
+ else
12898
+ write_file fname digest contents
12899
+
12900
+
12870
12901
end
12871
12902
module Bsb_ninja_global_vars
12872
12903
= struct
@@ -16875,6 +16906,8 @@ val load_file : string -> string
16875
16906
16876
16907
val rev_lines_of_file : string -> string list
16877
16908
16909
+ val rev_lines_of_chann : in_channel -> string list
16910
+
16878
16911
val write_file : string -> string -> unit
16879
16912
16880
16913
end = struct
@@ -16914,14 +16947,17 @@ let load_file f =
16914
16947
end
16915
16948
16916
16949
16917
- let rev_lines_of_file file =
16918
- Ext_pervasives.finally (open_in_bin file) close_in begin fun chan ->
16919
- let rec loop acc =
16950
+ let rev_lines_of_chann chan =
16951
+ let rec loop acc chan =
16920
16952
match input_line chan with
16921
- | line -> loop (line :: acc)
16953
+ | line -> loop (line :: acc) chan
16922
16954
| exception End_of_file -> close_in chan ; acc in
16923
- loop []
16924
- end
16955
+ loop [] chan
16956
+
16957
+
16958
+ let rev_lines_of_file file =
16959
+ Ext_pervasives.finally (open_in_bin file) close_in rev_lines_of_chann
16960
+
16925
16961
16926
16962
let write_file f content =
16927
16963
Ext_pervasives.finally (open_out_bin f) close_out begin fun oc ->
0 commit comments