Skip to content

Commit a0b6e85

Browse files
committed
[llvm] Use the underlying VFS when constructing RedirectingFileSystem (llvm#160942)
When the root node of the `RedirectingFileSystem` is to be resolved to the current working directory, we previously consulted the real FS instead of the provided underlying VFS. This PR fixes that issue.
1 parent 1f3ee8e commit a0b6e85

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

llvm/lib/Support/VirtualFileSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ class llvm::vfs::RedirectingFileSystemParser {
19741974
EC = FS->makeAbsolute(FullPath, Name);
19751975
Name = canonicalize(Name);
19761976
} else {
1977-
EC = sys::fs::make_absolute(Name);
1977+
EC = FS->makeAbsolute(Name);
19781978
}
19791979
if (EC) {
19801980
assert(NameValueNode && "Name presence should be checked earlier");

llvm/unittests/Support/VirtualFileSystemTest.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,7 @@ TEST_F(VFSFromYAMLTest, ReturnsExternalPathVFSHit) {
19541954
EXPECT_EQ(0, NumDiagnostics);
19551955
}
19561956

1957-
TEST_F(VFSFromYAMLTest, RootRelativeTest) {
1957+
TEST_F(VFSFromYAMLTest, RootRelativeToOverlayDirTest) {
19581958
IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
19591959
Lower->addDirectory("//root/foo/bar");
19601960
Lower->addRegularFile("//root/foo/bar/a");
@@ -2017,6 +2017,35 @@ TEST_F(VFSFromYAMLTest, RootRelativeTest) {
20172017
#endif
20182018
}
20192019

2020+
TEST_F(VFSFromYAMLTest, RootRelativeToCWDTest) {
2021+
auto Lower = makeIntrusiveRefCnt<DummyFileSystem>();
2022+
Lower->addDirectory("//root/foo/bar");
2023+
Lower->addRegularFile("//root/foo/bar/a");
2024+
Lower->addDirectory("//root/foo/bar/cwd");
2025+
Lower->addRegularFile("//root/foo/bar/cwd/a");
2026+
Lower->setCurrentWorkingDirectory("//root/foo/bar/cwd");
2027+
IntrusiveRefCntPtr<vfs::FileSystem> FS =
2028+
getFromYAMLString("{\n"
2029+
" 'case-sensitive': false,\n"
2030+
" 'root-relative': 'cwd',\n"
2031+
" 'roots': [\n"
2032+
" { 'name': 'b', 'type': 'file',\n"
2033+
" 'external-contents': '//root/foo/bar/a'\n"
2034+
" }\n"
2035+
" ]\n"
2036+
"}",
2037+
Lower, "//root/foo/bar/overlay");
2038+
2039+
ASSERT_NE(FS.get(), nullptr);
2040+
2041+
ErrorOr<vfs::Status> S1 = FS->status("//root/foo/bar/b");
2042+
ASSERT_TRUE(S1.getError());
2043+
2044+
ErrorOr<vfs::Status> S2 = FS->status("//root/foo/bar/cwd/b");
2045+
ASSERT_FALSE(S2.getError());
2046+
EXPECT_EQ("//root/foo/bar/a", S2->getName());
2047+
}
2048+
20202049
TEST_F(VFSFromYAMLTest, ReturnsInternalPathVFSHit) {
20212050
IntrusiveRefCntPtr<vfs::InMemoryFileSystem> BaseFS(
20222051
new vfs::InMemoryFileSystem);
@@ -2508,6 +2537,7 @@ TEST_F(VFSFromYAMLTest, RelativePaths) {
25082537
SmallString<128> CWD;
25092538
EC = llvm::sys::fs::current_path(CWD);
25102539
ASSERT_FALSE(EC);
2540+
Lower->setCurrentWorkingDirectory(CWD);
25112541

25122542
// Filename at root level without a parent directory.
25132543
IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString(

0 commit comments

Comments
 (0)