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 llvm-svn: 214607
This commit is contained in:
parent
6d0e97afcf
commit
228dda5ac5
|
@ -30,7 +30,7 @@
|
||||||
#include "QueryParser.h"
|
#include "QueryParser.h"
|
||||||
#include "QuerySession.h"
|
#include "QuerySession.h"
|
||||||
#include "clang/Frontend/ASTUnit.h"
|
#include "clang/Frontend/ASTUnit.h"
|
||||||
#include "clang/Tooling/CompilationDatabase.h"
|
#include "clang/Tooling/CommonOptionsParser.h"
|
||||||
#include "clang/Tooling/Tooling.h"
|
#include "clang/Tooling/Tooling.h"
|
||||||
#include "llvm/LineEditor/LineEditor.h"
|
#include "llvm/LineEditor/LineEditor.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
@ -46,45 +46,30 @@ using namespace clang::query;
|
||||||
using namespace clang::tooling;
|
using namespace clang::tooling;
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
static cl::opt<std::string> BuildPath("b", cl::desc("Specify build path"),
|
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
|
||||||
cl::value_desc("<path>"));
|
static cl::OptionCategory ClangQueryCategory("clang-query options");
|
||||||
|
|
||||||
static cl::list<std::string> Commands("c", cl::desc("Specify command to run"),
|
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",
|
static cl::list<std::string> CommandFiles("f",
|
||||||
cl::desc("Read commands from file"),
|
cl::desc("Read commands from file"),
|
||||||
cl::value_desc("<file>"));
|
cl::value_desc("file"),
|
||||||
|
cl::cat(ClangQueryCategory));
|
||||||
static cl::list<std::string> SourcePaths(cl::Positional,
|
|
||||||
cl::desc("<source0> [... <sourceN>]"),
|
|
||||||
cl::OneOrMore);
|
|
||||||
|
|
||||||
int main(int argc, const char **argv) {
|
int main(int argc, const char **argv) {
|
||||||
llvm::sys::PrintStackTraceOnErrorSignal();
|
llvm::sys::PrintStackTraceOnErrorSignal();
|
||||||
cl::ParseCommandLineOptions(argc, argv);
|
|
||||||
|
CommonOptionsParser OptionsParser(argc, argv, ClangQueryCategory);
|
||||||
|
|
||||||
if (!Commands.empty() && !CommandFiles.empty()) {
|
if (!Commands.empty() && !CommandFiles.empty()) {
|
||||||
llvm::errs() << argv[0] << ": cannot specify both -c and -f\n";
|
llvm::errs() << argv[0] << ": cannot specify both -c and -f\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<CompilationDatabase> Compilations(
|
ClangTool Tool(OptionsParser.getCompilations(),
|
||||||
FixedCompilationDatabase::loadFromCommandLine(argc, argv));
|
OptionsParser.getSourcePathList());
|
||||||
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);
|
|
||||||
std::vector<std::unique_ptr<ASTUnit>> ASTs;
|
std::vector<std::unique_ptr<ASTUnit>> ASTs;
|
||||||
if (Tool.buildASTs(ASTs) != 0)
|
if (Tool.buildASTs(ASTs) != 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue