[PATCH] D49197: FileManager: Try to compute RealPathName in getVirtualFile
Simon Marchi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 11 10:02:36 PDT 2018
simark updated this revision to Diff 155027.
simark added a comment.
Update commit message.
Repository:
rC Clang
https://reviews.llvm.org/D49197
Files:
lib/Basic/FileManager.cpp
unittests/Basic/FileManagerTest.cpp
Index: unittests/Basic/FileManagerTest.cpp
===================================================================
--- unittests/Basic/FileManagerTest.cpp
+++ unittests/Basic/FileManagerTest.cpp
@@ -322,4 +322,40 @@
EXPECT_EQ(Path, ExpectedResult);
}
+/// When calling getVirtualFile then getFile for the same file, the real path
+/// should be computed (in other words, getVirtualFile should compute the real
+/// path).
+TEST_F(FileManagerTest, getVirtualFileThenGetFileRealPathName) {
+ SmallString<64> RealPath;
+ SmallString<64> NonRealPath;
+ SmallString<64> WorkingDirectory;
+
+#ifdef _WIN32
+ RealPath = "C:\\a\\b";
+ NonRealPath = "C:\\a\\..\\a\\b";
+ WorkingDirectory = "C:\\";
+#else
+ RealPath = "/a/b";
+ NonRealPath = "/a/../a/b";
+ WorkingDirectory = "/";
+#endif
+
+ auto FS =
+ IntrusiveRefCntPtr<vfs::InMemoryFileSystem>(new vfs::InMemoryFileSystem);
+ ASSERT_TRUE(!FS->setCurrentWorkingDirectory(WorkingDirectory));
+
+ FS->addFile(RealPath, 0, llvm::MemoryBuffer::getMemBuffer(""));
+
+ FileSystemOptions Opts;
+ FileManager Manager(Opts, FS);
+
+ const FileEntry *VFE = Manager.getVirtualFile(NonRealPath, 0, 0);
+ ASSERT_TRUE(VFE != nullptr);
+ EXPECT_EQ(VFE->tryGetRealPathName(), RealPath);
+
+ const FileEntry *FE = Manager.getFile(NonRealPath);
+ ASSERT_TRUE(FE != nullptr);
+ EXPECT_EQ(FE->tryGetRealPathName(), RealPath);
+}
+
} // anonymous namespace
Index: lib/Basic/FileManager.cpp
===================================================================
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -390,6 +390,11 @@
UFE->UID = NextFileUID++;
UFE->IsValid = true;
UFE->File.reset();
+
+ SmallString<128> RealPathName;
+ if (!FS->getRealPath(InterndFileName, RealPathName))
+ UFE->RealPathName = RealPathName.str();
+
return UFE;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49197.155027.patch
Type: text/x-patch
Size: 1829 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180711/cdfab05f/attachment.bin>
More information about the cfe-commits
mailing list