diff options
author | Richard Howell <rhow@fb.com> | 2022-01-19 10:12:32 -0800 |
---|---|---|
committer | Ellis Hoag <ellis.sparky.hoag@gmail.com> | 2022-01-19 10:13:06 -0800 |
commit | 4f61749e16f63b0c9ebd9bdd1f8bf4f570a31692 (patch) | |
tree | 164d33e7e105a53d2b797dcf1315aa88d98fce42 /llvm/unittests/Support/VirtualFileSystemTest.cpp | |
parent | 88d81770f1101c8306bd1717755ef4eea0724deb (diff) | |
download | llvm-4f61749e16f63b0c9ebd9bdd1f8bf4f570a31692.zip llvm-4f61749e16f63b0c9ebd9bdd1f8bf4f570a31692.tar.gz llvm-4f61749e16f63b0c9ebd9bdd1f8bf4f570a31692.tar.bz2 |
[clang] support relative roots to vfs overlays
This diff adds support for relative roots to VFS overlays. The directory root
will be made absolute from the current working directory and will be used to
determine the path style to use. This supports the use of VFS overlays with
remote build systems that might use a different working directory for each
compilation.
Reviewed By: benlangmuir
Differential Revision: https://reviews.llvm.org/D116174
Diffstat (limited to 'llvm/unittests/Support/VirtualFileSystemTest.cpp')
-rw-r--r-- | llvm/unittests/Support/VirtualFileSystemTest.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index be32971..caae58f 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -2164,6 +2164,11 @@ TEST_F(VFSFromYAMLTest, RecursiveDirectoryIterationLevel) { TEST_F(VFSFromYAMLTest, RelativePaths) { IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + std::error_code EC; + SmallString<128> CWD; + EC = llvm::sys::fs::current_path(CWD); + ASSERT_FALSE(EC); + // Filename at root level without a parent directory. IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString( "{ 'roots': [\n" @@ -2172,16 +2177,26 @@ TEST_F(VFSFromYAMLTest, RelativePaths) { " }\n" "] }", Lower); - EXPECT_EQ(nullptr, FS.get()); + ASSERT_TRUE(FS.get() != nullptr); + SmallString<128> ExpectedPathNotInDir("file-not-in-directory.h"); + llvm::sys::fs::make_absolute(ExpectedPathNotInDir); + checkContents(FS->dir_begin(CWD, EC), {ExpectedPathNotInDir}); // Relative file path. FS = getFromYAMLString("{ 'roots': [\n" - " { 'type': 'file', 'name': 'relative/file/path.h',\n" + " { 'type': 'file', 'name': 'relative/path.h',\n" " 'external-contents': '//root/external/file'\n" " }\n" "] }", Lower); - EXPECT_EQ(nullptr, FS.get()); + ASSERT_TRUE(FS.get() != nullptr); + SmallString<128> Parent("relative"); + llvm::sys::fs::make_absolute(Parent); + auto I = FS->dir_begin(Parent, EC); + ASSERT_FALSE(EC); + // Convert to POSIX path for comparison of windows paths + ASSERT_EQ("relative/path.h", + getPosixPath(std::string(I->path().substr(CWD.size() + 1)))); // Relative directory path. FS = getFromYAMLString( @@ -2191,9 +2206,14 @@ TEST_F(VFSFromYAMLTest, RelativePaths) { " }\n" "] }", Lower); - EXPECT_EQ(nullptr, FS.get()); + ASSERT_TRUE(FS.get() != nullptr); + SmallString<128> Root("relative/directory"); + llvm::sys::fs::make_absolute(Root); + I = FS->dir_begin(Root, EC); + ASSERT_FALSE(EC); + ASSERT_EQ("path.h", std::string(I->path().substr(Root.size() + 1))); - EXPECT_EQ(3, NumDiagnostics); + EXPECT_EQ(0, NumDiagnostics); } TEST_F(VFSFromYAMLTest, NonFallthroughDirectoryIteration) { |