xazax.hun created this revision. The function map generator tool always creates absolute path. The correct logic to determine whether a path should be handled as absolute depends on the value of the CrossTU directory. Added a unit test to avoid regressions.
https://reviews.llvm.org/D38842 Files: lib/CrossTU/CrossTranslationUnit.cpp unittests/CrossTU/CrossTranslationUnitTest.cpp Index: unittests/CrossTU/CrossTranslationUnitTest.cpp =================================================================== --- unittests/CrossTU/CrossTranslationUnitTest.cpp +++ unittests/CrossTU/CrossTranslationUnitTest.cpp @@ -109,9 +109,9 @@ TEST(CrossTranslationUnit, IndexFormatCanBeParsed) { llvm::StringMap<std::string> Index; - Index["a"] = "b"; - Index["c"] = "d"; - Index["e"] = "f"; + Index["a"] = "/b/f1"; + Index["c"] = "/d/f2"; + Index["e"] = "/f/f3"; std::string IndexText = createCrossTUIndexString(Index); int IndexFD; @@ -134,5 +134,25 @@ 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 clang Index: lib/CrossTU/CrossTranslationUnit.cpp =================================================================== --- lib/CrossTU/CrossTranslationUnit.cpp +++ lib/CrossTU/CrossTranslationUnit.cpp @@ -93,7 +93,7 @@ index_error_code::multiple_definitions, IndexPath.str(), LineNo); StringRef FileName = LineRef.substr(Pos + 1); SmallString<256> FilePath = CrossTUDir; - if (llvm::sys::path::is_absolute(FileName)) + if (CrossTUDir.empty()) FilePath = FileName; else llvm::sys::path::append(FilePath, FileName);
Index: unittests/CrossTU/CrossTranslationUnitTest.cpp =================================================================== --- unittests/CrossTU/CrossTranslationUnitTest.cpp +++ unittests/CrossTU/CrossTranslationUnitTest.cpp @@ -109,9 +109,9 @@ TEST(CrossTranslationUnit, IndexFormatCanBeParsed) { llvm::StringMap<std::string> Index; - Index["a"] = "b"; - Index["c"] = "d"; - Index["e"] = "f"; + Index["a"] = "/b/f1"; + Index["c"] = "/d/f2"; + Index["e"] = "/f/f3"; std::string IndexText = createCrossTUIndexString(Index); int IndexFD; @@ -134,5 +134,25 @@ 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 clang Index: lib/CrossTU/CrossTranslationUnit.cpp =================================================================== --- lib/CrossTU/CrossTranslationUnit.cpp +++ lib/CrossTU/CrossTranslationUnit.cpp @@ -93,7 +93,7 @@ index_error_code::multiple_definitions, IndexPath.str(), LineNo); StringRef FileName = LineRef.substr(Pos + 1); SmallString<256> FilePath = CrossTUDir; - if (llvm::sys::path::is_absolute(FileName)) + if (CrossTUDir.empty()) FilePath = FileName; else llvm::sys::path::append(FilePath, FileName);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits