[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
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent 70c2a50b4e
commit ab9c18b85d

@ -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) with_file_out destfile ~f:(fun oc -> Yojson.Basic.pretty_to_channel oc json)
let consume_in chan_in = let with_channel_in ~f chan_in =
try while true do In_channel.input_line_exn chan_in |> ignore done with End_of_file -> () 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 with_process_in command read =
let chan = Unix.open_process_in command in let chan = Unix.open_process_in command in
let f () = read chan in let f () = read chan in

@ -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 write_json_to_file : string -> Yojson.Basic.json -> unit
val consume_in : In_channel.t -> 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 val with_process_in : string -> (In_channel.t -> 'a) -> 'a * Unix.Exit_or_signal.t

@ -179,4 +179,4 @@ let capture clang_cmd =
absolute paths. *) absolute paths. *)
let command_to_run = ClangCommand.command_to_run clang_cmd in 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 ; 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

Loading…
Cancel
Save