diff options
author | Haojian Wu <hokein@google.com> | 2019-03-25 12:49:46 +0000 |
---|---|---|
committer | Haojian Wu <hokein@google.com> | 2019-03-25 12:49:46 +0000 |
commit | 9ac2859cf2f2a47c8ec66ad4771bb35d627a789f (patch) | |
tree | 36f57b0e939d0ea3056ecfc234f4c7f36fc84155 /clang-tools-extra/pp-trace | |
parent | 478fc5c83e93503be764e6ef5d6cd1560e66b82e (diff) | |
download | llvm-9ac2859cf2f2a47c8ec66ad4771bb35d627a789f.tar.gz |
[pp-trace] Use ClangTool in pp-trace, NFC
Summary:
This patch partially reverts the commit rL356849.
Unfortunately, tooling::createExecutorFromCommandLineArgs doesn't
corperate well with our internal infrastructure, which leads failing
lit tests. We use ClangTool at the moment, until we find a better
solution to smooth it.
Reviewers: ioeric
Reviewed By: ioeric
Subscribers: jdoerfert, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D59764
llvm-svn: 356893
Diffstat (limited to 'clang-tools-extra/pp-trace')
-rw-r--r-- | clang-tools-extra/pp-trace/PPTrace.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/clang-tools-extra/pp-trace/PPTrace.cpp b/clang-tools-extra/pp-trace/PPTrace.cpp index 58d44a8b0e95..5155a8b243d7 100644 --- a/clang-tools-extra/pp-trace/PPTrace.cpp +++ b/clang-tools-extra/pp-trace/PPTrace.cpp @@ -124,13 +124,11 @@ private: int main(int argc, const char **argv) { using namespace clang::pp_trace; - InitLLVM X(argc, argv); - auto Exec = - clang::tooling::createExecutorFromCommandLineArgs(argc, argv, Cat); - if (!Exec) - error(toString(Exec.takeError())); - + auto OptionsParser = clang::tooling::CommonOptionsParser::create( + argc, argv, Cat, llvm::cl::ZeroOrMore); + if (!OptionsParser) + error(toString(OptionsParser.takeError())); // Parse the IgnoreCallbacks list into strings. SmallVector<StringRef, 32> Patterns; FilterType Filters; @@ -139,20 +137,29 @@ int main(int argc, const char **argv) { for (StringRef Pattern : Patterns) { Pattern = Pattern.trim(); bool Enabled = !Pattern.consume_front("-"); - if (Expected<GlobPattern> Pat = GlobPattern::create(Pattern)) + Expected<GlobPattern> Pat = GlobPattern::create(Pattern); + if (Pat) Filters.emplace_back(std::move(*Pat), Enabled); else error(toString(Pat.takeError())); } + // Create the tool and run the compilation. + clang::tooling::ClangTool Tool(OptionsParser->getCompilations(), + OptionsParser->getSourcePathList()); + std::error_code EC; llvm::ToolOutputFile Out(OutputFileName, EC, llvm::sys::fs::F_Text); if (EC) error(EC.message()); + PPTraceFrontendActionFactory Factory(Filters, Out.os()); + int HadErrors = Tool.run(&Factory); + + // If we had errors, exit early. + if (HadErrors) + return HadErrors; - if (auto Err = Exec->get()->execute( - llvm::make_unique<PPTraceFrontendActionFactory>(Filters, Out.os()))) - error(toString(std::move(Err))); Out.keep(); + return 0; } |