From 68332a16a06b98201a4684069190ecf2d0f318e0 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Thu, 17 Nov 2016 04:44:37 -0800 Subject: [PATCH] [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 --- infer/src/clang/Capture.re | 14 ++++++++++---- infer/src/clang/ClangWrapper.re | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/infer/src/clang/Capture.re b/infer/src/clang/Capture.re index 77248ab18..1a463e781 100644 --- a/infer/src/clang/Capture.re +++ b/infer/src/clang/Capture.re @@ -110,15 +110,21 @@ 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 */ switch (with_process_in clang_command read) { | (res, Unix.WEXITED 0) => res | (_, Unix.WEXITED n) => /* exit with the same error code as clang in case of compilation failure */ - exit n - | _ => exit 1 - }; + exit_with_error n + | _ => exit_with_error 1 + } +}; let run_plugin_and_frontend source_path frontend clang_args => { let clang_command = ClangCommand.command_to_run (ClangCommand.with_plugin_args clang_args); diff --git a/infer/src/clang/ClangWrapper.re b/infer/src/clang/ClangWrapper.re index 5b0cabe69..a5364049f 100644 --- a/infer/src/clang/ClangWrapper.re +++ b/infer/src/clang/ClangWrapper.re @@ -78,10 +78,10 @@ let exec_action_item = | ClangError error => { /* 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. */ - Logging.err "%s" error; + Logging.stderr "%s@." error; exit 1 } - | ClangWarning warning => Logging.err "%s@\n" warning + | ClangWarning warning => Logging.stderr "%s@\n" warning | Command clang_cmd => Capture.capture clang_cmd; let exe args xx_suffix => {