summaryrefslogtreecommitdiffstats
path: root/lib/Tooling/Tooling.cpp
diff options
context:
space:
mode:
authorIlya Biryukov <ibiryukov@google.com>2018-09-11 07:29:09 +0000
committerIlya Biryukov <ibiryukov@google.com>2018-09-11 07:29:09 +0000
commitda0bf49b457141b5a563b7d29052ca1918200a59 (patch)
tree5696375769f616cdc1fb660f8cc66aa0d84e40dd /lib/Tooling/Tooling.cpp
parent3f141b1ed25ea72c12415d25407f823690d44b22 (diff)
[Tooling] Restore working dir in ClangTool.
Summary: And add an option to disable this behavior. The option is only used in AllTUsExecutor to avoid races when running concurrently on multiple threads. This fixes PR38869 introduced by r340937. Reviewers: ioeric, steveire Reviewed By: ioeric Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51864 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@341910 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/Tooling.cpp')
-rw-r--r--lib/Tooling/Tooling.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp
index 1ec285cc47..395d2d7a04 100644
--- a/lib/Tooling/Tooling.cpp
+++ b/lib/Tooling/Tooling.cpp
@@ -441,6 +441,17 @@ int ClangTool::run(ToolAction *Action) {
AbsolutePaths.push_back(std::move(*AbsPath));
}
+ // Remember the working directory in case we need to restore it.
+ std::string InitialWorkingDir;
+ if (RestoreCWD) {
+ if (auto CWD = OverlayFileSystem->getCurrentWorkingDirectory()) {
+ InitialWorkingDir = std::move(*CWD);
+ } else {
+ llvm::errs() << "Could not get working directory: "
+ << CWD.getError().message() << "\n";
+ }
+ }
+
for (llvm::StringRef File : AbsolutePaths) {
// Currently implementations of CompilationDatabase::getCompileCommands can
// change the state of the file system (e.g. prepare generated headers), so
@@ -508,6 +519,13 @@ int ClangTool::run(ToolAction *Action) {
}
}
}
+
+ if (!InitialWorkingDir.empty()) {
+ if (auto EC =
+ OverlayFileSystem->setCurrentWorkingDirectory(InitialWorkingDir))
+ llvm::errs() << "Error when trying to restore working dir: "
+ << EC.message() << "\n";
+ }
return ProcessingFailed ? 1 : (FileSkipped ? 2 : 0);
}
@@ -544,6 +562,10 @@ int ClangTool::buildASTs(std::vector<std::unique_ptr<ASTUnit>> &ASTs) {
return run(&Action);
}
+void ClangTool::setRestoreWorkingDir(bool RestoreCWD) {
+ this->RestoreCWD = RestoreCWD;
+}
+
namespace clang {
namespace tooling {