[PATCH] D53170: [clang-doc] Switch to default to all-TUs executor

Julie Hockett via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 11 14:27:38 PDT 2018


juliehockett updated this revision to Diff 169304.

https://reviews.llvm.org/D53170

Files:
  clang-tools-extra/clang-doc/tool/ClangDocMain.cpp


Index: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
===================================================================
--- clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
+++ clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
@@ -30,8 +30,7 @@
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/CommonOptionsParser.h"
-#include "clang/Tooling/Execution.h"
-#include "clang/Tooling/StandaloneExecution.h"
+#include "clang/Tooling/ToolExecutorPluginRegistry.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/Support/CommandLine.h"
@@ -88,6 +87,11 @@
     llvm::cl::desc("Use only doxygen-style comments to generate docs."),
     llvm::cl::init(false), llvm::cl::cat(ClangDocCategory));
 
+static llvm::cl::opt<std::string> ClangDocExecutorName(
+    "doc-executor",
+    llvm::cl::desc("The name of the executor to use in clang-doc."),
+    llvm::cl::init("all-TUs"));
+
 bool CreateDirectory(const Twine &DirName, bool ClearDirectory = false) {
   std::error_code OK;
   llvm::SmallString<128> DocsRootPath;
@@ -195,12 +199,40 @@
   return Err;
 }
 
+llvm::Expected<std::unique_ptr<ToolExecutor>>
+createClangDocExecutor(int &argc, const char **argv,
+                       llvm::cl::OptionCategory &Category) {
+  auto OptionsParser =
+      CommonOptionsParser::create(argc, argv, Category, llvm::cl::ZeroOrMore);
+  if (!OptionsParser)
+    return OptionsParser.takeError();
+  for (auto I = ToolExecutorPluginRegistry::begin(),
+            E = ToolExecutorPluginRegistry::end();
+       I != E; ++I) {
+    if (I->getName() != ClangDocExecutorName)
+      continue;
+    std::unique_ptr<ToolExecutorPlugin> Plugin(I->instantiate());
+    llvm::Expected<std::unique_ptr<ToolExecutor>> Executor =
+        Plugin->create(*OptionsParser);
+    if (!Executor) {
+      return llvm::make_error<llvm::StringError>(
+          llvm::Twine("Failed to create '") + I->getName() +
+              "': " + llvm::toString(Executor.takeError()) + "\n",
+          llvm::inconvertibleErrorCode());
+    }
+    return std::move(*Executor);
+  }
+  return llvm::make_error<llvm::StringError>(llvm::Twine("Executor \"") +
+                                                 ClangDocExecutorName +
+                                                 "\" is not registered.",
+                                             llvm::inconvertibleErrorCode());
+}
+
 int main(int argc, const char **argv) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   std::error_code OK;
 
-  auto Exec = clang::tooling::createExecutorFromCommandLineArgs(
-      argc, argv, ClangDocCategory);
+  auto Exec = createClangDocExecutor(argc, argv, ClangDocCategory);
 
   if (!Exec) {
     llvm::errs() << toString(Exec.takeError()) << "\n";


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53170.169304.patch
Type: text/x-patch
Size: 2805 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181011/1031fb50/attachment.bin>


More information about the cfe-commits mailing list