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.
llvm-svn: 159990
diff --git a/clang/lib/Tooling/Tooling.cpp b/clang/lib/Tooling/Tooling.cpp
index abac182..5d41172 100644
--- a/clang/lib/Tooling/Tooling.cpp
+++ b/clang/lib/Tooling/Tooling.cpp
@@ -115,20 +115,13 @@
return Invocation.run();
}
-/// \brief Returns the absolute path of 'File', by prepending it with
-/// 'BaseDirectory' if 'File' is not absolute.
-///
-/// Otherwise returns 'File'.
-/// If 'File' starts with "./", the returned path will not contain the "./".
-/// Otherwise, the returned path will contain the literal path-concatenation of
-/// 'BaseDirectory' and 'File'.
-///
-/// \param File Either an absolute or relative path.
-/// \param BaseDirectory An absolute path.
-static std::string getAbsolutePath(
- StringRef File, StringRef BaseDirectory) {
+std::string getAbsolutePath(StringRef File) {
+ llvm::SmallString<1024> BaseDirectory;
+ if (const char *PWD = ::getenv("PWD"))
+ BaseDirectory = PWD;
+ else
+ llvm::sys::fs::current_path(BaseDirectory);
SmallString<1024> PathStorage;
- assert(llvm::sys::path::is_absolute(BaseDirectory));
if (llvm::sys::path::is_absolute(File)) {
llvm::sys::path::native(File, PathStorage);
return PathStorage.str();
@@ -240,14 +233,8 @@
ArrayRef<std::string> SourcePaths)
: Files((FileSystemOptions())),
ArgsAdjuster(new ClangSyntaxOnlyAdjuster()) {
- llvm::SmallString<1024> BaseDirectory;
- if (const char *PWD = ::getenv("PWD"))
- BaseDirectory = PWD;
- else
- llvm::sys::fs::current_path(BaseDirectory);
for (unsigned I = 0, E = SourcePaths.size(); I != E; ++I) {
- llvm::SmallString<1024> File(getAbsolutePath(
- SourcePaths[I], BaseDirectory));
+ llvm::SmallString<1024> File(getAbsolutePath(SourcePaths[I]));
std::vector<CompileCommand> CompileCommandsForFile =
Compilations.getCompileCommands(File.str());