Skip to content

Commit 3f4dc4a

Browse files
authored
just run rescript! (#5073)
* smart rescript * tweaks for latency * address comments
1 parent 3b094e1 commit 3f4dc4a

File tree

10 files changed

+146
-54
lines changed

10 files changed

+146
-54
lines changed

jscomp/ext/ext_sys.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525
(** TODO: not exported yet, wait for Windows Fix*)
26-
let is_directory_no_exn f =
27-
try Sys.is_directory f with _ -> false
26+
#if BS_BROWSER
27+
let is_directory_no_exn f =
28+
try Sys.is_directory f with _ -> false
29+
#else
30+
external is_directory_no_exn : string -> bool = "caml_sys_is_directory_no_exn"
31+
#end
2832

2933

3034
let is_windows_or_cygwin = Sys.win32 || Sys.cygwin

jscomp/main/rescript_main.ml

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,25 @@ let install_target () =
111111
if eid <> 0 then
112112
Bsb_unix.command_fatal_error install_command eid
113113

114-
114+
(** check if every dependency installation dierctory is there
115+
This is in hot path, so we want it to be fast.
116+
The heuristics is that if the installation directory is not there,
117+
we definitely need build the world.
118+
If it is there, we do not check if it is up-to-date, since that's
119+
going be slow, user can use `-with-deps` to enforce such check
120+
*)
121+
let check_deps_installation_directory (config_opt : Bsb_config_types.t option)
122+
make_world =
123+
match config_opt with
124+
| Some {bs_dependencies; bs_dev_dependencies} ->
125+
if not (
126+
Ext_list.for_all bs_dependencies
127+
(fun x -> Ext_sys.is_directory_no_exn x.package_install_path ) &&
128+
Ext_list.for_all bs_dev_dependencies
129+
(fun x -> Ext_sys.is_directory_no_exn x.package_install_path)) then
130+
make_world := true
131+
| None ->
132+
()
115133

116134
let build_subcommand ~start argv argv_len =
117135
let i = Ext_array.rfind_with_index argv Ext_string.equal separator in
@@ -141,7 +159,8 @@ let build_subcommand ~start argv argv_len =
141159
Bsb_ninja_regen.regenerate_ninja
142160
~package_kind:Toplevel
143161
~per_proj_dir:Bsb_global_paths.cwd
144-
~forced:!force_regenerate in
162+
~forced:!force_regenerate in
163+
check_deps_installation_directory config_opt make_world;
145164
if !make_world then
146165
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
147166
if !do_install then
@@ -199,34 +218,39 @@ let info_subcommand ~start argv =
199218
| None -> assert false
200219
| Some {file_groups = {files}} ->
201220
Ext_list.iter files (fun {sources } ->
202-
Map_string.iter sources (fun _ {info;syntax_kind;name_sans_extension} ->
203-
let extensions =
204-
match syntax_kind,info with
205-
| _, Intf -> assert false
206-
| Reason , Impl -> [".re" ]
207-
| Reason, Impl_intf -> [".re"; ".rei"]
208-
| Ml, Impl -> [".ml"]
209-
| Ml, Impl_intf -> [".ml"; ".mli"]
210-
| Res, Impl -> [".res"]
211-
| Res, Impl_intf -> [".res"; ".resi"] in
212-
Ext_list.iter extensions (fun x ->
213-
print_endline (name_sans_extension ^ x )
214-
)
221+
Map_string.iter sources (fun _ {info;syntax_kind;name_sans_extension} ->
222+
let extensions =
223+
match syntax_kind,info with
224+
| _, Intf -> assert false
225+
| Reason , Impl -> [".re" ]
226+
| Reason, Impl_intf -> [".re"; ".rei"]
227+
| Ml, Impl -> [".ml"]
228+
| Ml, Impl_intf -> [".ml"; ".mli"]
229+
| Res, Impl -> [".res"]
230+
| Res, Impl_intf -> [".res"; ".resi"] in
231+
Ext_list.iter extensions (fun x ->
232+
print_endline (name_sans_extension ^ x )
233+
)
234+
)
215235
)
216-
)
217236
end
218237
) ;;
238+
219239
(* see discussion #929, if we catch the exception, we don't have stacktrace... *)
220240
let () =
221241
let argv = Sys.argv in
222242
let argv_len = Array.length argv in
223243
try
224244
if argv_len = 1 then begin
225245
(* specialize this path which is used in watcher *)
226-
Bsb_ninja_regen.regenerate_ninja
227-
~package_kind:Toplevel
228-
~forced:false
229-
~per_proj_dir:Bsb_global_paths.cwd |> ignore;
246+
let config_opt =
247+
Bsb_ninja_regen.regenerate_ninja
248+
~package_kind:Toplevel
249+
~forced:false
250+
~per_proj_dir:Bsb_global_paths.cwd in
251+
check_deps_installation_directory config_opt make_world;
252+
if !make_world then
253+
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||];
230254
ninja_command_exit [||]
231255
end else
232256
match argv.(1) with

jscomp/stubs/ext_basic_hash_stubs.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <stdint.h>
55
#include "caml/memory.h"
66
#include "caml/signals.h"
7+
#include "caml/misc.h"
8+
#include <sys/stat.h>
79
typedef uint32_t uint32;
810

911
#define FINAL_MIX(h) \
@@ -175,6 +177,37 @@ CAMLprim value caml_stale_file(value path)
175177
CAMLreturn(Val_unit);
176178
}
177179
#endif
180+
181+
182+
CAMLprim value caml_sys_is_directory_no_exn(value name)
183+
{
184+
CAMLparam1(name);
185+
#ifdef _WIN32
186+
struct _stati64 st;
187+
#else
188+
struct stat st;
189+
#endif
190+
char_os * p;
191+
int ret;
192+
193+
194+
if(!caml_string_is_c_safe(name)){
195+
CAMLreturn(Val_false);
196+
}
197+
198+
p = caml_stat_strdup_to_os(String_val(name));
199+
caml_enter_blocking_section();
200+
ret = CAML_SYS_STAT(p, &st);
201+
caml_leave_blocking_section();
202+
caml_stat_free(p);
203+
204+
if (ret == -1) CAMLreturn(Val_false);
205+
#ifdef S_ISDIR
206+
CAMLreturn(Val_bool(S_ISDIR(st.st_mode)));
207+
#else
208+
CAMLreturn(Val_bool(st.st_mode & S_IFDIR));
209+
#endif
210+
}
178211
/* local variables: */
179212
/* compile-command: "ocamlopt.opt -c ext_basic_hash_stubs.c" */
180213
/* end: */

lib/4.06.1/bsb.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5226,8 +5226,9 @@ end = struct
52265226
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
52275227

52285228
(** TODO: not exported yet, wait for Windows Fix*)
5229-
let is_directory_no_exn f =
5230-
try Sys.is_directory f with _ -> false
5229+
5230+
external is_directory_no_exn : string -> bool = "caml_sys_is_directory_no_exn"
5231+
52315232

52325233

52335234
let is_windows_or_cygwin = Sys.win32 || Sys.cygwin

lib/4.06.1/rescript.ml

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5163,8 +5163,9 @@ end = struct
51635163
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
51645164

51655165
(** TODO: not exported yet, wait for Windows Fix*)
5166-
let is_directory_no_exn f =
5167-
try Sys.is_directory f with _ -> false
5166+
5167+
external is_directory_no_exn : string -> bool = "caml_sys_is_directory_no_exn"
5168+
51685169

51695170

51705171
let is_windows_or_cygwin = Sys.win32 || Sys.cygwin
@@ -16678,7 +16679,25 @@ let install_target () =
1667816679
if eid <> 0 then
1667916680
Bsb_unix.command_fatal_error install_command eid
1668016681

16681-
16682+
(** check if every dependency installation dierctory is there
16683+
This is in hot path, so we want it to be fast.
16684+
The heuristics is that if the installation directory is not there,
16685+
we definitely need build the world.
16686+
If it is there, we do not check if it is up-to-date, since that's
16687+
going be slow, user can use `-with-deps` to enforce such check
16688+
*)
16689+
let check_deps_installation_directory (config_opt : Bsb_config_types.t option)
16690+
make_world =
16691+
match config_opt with
16692+
| Some {bs_dependencies; bs_dev_dependencies} ->
16693+
if not (
16694+
Ext_list.for_all bs_dependencies
16695+
(fun x -> Ext_sys.is_directory_no_exn x.package_install_path ) &&
16696+
Ext_list.for_all bs_dev_dependencies
16697+
(fun x -> Ext_sys.is_directory_no_exn x.package_install_path)) then
16698+
make_world := true
16699+
| None ->
16700+
()
1668216701

1668316702
let build_subcommand ~start argv argv_len =
1668416703
let i = Ext_array.rfind_with_index argv Ext_string.equal separator in
@@ -16708,7 +16727,8 @@ let build_subcommand ~start argv argv_len =
1670816727
Bsb_ninja_regen.regenerate_ninja
1670916728
~package_kind:Toplevel
1671016729
~per_proj_dir:Bsb_global_paths.cwd
16711-
~forced:!force_regenerate in
16730+
~forced:!force_regenerate in
16731+
check_deps_installation_directory config_opt make_world;
1671216732
if !make_world then
1671316733
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
1671416734
if !do_install then
@@ -16766,34 +16786,39 @@ let info_subcommand ~start argv =
1676616786
| None -> assert false
1676716787
| Some {file_groups = {files}} ->
1676816788
Ext_list.iter files (fun {sources } ->
16769-
Map_string.iter sources (fun _ {info;syntax_kind;name_sans_extension} ->
16770-
let extensions =
16771-
match syntax_kind,info with
16772-
| _, Intf -> assert false
16773-
| Reason , Impl -> [".re" ]
16774-
| Reason, Impl_intf -> [".re"; ".rei"]
16775-
| Ml, Impl -> [".ml"]
16776-
| Ml, Impl_intf -> [".ml"; ".mli"]
16777-
| Res, Impl -> [".res"]
16778-
| Res, Impl_intf -> [".res"; ".resi"] in
16779-
Ext_list.iter extensions (fun x ->
16780-
print_endline (name_sans_extension ^ x )
16781-
)
16789+
Map_string.iter sources (fun _ {info;syntax_kind;name_sans_extension} ->
16790+
let extensions =
16791+
match syntax_kind,info with
16792+
| _, Intf -> assert false
16793+
| Reason , Impl -> [".re" ]
16794+
| Reason, Impl_intf -> [".re"; ".rei"]
16795+
| Ml, Impl -> [".ml"]
16796+
| Ml, Impl_intf -> [".ml"; ".mli"]
16797+
| Res, Impl -> [".res"]
16798+
| Res, Impl_intf -> [".res"; ".resi"] in
16799+
Ext_list.iter extensions (fun x ->
16800+
print_endline (name_sans_extension ^ x )
16801+
)
16802+
)
1678216803
)
16783-
)
1678416804
end
1678516805
) ;;
16806+
1678616807
(* see discussion #929, if we catch the exception, we don't have stacktrace... *)
1678716808
let () =
1678816809
let argv = Sys.argv in
1678916810
let argv_len = Array.length argv in
1679016811
try
1679116812
if argv_len = 1 then begin
1679216813
(* specialize this path which is used in watcher *)
16793-
Bsb_ninja_regen.regenerate_ninja
16794-
~package_kind:Toplevel
16795-
~forced:false
16796-
~per_proj_dir:Bsb_global_paths.cwd |> ignore;
16814+
let config_opt =
16815+
Bsb_ninja_regen.regenerate_ninja
16816+
~package_kind:Toplevel
16817+
~forced:false
16818+
~per_proj_dir:Bsb_global_paths.cwd in
16819+
check_deps_installation_directory config_opt make_world;
16820+
if !make_world then
16821+
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||];
1679716822
ninja_command_exit [||]
1679816823
end else
1679916824
match argv.(1) with

lib/4.06.1/unstable/all_ounit_tests.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14278,8 +14278,9 @@ end = struct
1427814278
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
1427914279

1428014280
(** TODO: not exported yet, wait for Windows Fix*)
14281-
let is_directory_no_exn f =
14282-
try Sys.is_directory f with _ -> false
14281+
14282+
external is_directory_no_exn : string -> bool = "caml_sys_is_directory_no_exn"
14283+
1428314284

1428414285

1428514286
let is_windows_or_cygwin = Sys.win32 || Sys.cygwin

lib/4.06.1/unstable/bspack.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10788,8 +10788,9 @@ end = struct
1078810788
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
1078910789

1079010790
(** TODO: not exported yet, wait for Windows Fix*)
10791-
let is_directory_no_exn f =
10792-
try Sys.is_directory f with _ -> false
10791+
10792+
external is_directory_no_exn : string -> bool = "caml_sys_is_directory_no_exn"
10793+
1079310794

1079410795

1079510796
let is_windows_or_cygwin = Sys.win32 || Sys.cygwin

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90042,8 +90042,9 @@ end = struct
9004290042
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
9004390043

9004490044
(** TODO: not exported yet, wait for Windows Fix*)
90045-
let is_directory_no_exn f =
90046-
try Sys.is_directory f with _ -> false
90045+
let is_directory_no_exn f =
90046+
try Sys.is_directory f with _ -> false
90047+
9004790048

9004890049

9004990050
let is_windows_or_cygwin = Sys.win32 || Sys.cygwin

lib/4.06.1/whole_compiler.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364983,8 +364983,9 @@ end = struct
364983364983
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
364984364984

364985364985
(** TODO: not exported yet, wait for Windows Fix*)
364986-
let is_directory_no_exn f =
364987-
try Sys.is_directory f with _ -> false
364986+
364987+
external is_directory_no_exn : string -> bool = "caml_sys_is_directory_no_exn"
364988+
364988364989

364989364990

364990364991
let is_windows_or_cygwin = Sys.win32 || Sys.cygwin

rescript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Run rescript subcommand -h for more details,
130130
For example:
131131
rescript build -h
132132
rescript format -h
133+
The default \`rescript\` is equivalent to \`rescript build\` subcommand
133134
`);
134135
}
135136

0 commit comments

Comments
 (0)