diff options
author | Manuel Klimek <klimek@google.com> | 2012-07-10 13:10:51 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2012-07-10 13:10:51 +0000 |
commit | 8fa2fb859a4cb8e67d9763225281d9b0aa9cb59f (patch) | |
tree | baba2e136725c1e8cba0ce410db39759981af927 /lib/Tooling/CompilationDatabase.cpp | |
parent | 3f6d513d51a382371669f4d0b943fa830fffeef2 (diff) |
Adds support for auto-detection of compilation databases
from a source file and changes clang-check to make use of this.
This makes clang-check just work on in-tree builds, and allows
easy setup via a symlink per source directory to make clang-check
work without any extra configuration.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159990 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/CompilationDatabase.cpp')
-rw-r--r-- | lib/Tooling/CompilationDatabase.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/Tooling/CompilationDatabase.cpp b/lib/Tooling/CompilationDatabase.cpp index 227fa82926..8e911123bc 100644 --- a/lib/Tooling/CompilationDatabase.cpp +++ b/lib/Tooling/CompilationDatabase.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/Tooling/CompilationDatabase.h" +#include "clang/Tooling/Tooling.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/YAMLParser.h" #include "llvm/Support/Path.h" @@ -121,6 +122,23 @@ CompilationDatabase::loadFromDirectory(StringRef BuildDirectory, return Database.take(); } +CompilationDatabase * +CompilationDatabase::autoDetectFromSource(StringRef SourceFile, + std::string &ErrorMessage) { + llvm::SmallString<1024> AbsolutePath(getAbsolutePath(SourceFile)); + StringRef Directory = llvm::sys::path::parent_path(AbsolutePath); + while (!Directory.empty()) { + std::string LoadErrorMessage; + if (CompilationDatabase *DB = loadFromDirectory(Directory, + LoadErrorMessage)) + return DB; + Directory = llvm::sys::path::parent_path(Directory); + } + ErrorMessage = ("Could not auto-detect compilation database for file \"" + + SourceFile + "\"").str(); + return NULL; +} + FixedCompilationDatabase * FixedCompilationDatabase::loadFromCommandLine(int &Argc, const char **Argv, @@ -283,4 +301,3 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { } // end namespace tooling } // end namespace clang - |