aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/VirtualFileSystem.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2016-01-09 16:33:16 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2016-01-09 16:33:16 +0000
commite9e76079745dc2eb9de11badacaa9665a2c39511 (patch)
tree857919aeb16f0c71e2ad4d94ae7c938839c4cfe8 /clang/lib/Basic/VirtualFileSystem.cpp
parent88c163460cbe0cad01eef47cceb4f607261b9e66 (diff)
downloadllvm-e9e76079745dc2eb9de11badacaa9665a2c39511.zip
llvm-e9e76079745dc2eb9de11badacaa9665a2c39511.tar.gz
llvm-e9e76079745dc2eb9de11badacaa9665a2c39511.tar.bz2
[vfs] Normalize working directory if requested.
FixedCompilationDatabase sets the working dir to "." by default. For chdir(".") this is a noop but this lead to InMemoryFileSystem to create bogus paths. Fixes PR25327. llvm-svn: 257260
Diffstat (limited to 'clang/lib/Basic/VirtualFileSystem.cpp')
-rw-r--r--clang/lib/Basic/VirtualFileSystem.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp
index cf5a8d6..6977f40 100644
--- a/clang/lib/Basic/VirtualFileSystem.cpp
+++ b/clang/lib/Basic/VirtualFileSystem.cpp
@@ -658,6 +658,23 @@ directory_iterator InMemoryFileSystem::dir_begin(const Twine &Dir,
EC = make_error_code(llvm::errc::not_a_directory);
return directory_iterator(std::make_shared<InMemoryDirIterator>());
}
+
+std::error_code InMemoryFileSystem::setCurrentWorkingDirectory(const Twine &P) {
+ SmallString<128> Path;
+ P.toVector(Path);
+
+ // Fix up relative paths. This just prepends the current working directory.
+ std::error_code EC = makeAbsolute(Path);
+ assert(!EC);
+ (void)EC;
+
+ if (useNormalizedPaths())
+ llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true);
+
+ if (!Path.empty())
+ WorkingDirectory = Path.str();
+ return std::error_code();
+}
}
}