aboutsummaryrefslogtreecommitdiffhomepage
path: root/kernel/nativelib.ml
diff options
context:
space:
mode:
authorGravatar Maxime Dénès <mail@maximedenes.fr>2014-12-16 00:06:13 +0100
committerGravatar Maxime Dénès <mail@maximedenes.fr>2014-12-16 00:06:13 +0100
commit8bda62e798c4e89c8c3f9406327899e394f7be0f (patch)
treeac7df2ec0c3f7b2740363428f77dadc64b774af1 /kernel/nativelib.ml
parent0e730e4fa316cbfbd2d6dc60276498f57f500e0e (diff)
Fix for #3154: use CUnix.sys_command to call native compiler.
Patch by CJ on bugzilla. CUnix.sys_command doesn't rely on a shell, so extra care with cmd.exe vs sh is no longer required.
Diffstat (limited to 'kernel/nativelib.ml')
-rw-r--r--kernel/nativelib.ml20
1 files changed, 11 insertions, 9 deletions
diff --git a/kernel/nativelib.ml b/kernel/nativelib.ml
index 811319a9b..8cda85ec6 100644
--- a/kernel/nativelib.ml
+++ b/kernel/nativelib.ml
@@ -32,7 +32,7 @@ let source_ext = ".native"
(* Global settings and utilies for interface with OCaml *)
let compiler_name =
- Filename.quote (if Dynlink.is_native then ocamlopt () else ocamlc ())
+ if Dynlink.is_native then ocamlopt () else ocamlc ()
let ( / ) = Filename.concat
@@ -62,20 +62,22 @@ let write_ml_code fn ?(header=[]) code =
let call_compiler ml_filename =
let load_path = !get_load_paths () in
let load_path = List.map (fun dn -> dn / output_dir) load_path in
- let include_dirs = List.map Filename.quote (include_dirs () @ load_path) in
- let include_dirs = String.concat " -I " include_dirs in
+ let include_dirs = List.flatten (List.map (fun x -> ["-I"; x]) (include_dirs () @ load_path)) in
let f = Filename.chop_extension ml_filename in
let link_filename = f ^ ".cmo" in
let link_filename = Dynlink.adapt_filename link_filename in
let remove f = if Sys.file_exists f then Sys.remove f in
remove link_filename;
remove (f ^ ".cmi");
- let comp_cmd =
- Format.sprintf "%s -%s -o %s -rectypes -w a -I %s -impl %s"
- compiler_name (if Dynlink.is_native then "shared" else "c")
- (Filename.quote link_filename) include_dirs (Filename.quote ml_filename)
- in
- Sys.command comp_cmd, link_filename
+ let args =
+ (if Dynlink.is_native then "-shared" else "-c")
+ ::"-o"::link_filename
+ ::"-rectypes"
+ ::"-w"::"a"
+ ::include_dirs
+ @ ["-impl"; ml_filename] in
+ if !Flags.debug then Pp.msg_debug (Pp.str (compiler_name ^ " " ^ (String.concat " " args)));
+ CUnix.sys_command compiler_name args = Unix.WEXITED 0, link_filename
let compile fn code =
write_ml_code fn code;