From ab9c18b85dc0bea2cb939080c3aa0512ecdcc8d7 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Tue, 6 Feb 2018 09:26:05 -0800 Subject: [PATCH] [clang] echo clang stdout when running non-plugin commands Summary: In some cases infer runs clang commands where we do not attach the plugin, notably for pre-processor-only commands like `clang -E foo.c`. Usually these commands are used by build systems to test their output, so infer should not swallow it. This makes infer echo the stdout of clang whenever we do not attach the plugin to clang. When the plugin is attached, stdout is captured because that's where the plugin outputs its results, so we cannot do the same in this case (not that we would want to yet). Fixes #696. Reviewed By: mbouaziz Differential Revision: D6912101 fbshipit-source-id: c4ad2e4 --- infer/src/base/Utils.ml | 8 ++++++-- infer/src/base/Utils.mli | 4 ++++ infer/src/clang/Capture.ml | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/infer/src/base/Utils.ml b/infer/src/base/Utils.ml index 32415dff4..ae302ef11 100644 --- a/infer/src/base/Utils.ml +++ b/infer/src/base/Utils.ml @@ -193,10 +193,14 @@ let write_json_to_file destfile json = with_file_out destfile ~f:(fun oc -> Yojson.Basic.pretty_to_channel oc json) -let consume_in chan_in = - try while true do In_channel.input_line_exn chan_in |> ignore done with End_of_file -> () +let with_channel_in ~f chan_in = + try while true do f @@ In_channel.input_line_exn chan_in done with End_of_file -> () +let consume_in chan_in = with_channel_in ~f:ignore chan_in + +let echo_in chan_in = with_channel_in ~f:print_endline chan_in + let with_process_in command read = let chan = Unix.open_process_in command in let f () = read chan in diff --git a/infer/src/base/Utils.mli b/infer/src/base/Utils.mli index 93e5d2e38..acf3892c7 100644 --- a/infer/src/base/Utils.mli +++ b/infer/src/base/Utils.mli @@ -59,6 +59,10 @@ val with_file_out : string -> f:(Out_channel.t -> 'a) -> 'a val write_json_to_file : string -> Yojson.Basic.json -> unit val consume_in : In_channel.t -> unit +(** consume and ignore all the lines from the channel until End_of_file is reached *) + +val echo_in : In_channel.t -> unit +(** echo the lines we get to stdout until End_of_file is reached *) val with_process_in : string -> (In_channel.t -> 'a) -> 'a * Unix.Exit_or_signal.t diff --git a/infer/src/clang/Capture.ml b/infer/src/clang/Capture.ml index 3482ef39f..8697e2961 100644 --- a/infer/src/clang/Capture.ml +++ b/infer/src/clang/Capture.ml @@ -179,4 +179,4 @@ let capture clang_cmd = absolute paths. *) let command_to_run = ClangCommand.command_to_run clang_cmd in L.(debug Capture Quiet) "Running non-cc command without capture: %s@\n" command_to_run ; - run_clang command_to_run Utils.consume_in + run_clang command_to_run Utils.echo_in