Skip to content

Commit 32842fd

Browse files
authored
Merge pull request #4756 from rescript-lang/track_ppx_changes
rebuild when ppx binary changes
2 parents 3e4c4a4 + 8a1d17d commit 32842fd

16 files changed

+171
-199
lines changed

darwin/ninja.exe

8 Bytes
Binary file not shown.

jscomp/bsb/bsb_ninja_check.ml

Lines changed: 65 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424

2525
[@@@warning "+9"]
2626

27-
type t =
28-
{
29-
dir_or_files : string array ;
30-
st_mtimes : float array;
31-
source_directory : string ;
32-
}
3327
(* float_of_string_opt *)
3428
external hexstring_of_float : float -> int -> char -> string
3529
= "caml_hexstring_of_float"
@@ -41,54 +35,6 @@ let hex_of_float f = hexstring_of_float f (-1) '-'
4135
float_of_string (hex_of_float f) = f
4236
*)
4337

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-
9238

9339

9440
type check_result =
@@ -113,35 +59,66 @@ let pp_check_result fmt (check_resoult : check_result) =
11359
"Bsb forced rebuild"
11460
| Other s -> s)
11561

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
12791

12892

93+
(* TODO: for such small data structure, maybe text format is better *)
12994

13095

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
145122

146123
(** check time stamp for all files
147124
TODO: those checks system call can be saved later
@@ -153,23 +130,23 @@ let check ~(per_proj_dir:string) ~forced ~file : check_result =
153130
match open_in_bin file with (* Windows binary mode*)
154131
| exception _ -> Bsb_file_not_exist
155132
| 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
163138
if per_proj_dir <> source_directory then Bsb_source_directory_changed else
164139
if forced then Bsb_forced (* No need walk through *)
165-
else
140+
else begin
166141
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
168143
with e ->
169144
begin
170145
Bsb_log.info
171146
"@{<info>Stat miss %s@}@."
172147
(Printexc.to_string e);
173148
Bsb_file_not_exist
174149
end
150+
end
151+
| _ -> Bsb_file_corrupted
175152

jscomp/bsb/bsb_ninja_check.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ val pp_check_result :
6262
val record :
6363
per_proj_dir:string ->
6464
file:string ->
65+
config:Bsb_config_types.t ->
6566
string list ->
6667
unit
6768

jscomp/bsb/bsb_ninja_gen.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ let output_ninja_and_namespace_map
117117
} : Bsb_config_types.t) : unit
118118
=
119119
let lib_artifacts_dir = Bsb_config.lib_bs in
120-
let cwd_lib_bs = per_proj_dir // lib_artifacts_dir in
121-
let ppx_flags = Bsb_build_util.ppx_flags ppx_files in
120+
let cwd_lib_bs = per_proj_dir // lib_artifacts_dir in
122121
let oc = open_out_bin (cwd_lib_bs // Literals.build_ninja) in
123122
let warnings = Bsb_warning.to_bsb_string ~toplevel warning in
124123
let bsc_flags = (get_bsc_flags bsc_flags) in
@@ -180,7 +179,7 @@ let output_ninja_and_namespace_map
180179
~bsc:bsc_path
181180
~warnings
182181
~bs_dep
183-
~ppx_flags
182+
~ppx_files
184183
~bsc_flags
185184
~dpkg_incls (* dev dependencies *)
186185
~lib_incls (* its own libs *)

jscomp/bsb/bsb_ninja_regen.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ let regenerate_ninja
5858
Bsb_clean.clean_self per_proj_dir;
5959
end ;
6060

61-
let config =
61+
let config : Bsb_config_types.t =
6262
Bsb_config_parse.interpret_json
6363
~toplevel_package_specs
6464
~per_proj_dir in
@@ -80,7 +80,7 @@ let regenerate_ninja
8080
~per_proj_dir ~toplevel config ;
8181
(* PR2184: we still need record empty dir
8282
since it may add files in the future *)
83-
Bsb_ninja_check.record ~per_proj_dir ~file:output_deps
83+
Bsb_ninja_check.record ~per_proj_dir ~config ~file:output_deps
8484
(Literals.bsconfig_json::config.file_groups.globbed_dirs) ;
8585
Some config
8686

jscomp/bsb/bsb_ninja_rule.ml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ let make_custom_rules
127127
~bsc
128128
~warnings
129129
~bs_dep
130-
~ppx_flags
130+
~(ppx_files : Bsb_config_types.ppx list)
131131
~bsc_flags
132132
~dpkg_incls
133133
~lib_incls
@@ -186,6 +186,16 @@ let make_custom_rules
186186
Ext_buffer.add_char_string buf ' ' warnings;
187187
Ext_buffer.add_string buf " -bs-v ";
188188
Ext_buffer.add_string buf Bs_version.version;
189+
(match ppx_files with
190+
| [ ] -> ()
191+
| _ ->
192+
Ext_list.iter ppx_files (fun x ->
193+
match string_of_float (Unix.stat x.name).st_mtime with
194+
| exception _ -> ()
195+
| st -> Ext_buffer.add_char_string buf ',' st
196+
);
197+
Ext_buffer.add_char_string buf ' '
198+
(Bsb_build_util.ppx_flags ppx_files));
189199
(match refmt with
190200
| None -> ()
191201
| Some x ->
@@ -205,7 +215,6 @@ let make_custom_rules
205215
-> Ext_buffer.add_string buf " -bs-jsx 3"
206216
);
207217

208-
Ext_buffer.add_char_string buf ' ' ppx_flags;
209218
Ext_buffer.add_char_string buf ' ' bsc_flags;
210219
Ext_buffer.add_string buf " -bs-ast -o $out $in";
211220
Ext_buffer.contents buf

jscomp/bsb/bsb_ninja_rule.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ val make_custom_rules :
8282
bsc:string ->
8383
warnings:string ->
8484
bs_dep:string ->
85-
ppx_flags:string ->
85+
ppx_files:Bsb_config_types.ppx list ->
8686
bsc_flags:string ->
8787
dpkg_incls:string ->
8888
lib_incls:string ->

jscomp/common/bs_version.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* You should have received a copy of the GNU Lesser General Public License
2323
* along with this program; if not, write to the Free Software
2424
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
25-
let version = "8.3.0-dev.2"
25+
let version = "8.4.0-dev.1"
2626
let header =
2727
"// Generated by ReScript, PLEASE EDIT WITH CARE"
2828
let package_name = "bs-platform"

0 commit comments

Comments
 (0)