[PATCH] D141016: [vfs] Use FS->WorkingDirectory when converting relative path to ABS
Haowei Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 4 15:41:38 PST 2023
haowei created this revision.
haowei added reviewers: bnbarham, phosek, abrachet.
Herald added a subscriber: hiraditya.
Herald added a project: All.
haowei requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is a follow up of change D137473 <https://reviews.llvm.org/D137473>
When parsing root directory from a VFS YAML file, llvm always uses process working directory (PWD) as the current working directory if "root-relative" option is not set to "overlay-dir". This behavior prevents clang's `--working-directory` flag from taking effect when processing a relative root directory. This patch changes the default PWD to FS->WorkingDirectory, which fixes the issue.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D141016
Files:
llvm/lib/Support/VirtualFileSystem.cpp
llvm/unittests/Support/VirtualFileSystemTest.cpp
Index: llvm/unittests/Support/VirtualFileSystemTest.cpp
===================================================================
--- llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -2408,8 +2408,6 @@
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.
@@ -2421,9 +2419,12 @@
"] }",
Lower);
ASSERT_TRUE(FS.get() != nullptr);
+ llvm::ErrorOr<std::string> CWD = FS->getCurrentWorkingDirectory();
+ ASSERT_TRUE(CWD);
+
SmallString<128> ExpectedPathNotInDir("file-not-in-directory.h");
llvm::sys::fs::make_absolute(ExpectedPathNotInDir);
- checkContents(FS->dir_begin(CWD, EC), {ExpectedPathNotInDir});
+ checkContents(FS->dir_begin(CWD.get(), EC), {ExpectedPathNotInDir});
// Relative file path.
FS = getFromYAMLString("{ 'roots': [\n"
@@ -2439,7 +2440,7 @@
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))));
+ getPosixPath(std::string(I->path().substr(CWD->size() + 1))));
// Relative directory path.
FS = getFromYAMLString(
Index: llvm/lib/Support/VirtualFileSystem.cpp
===================================================================
--- llvm/lib/Support/VirtualFileSystem.cpp
+++ llvm/lib/Support/VirtualFileSystem.cpp
@@ -1224,6 +1224,11 @@
ExternalFS->getCurrentWorkingDirectory()) {
WorkingDirectory = *ExternalWorkingDirectory;
}
+ if (WorkingDirectory == "") {
+ SmallString<256> cwd;
+ llvm::sys::fs::current_path(cwd);
+ WorkingDirectory = std::string(cwd);
+ }
}
/// Directory iterator implementation for \c RedirectingFileSystem's
@@ -1927,7 +1932,7 @@
EC = FS->makeAbsolute(FullPath, Name);
Name = canonicalize(Name);
} else {
- EC = sys::fs::make_absolute(Name);
+ EC = FS->makeAbsolute(Name);
}
if (EC) {
assert(NameValueNode && "Name presence should be checked earlier");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141016.486414.patch
Type: text/x-patch
Size: 2278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230104/5c630724/attachment.bin>
More information about the llvm-commits
mailing list