Reland "[clang][FileManager] fillRealPathName even if we aren't opening the file"

This reverts commit e2bb3121fd.
+ fixed test for Windows

llvm-svn: 354291
This commit is contained in:
Jan Korous 2019-02-18 22:33:40 +00:00
parent 9f14d169cc
commit cd8607db2d
2 changed files with 32 additions and 0 deletions

View 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;
}

View 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