[PATCH] D52753: [tooling] Create executor by name

Julie Hockett via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 1 15:58:52 PDT 2018


juliehockett created this revision.
juliehockett added a reviewer: ioeric.
juliehockett added a project: clang.

Allow creation of a ToolExecutor given a name and a set of parsed options. This is useful in the case where the calling tool always wants to use a particular non-default implementation (e.g. the tool should always be run with the all-TUs executor)


https://reviews.llvm.org/D52753

Files:
  clang/include/clang/Tooling/Execution.h
  clang/lib/Tooling/Execution.cpp


Index: clang/lib/Tooling/Execution.cpp
===================================================================
--- clang/lib/Tooling/Execution.cpp
+++ clang/lib/Tooling/Execution.cpp
@@ -64,15 +64,23 @@
                                   /*Overview=*/Overview);
   if (!OptionsParser)
     return OptionsParser.takeError();
+  return createExecutorImpl(ExecutorName, OptionsParser.get());
+}
+
+llvm::Expected<std::unique_ptr<ToolExecutor>>
+createExecutorImpl(StringRef ExecutorName, CommonOptionsParser &OptionsParser) {
+  if (ExecutorName.empty())
+    return llvm::make_error<llvm::StringError>("Must provide an executor name.",
+                                               llvm::inconvertibleErrorCode());
   for (auto I = ToolExecutorPluginRegistry::begin(),
             E = ToolExecutorPluginRegistry::end();
        I != E; ++I) {
     if (I->getName() != ExecutorName) {
       continue;
     }
     std::unique_ptr<ToolExecutorPlugin> Plugin(I->instantiate());
     llvm::Expected<std::unique_ptr<ToolExecutor>> Executor =
-        Plugin->create(*OptionsParser);
+        Plugin->create(OptionsParser);
     if (!Executor) {
       return llvm::make_error<llvm::StringError>(
           llvm::Twine("Failed to create '") + I->getName() +
@@ -95,6 +103,11 @@
                                                          Overview);
 }
 
+llvm::Expected<std::unique_ptr<ToolExecutor>>
+createExecutor(StringRef ExecutorName, CommonOptionsParser &OptionsParser) {
+  return internal::createExecutorImpl(ExecutorName, OptionsParser);
+}
+
 // This anchor is used to force the linker to link in the generated object file
 // and thus register the StandaloneToolExecutorPlugin etc.
 extern volatile int StandaloneToolExecutorAnchorSource;
Index: clang/include/clang/Tooling/Execution.h
===================================================================
--- clang/include/clang/Tooling/Execution.h
+++ clang/include/clang/Tooling/Execution.h
@@ -179,11 +179,23 @@
                                   llvm::cl::OptionCategory &Category,
                                   const char *Overview = nullptr);
 
+/// This creates a ToolExecutor that is in the global registry.
+///
+/// This picks the executor based on the provided name. The caller must parse
+/// commandline arguments with `CommonOptionsParser` prior to calling this.
+///
+/// If no name is provided, or the provided name is not found, an error will be
+/// returned.
+llvm::Expected<std::unique_ptr<ToolExecutor>>
+createExecutor(StringRef ExecutorName, CommonOptionsParser &OptionsParser);
+
 namespace internal {
 llvm::Expected<std::unique_ptr<ToolExecutor>>
 createExecutorFromCommandLineArgsImpl(int &argc, const char **argv,
                                       llvm::cl::OptionCategory &Category,
                                       const char *Overview = nullptr);
+llvm::Expected<std::unique_ptr<ToolExecutor>>
+createExecutorImpl(StringRef ExecutorName, CommonOptionsParser &OptionsParser);
 } // end namespace internal
 
 } // end namespace tooling


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52753.167850.patch
Type: text/x-patch
Size: 3032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181001/3819da0b/attachment-0001.bin>


More information about the cfe-commits mailing list