commit bee0b0763782fe5e1ee206621fde904eb94f56b5
parent 9f726132ffbe027b9e938b3201602cd761cc4bbd
Author: Kyle Milz <kyle@0x30.net>
Date: Sun, 31 Jul 2016 22:35:50 -0600
src: send citrun-inst diagnostic messages to log
Diffstat:
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/inst_main.cc b/src/inst_main.cc
@@ -17,6 +17,7 @@
#include <sys/time.h> // utimes
#include <sys/wait.h> // waitpid
+#include <clang/Frontend/TextDiagnosticPrinter.h>
#include <clang/Tooling/CommonOptionsParser.h>
#include <clang/Tooling/Tooling.h>
#include <cstdio> // tmpnam
@@ -154,12 +155,11 @@ CitrunInst::instrument()
clang::tooling::CommonOptionsParser op(clang_argc, &clang_argv[0], ToolingCategory);
clang::tooling::ClangTool Tool(op.getCompilations(), op.getSourcePathList());
- // ClangTool::run accepts a FrontendActionFactory, which is then used to
- // create new objects implementing the FrontendAction interface. Here we
- // use the helper newFrontendActionFactory to create a default factory
- // that will return a new MyFrontendAction object every time. To
- // further customize this, we could create our own factory class.
- // int ret = Tool.run(new MFAF(inst_files));
+ std::error_code ec;
+ llvm::raw_fd_ostream output("citrun.log", ec, llvm::sys::fs::F_None);
+ clang::DiagnosticOptions diags;
+
+ Tool.setDiagnosticConsumer(new clang::TextDiagnosticPrinter(output, &diags, false));
int ret = Tool.run(&(*clang::tooling::newFrontendActionFactory<InstrumentAction>()));
if (ret == 0)
diff --git a/t/inst_fail.t b/t/inst_fail.t
@@ -5,13 +5,14 @@ echo 1..2
tmpfile=`mktemp`
logfile=`mktemp`
-echo "int main(void) { return 0; " > $tmpfile
+echo "int main(void) { return 0; " > $tmpfile.c
export PATH="`pwd`/src:${PATH}"
-gcc -c -x c $tmpfile 2> $logfile
+gcc -c $tmpfile.c 2> $logfile
[ $? -eq 1 ] && echo ok 1
grep -q "error: expected" $logfile && echo ok 2
+rm $tmpfile.c
rm $tmpfile
rm $logfile