mirror of https://github.com/microsoft/clang.git
[CrossTU] Fix handling of Cross Translation Unit directory path
Differential Revision: https://reviews.llvm.org/D38842 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316764 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d2d3a85d27
commit
224b1ed240
|
@ -93,10 +93,7 @@ parseCrossTUIndex(StringRef IndexPath, StringRef CrossTUDir) {
|
||||||
index_error_code::multiple_definitions, IndexPath.str(), LineNo);
|
index_error_code::multiple_definitions, IndexPath.str(), LineNo);
|
||||||
StringRef FileName = LineRef.substr(Pos + 1);
|
StringRef FileName = LineRef.substr(Pos + 1);
|
||||||
SmallString<256> FilePath = CrossTUDir;
|
SmallString<256> FilePath = CrossTUDir;
|
||||||
if (llvm::sys::path::is_absolute(FileName))
|
llvm::sys::path::append(FilePath, FileName);
|
||||||
FilePath = FileName;
|
|
||||||
else
|
|
||||||
llvm::sys::path::append(FilePath, FileName);
|
|
||||||
Result[FunctionLookupName] = FilePath.str().str();
|
Result[FunctionLookupName] = FilePath.str().str();
|
||||||
} else
|
} else
|
||||||
return llvm::make_error<IndexError>(
|
return llvm::make_error<IndexError>(
|
||||||
|
|
|
@ -109,9 +109,9 @@ TEST(CrossTranslationUnit, CanLoadFunctionDefinition) {
|
||||||
|
|
||||||
TEST(CrossTranslationUnit, IndexFormatCanBeParsed) {
|
TEST(CrossTranslationUnit, IndexFormatCanBeParsed) {
|
||||||
llvm::StringMap<std::string> Index;
|
llvm::StringMap<std::string> Index;
|
||||||
Index["a"] = "b";
|
Index["a"] = "/b/f1";
|
||||||
Index["c"] = "d";
|
Index["c"] = "/d/f2";
|
||||||
Index["e"] = "f";
|
Index["e"] = "/f/f3";
|
||||||
std::string IndexText = createCrossTUIndexString(Index);
|
std::string IndexText = createCrossTUIndexString(Index);
|
||||||
|
|
||||||
int IndexFD;
|
int IndexFD;
|
||||||
|
@ -134,5 +134,25 @@ TEST(CrossTranslationUnit, IndexFormatCanBeParsed) {
|
||||||
EXPECT_TRUE(Index.count(E.getKey()));
|
EXPECT_TRUE(Index.count(E.getKey()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(CrossTranslationUnit, CTUDirIsHandledCorrectly) {
|
||||||
|
llvm::StringMap<std::string> Index;
|
||||||
|
Index["a"] = "/b/c/d";
|
||||||
|
std::string IndexText = createCrossTUIndexString(Index);
|
||||||
|
|
||||||
|
int IndexFD;
|
||||||
|
llvm::SmallString<256> IndexFileName;
|
||||||
|
ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD,
|
||||||
|
IndexFileName));
|
||||||
|
llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD);
|
||||||
|
IndexFile.os() << IndexText;
|
||||||
|
IndexFile.os().flush();
|
||||||
|
EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
|
||||||
|
llvm::Expected<llvm::StringMap<std::string>> IndexOrErr =
|
||||||
|
parseCrossTUIndex(IndexFileName, "/ctudir");
|
||||||
|
EXPECT_TRUE((bool)IndexOrErr);
|
||||||
|
llvm::StringMap<std::string> ParsedIndex = IndexOrErr.get();
|
||||||
|
EXPECT_EQ(ParsedIndex["a"], "/ctudir/b/c/d");
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace cross_tu
|
} // end namespace cross_tu
|
||||||
} // end namespace clang
|
} // end namespace clang
|
||||||
|
|
Loading…
Reference in New Issue