]> granicus.if.org Git - clang/commitdiff
Reland "[clang][FileManager] fillRealPathName even if we aren't opening the file"
authorJan Korous <jkorous@apple.com>
Mon, 18 Feb 2019 22:33:40 +0000 (22:33 +0000)
committerJan Korous <jkorous@apple.com>
Mon, 18 Feb 2019 22:33:40 +0000 (22:33 +0000)
This reverts commit e2bb3121fd4ab5b01f9ec1d2e3e9877db9c6a54c.
+ fixed test for Windows

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354291 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/FileManager.cpp
unittests/Basic/FileManagerTest.cpp

index 75caff95559e674f525f336e3ef0f384641f4194..41026763377aa15a731f7645744c262aab8e454e 100644 (file)
@@ -267,6 +267,9 @@ const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
   if (UFE.File) {
     if (auto PathName = UFE.File->getName())
       fillRealPathName(&UFE, *PathName);
+  } else if (!openFile) {
+    // We should still fill the path even if we aren't opening the file.
+    fillRealPathName(&UFE, InterndFileName);
   }
   return &UFE;
 }
index 9f051976ca0de134670308f4076fd35429da2699..5262dad2bce6dc0206f4028b7699b08061d4390d 100644 (file)
@@ -346,4 +346,33 @@ TEST_F(FileManagerTest, getVirtualFileFillsRealPathName) {
   EXPECT_EQ(file->tryGetRealPathName(), ExpectedResult);
 }
 
+TEST_F(FileManagerTest, getFileDontOpenRealPath) {
+  SmallString<64> CustomWorkingDir;
+#ifdef _WIN32
+  CustomWorkingDir = "C:/";
+#else
+  CustomWorkingDir = "/";
+#endif
+
+  auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>(
+      new llvm::vfs::InMemoryFileSystem);
+  // setCurrentworkingdirectory must finish without error.
+  ASSERT_TRUE(!FS->setCurrentWorkingDirectory(CustomWorkingDir));
+
+  FileSystemOptions Opts;
+  FileManager Manager(Opts, FS);
+
+  auto statCache = llvm::make_unique<FakeStatCache>();
+  statCache->InjectDirectory("/tmp/abc", 42);
+  SmallString<64> Path("/tmp/abc/foo.cpp");
+  statCache->InjectFile(Path.str().str().c_str(), 43);
+  manager.setStatCache(std::move(statCache));
+
+  const FileEntry *file = manager.getFile(Path, /*openFile=*/false);
+
+  ASSERT_TRUE(file != nullptr);
+
+  ASSERT_EQ(file->tryGetRealPathName(), Path);
+}
+
 } // anonymous namespace