Skip to content

Commit 548214e

Browse files
authored
Merge pull request #3756 from BuckleScript/fix_windows_quoting
quoting command line on windows properly
2 parents 445e91a + 5e09d1c commit 548214e

File tree

7 files changed

+841
-764
lines changed

7 files changed

+841
-764
lines changed

jscomp/main/js_main.ml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ let process_file ppf sourcefile =
7878
match input with
7979
| Re ->
8080
setup_reason_context ();
81-
Js_implementation.implementation ppf (reason_pp ~sourcefile) opref
81+
let tmpfile = reason_pp ~sourcefile in
82+
Js_implementation.implementation ppf tmpfile opref ;
83+
Ast_reason_pp.clean tmpfile
8284
| Rei ->
8385
setup_reason_context ();
84-
Js_implementation.interface ppf (reason_pp ~sourcefile) opref
86+
let tmpfile = (reason_pp ~sourcefile) in
87+
Js_implementation.interface ppf tmpfile opref ;
88+
Ast_reason_pp.clean tmpfile
8589
| Reiast
8690
->
8791
setup_reason_context ();
@@ -142,9 +146,9 @@ let intf filename =
142146
let eval (s : string) ~suffix =
143147
let tmpfile = Filename.temp_file "eval" suffix in
144148
Ext_io.write_file tmpfile s;
145-
Ext_pervasives.finally tmpfile anonymous ~clean:(fun _ ->
146-
try Sys.remove tmpfile with _ -> ()
147-
)
149+
anonymous tmpfile;
150+
Ast_reason_pp.clean tmpfile
151+
148152

149153
let (//) = Filename.concat
150154

jscomp/syntax/ast_reason_pp.ml

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,44 @@
2525

2626

2727
exception Pp_error
28+
29+
let cmd_nix_quote cmd sourcefile tmpfile : string =
30+
Ext_filename.maybe_quote cmd ^ " --print=binary " ^
31+
Ext_filename.maybe_quote sourcefile ^
32+
" > " ^ Ext_filename.maybe_quote tmpfile
33+
34+
let cmd_windows_quote cmd sourcefile tmpfile : string=
35+
"cmd /S/C \"" ^
36+
cmd_nix_quote cmd sourcefile tmpfile
37+
^ "\""
38+
39+
40+
let clean tmpfile =
41+
(if not !Clflags.verbose then try Sys.remove tmpfile with _ -> () )
42+
2843
(* Sync up with {!Pparse.preprocess}
2944
The generated file should not sit
3045
in the same directory as sourctree
3146
*)
32-
let pp (sourcefile : string) =
33-
34-
47+
let pp (sourcefile : string) =
3548
let tmpfile = Filename.temp_file "bspp" "" in
3649
let pp = (*TODO: check to avoid double quoting *)
37-
Ext_filename.maybe_quote
3850
(match !Js_config.refmt with
3951
| None ->
4052
Filename.concat (Filename.dirname Sys.executable_name) "refmt.exe"
4153
| Some x -> x)
4254
in
43-
let comm = Printf.sprintf "%s --print=binary %s > %s"
44-
pp (Ext_filename.maybe_quote sourcefile) tmpfile
55+
let comm =
56+
if Sys.win32 then cmd_windows_quote pp sourcefile tmpfile
57+
else cmd_nix_quote pp sourcefile tmpfile
4558
in
59+
if !Clflags.verbose then begin
60+
prerr_string "+ ";
61+
prerr_endline comm;
62+
prerr_newline ()
63+
end ;
4664
if Sys.command comm <> 0 then begin
47-
(try Sys.remove tmpfile with _ -> ());
65+
clean tmpfile;
4866
raise Pp_error
4967
end;
5068
tmpfile

jscomp/syntax/ast_reason_pp.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ exception Pp_error
2727

2828
val pp :
2929
string ->
30-
string
30+
string
31+
32+
val clean:
33+
string ->
34+
unit

lib/4.02.3/unstable/js_compiler.ml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119194,6 +119194,10 @@ exception Pp_error
119194119194
val pp :
119195119195
string ->
119196119196
string
119197+
119198+
val clean:
119199+
string ->
119200+
unit
119197119201
end = struct
119198119202
#1 "ast_reason_pp.ml"
119199119203
(* Copyright (C) 2019- Authors of BuckleScript
@@ -119223,26 +119227,44 @@ end = struct
119223119227

119224119228

119225119229
exception Pp_error
119230+
119231+
let cmd_nix_quote cmd sourcefile tmpfile : string =
119232+
Ext_filename.maybe_quote cmd ^ " --print=binary " ^
119233+
Ext_filename.maybe_quote sourcefile ^
119234+
" > " ^ Ext_filename.maybe_quote tmpfile
119235+
119236+
let cmd_windows_quote cmd sourcefile tmpfile : string=
119237+
"cmd /S/C \"" ^
119238+
cmd_nix_quote cmd sourcefile tmpfile
119239+
^ "\""
119240+
119241+
119242+
let clean tmpfile =
119243+
(if not !Clflags.verbose then try Sys.remove tmpfile with _ -> () )
119244+
119226119245
(* Sync up with {!Pparse.preprocess}
119227119246
The generated file should not sit
119228119247
in the same directory as sourctree
119229119248
*)
119230-
let pp (sourcefile : string) =
119231-
119232-
119249+
let pp (sourcefile : string) =
119233119250
let tmpfile = Filename.temp_file "bspp" "" in
119234119251
let pp = (*TODO: check to avoid double quoting *)
119235-
Ext_filename.maybe_quote
119236119252
(match !Js_config.refmt with
119237119253
| None ->
119238119254
Filename.concat (Filename.dirname Sys.executable_name) "refmt.exe"
119239119255
| Some x -> x)
119240119256
in
119241-
let comm = Printf.sprintf "%s --print=binary %s > %s"
119242-
pp (Ext_filename.maybe_quote sourcefile) tmpfile
119257+
let comm =
119258+
if Sys.win32 then cmd_windows_quote pp sourcefile tmpfile
119259+
else cmd_nix_quote pp sourcefile tmpfile
119243119260
in
119261+
if !Clflags.verbose then begin
119262+
prerr_string "+ ";
119263+
prerr_endline comm;
119264+
prerr_newline ()
119265+
end ;
119244119266
if Sys.command comm <> 0 then begin
119245-
(try Sys.remove tmpfile with _ -> ());
119267+
clean tmpfile;
119246119268
raise Pp_error
119247119269
end;
119248119270
tmpfile

0 commit comments

Comments
 (0)