diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/Frontend/ModuleDependencyCollector.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Frontend/ModuleDependencyCollector.cpp | 52 |
1 files changed, 6 insertions, 46 deletions
diff --git a/contrib/llvm-project/clang/lib/Frontend/ModuleDependencyCollector.cpp b/contrib/llvm-project/clang/lib/Frontend/ModuleDependencyCollector.cpp index b54eb97d6c47..2e4e64f827b0 100644 --- a/contrib/llvm-project/clang/lib/Frontend/ModuleDependencyCollector.cpp +++ b/contrib/llvm-project/clang/lib/Frontend/ModuleDependencyCollector.cpp @@ -156,72 +156,32 @@ void ModuleDependencyCollector::writeFileMap() { VFSWriter.write(OS); } -bool ModuleDependencyCollector::getRealPath(StringRef SrcPath, - SmallVectorImpl<char> &Result) { - using namespace llvm::sys; - SmallString<256> RealPath; - StringRef FileName = path::filename(SrcPath); - std::string Dir = path::parent_path(SrcPath).str(); - auto DirWithSymLink = SymLinkMap.find(Dir); - - // Use real_path to fix any symbolic link component present in a path. - // Computing the real path is expensive, cache the search through the - // parent path directory. - if (DirWithSymLink == SymLinkMap.end()) { - if (llvm::sys::fs::real_path(Dir, RealPath)) - return false; - SymLinkMap[Dir] = std::string(RealPath.str()); - } else { - RealPath = DirWithSymLink->second; - } - - path::append(RealPath, FileName); - Result.swap(RealPath); - return true; -} - std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src, StringRef Dst) { using namespace llvm::sys; + llvm::FileCollector::PathCanonicalizer::PathStorage Paths = + Canonicalizer.canonicalize(Src); - // We need an absolute src path to append to the root. - SmallString<256> AbsoluteSrc = Src; - fs::make_absolute(AbsoluteSrc); - // Canonicalize src to a native path to avoid mixed separator styles. - path::native(AbsoluteSrc); - // Remove redundant leading "./" pieces and consecutive separators. - AbsoluteSrc = path::remove_leading_dotslash(AbsoluteSrc); - - // Canonicalize the source path by removing "..", "." components. - SmallString<256> VirtualPath = AbsoluteSrc; - path::remove_dots(VirtualPath, /*remove_dot_dot=*/true); - - // If a ".." component is present after a symlink component, remove_dots may - // lead to the wrong real destination path. Let the source be canonicalized - // like that but make sure we always use the real path for the destination. - SmallString<256> CopyFrom; - if (!getRealPath(AbsoluteSrc, CopyFrom)) - CopyFrom = VirtualPath; SmallString<256> CacheDst = getDest(); if (Dst.empty()) { // The common case is to map the virtual path to the same path inside the // cache. - path::append(CacheDst, path::relative_path(CopyFrom)); + path::append(CacheDst, path::relative_path(Paths.CopyFrom)); } else { // When collecting entries from input vfsoverlays, copy the external // contents into the cache but still map from the source. if (!fs::exists(Dst)) return std::error_code(); path::append(CacheDst, Dst); - CopyFrom = Dst; + Paths.CopyFrom = Dst; } // Copy the file into place. if (std::error_code EC = fs::create_directories(path::parent_path(CacheDst), /*IgnoreExisting=*/true)) return EC; - if (std::error_code EC = fs::copy_file(CopyFrom, CacheDst)) + if (std::error_code EC = fs::copy_file(Paths.CopyFrom, CacheDst)) return EC; // Always map a canonical src path to its real path into the YAML, by doing @@ -229,7 +189,7 @@ std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src, // overlay, which is a way to emulate symlink inside the VFS; this is also // needed for correctness, not doing that can lead to module redefinition // errors. - addFileMapping(VirtualPath, CacheDst); + addFileMapping(Paths.VirtualPath, CacheDst); return std::error_code(); } |