diff options
author | Haowei Wu <haowei@google.com> | 2022-11-04 16:40:10 -0700 |
---|---|---|
committer | Haowei Wu <haowei@google.com> | 2022-12-16 11:45:36 -0800 |
commit | a903ecb4a26d8cf9a2e9e8369105682fd98f3982 (patch) | |
tree | edea150d3c6b978839ad3b023e0a458c13247298 /llvm/unittests/Support/VirtualFileSystemTest.cpp | |
parent | 40d29c0a714d7a19110f6f43d0af4c3df249c458 (diff) | |
download | llvm-a903ecb4a26d8cf9a2e9e8369105682fd98f3982.zip llvm-a903ecb4a26d8cf9a2e9e8369105682fd98f3982.tar.gz llvm-a903ecb4a26d8cf9a2e9e8369105682fd98f3982.tar.bz2 |
[vfs] Allow root paths relative to the vfsoverlay YAML file
This change adds 'root-relative' option in vfsoverlay YAML file format
so the root patchs can be relative to the YAML file directory instead of
the current working directory.
Differential Revision: https://reviews.llvm.org/D137473
Diffstat (limited to 'llvm/unittests/Support/VirtualFileSystemTest.cpp')
-rw-r--r-- | llvm/unittests/Support/VirtualFileSystemTest.cpp | 75 |
1 files changed, 70 insertions, 5 deletions
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index e4f93ca..242bb76 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -1456,18 +1456,20 @@ public: std::unique_ptr<vfs::FileSystem> getFromYAMLRawString(StringRef Content, - IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS) { + IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS, + StringRef YAMLFilePath = "") { std::unique_ptr<MemoryBuffer> Buffer = MemoryBuffer::getMemBuffer(Content); - return getVFSFromYAML(std::move(Buffer), CountingDiagHandler, "", this, - ExternalFS); + return getVFSFromYAML(std::move(Buffer), CountingDiagHandler, YAMLFilePath, + this, ExternalFS); } std::unique_ptr<vfs::FileSystem> getFromYAMLString( StringRef Content, - IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS = new DummyFileSystem()) { + IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS = new DummyFileSystem(), + StringRef YAMLFilePath = "") { std::string VersionPlusContent("{\n 'version':0,\n"); VersionPlusContent += Content.slice(Content.find('{') + 1, StringRef::npos); - return getFromYAMLRawString(VersionPlusContent, ExternalFS); + return getFromYAMLRawString(VersionPlusContent, ExternalFS, YAMLFilePath); } // This is intended as a "XFAIL" for windows hosts. @@ -1853,6 +1855,69 @@ TEST_F(VFSFromYAMLTest, ReturnsExternalPathVFSHit) { EXPECT_EQ(0, NumDiagnostics); } +TEST_F(VFSFromYAMLTest, RootRelativeTest) { + IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem()); + Lower->addDirectory("//root/foo/bar"); + Lower->addRegularFile("//root/foo/bar/a"); + IntrusiveRefCntPtr<vfs::FileSystem> FS = + getFromYAMLString("{\n" + " 'case-sensitive': false,\n" + " 'root-relative': 'overlay-dir',\n" + " 'roots': [\n" + " { 'name': 'b', 'type': 'file',\n" + " 'external-contents': '//root/foo/bar/a'\n" + " }\n" + " ]\n" + "}", + Lower, "//root/foo/bar/overlay"); + + ASSERT_NE(FS.get(), nullptr); + ErrorOr<vfs::Status> S = FS->status("//root/foo/bar/b"); + ASSERT_FALSE(S.getError()); + EXPECT_EQ("//root/foo/bar/a", S->getName()); + + // On Windows, with overlay-relative set to true, the relative + // path in external-contents field will be prepend by OverlayDir + // with native path separator, regardless of the actual path separator + // used in YAMLFilePath field. +#ifndef _WIN32 + FS = getFromYAMLString("{\n" + " 'case-sensitive': false,\n" + " 'overlay-relative': true,\n" + " 'root-relative': 'overlay-dir',\n" + " 'roots': [\n" + " { 'name': 'b', 'type': 'file',\n" + " 'external-contents': 'a'\n" + " }\n" + " ]\n" + "}", + Lower, "//root/foo/bar/overlay"); + ASSERT_NE(FS.get(), nullptr); + S = FS->status("//root/foo/bar/b"); + ASSERT_FALSE(S.getError()); + EXPECT_EQ("//root/foo/bar/a", S->getName()); +#else + IntrusiveRefCntPtr<DummyFileSystem> LowerWindows(new DummyFileSystem()); + LowerWindows->addDirectory("\\\\root\\foo\\bar"); + LowerWindows->addRegularFile("\\\\root\\foo\\bar\\a"); + FS = getFromYAMLString("{\n" + " 'case-sensitive': false,\n" + " 'overlay-relative': true,\n" + " 'root-relative': 'overlay-dir',\n" + " 'roots': [\n" + " { 'name': 'b', 'type': 'file',\n" + " 'external-contents': 'a'\n" + " }\n" + " ]\n" + "}", + LowerWindows, "\\\\root\\foo\\bar\\overlay"); + ASSERT_NE(FS.get(), nullptr); + S = FS->status("\\\\root\\foo\\bar\\b"); + ASSERT_FALSE(S.getError()); + EXPECT_EQ("\\\\root\\foo\\bar\\a", S->getName()); +#endif +} + TEST_F(VFSFromYAMLTest, ReturnsInternalPathVFSHit) { IntrusiveRefCntPtr<vfs::InMemoryFileSystem> BaseFS( new vfs::InMemoryFileSystem); |