diff options
author | Alexander Kornienko <alexfh@google.com> | 2014-08-02 01:02:33 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2014-08-02 01:02:33 +0000 |
commit | 23af33b85d310336624c971e6bd65aeddbc106c5 (patch) | |
tree | 19aa32678e10604b1cdb427c939b2a1cb3ee190c /clang-query | |
parent | f97701d490f91403b66427b5730074b9d7428395 (diff) |
Use CommonOptionsParser in clang-query. This fixes its support of the fixed
compilation database and makes it behave consistently with other clang tools.
Reviewers: klimek, pcc
Reviewed By: pcc
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D4763
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@214607 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-query')
-rw-r--r-- | clang-query/tool/ClangQuery.cpp | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/clang-query/tool/ClangQuery.cpp b/clang-query/tool/ClangQuery.cpp index d38451a7..df7190d4 100644 --- a/clang-query/tool/ClangQuery.cpp +++ b/clang-query/tool/ClangQuery.cpp @@ -30,7 +30,7 @@ #include "QueryParser.h" #include "QuerySession.h" #include "clang/Frontend/ASTUnit.h" -#include "clang/Tooling/CompilationDatabase.h" +#include "clang/Tooling/CommonOptionsParser.h" #include "clang/Tooling/Tooling.h" #include "llvm/LineEditor/LineEditor.h" #include "llvm/Support/CommandLine.h" @@ -46,45 +46,30 @@ using namespace clang::query; using namespace clang::tooling; using namespace llvm; -static cl::opt<std::string> BuildPath("b", cl::desc("Specify build path"), - cl::value_desc("<path>")); +static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage); +static cl::OptionCategory ClangQueryCategory("clang-query options"); static cl::list<std::string> Commands("c", cl::desc("Specify command to run"), - cl::value_desc("<command>")); + cl::value_desc("command"), + cl::cat(ClangQueryCategory)); static cl::list<std::string> CommandFiles("f", cl::desc("Read commands from file"), - cl::value_desc("<file>")); - -static cl::list<std::string> SourcePaths(cl::Positional, - cl::desc("<source0> [... <sourceN>]"), - cl::OneOrMore); + cl::value_desc("file"), + cl::cat(ClangQueryCategory)); int main(int argc, const char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(); - cl::ParseCommandLineOptions(argc, argv); + + CommonOptionsParser OptionsParser(argc, argv, ClangQueryCategory); if (!Commands.empty() && !CommandFiles.empty()) { llvm::errs() << argv[0] << ": cannot specify both -c and -f\n"; return 1; } - std::unique_ptr<CompilationDatabase> Compilations( - FixedCompilationDatabase::loadFromCommandLine(argc, argv)); - if (!Compilations) { // Couldn't find a compilation DB from the command line - std::string ErrorMessage; - Compilations.reset( - !BuildPath.empty() ? - CompilationDatabase::autoDetectFromDirectory(BuildPath, ErrorMessage) : - CompilationDatabase::autoDetectFromSource(SourcePaths[0], ErrorMessage) - ); - - // Still no compilation DB? - bail. - if (!Compilations) - llvm::report_fatal_error(ErrorMessage); - } - - ClangTool Tool(*Compilations, SourcePaths); + ClangTool Tool(OptionsParser.getCompilations(), + OptionsParser.getSourcePathList()); std::vector<std::unique_ptr<ASTUnit>> ASTs; if (Tool.buildASTs(ASTs) != 0) return 1; |