diff options
| author | Eric Liu <ioeric@google.com> | 2018-05-17 10:26:23 +0000 |
|---|---|---|
| committer | Eric Liu <ioeric@google.com> | 2018-05-17 10:26:23 +0000 |
| commit | 5fb18fec5dd00c6576a00a5fcd0e89789ba0f7a8 (patch) | |
| tree | 3b554db0d546175f7cf52073c4867834c1f63b71 /clang/lib/Basic | |
| parent | 848405b164e368601797cad493f5131ea86849da (diff) | |
| download | bcm5719-llvm-5fb18fec5dd00c6576a00a5fcd0e89789ba0f7a8.tar.gz bcm5719-llvm-5fb18fec5dd00c6576a00a5fcd0e89789ba0f7a8.zip | |
Add vfs::FileSystem::getRealPath
Summary: And change `FileManager::getCanonicalName` to use getRealPath.
Reviewers: bkramer
Reviewed By: bkramer
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D46942
llvm-svn: 332590
Diffstat (limited to 'clang/lib/Basic')
| -rw-r--r-- | clang/lib/Basic/FileManager.cpp | 18 | ||||
| -rw-r--r-- | clang/lib/Basic/VirtualFileSystem.cpp | 13 |
2 files changed, 15 insertions, 16 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 14a9033b204..5cbcdf4477e 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -534,23 +534,9 @@ StringRef FileManager::getCanonicalName(const DirectoryEntry *Dir) { StringRef CanonicalName(Dir->getName()); -#ifdef LLVM_ON_UNIX - char CanonicalNameBuf[PATH_MAX]; - if (realpath(Dir->getName().str().c_str(), CanonicalNameBuf)) + SmallString<4096> CanonicalNameBuf; + if (!FS->getRealPath(Dir->getName(), CanonicalNameBuf)) CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage); -#else - SmallString<256> CanonicalNameBuf(CanonicalName); - llvm::sys::fs::make_absolute(CanonicalNameBuf); - llvm::sys::path::native(CanonicalNameBuf); - // We've run into needing to remove '..' here in the wild though, so - // remove it. - // On Windows, symlinks are significantly less prevalent, so removing - // '..' is pretty safe. - // Ideally we'd have an equivalent of `realpath` and could implement - // sys::fs::canonical across all the platforms. - llvm::sys::path::remove_dots(CanonicalNameBuf, /* remove_dot_dot */ true); - CanonicalName = StringRef(CanonicalNameBuf).copy(CanonicalNameStorage); -#endif CanonicalDirNames.insert(std::make_pair(Dir, CanonicalName)); return CanonicalName; diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp index 84684a41656..1727b7d0e78 100644 --- a/clang/lib/Basic/VirtualFileSystem.cpp +++ b/clang/lib/Basic/VirtualFileSystem.cpp @@ -139,6 +139,11 @@ std::error_code FileSystem::makeAbsolute(SmallVectorImpl<char> &Path) const { return llvm::sys::fs::make_absolute(WorkingDir.get(), Path); } +std::error_code FileSystem::getRealPath(const Twine &Path, + SmallVectorImpl<char> &Output) const { + return errc::operation_not_permitted; +} + bool FileSystem::exists(const Twine &Path) { auto Status = status(Path); return Status && Status->exists(); @@ -236,6 +241,8 @@ public: llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override; std::error_code setCurrentWorkingDirectory(const Twine &Path) override; + std::error_code getRealPath(const Twine &Path, + SmallVectorImpl<char> &Output) const override; }; } // namespace @@ -274,6 +281,12 @@ std::error_code RealFileSystem::setCurrentWorkingDirectory(const Twine &Path) { return llvm::sys::fs::set_current_path(Path); } +std::error_code +RealFileSystem::getRealPath(const Twine &Path, + SmallVectorImpl<char> &Output) const { + return llvm::sys::fs::real_path(Path, Output); +} + IntrusiveRefCntPtr<FileSystem> vfs::getRealFileSystem() { static IntrusiveRefCntPtr<FileSystem> FS = new RealFileSystem(); return FS; |

