Skip to content

Commit 0fc972d

Browse files
authored
[llvm] Use the underlying VFS when constructing RedirectingFileSystem (#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 47b8bc4 commit 0fc972d

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
@@ -1973,7 +1973,7 @@ class llvm::vfs::RedirectingFileSystemParser {
19731973
EC = FS->makeAbsolute(FullPath, Name);
19741974
Name = canonicalize(Name);
19751975
} else {
1976-
EC = sys::fs::make_absolute(Name);
1976+
EC = FS->makeAbsolute(Name);
19771977
}
19781978
if (EC) {
19791979
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
@@ -1941,7 +1941,7 @@ TEST_F(VFSFromYAMLTest, ReturnsExternalPathVFSHit) {
19411941
EXPECT_EQ(0, NumDiagnostics);
19421942
}
19431943

1944-
TEST_F(VFSFromYAMLTest, RootRelativeTest) {
1944+
TEST_F(VFSFromYAMLTest, RootRelativeToOverlayDirTest) {
19451945
auto Lower = makeIntrusiveRefCnt<DummyFileSystem>();
19461946
Lower->addDirectory("//root/foo/bar");
19471947
Lower->addRegularFile("//root/foo/bar/a");
@@ -2004,6 +2004,35 @@ TEST_F(VFSFromYAMLTest, RootRelativeTest) {
20042004
#endif
20052005
}
20062006

2007+
TEST_F(VFSFromYAMLTest, RootRelativeToCWDTest) {
2008+
auto Lower = makeIntrusiveRefCnt<DummyFileSystem>();
2009+
Lower->addDirectory("//root/foo/bar");
2010+
Lower->addRegularFile("//root/foo/bar/a");
2011+
Lower->addDirectory("//root/foo/bar/cwd");
2012+
Lower->addRegularFile("//root/foo/bar/cwd/a");
2013+
Lower->setCurrentWorkingDirectory("//root/foo/bar/cwd");
2014+
IntrusiveRefCntPtr<vfs::FileSystem> FS =
2015+
getFromYAMLString("{\n"
2016+
" 'case-sensitive': false,\n"
2017+
" 'root-relative': 'cwd',\n"
2018+
" 'roots': [\n"
2019+
" { 'name': 'b', 'type': 'file',\n"
2020+
" 'external-contents': '//root/foo/bar/a'\n"
2021+
" }\n"
2022+
" ]\n"
2023+
"}",
2024+
Lower, "//root/foo/bar/overlay");
2025+
2026+
ASSERT_NE(FS.get(), nullptr);
2027+
2028+
ErrorOr<vfs::Status> S1 = FS->status("//root/foo/bar/b");
2029+
ASSERT_TRUE(S1.getError());
2030+
2031+
ErrorOr<vfs::Status> S2 = FS->status("//root/foo/bar/cwd/b");
2032+
ASSERT_FALSE(S2.getError());
2033+
EXPECT_EQ("//root/foo/bar/a", S2->getName());
2034+
}
2035+
20072036
TEST_F(VFSFromYAMLTest, ReturnsInternalPathVFSHit) {
20082037
auto BaseFS = makeIntrusiveRefCnt<vfs::InMemoryFileSystem>();
20092038
BaseFS->addFile("//root/foo/realname", 0,
@@ -2489,6 +2518,7 @@ TEST_F(VFSFromYAMLTest, RelativePaths) {
24892518
SmallString<128> CWD;
24902519
EC = llvm::sys::fs::current_path(CWD);
24912520
ASSERT_FALSE(EC);
2521+
Lower->setCurrentWorkingDirectory(CWD);
24922522

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

0 commit comments

Comments
 (0)