Skip to content

Commit 94f3fa2

Browse files
committed
fix bsb -clean bug
1 parent ea85772 commit 94f3fa2

File tree

6 files changed

+37
-29
lines changed

6 files changed

+37
-29
lines changed

jscomp/bsb/bsb_clean.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ let ninja_clean bsc_dir proj_dir =
3131
let cmd = bsc_dir // "ninja.exe" in
3232
let cwd = proj_dir // Bsb_config.lib_bs in
3333
if Sys.file_exists cwd then
34-
Bsb_unix.run_command_execv { cmd ; args = [|cmd; "-t"; "clean"|] ; cwd };
34+
let eid =
35+
(Bsb_unix.run_command_execv { cmd ; args = [|cmd; "-t"; "clean"|] ; cwd }) in
36+
if eid <> 0 then
37+
Bsb_log.warn "@{<warning>ninja clean failed@}@."
3538
with e ->
36-
Bsb_log.warn "@{<warning>ninja clean failed : %s @." (Printexc.to_string e)
39+
Bsb_log.warn "@{<warning>ninja clean failed@} : %s @." (Printexc.to_string e)
3740

3841
let clean_bs_garbage bsc_dir proj_dir =
3942
Bsb_log.info "@{<info>Cleaning:@} in %s@." proj_dir ;

jscomp/bsb/bsb_unix.ml

+12-22
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ let log cmd =
3636
Bsb_log.info "@{<info>Entering@} %s @." cmd.cwd ;
3737
Bsb_log.info "@{<info>Cmd:@} " ;
3838
Bsb_log.info_args cmd.args
39-
40-
let fail cmd =
41-
Bsb_log.error "@{<error>Failure:@} %s \n Location: %s@." cmd.cmd cmd.cwd
4239

43-
let run_command_execv_unix cmd =
40+
let command_fatal_error cmd eid =
41+
Bsb_log.error "@{<error>Failure:@} %s \n Location: %s@." cmd.cmd cmd.cwd;
42+
exit eid
43+
44+
let run_command_execv_unix cmd : int =
4445
match Unix.fork () with
4546
| 0 ->
4647
log cmd;
@@ -51,16 +52,11 @@ let run_command_execv_unix cmd =
5152
| pid, process_status ->
5253
match process_status with
5354
| Unix.WEXITED eid ->
54-
if eid <> 0 then
55-
begin
56-
fail cmd;
57-
exit eid
58-
end;
55+
eid
5956
| Unix.WSIGNALED _ | Unix.WSTOPPED _ ->
60-
begin
61-
Bsb_log.error "@{<error>Interrupted:@} %s@." cmd.cmd;
62-
exit 2
63-
end
57+
Bsb_log.error "@{<error>Interrupted:@} %s@." cmd.cmd;
58+
2
59+
6460

6561

6662
(** TODO: the args are not quoted, here
@@ -75,15 +71,9 @@ let run_command_execv_win (cmd : command) =
7571
Sys.command
7672
(String.concat Ext_string.single_space
7773
( Filename.quote cmd.cmd ::( List.tl @@ Array.to_list cmd.args))) in
78-
if eid <> 0 then
79-
begin
80-
fail cmd;
81-
exit eid
82-
end
83-
else begin
84-
Bsb_log.info "@{<info>Leaving@} %s => %s @." cmd.cwd old_cwd;
85-
Unix.chdir old_cwd
86-
end
74+
Bsb_log.info "@{<info>Leaving@} %s => %s @." cmd.cwd old_cwd;
75+
Unix.chdir old_cwd;
76+
eid
8777

8878

8979
let run_command_execv =

jscomp/bsb/bsb_unix.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ type command =
3030
}
3131

3232

33+
val command_fatal_error : command -> int -> unit
3334

34-
35-
val run_command_execv : command -> unit
35+
val run_command_execv : command -> int
3636

3737

3838
val remove_dir_recursive : string -> unit

jscomp/bsb/bsb_world.ml

+8-3
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,16 @@ let build_bs_deps cwd deps =
8383
~override_package_specs:(Some deps)
8484
~forced:true
8585
cwd bsc_dir in (* set true to force regenrate ninja file so we have [config_opt]*)
86-
Bsb_unix.run_command_execv
87-
{cmd = vendor_ninja;
86+
let command =
87+
{Bsb_unix.cmd = vendor_ninja;
8888
cwd = cwd // Bsb_config.lib_bs;
8989
args = [|vendor_ninja|]
90-
};
90+
} in
91+
let eid =
92+
Bsb_unix.run_command_execv
93+
command in
94+
if eid <> 0 then
95+
Bsb_unix.command_fatal_error command eid;
9196
(* When ninja is not regenerated, ninja will still do the build,
9297
still need reinstall check
9398
Note that we can check if ninja print "no work to do",

jscomp/ext/ext_namespace.ml

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ type file_kind =
6464
let suffix_js = ".js"
6565
let bs_suffix_js = ".bs.js"
6666

67+
let ends_with_bs_suffix_then_chop s =
68+
Ext_string.ends_with_then_chop s bs_suffix_js
69+
6770
let js_name_of_basename bs_suffix s =
6871
remove_ns_suffix s ^
6972
(if bs_suffix then bs_suffix_js else suffix_js )

jscomp/ext/ext_namespace.mli

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ val make : ns:string -> string -> string
3131
val try_split_module_name :
3232
string -> (string * string ) option
3333

34+
(** [ends_with_bs_suffix_then_chop filename]
35+
is used to help we have dangling modules
36+
*)
37+
val ends_with_bs_suffix_then_chop :
38+
string -> string option
39+
40+
3441
(* Note we have to output uncapitalized file Name,
3542
or at least be consistent, since by reading cmi file on Case insensitive OS, we don't really know it is `list.cmi` or `List.cmi`, so that `require (./list.js)` or `require(./List.js)`
3643
relevant issues: #1609, #913

0 commit comments

Comments
 (0)