From de6c7696d2ce8f3424146ebe0b6cf172361b9b87 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 17 Jun 2021 12:46:21 +0200 Subject: [PATCH] ProjectExplorer: Provide a way to extend RunWorkerFactory In the light of docker support it would be nice to have a way to tell existing RunWorkerFactories that they also work for docker, or generally to increase the scope to which they apply after construction time. Small con: Some more boiler plate, Small pros: Setup using the new method looks similar to what we use in the other factories, and the Factories types are recognizable when debugging. Change-Id: Idb1757f519e7151b835326aa8b98aeaa4a372cc4 Reviewed-by: Christian Kandeler --- .../customexecutablerunconfiguration.cpp | 15 ++++++++--- .../customexecutablerunconfiguration.h | 9 ++++++- .../projectexplorer/projectexplorer.cpp | 6 +---- src/plugins/projectexplorer/runcontrol.cpp | 25 +++++++++++++++++++ src/plugins/projectexplorer/runcontrol.h | 11 +++++++- 5 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp index d2f1d932c46..1c8b125b578 100644 --- a/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp +++ b/src/plugins/projectexplorer/customexecutablerunconfiguration.cpp @@ -55,12 +55,12 @@ using namespace Utils; namespace ProjectExplorer { -const char CUSTOM_EXECUTABLE_ID[] = "ProjectExplorer.CustomExecutableRunConfiguration"; +const char CUSTOM_EXECUTABLE_RUNCONFIG_ID[] = "ProjectExplorer.CustomExecutableRunConfiguration"; // CustomExecutableRunConfiguration CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target) - : CustomExecutableRunConfiguration(target, CUSTOM_EXECUTABLE_ID) + : CustomExecutableRunConfiguration(target, CUSTOM_EXECUTABLE_RUNCONFIG_ID) {} CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target, Utils::Id id) @@ -132,12 +132,19 @@ Tasks CustomExecutableRunConfiguration::checkForIssues() const return tasks; } -// Factory +// Factories CustomExecutableRunConfigurationFactory::CustomExecutableRunConfigurationFactory() : FixedRunConfigurationFactory(CustomExecutableRunConfiguration::tr("Custom Executable")) { - registerRunConfiguration(CUSTOM_EXECUTABLE_ID); + registerRunConfiguration(CUSTOM_EXECUTABLE_RUNCONFIG_ID); +} + +CustomExecutableRunWorkerFactory::CustomExecutableRunWorkerFactory() +{ + setProduct(); + addSupportedRunMode(Constants::NORMAL_RUN_MODE); + addSupportedRunConfig(CUSTOM_EXECUTABLE_RUNCONFIG_ID); } } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/customexecutablerunconfiguration.h b/src/plugins/projectexplorer/customexecutablerunconfiguration.h index 090058305b6..d7d90193bc5 100644 --- a/src/plugins/projectexplorer/customexecutablerunconfiguration.h +++ b/src/plugins/projectexplorer/customexecutablerunconfiguration.h @@ -25,7 +25,8 @@ #pragma once -#include "projectexplorer/runconfigurationaspects.h" +#include "runconfigurationaspects.h" +#include "runcontrol.h" namespace ProjectExplorer { @@ -54,4 +55,10 @@ public: CustomExecutableRunConfigurationFactory(); }; +class CustomExecutableRunWorkerFactory : public RunWorkerFactory +{ +public: + CustomExecutableRunWorkerFactory(); +}; + } // namespace ProjectExplorer diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 0033c72bd9c..ef568c05ca6 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -631,11 +631,7 @@ public: CurrentProjectFind m_curretProjectFind; CustomExecutableRunConfigurationFactory m_customExecutableRunConfigFactory; - RunWorkerFactory m_customExecutableRunWorkerFactory{ - RunWorkerFactory::make(), - {Constants::NORMAL_RUN_MODE}, - {m_customExecutableRunConfigFactory.runConfigurationId()} - }; + CustomExecutableRunWorkerFactory m_customExecutableRunWorkerFactory; ProjectFileWizardExtension m_projectFileWizardExtension; diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index bbde5b4f66b..e95c971282e 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -80,6 +80,11 @@ static QList g_runWorkerFactories; static QSet g_runModes; static QSet g_runConfigs; +RunWorkerFactory::RunWorkerFactory() +{ + g_runWorkerFactories.append(this); +} + RunWorkerFactory::RunWorkerFactory(const WorkerCreator &producer, const QList &runModes, const QList &runConfigs, @@ -103,6 +108,26 @@ RunWorkerFactory::~RunWorkerFactory() g_runWorkerFactories.removeOne(this); } +void RunWorkerFactory::setProducer(const WorkerCreator &producer) +{ + m_producer = producer; +} + +void RunWorkerFactory::addSupportedRunMode(Utils::Id runMode) +{ + m_supportedRunModes.append(runMode); +} + +void RunWorkerFactory::addSupportedRunConfig(Utils::Id runConfig) +{ + m_supportedRunConfigurations.append(runConfig); +} + +void RunWorkerFactory::addSupportedDeviceType(Utils::Id deviceType) +{ + m_supportedDeviceTypes.append(deviceType); +} + bool RunWorkerFactory::canRun(Utils::Id runMode, Utils::Id deviceType, const QString &runConfigId) const diff --git a/src/plugins/projectexplorer/runcontrol.h b/src/plugins/projectexplorer/runcontrol.h index b900ee9b8df..f0a5720dbb3 100644 --- a/src/plugins/projectexplorer/runcontrol.h +++ b/src/plugins/projectexplorer/runcontrol.h @@ -141,11 +141,12 @@ private: const std::unique_ptr d; }; -class PROJECTEXPLORER_EXPORT RunWorkerFactory final +class PROJECTEXPLORER_EXPORT RunWorkerFactory { public: using WorkerCreator = std::function; + RunWorkerFactory(); RunWorkerFactory(const WorkerCreator &producer, const QList &runModes, const QList &runConfigs = {}, @@ -165,6 +166,14 @@ public: // For debugging only. static void dumpAll(); +protected: + template + void setProduct() { setProducer([](RunControl *rc) { return new Worker(rc); }); } + void setProducer(const WorkerCreator &producer); + void addSupportedRunMode(Utils::Id runMode); + void addSupportedRunConfig(Utils::Id runConfig); + void addSupportedDeviceType(Utils::Id deviceType); + private: WorkerCreator m_producer; QList m_supportedRunModes;