[buck-compdb] use wrapper that protects from SIGQUIT

Summary: As per title.

Reviewed By: jvillard

Differential Revision: D21348841

fbshipit-source-id: 41e837dd3
master
Nikos Gorogiannis 5 years ago committed by Facebook GitHub Bot
parent 8843bb00a8
commit 2973828675

@ -260,27 +260,6 @@ let with_process_in command read =
do_finally_swallow_timeout ~f ~finally do_finally_swallow_timeout ~f ~finally
let with_process_lines ~(debug : ('a, F.formatter, unit) format -> 'a) ~cmd ~tmp_prefix ~f =
let shell_cmd = List.map ~f:Escape.escape_shell cmd |> String.concat ~sep:" " in
let verbose_err_file = Filename.temp_file tmp_prefix ".err" in
let shell_cmd_redirected = Printf.sprintf "%s 2>'%s'" shell_cmd verbose_err_file in
debug "Trying to execute: %s@\n%!" shell_cmd_redirected ;
let input_lines chan = In_channel.input_lines ~fix_win_eol:true chan in
let res = with_process_in shell_cmd_redirected input_lines in
let verbose_errlog = with_file_in verbose_err_file ~f:In_channel.input_all in
if not (String.equal verbose_errlog "") then
debug "@\nlog:@\n<<<<<<@\n%s@\n>>>>>>@\n%!" verbose_errlog ;
match res with
| lines, Ok () ->
f lines
| lines, (Error _ as err) ->
let output = String.concat ~sep:"\n" lines in
L.(die ExternalError)
"*** Failed to execute: %s@\n*** Command: %s@\n*** Output:@\n%s@."
(Unix.Exit_or_signal.to_string_hum err)
shell_cmd output
let is_dir_kind (kind : Unix.file_kind) = match kind with S_DIR -> true | _ -> false let is_dir_kind (kind : Unix.file_kind) = match kind with S_DIR -> true | _ -> false
(** Recursively create a directory if it does not exist already. *) (** Recursively create a directory if it does not exist already. *)

@ -84,15 +84,6 @@ val with_channel_in : f:(string -> unit) -> In_channel.t -> unit
val with_process_in : string -> (In_channel.t -> 'a) -> 'a * Unix.Exit_or_signal.t val with_process_in : string -> (In_channel.t -> 'a) -> 'a * Unix.Exit_or_signal.t
val with_process_lines :
debug:((string -> unit, Format.formatter, unit) format -> string -> unit)
-> cmd:string list
-> tmp_prefix:string
-> f:(string list -> 'res)
-> 'res
(** Runs the command [cmd] and calls [f] on the output lines. Uses [debug] to print debug
information, and [tmp_prefix] as a prefix for temporary files. *)
val create_dir : string -> unit val create_dir : string -> unit
(** recursively create a directory if it does not exist already *) (** recursively create a directory if it does not exist already *)

@ -86,7 +86,7 @@ let get_compilation_database_files_buck db_deps ~prog ~args =
in in
Logging.(debug Linters Quiet) Logging.(debug Linters Quiet)
"Processed buck command is: 'buck %a'@\n" (Pp.seq F.pp_print_string) build_args ; "Processed buck command is: 'buck %a'@\n" (Pp.seq F.pp_print_string) build_args ;
Process.create_process_and_wait ~prog ~args:build_args ; Buck.wrap_buck_call ~label:"compdb_build" (prog :: build_args) |> ignore ;
let buck_targets_shell = let buck_targets_shell =
prog :: "targets" prog :: "targets"
:: List.rev_append :: List.rev_append
@ -115,9 +115,7 @@ let get_compilation_database_files_buck db_deps ~prog ~args =
in in
List.fold ~f:scan_output ~init:[] lines List.fold ~f:scan_output ~init:[] lines
in in
Utils.with_process_lines Buck.wrap_buck_call ~label:"compdb_targets" buck_targets_shell |> on_target_lines
~debug:L.(debug Capture Quiet)
~cmd:buck_targets_shell ~tmp_prefix:"buck_targets_" ~f:on_target_lines
| _ -> | _ ->
Process.print_error_and_exit "Incorrect buck command: %s %a. Please use buck build <targets>" Process.print_error_and_exit "Incorrect buck command: %s %a. Please use buck build <targets>"
prog (Pp.seq F.pp_print_string) args prog (Pp.seq F.pp_print_string) args

Loading…
Cancel
Save