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> +createExecutor(StringRef ExecutorName, CommonOptionsParser &OptionsParser); + namespace internal { llvm::Expected> createExecutorFromCommandLineArgsImpl(int &argc, const char **argv, llvm::cl::OptionCategory &Category, const char *Overview = nullptr); +llvm::Expected> +createExecutorImpl(StringRef ExecutorName, CommonOptionsParser &OptionsParser); } // end namespace internal } // end namespace tooling Index: clang/lib/Tooling/Execution.cpp =================================================================== --- clang/lib/Tooling/Execution.cpp +++ clang/lib/Tooling/Execution.cpp @@ -64,6 +64,14 @@ /*Overview=*/Overview); if (!OptionsParser) return OptionsParser.takeError(); + return createExecutorImpl(ExecutorName, OptionsParser.get()); +} + +llvm::Expected> +createExecutorImpl(StringRef ExecutorName, CommonOptionsParser &OptionsParser) { + if (ExecutorName.empty()) + return llvm::make_error("Must provide an executor name.", + llvm::inconvertibleErrorCode()); for (auto I = ToolExecutorPluginRegistry::begin(), E = ToolExecutorPluginRegistry::end(); I != E; ++I) { @@ -72,7 +80,7 @@ } std::unique_ptr Plugin(I->instantiate()); llvm::Expected> Executor = - Plugin->create(*OptionsParser); + Plugin->create(OptionsParser); if (!Executor) { return llvm::make_error( llvm::Twine("Failed to create '") + I->getName() + @@ -95,6 +103,11 @@ Overview); } +llvm::Expected> +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;