Allow tools to work without compilation database

Russell Wallace via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 2 23:51:52 PST 2015


Per discussion at
http://lists.llvm.org/pipermail/cfe-dev/2015-December/046321.html allow
tools to work in the absence of a compilation database, but warn the user
about the absence.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151203/85e2510c/attachment.html>
-------------- next part --------------
Index: lib/Tooling/CommonOptionsParser.cpp
===================================================================
--- lib/Tooling/CommonOptionsParser.cpp	(revision 254518)
+++ lib/Tooling/CommonOptionsParser.cpp	(working copy)
@@ -116,8 +116,7 @@
 
   cl::HideUnrelatedOptions(Category);
 
-  Compilations.reset(FixedCompilationDatabase::loadFromCommandLine(argc,
-                                                                   argv));
+  Compilations.reset(FixedCompilationDatabase::loadFromCommandLine(argc, argv));
   cl::ParseCommandLineOptions(argc, argv, Overview);
   SourcePathList = SourcePaths;
   if (!Compilations) {
@@ -129,8 +128,13 @@
       Compilations = CompilationDatabase::autoDetectFromSource(SourcePaths[0],
                                                                ErrorMessage);
     }
-    if (!Compilations)
-      llvm::report_fatal_error(ErrorMessage);
+    if (!Compilations) {
+      errs() << "Compilation database not found - using default options\n";
+      int argc = 1;
+      const char *argv[] = {"--"};
+      Compilations.reset(
+          FixedCompilationDatabase::loadFromCommandLine(argc, argv));
+    }
   }
   auto AdjustingCompilations =
       llvm::make_unique<ArgumentsAdjustingCompilations>(


More information about the cfe-commits mailing list