From 8843bb00a8e684a65d168e7e5a58251a82cc77af Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Fri, 1 May 2020 12:19:54 -0700 Subject: [PATCH] [buck-java] use buck wrapper that protects from SIGQUIT Summary: As per title. Reviewed By: jvillard Differential Revision: D21348709 fbshipit-source-id: 51288d837 --- infer/src/integration/Buck.mli | 12 +++++++++ infer/src/integration/BuckGenrule.ml | 39 +++++++--------------------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/infer/src/integration/Buck.mli b/infer/src/integration/Buck.mli index f734e6fc8..11342705c 100644 --- a/infer/src/integration/Buck.mli +++ b/infer/src/integration/Buck.mli @@ -7,6 +7,18 @@ open! IStd +val wrap_buck_call : + ?extend_env:(string * string) list -> label:string -> string list -> string list +(** Wrap a call to buck while (i) logging standard error to our standard error in real time; (ii) + redirecting standard out to a file, the contents of which are returned; (iii) protect the child + process from [SIGQUIT]. + + In a call [wrap_buck_call ~extend_env ~label cmd], [extend_env] is a list of pairs + [(variable, value)] that will extend the environment of the subprocess; [label] is appended to + [buck_] to make the prefix of the temporary file storing the standard output of the command, for + quick identification; [cmd] is a list of strings making up the shell command to execute; the + return value is the standard output of the command split on newlines. *) + val buck_config : BuckMode.t -> string list val parse_command_and_targets : diff --git a/infer/src/integration/BuckGenrule.ml b/infer/src/integration/BuckGenrule.ml index 2842ffe49..eac6e2192 100644 --- a/infer/src/integration/BuckGenrule.ml +++ b/infer/src/integration/BuckGenrule.ml @@ -9,7 +9,7 @@ open! IStd module F = Format module L = Logging -(* example build report json output +(* example build report json output [ { "success" : true, @@ -29,13 +29,13 @@ module L = Logging "type" : "BUILT_LOCALLY", "output" : "buck-out/gen/module1/module1_infer/infer_out" }, - "//module3:module1_infer" : { - "success" : "SUCCESS", - "type" : "BUILT_LOCALLY", - "outputs" : { - "DEFAULT" : [ "buck-out/gen/module1/module3_infer/infer_out" ] - } - } + "//module3:module1_infer" : { + "success" : "SUCCESS", + "type" : "BUILT_LOCALLY", + "outputs" : { + "DEFAULT" : [ "buck-out/gen/module1/module3_infer/infer_out" ] + } + } }, "failures" : { } }% @@ -95,32 +95,13 @@ let infer_deps_of_build_report build_report = let run_buck_capture cmd = - let shell_cmd = - List.map ~f:Escape.escape_shell cmd - |> String.concat ~sep:" " - |> fun cmd -> Printf.sprintf "%s 2>&1" cmd - in let path_var = "PATH" in let new_path = Sys.getenv path_var |> Option.value_map ~default:Config.bin_dir ~f:(fun old_path -> Config.bin_dir ^ ":" ^ old_path) in - let env = `Extend [(path_var, new_path)] in - let ({stdin; stdout; stderr; pid} : Unix.Process_info.t) = - Unix.create_process_env ~prog:"sh" ~args:["-c"; shell_cmd] ~env () - in - let buck_stdout = Unix.in_channel_of_descr stdout in - Utils.with_channel_in buck_stdout ~f:(L.progress "BUCK: %s@.") ; - Unix.close stdin ; - Unix.close stderr ; - In_channel.close buck_stdout ; - match Unix.waitpid pid with - | Ok () -> - () - | Error _ as err -> - L.(die ExternalError) - "*** Buck genrule capture failed to execute: %s@\n***@." - (Unix.Exit_or_signal.to_string_hum err) + let extend_env = [(path_var, new_path)] in + Buck.wrap_buck_call ~extend_env ~label:"build" cmd |> ignore let capture build_cmd =