ilya-biryukov created this revision. ilya-biryukov added reviewers: ioeric, sammccall.
Resolve all relative paths before running the tool instead. This fixes the usage of ClangTool in AllTUsExecutor. The executor will try running multiple ClangTool instances in parallel with compile commands that usually have the same working directory. Changing working directory is a global operation, so we end up changing working directory in the middle of running other actions, which leads to spurious compile errors. Repository: rC Clang https://reviews.llvm.org/D51407 Files: lib/Tooling/Tooling.cpp Index: lib/Tooling/Tooling.cpp =================================================================== --- lib/Tooling/Tooling.cpp +++ lib/Tooling/Tooling.cpp @@ -411,15 +411,6 @@ // This just needs to be some symbol in the binary. static int StaticSymbol; - std::string InitialDirectory; - if (llvm::ErrorOr<std::string> CWD = - OverlayFileSystem->getCurrentWorkingDirectory()) { - InitialDirectory = std::move(*CWD); - } else { - llvm::report_fatal_error("Cannot detect current path: " + - Twine(CWD.getError().message())); - } - // First insert all absolute paths into the in-memory VFS. These are global // for all compile commands. if (SeenWorkingDirectories.insert("/").second) @@ -431,9 +422,14 @@ bool ProcessingFailed = false; bool FileSkipped = false; - for (const auto &SourcePath : SourcePaths) { - std::string File(getAbsolutePath(SourcePath)); - + // Compute all absolute paths before we run any actions, as those will change + // the working directory. + std::vector<std::string> AbsolutePaths; + AbsolutePaths.reserve(SourcePaths.size()); + for (const auto &SourcePath : SourcePaths) + AbsolutePaths.push_back(getAbsolutePath(SourcePath)); + + for (llvm::StringRef File : AbsolutePaths) { // Currently implementations of CompilationDatabase::getCompileCommands can // change the state of the file system (e.g. prepare generated headers), so // this method needs to run right before we invoke the tool, as the next @@ -498,11 +494,6 @@ llvm::errs() << "Error while processing " << File << ".\n"; ProcessingFailed = true; } - // Return to the initial directory to correctly resolve next file by - // relative path. - if (OverlayFileSystem->setCurrentWorkingDirectory(InitialDirectory.c_str())) - llvm::report_fatal_error("Cannot chdir into \"" + - Twine(InitialDirectory) + "\n!"); } } return ProcessingFailed ? 1 : (FileSkipped ? 2 : 0);
Index: lib/Tooling/Tooling.cpp =================================================================== --- lib/Tooling/Tooling.cpp +++ lib/Tooling/Tooling.cpp @@ -411,15 +411,6 @@ // This just needs to be some symbol in the binary. static int StaticSymbol; - std::string InitialDirectory; - if (llvm::ErrorOr<std::string> CWD = - OverlayFileSystem->getCurrentWorkingDirectory()) { - InitialDirectory = std::move(*CWD); - } else { - llvm::report_fatal_error("Cannot detect current path: " + - Twine(CWD.getError().message())); - } - // First insert all absolute paths into the in-memory VFS. These are global // for all compile commands. if (SeenWorkingDirectories.insert("/").second) @@ -431,9 +422,14 @@ bool ProcessingFailed = false; bool FileSkipped = false; - for (const auto &SourcePath : SourcePaths) { - std::string File(getAbsolutePath(SourcePath)); - + // Compute all absolute paths before we run any actions, as those will change + // the working directory. + std::vector<std::string> AbsolutePaths; + AbsolutePaths.reserve(SourcePaths.size()); + for (const auto &SourcePath : SourcePaths) + AbsolutePaths.push_back(getAbsolutePath(SourcePath)); + + for (llvm::StringRef File : AbsolutePaths) { // Currently implementations of CompilationDatabase::getCompileCommands can // change the state of the file system (e.g. prepare generated headers), so // this method needs to run right before we invoke the tool, as the next @@ -498,11 +494,6 @@ llvm::errs() << "Error while processing " << File << ".\n"; ProcessingFailed = true; } - // Return to the initial directory to correctly resolve next file by - // relative path. - if (OverlayFileSystem->setCurrentWorkingDirectory(InitialDirectory.c_str())) - llvm::report_fatal_error("Cannot chdir into \"" + - Twine(InitialDirectory) + "\n!"); } } return ProcessingFailed ? 1 : (FileSkipped ? 2 : 0);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits