diff options
Diffstat (limited to 'clang/lib/Frontend/ModuleDependencyCollector.cpp')
-rw-r--r-- | clang/lib/Frontend/ModuleDependencyCollector.cpp | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/clang/lib/Frontend/ModuleDependencyCollector.cpp b/clang/lib/Frontend/ModuleDependencyCollector.cpp index 578910a..9b34d42 100644 --- a/clang/lib/Frontend/ModuleDependencyCollector.cpp +++ b/clang/lib/Frontend/ModuleDependencyCollector.cpp @@ -201,7 +201,8 @@ bool ModuleDependencyCollector::getRealPath(StringRef SrcPath, return true; } -std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src) { +std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src, + StringRef Dst) { using namespace llvm::sys; // We need an absolute src path to append to the root. @@ -213,23 +214,35 @@ std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src) { AbsoluteSrc = path::remove_leading_dotslash(AbsoluteSrc); // Canonicalize the source path by removing "..", "." components. - SmallString<256> CanonicalPath = AbsoluteSrc; - path::remove_dots(CanonicalPath, /*remove_dot_dot=*/true); + 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> RealPath; - if (!getRealPath(AbsoluteSrc, RealPath)) - RealPath = CanonicalPath; - SmallString<256> Dest = getDest(); - path::append(Dest, path::relative_path(RealPath)); + 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)); + } 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; + } // Copy the file into place. - if (std::error_code EC = fs::create_directories(path::parent_path(Dest), - /*IgnoreExisting=*/true)) + if (std::error_code EC = fs::create_directories(path::parent_path(CacheDst), + /*IgnoreExisting=*/true)) return EC; - if (std::error_code EC = fs::copy_file(RealPath, Dest)) + if (std::error_code EC = fs::copy_file(CopyFrom, CacheDst)) return EC; // Always map a canonical src path to its real path into the YAML, by doing @@ -237,12 +250,12 @@ 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 redifinition // errors. - addFileMapping(CanonicalPath, Dest); + addFileMapping(VirtualPath, CacheDst); return std::error_code(); } -void ModuleDependencyCollector::addFile(StringRef Filename) { +void ModuleDependencyCollector::addFile(StringRef Filename, StringRef FileDst) { if (insertSeen(Filename)) - if (copyToRoot(Filename)) + if (copyToRoot(Filename, FileDst)) HasErrors = true; } |