summaryrefslogtreecommitdiff
path: root/lib/Tooling/JSONCompilationDatabase.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2012-10-08 16:08:15 +0000
committerDaniel Jasper <djasper@google.com>2012-10-08 16:08:15 +0000
commitd3420c906e3605d94c084e8b8b1f3fa490093c86 (patch)
tree2a1722cf436983cf2fcefbe3e56bdb6e538c3c57 /lib/Tooling/JSONCompilationDatabase.cpp
parent6b34c176994aaa781eff6cd8755a48cfb109e809 (diff)
downloadclang-d3420c906e3605d94c084e8b8b1f3fa490093c86.tar.gz
Support symlinks and relative paths in complilation databases.
Review: http://llvm-reviews.chandlerc.com/D30 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165392 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/JSONCompilationDatabase.cpp')
-rw-r--r--lib/Tooling/JSONCompilationDatabase.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/Tooling/JSONCompilationDatabase.cpp b/lib/Tooling/JSONCompilationDatabase.cpp
index 1c3cd8427c..cf35a25666 100644
--- a/lib/Tooling/JSONCompilationDatabase.cpp
+++ b/lib/Tooling/JSONCompilationDatabase.cpp
@@ -164,8 +164,18 @@ std::vector<CompileCommand>
JSONCompilationDatabase::getCompileCommands(StringRef FilePath) const {
llvm::SmallString<128> NativeFilePath;
llvm::sys::path::native(FilePath, NativeFilePath);
+ std::vector<StringRef> PossibleMatches;
+ std::string Error;
+ llvm::raw_string_ostream ES(Error);
+ StringRef Match = MatchTrie.findEquivalent(NativeFilePath.str(), ES);
+ if (Match.empty()) {
+ if (Error.empty())
+ Error = "No match found.";
+ llvm::outs() << Error << "\n";
+ return std::vector<CompileCommand>();
+ }
llvm::StringMap< std::vector<CompileCommandRef> >::const_iterator
- CommandsRefI = IndexByFile.find(NativeFilePath);
+ CommandsRefI = IndexByFile.find(Match);
if (CommandsRefI == IndexByFile.end())
return std::vector<CompileCommand>();
const std::vector<CompileCommandRef> &CommandsRef = CommandsRefI->getValue();
@@ -271,10 +281,20 @@ bool JSONCompilationDatabase::parse(std::string &ErrorMessage) {
return false;
}
llvm::SmallString<8> FileStorage;
+ StringRef FileName = File->getValue(FileStorage);
llvm::SmallString<128> NativeFilePath;
- llvm::sys::path::native(File->getValue(FileStorage), NativeFilePath);
+ if (llvm::sys::path::is_relative(FileName)) {
+ llvm::SmallString<8> DirectoryStorage;
+ llvm::SmallString<128> AbsolutePath(
+ Directory->getValue(DirectoryStorage));
+ llvm::sys::path::append(AbsolutePath, FileName);
+ llvm::sys::path::native(AbsolutePath.str(), NativeFilePath);
+ } else {
+ llvm::sys::path::native(FileName, NativeFilePath);
+ }
IndexByFile[NativeFilePath].push_back(
- CompileCommandRef(Directory, Command));
+ CompileCommandRef(Directory, Command));
+ MatchTrie.insert(NativeFilePath.str());
}
return true;
}