]> granicus.if.org Git - clang/commitdiff
Add a hook to supply a custom CompilationDatabase. To add a custom CompilationDatabas...
authorDaniel Jasper <djasper@google.com>
Wed, 11 Jul 2012 19:13:13 +0000 (19:13 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 11 Jul 2012 19:13:13 +0000 (19:13 +0000)
Differential Revision: http://llvm-reviews.chandlerc.com/D4

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160061 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Tooling/CompilationDatabase.cpp
lib/Tooling/CustomCompilationDatabase.h [new file with mode: 0644]

index a06343ddab6ee9994aa41ef136a3a6af5c9a21c3..d54a5e79ebdc05bcf5e6bbd7221aa1a36ee01eca 100644 (file)
 #include "llvm/Support/Path.h"
 #include "llvm/Support/system_error.h"
 
+#ifdef USE_CUSTOM_COMPILATION_DATABASE
+#include "CustomCompilationDatabase.h"
+#endif
+
 namespace clang {
 namespace tooling {
 
@@ -124,6 +128,11 @@ CompilationDatabase::loadFromDirectory(StringRef BuildDirectory,
 
 static CompilationDatabase *
 findCompilationDatabaseFromDirectory(StringRef Directory) {
+#ifdef USE_CUSTOM_COMPILATION_DATABASE
+  if (CompilationDatabase *DB =
+      ::findCompilationDatabaseForDirectory(Directory))
+    return DB;
+#endif
   while (!Directory.empty()) {
     std::string LoadErrorMessage;
 
diff --git a/lib/Tooling/CustomCompilationDatabase.h b/lib/Tooling/CustomCompilationDatabase.h
new file mode 100644 (file)
index 0000000..a24915a
--- /dev/null
@@ -0,0 +1,37 @@
+//===--- CustomCompilationDatabase.h --------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file contains a hook to supply a custom \c CompilationDatabase
+//  implementation.
+//
+//  The mechanism can be used by IDEs or non-public code bases to integrate with
+//  their build system. Currently we support statically linking in an
+//  implementation of \c findCompilationDatabaseForDirectory and enabling it
+//  with -DUSE_CUSTOM_COMPILATION_DATABASE when compiling the Tooling library.
+//
+//  FIXME: The strategy forward is to provide a plugin system that can load
+//  custom compilation databases and make enabling that a build option.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/StringRef.h"
+
+namespace clang {
+namespace tooling {
+class CompilationDatabase;
+}
+}
+
+/// \brief Returns a CompilationDatabase for the given \c Directory.
+///
+/// \c Directory can be any directory within a project. This methods will
+/// then try to find compilation database files in \c Directory or any of its
+/// parents. If a compilation database cannot be found or loaded, returns NULL.
+clang::tooling::CompilationDatabase *findCompilationDatabaseForDirectory(
+  llvm::StringRef Directory);