[clang] always print clang errors on stderr

Summary:
clang errors would get diverted to log files instead of being printed on the
console. Also log other types of clang errors and warnings more often.

Before:

  $ infer -- clang -c nosuchfile.c
  $ # nothing gets printed, exit code set to 1

After:

  $ infer -- clang -c nosuchfile.c
  clang-4.0: error: no such file or directory: 'nosuchfile.c'

Also print more messages in case of compilation errors:

  $ echo ')' >> a.c
  $ infer -- clang -c a.c
  a.c:1:1: error: expected identifier or '('
  )
  ^
  1 error generated.
  Error: the following clang command did not run successfully:
    '/home/jul/infer/facebook-clang-plugins/clang/install/bin/clang-4.0' "@/home/jul/infer/examples/infer-out/clang/clang_command_2a0a84.txt"

(only the last 2 lines are new)

Reviewed By: akotulski

Differential Revision: D4183039

fbshipit-source-id: b9a9065
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent 81856c0d15
commit 68332a16a0

@ -110,14 +110,20 @@ let run_and_validate_clang_frontend ast_source =>
} }
}; };
let run_clang clang_command read => let run_clang clang_command read => {
let exit_with_error exit_code => {
Logging.stderr
"Error: the following clang command did not run successfully:@\n %s@\n" clang_command;
exit exit_code
};
/* NOTE: exceptions will propagate through without exiting here */ /* NOTE: exceptions will propagate through without exiting here */
switch (with_process_in clang_command read) { switch (with_process_in clang_command read) {
| (res, Unix.WEXITED 0) => res | (res, Unix.WEXITED 0) => res
| (_, Unix.WEXITED n) => | (_, Unix.WEXITED n) =>
/* exit with the same error code as clang in case of compilation failure */ /* exit with the same error code as clang in case of compilation failure */
exit n exit_with_error n
| _ => exit 1 | _ => exit_with_error 1
}
}; };
let run_plugin_and_frontend source_path frontend clang_args => { let run_plugin_and_frontend source_path frontend clang_args => {

@ -78,10 +78,10 @@ let exec_action_item =
| ClangError error => { | ClangError error => {
/* An error in the output of `clang -### ...`. Outputs the error and fail. This is because /* An error in the output of `clang -### ...`. Outputs the error and fail. This is because
`clang -###` pretty much never fails, but warns of failures on stderr instead. */ `clang -###` pretty much never fails, but warns of failures on stderr instead. */
Logging.err "%s" error; Logging.stderr "%s@." error;
exit 1 exit 1
} }
| ClangWarning warning => Logging.err "%s@\n" warning | ClangWarning warning => Logging.stderr "%s@\n" warning
| Command clang_cmd => Capture.capture clang_cmd; | Command clang_cmd => Capture.capture clang_cmd;
let exe args xx_suffix => { let exe args xx_suffix => {

Loading…
Cancel
Save