From a8c8e9cac1434c602a227bec5e155715ba30e4e7 Mon Sep 17 00:00:00 2001 From: Rafal Gwozdzinski Date: Thu, 30 Mar 2023 12:01:53 +0200 Subject: [PATCH] Provide lib_config for spawning Unix processes --- src/ocaml/driver/pparse.ml | 2 +- src/utils/lib_config.ml | 7 ++++++- src/utils/lib_config.mli | 7 +++++++ src/utils/std.ml | 6 ++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/ocaml/driver/pparse.ml b/src/ocaml/driver/pparse.ml index ab397e930a..a531193419 100644 --- a/src/ocaml/driver/pparse.ml +++ b/src/ocaml/driver/pparse.ml @@ -46,7 +46,7 @@ let merlin_system_command = windows_merlin_system_command else fun cmd ~cwd -> - Sys.command (Printf.sprintf "cd %s && %s" (Filename.quote cwd) cmd) + !Std.System_command.unix ~cmd:cmd ~cwd let ppx_commandline cmd fn_in fn_out = Printf.sprintf "%s %s %s%s" diff --git a/src/utils/lib_config.ml b/src/utils/lib_config.ml index 3f2ad97a8e..6f1671ec6d 100644 --- a/src/utils/lib_config.ml +++ b/src/utils/lib_config.ml @@ -7,4 +7,9 @@ let program_name () = !program_name module Json = struct let set_pretty_to_string f = Std.Json.pretty_to_string := f -end \ No newline at end of file +end + +module System_command = struct + let set_unix f = + Std.System_command.unix := f +end diff --git a/src/utils/lib_config.mli b/src/utils/lib_config.mli index 4a05071f55..9a6861f365 100644 --- a/src/utils/lib_config.mli +++ b/src/utils/lib_config.mli @@ -15,3 +15,10 @@ module Json : sig is [Yojson.Basic.pretty_to_string]. *) val set_pretty_to_string : (Std.json -> string) -> unit end + +(** Merlin spawns child processes for preprocessors (pp and ppx), which can be + customized via [System_command] *) +module System_command : sig + (** [set_unix] sets an implementation for Unix systems. *) + val set_unix : (cmd:string -> cwd:string -> int) -> unit +end diff --git a/src/utils/std.ml b/src/utils/std.ml index 6fd8359061..45a7828792 100644 --- a/src/utils/std.ml +++ b/src/utils/std.ml @@ -57,6 +57,12 @@ module Json = struct A common one is `Yojson.Basic.pretty_to_string`." end +module System_command = struct + let unix = ref @@ + fun ~cmd ~cwd -> + Sys.command (Printf.sprintf "cd %s && %s" (Filename.quote cwd) cmd) +end + module Hashtbl = struct include Hashtbl