Skip to content

just run rescript! #5073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions jscomp/ext/ext_sys.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

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


let is_windows_or_cygwin = Sys.win32 || Sys.cygwin
Expand Down
64 changes: 44 additions & 20 deletions jscomp/main/rescript_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,25 @@ let install_target () =
if eid <> 0 then
Bsb_unix.command_fatal_error install_command eid


(** check if every dependency installation dierctory is there
This is in hot path, so we want it to be fast.
The heuristics is that if the installation directory is not there,
we definitely need build the world.
If it is there, we do not check if it is up-to-date, since that's
going be slow, user can use `-with-deps` to enforce such check
*)
let check_deps_installation_directory (config_opt : Bsb_config_types.t option)
make_world =
match config_opt with
| Some {bs_dependencies; bs_dev_dependencies} ->
if not (
Ext_list.for_all bs_dependencies
(fun x -> Ext_sys.is_directory_no_exn x.package_install_path ) &&
Ext_list.for_all bs_dev_dependencies
(fun x -> Ext_sys.is_directory_no_exn x.package_install_path)) then
make_world := true
| None ->
()

let build_subcommand ~start argv argv_len =
let i = Ext_array.rfind_with_index argv Ext_string.equal separator in
Expand Down Expand Up @@ -141,7 +159,8 @@ let build_subcommand ~start argv argv_len =
Bsb_ninja_regen.regenerate_ninja
~package_kind:Toplevel
~per_proj_dir:Bsb_global_paths.cwd
~forced:!force_regenerate in
~forced:!force_regenerate in
check_deps_installation_directory config_opt make_world;
if !make_world then
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
if !do_install then
Expand Down Expand Up @@ -199,34 +218,39 @@ let info_subcommand ~start argv =
| None -> assert false
| Some {file_groups = {files}} ->
Ext_list.iter files (fun {sources } ->
Map_string.iter sources (fun _ {info;syntax_kind;name_sans_extension} ->
let extensions =
match syntax_kind,info with
| _, Intf -> assert false
| Reason , Impl -> [".re" ]
| Reason, Impl_intf -> [".re"; ".rei"]
| Ml, Impl -> [".ml"]
| Ml, Impl_intf -> [".ml"; ".mli"]
| Res, Impl -> [".res"]
| Res, Impl_intf -> [".res"; ".resi"] in
Ext_list.iter extensions (fun x ->
print_endline (name_sans_extension ^ x )
)
Map_string.iter sources (fun _ {info;syntax_kind;name_sans_extension} ->
let extensions =
match syntax_kind,info with
| _, Intf -> assert false
| Reason , Impl -> [".re" ]
| Reason, Impl_intf -> [".re"; ".rei"]
| Ml, Impl -> [".ml"]
| Ml, Impl_intf -> [".ml"; ".mli"]
| Res, Impl -> [".res"]
| Res, Impl_intf -> [".res"; ".resi"] in
Ext_list.iter extensions (fun x ->
print_endline (name_sans_extension ^ x )
)
)
)
)
end
) ;;

(* see discussion #929, if we catch the exception, we don't have stacktrace... *)
let () =
let argv = Sys.argv in
let argv_len = Array.length argv in
try
if argv_len = 1 then begin
(* specialize this path which is used in watcher *)
Bsb_ninja_regen.regenerate_ninja
~package_kind:Toplevel
~forced:false
~per_proj_dir:Bsb_global_paths.cwd |> ignore;
let config_opt =
Bsb_ninja_regen.regenerate_ninja
~package_kind:Toplevel
~forced:false
~per_proj_dir:Bsb_global_paths.cwd in
check_deps_installation_directory config_opt make_world;
if !make_world then
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||];
ninja_command_exit [||]
end else
match argv.(1) with
Expand Down
33 changes: 33 additions & 0 deletions jscomp/stubs/ext_basic_hash_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <stdint.h>
#include "caml/memory.h"
#include "caml/signals.h"
#include "caml/misc.h"
#include <sys/stat.h>
typedef uint32_t uint32;

#define FINAL_MIX(h) \
Expand Down Expand Up @@ -175,6 +177,37 @@ CAMLprim value caml_stale_file(value path)
CAMLreturn(Val_unit);
}
#endif


CAMLprim value caml_sys_is_directory_no_exn(value name)
{
CAMLparam1(name);
#ifdef _WIN32
struct _stati64 st;
#else
struct stat st;
#endif
char_os * p;
int ret;


if(!caml_string_is_c_safe(name)){
CAMLreturn(Val_false);
}

p = caml_stat_strdup_to_os(String_val(name));
caml_enter_blocking_section();
ret = CAML_SYS_STAT(p, &st);
caml_leave_blocking_section();
caml_stat_free(p);

if (ret == -1) CAMLreturn(Val_false);
#ifdef S_ISDIR
CAMLreturn(Val_bool(S_ISDIR(st.st_mode)));
#else
CAMLreturn(Val_bool(st.st_mode & S_IFDIR));
#endif
}
/* local variables: */
/* compile-command: "ocamlopt.opt -c ext_basic_hash_stubs.c" */
/* end: */
Expand Down
5 changes: 3 additions & 2 deletions lib/4.06.1/bsb.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5226,8 +5226,9 @@ end = struct
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

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

external is_directory_no_exn : string -> bool = "caml_sys_is_directory_no_exn"



let is_windows_or_cygwin = Sys.win32 || Sys.cygwin
Expand Down
69 changes: 47 additions & 22 deletions lib/4.06.1/rescript.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5163,8 +5163,9 @@ end = struct
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

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

external is_directory_no_exn : string -> bool = "caml_sys_is_directory_no_exn"



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


(** check if every dependency installation dierctory is there
This is in hot path, so we want it to be fast.
The heuristics is that if the installation directory is not there,
we definitely need build the world.
If it is there, we do not check if it is up-to-date, since that's
going be slow, user can use `-with-deps` to enforce such check
*)
let check_deps_installation_directory (config_opt : Bsb_config_types.t option)
make_world =
match config_opt with
| Some {bs_dependencies; bs_dev_dependencies} ->
if not (
Ext_list.for_all bs_dependencies
(fun x -> Ext_sys.is_directory_no_exn x.package_install_path ) &&
Ext_list.for_all bs_dev_dependencies
(fun x -> Ext_sys.is_directory_no_exn x.package_install_path)) then
make_world := true
| None ->
()

let build_subcommand ~start argv argv_len =
let i = Ext_array.rfind_with_index argv Ext_string.equal separator in
Expand Down Expand Up @@ -16708,7 +16727,8 @@ let build_subcommand ~start argv argv_len =
Bsb_ninja_regen.regenerate_ninja
~package_kind:Toplevel
~per_proj_dir:Bsb_global_paths.cwd
~forced:!force_regenerate in
~forced:!force_regenerate in
check_deps_installation_directory config_opt make_world;
if !make_world then
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt ninja_args;
if !do_install then
Expand Down Expand Up @@ -16766,34 +16786,39 @@ let info_subcommand ~start argv =
| None -> assert false
| Some {file_groups = {files}} ->
Ext_list.iter files (fun {sources } ->
Map_string.iter sources (fun _ {info;syntax_kind;name_sans_extension} ->
let extensions =
match syntax_kind,info with
| _, Intf -> assert false
| Reason , Impl -> [".re" ]
| Reason, Impl_intf -> [".re"; ".rei"]
| Ml, Impl -> [".ml"]
| Ml, Impl_intf -> [".ml"; ".mli"]
| Res, Impl -> [".res"]
| Res, Impl_intf -> [".res"; ".resi"] in
Ext_list.iter extensions (fun x ->
print_endline (name_sans_extension ^ x )
)
Map_string.iter sources (fun _ {info;syntax_kind;name_sans_extension} ->
let extensions =
match syntax_kind,info with
| _, Intf -> assert false
| Reason , Impl -> [".re" ]
| Reason, Impl_intf -> [".re"; ".rei"]
| Ml, Impl -> [".ml"]
| Ml, Impl_intf -> [".ml"; ".mli"]
| Res, Impl -> [".res"]
| Res, Impl_intf -> [".res"; ".resi"] in
Ext_list.iter extensions (fun x ->
print_endline (name_sans_extension ^ x )
)
)
)
)
end
) ;;

(* see discussion #929, if we catch the exception, we don't have stacktrace... *)
let () =
let argv = Sys.argv in
let argv_len = Array.length argv in
try
if argv_len = 1 then begin
(* specialize this path which is used in watcher *)
Bsb_ninja_regen.regenerate_ninja
~package_kind:Toplevel
~forced:false
~per_proj_dir:Bsb_global_paths.cwd |> ignore;
let config_opt =
Bsb_ninja_regen.regenerate_ninja
~package_kind:Toplevel
~forced:false
~per_proj_dir:Bsb_global_paths.cwd in
check_deps_installation_directory config_opt make_world;
if !make_world then
Bsb_world.make_world_deps Bsb_global_paths.cwd config_opt [||];
ninja_command_exit [||]
end else
match argv.(1) with
Expand Down
5 changes: 3 additions & 2 deletions lib/4.06.1/unstable/all_ounit_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14278,8 +14278,9 @@ end = struct
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

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

external is_directory_no_exn : string -> bool = "caml_sys_is_directory_no_exn"



let is_windows_or_cygwin = Sys.win32 || Sys.cygwin
Expand Down
5 changes: 3 additions & 2 deletions lib/4.06.1/unstable/bspack.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10788,8 +10788,9 @@ end = struct
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

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

external is_directory_no_exn : string -> bool = "caml_sys_is_directory_no_exn"



let is_windows_or_cygwin = Sys.win32 || Sys.cygwin
Expand Down
5 changes: 3 additions & 2 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90042,8 +90042,9 @@ end = struct
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

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



let is_windows_or_cygwin = Sys.win32 || Sys.cygwin
Expand Down
5 changes: 3 additions & 2 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -364983,8 +364983,9 @@ end = struct
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

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

external is_directory_no_exn : string -> bool = "caml_sys_is_directory_no_exn"



let is_windows_or_cygwin = Sys.win32 || Sys.cygwin
Expand Down
1 change: 1 addition & 0 deletions rescript
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ Run rescript subcommand -h for more details,
For example:
rescript build -h
rescript format -h
The default \`rescript\` is equivalent to \`rescript build\` subcommand
`);
}

Expand Down