Add fall-back mode for clang tools.

Run without flags if we cannot load a compilation database. This matches
the behavior of clang itself when simply called with a source file.

Based on a patch by Russell Wallace.

llvm-svn: 254599
This commit is contained in:
Manuel Klimek 2015-12-03 10:38:53 +00:00
parent 0f1223053c
commit 6003384ea9
1 changed files with 7 additions and 4 deletions

View File

@ -116,8 +116,7 @@ CommonOptionsParser::CommonOptionsParser(
cl::HideUnrelatedOptions(Category);
Compilations.reset(FixedCompilationDatabase::loadFromCommandLine(argc,
argv));
Compilations.reset(FixedCompilationDatabase::loadFromCommandLine(argc, argv));
cl::ParseCommandLineOptions(argc, argv, Overview);
SourcePathList = SourcePaths;
if ((OccurrencesFlag == cl::ZeroOrMore || OccurrencesFlag == cl::Optional) &&
@ -132,8 +131,12 @@ CommonOptionsParser::CommonOptionsParser(
Compilations = CompilationDatabase::autoDetectFromSource(SourcePaths[0],
ErrorMessage);
}
if (!Compilations)
llvm::report_fatal_error(ErrorMessage);
if (!Compilations) {
llvm::errs() << "Error while trying to load a compilation database:\n"
<< ErrorMessage << "Running without flags.\n";
Compilations.reset(
new FixedCompilationDatabase(".", std::vector<std::string>()));
}
}
auto AdjustingCompilations =
llvm::make_unique<ArgumentsAdjustingCompilations>(