[buck] use temp file instead of pipe for buck comms

Summary: Sometimes buck hangs with the new integration and using pipes.  Use a temp file for standard output and redirect stderr.

Reviewed By: jvillard

Differential Revision: D20856346

fbshipit-source-id: 13a5f90d5
master
Nikos Gorogiannis 5 years ago committed by Facebook GitHub Bot
parent 6e235d877e
commit 1e25cf2168

@ -381,19 +381,24 @@ let capture_buck_args =
let run_buck_build prog buck_build_args = let run_buck_build prog buck_build_args =
L.debug Capture Verbose "%s %s@." prog (List.to_string ~f:Fn.id buck_build_args) ; L.debug Capture Verbose "%s %s@." prog (List.to_string ~f:Fn.id buck_build_args) ;
let buck_output_file = Filename.temp_file ~in_dir:Config.temp_file_dir "buck_output" ".log" in
let infer_args = let infer_args =
Option.fold (Sys.getenv CommandLineOption.args_env_var) ~init:"--fcp-syntax-only" Option.fold (Sys.getenv CommandLineOption.args_env_var) ~init:"--fcp-syntax-only"
~f:(fun acc arg -> Printf.sprintf "%s%c%s" acc CommandLineOption.env_var_sep arg) ~f:(fun acc arg -> Printf.sprintf "%s%c%s" acc CommandLineOption.env_var_sep arg)
in in
let shell_cmd =
List.map ~f:Escape.escape_shell (prog :: buck_build_args)
|> String.concat ~sep:" "
|> fun cmd -> Printf.sprintf "%s >'%s'" cmd buck_output_file
in
let env = `Extend [(CommandLineOption.args_env_var, infer_args)] in
let {Unix.Process_info.stdin; stdout; stderr; pid} = let {Unix.Process_info.stdin; stdout; stderr; pid} =
Unix.create_process_env ~prog ~args:buck_build_args Unix.create_process_env ~prog:"sh" ~args:["-c"; shell_cmd] ~env ()
~env:(`Extend [(CommandLineOption.args_env_var, infer_args)])
()
in in
let buck_stderr = Unix.in_channel_of_descr stderr in let buck_stderr = Unix.in_channel_of_descr stderr in
let buck_stdout = Unix.in_channel_of_descr stdout in
Utils.with_channel_in buck_stderr ~f:(L.progress "BUCK: %s@.") ; Utils.with_channel_in buck_stderr ~f:(L.progress "BUCK: %s@.") ;
Unix.close stdin ; Unix.close stdin ;
Unix.close stdout ;
In_channel.close buck_stderr ; In_channel.close buck_stderr ;
(* Process a line of buck stdout output, in this case the result of '--show-output' (* Process a line of buck stdout output, in this case the result of '--show-output'
These paths (may) contain a 'infer-deps.txt' file, which we will later merge These paths (may) contain a 'infer-deps.txt' file, which we will later merge
@ -408,9 +413,12 @@ let run_buck_build prog buck_build_args =
L.die ExternalError "Couldn't parse buck target output: %s" line L.die ExternalError "Couldn't parse buck target output: %s" line
in in
match Unix.waitpid pid with match Unix.waitpid pid with
| Ok () -> | Ok () -> (
let res = In_channel.fold_lines buck_stdout ~init:[] ~f:process_buck_line in match Utils.read_file buck_output_file with
In_channel.close buck_stdout ; res | Ok lines ->
List.fold lines ~init:[] ~f:process_buck_line
| Error err ->
L.die ExternalError "*** capture failed to execute: %s" err )
| Error _ as err -> | Error _ as err ->
L.die ExternalError "*** capture failed to execute: %s" L.die ExternalError "*** capture failed to execute: %s"
(Unix.Exit_or_signal.to_string_hum err) (Unix.Exit_or_signal.to_string_hum err)

Loading…
Cancel
Save