Skip to content

Commit 1f3ee8e

Browse files
committed
[clang] Use the VFS in ModuleDependencyCollector (llvm#160944)
This PR starts using the correct VFS in `ModuleDependencyCollector` instead of using the real FS directly. This matches compiler's behavior for other input files.
1 parent 10ea99a commit 1f3ee8e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

clang/lib/Frontend/ModuleDependencyCollector.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ void ModuleDependencyCollector::attachToPreprocessor(Preprocessor &PP) {
9191
std::make_unique<ModuleDependencyMMCallbacks>(*this));
9292
}
9393

94-
static bool isCaseSensitivePath(StringRef Path) {
94+
static bool isCaseSensitivePath(llvm::vfs::FileSystem &VFS, StringRef Path) {
9595
SmallString<256> TmpDest = Path, UpperDest, RealDest;
9696
// Remove component traversals, links, etc.
97-
if (llvm::sys::fs::real_path(Path, TmpDest))
97+
if (VFS.getRealPath(Path, TmpDest))
9898
return true; // Current default value in vfs.yaml
9999
Path = TmpDest;
100100

@@ -104,7 +104,7 @@ static bool isCaseSensitivePath(StringRef Path) {
104104
// already expects when sensitivity isn't setup.
105105
for (auto &C : Path)
106106
UpperDest.push_back(toUppercase(C));
107-
if (!llvm::sys::fs::real_path(UpperDest, RealDest) && Path == RealDest)
107+
if (!VFS.getRealPath(UpperDest, RealDest) && Path == RealDest)
108108
return false;
109109
return true;
110110
}
@@ -121,7 +121,8 @@ void ModuleDependencyCollector::writeFileMap() {
121121

122122
// Explicitly set case sensitivity for the YAML writer. For that, find out
123123
// the sensitivity at the path where the headers all collected to.
124-
VFSWriter.setCaseSensitivity(isCaseSensitivePath(VFSDir));
124+
VFSWriter.setCaseSensitivity(
125+
isCaseSensitivePath(Canonicalizer.getFileSystem(), VFSDir));
125126

126127
// Do not rely on real path names when executing the crash reproducer scripts
127128
// since we only want to actually use the files we have on the VFS cache.
@@ -153,7 +154,7 @@ std::error_code ModuleDependencyCollector::copyToRoot(StringRef Src,
153154
} else {
154155
// When collecting entries from input vfsoverlays, copy the external
155156
// contents into the cache but still map from the source.
156-
if (!fs::exists(Dst))
157+
if (!Canonicalizer.getFileSystem().exists(Dst))
157158
return std::error_code();
158159
path::append(CacheDst, Dst);
159160
Paths.CopyFrom = Dst;

llvm/include/llvm/Support/FileCollector.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class LLVM_ABI FileCollector : public FileCollectorBase {
8181
/// Canonicalize a pair of virtual and real paths.
8282
LLVM_ABI PathStorage canonicalize(StringRef SrcPath);
8383

84+
/// Return the underlying file system.
85+
vfs::FileSystem &getFileSystem() const { return *VFS; };
86+
8487
explicit PathCanonicalizer(IntrusiveRefCntPtr<vfs::FileSystem> VFS)
8588
: VFS(std::move(VFS)) {}
8689

0 commit comments

Comments
 (0)