24
24
25
25
[@@@ warning " +9" ]
26
26
27
- type t =
28
- {
29
- dir_or_files : string array ;
30
- st_mtimes : float array ;
31
- source_directory : string ;
32
- }
33
27
(* float_of_string_opt *)
34
28
external hexstring_of_float : float -> int -> char -> string
35
29
= " caml_hexstring_of_float"
@@ -41,54 +35,6 @@ let hex_of_float f = hexstring_of_float f (-1) '-'
41
35
float_of_string (hex_of_float f) = f
42
36
*)
43
37
44
- let encode ( {source_directory ; st_mtimes; dir_or_files} : t )
45
- (buf : Ext_buffer.t )=
46
- Ext_buffer. add_string_char buf Bs_version. version '\n' ;
47
- Ext_buffer. add_string_char buf source_directory '\n' ;
48
- let dir_or_files_len = Array. length dir_or_files in
49
- (if dir_or_files_len <> 0 then begin
50
- Ext_buffer. add_string buf dir_or_files.(0 );
51
- for i = 1 to dir_or_files_len - 1 do
52
- Ext_buffer. add_char_string buf '\t' dir_or_files.(i)
53
- done
54
- end );
55
- Ext_buffer. add_char buf '\n' ;
56
- let st_mtimes_len = Array. length st_mtimes in
57
- (if st_mtimes_len <> 0 then begin
58
- Ext_buffer. add_string buf (hex_of_float st_mtimes.(0 ));
59
- for i = 1 to st_mtimes_len - 1 do
60
- Ext_buffer. add_char_string buf '\t' (hex_of_float st_mtimes.(i))
61
- done
62
- end );
63
- Ext_buffer. add_char buf '\n'
64
-
65
- let decode_exn ic =
66
- let source_directory = input_line ic in
67
- let dir_or_files = input_line ic in
68
- let dir_or_files =
69
- Array. of_list
70
- (Ext_string. split dir_or_files '\t' ) in
71
- let st_mtimes_line =
72
- input_line ic in
73
- let st_mtimes =
74
- Ext_array. of_list_map
75
- (Ext_string. split st_mtimes_line '\t' )
76
- (fun x -> float_of_string x) in
77
- close_in ic ;
78
- {dir_or_files; st_mtimes; source_directory}
79
-
80
-
81
- (* TODO: for such small data structure, maybe text format is better *)
82
-
83
- let write (fname : string ) (x : t ) =
84
- let buf = Ext_buffer. create 1_000 in
85
- encode x buf;
86
- let oc = open_out_bin fname in
87
- Ext_buffer. output_buffer oc buf ;
88
- close_out oc
89
-
90
-
91
-
92
38
93
39
94
40
type check_result =
@@ -113,35 +59,66 @@ let pp_check_result fmt (check_resoult : check_result) =
113
59
" Bsb forced rebuild"
114
60
| Other s -> s)
115
61
116
- let rec check_aux cwd (xs : string array ) (ys : float array ) i finish =
117
- if i = finish then Good
118
- else
119
- let current_file = Array. unsafe_get xs i in
120
-
121
- let stat = Unix. stat (Filename. concat cwd current_file) in
122
- if stat.st_mtime < = Array. unsafe_get ys i then
123
- check_aux cwd xs ys (i + 1 ) finish
124
- else Other current_file
125
-
126
-
62
+ let rec check_aux cwd (xs : string list ) =
63
+ match xs with
64
+ | [] -> Good
65
+ | "===" :: rest ->
66
+ check_global rest
67
+ | item :: rest
68
+ ->
69
+ match Ext_string. split item '\t' with
70
+ | [file; stamp] ->
71
+ let stamp = float_of_string stamp in
72
+ let cur_file = (Filename. concat cwd file) in
73
+ let stat = Unix. stat cur_file in
74
+ if stat.st_mtime < = stamp then
75
+ check_aux cwd rest
76
+ else Other cur_file
77
+ | _ -> Bsb_file_corrupted
78
+ and check_global rest =
79
+ match rest with
80
+ | [] -> Good
81
+ | item :: rest ->
82
+ match Ext_string. split item '\t' with
83
+ | [file; stamp] ->
84
+ let stamp = float_of_string stamp in
85
+ let cur_file = file in
86
+ let stat = Unix. stat cur_file in
87
+ if stat.st_mtime <> stamp then
88
+ check_global rest
89
+ else Other cur_file
90
+ | _ -> Bsb_file_corrupted
127
91
128
92
93
+ (* TODO: for such small data structure, maybe text format is better *)
129
94
130
95
131
- let record ~per_proj_dir ~file (file_or_dirs : string list ) : unit =
132
- let dir_or_files = Array. of_list file_or_dirs in
133
- let st_mtimes =
134
- Ext_array. map dir_or_files
135
- (fun x ->
136
- (Unix. stat (Filename. concat per_proj_dir x )).st_mtime
137
- )
138
- in
139
- write file
140
- {
141
- st_mtimes ;
142
- dir_or_files;
143
- source_directory = per_proj_dir ;
144
- }
96
+ let record
97
+ ~per_proj_dir ~file
98
+ ~(config :Bsb_config_types.t ) (file_or_dirs : string list ) : unit =
99
+ let _ = config in
100
+ let buf = Ext_buffer. create 1_000 in
101
+ Ext_buffer. add_string_char buf Bs_version. version '\n' ;
102
+ Ext_buffer. add_string_char buf per_proj_dir '\n' ;
103
+ Ext_list. iter file_or_dirs (fun f ->
104
+ Ext_buffer. add_string_char buf f '\t' ;
105
+ Ext_buffer. add_string_char buf
106
+ (hex_of_float (Unix. stat (Filename. concat per_proj_dir f)).st_mtime) '\n' ;
107
+ );
108
+ begin match config.ppx_files with
109
+ | [] -> ()
110
+ | files ->
111
+ Ext_buffer. add_string buf " ===\n " ;
112
+ Ext_list. iter files (fun {name ; args = _ } ->
113
+ try
114
+ let stamp = (Unix. stat name).st_mtime in
115
+ Ext_buffer. add_string_char buf name '\t' ;
116
+ Ext_buffer. add_string_char buf (hex_of_float stamp) '\n'
117
+ with _ -> () )
118
+ end ;
119
+ let oc = open_out_bin file in
120
+ Ext_buffer. output_buffer oc buf ;
121
+ close_out oc
145
122
146
123
(* * check time stamp for all files
147
124
TODO: those checks system call can be saved later
@@ -153,23 +130,23 @@ let check ~(per_proj_dir:string) ~forced ~file : check_result =
153
130
match open_in_bin file with (* Windows binary mode*)
154
131
| exception _ -> Bsb_file_not_exist
155
132
| ic ->
156
- if input_line ic <> Bs_version. version then Bsb_bsc_version_mismatch
157
- else
158
- match decode_exn ic with
159
- | exception _ -> Bsb_file_corrupted (* corrupted file *)
160
- | {
161
- dir_or_files ; source_directory; st_mtimes
162
- } ->
133
+ match List. rev (Ext_io. rev_lines_of_chann ic) with
134
+ | exception _ -> Bsb_file_corrupted
135
+ | version :: source_directory :: dir_or_files ->
136
+ if version <> Bs_version. version then Bsb_bsc_version_mismatch
137
+ else
163
138
if per_proj_dir <> source_directory then Bsb_source_directory_changed else
164
139
if forced then Bsb_forced (* No need walk through *)
165
- else
140
+ else begin
166
141
try
167
- check_aux per_proj_dir dir_or_files st_mtimes 0 ( Array. length dir_or_files)
142
+ check_aux per_proj_dir dir_or_files
168
143
with e ->
169
144
begin
170
145
Bsb_log. info
171
146
" @{<info>Stat miss %s@}@."
172
147
(Printexc. to_string e);
173
148
Bsb_file_not_exist
174
149
end
150
+ end
151
+ | _ -> Bsb_file_corrupted
175
152
0 commit comments