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 <christian.kandeler@qt.io>
This commit is contained in:
hjk
2021-06-17 12:46:21 +02:00
parent c533e5c43c
commit de6c7696d2
5 changed files with 55 additions and 11 deletions

View File

@@ -55,12 +55,12 @@ using namespace Utils;
namespace ProjectExplorer { namespace ProjectExplorer {
const char CUSTOM_EXECUTABLE_ID[] = "ProjectExplorer.CustomExecutableRunConfiguration"; const char CUSTOM_EXECUTABLE_RUNCONFIG_ID[] = "ProjectExplorer.CustomExecutableRunConfiguration";
// CustomExecutableRunConfiguration // CustomExecutableRunConfiguration
CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target) CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target)
: CustomExecutableRunConfiguration(target, CUSTOM_EXECUTABLE_ID) : CustomExecutableRunConfiguration(target, CUSTOM_EXECUTABLE_RUNCONFIG_ID)
{} {}
CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target, Utils::Id id) CustomExecutableRunConfiguration::CustomExecutableRunConfiguration(Target *target, Utils::Id id)
@@ -132,12 +132,19 @@ Tasks CustomExecutableRunConfiguration::checkForIssues() const
return tasks; return tasks;
} }
// Factory // Factories
CustomExecutableRunConfigurationFactory::CustomExecutableRunConfigurationFactory() : CustomExecutableRunConfigurationFactory::CustomExecutableRunConfigurationFactory() :
FixedRunConfigurationFactory(CustomExecutableRunConfiguration::tr("Custom Executable")) FixedRunConfigurationFactory(CustomExecutableRunConfiguration::tr("Custom Executable"))
{ {
registerRunConfiguration<CustomExecutableRunConfiguration>(CUSTOM_EXECUTABLE_ID); registerRunConfiguration<CustomExecutableRunConfiguration>(CUSTOM_EXECUTABLE_RUNCONFIG_ID);
}
CustomExecutableRunWorkerFactory::CustomExecutableRunWorkerFactory()
{
setProduct<SimpleTargetRunner>();
addSupportedRunMode(Constants::NORMAL_RUN_MODE);
addSupportedRunConfig(CUSTOM_EXECUTABLE_RUNCONFIG_ID);
} }
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -25,7 +25,8 @@
#pragma once #pragma once
#include "projectexplorer/runconfigurationaspects.h" #include "runconfigurationaspects.h"
#include "runcontrol.h"
namespace ProjectExplorer { namespace ProjectExplorer {
@@ -54,4 +55,10 @@ public:
CustomExecutableRunConfigurationFactory(); CustomExecutableRunConfigurationFactory();
}; };
class CustomExecutableRunWorkerFactory : public RunWorkerFactory
{
public:
CustomExecutableRunWorkerFactory();
};
} // namespace ProjectExplorer } // namespace ProjectExplorer

View File

@@ -631,11 +631,7 @@ public:
CurrentProjectFind m_curretProjectFind; CurrentProjectFind m_curretProjectFind;
CustomExecutableRunConfigurationFactory m_customExecutableRunConfigFactory; CustomExecutableRunConfigurationFactory m_customExecutableRunConfigFactory;
RunWorkerFactory m_customExecutableRunWorkerFactory{ CustomExecutableRunWorkerFactory m_customExecutableRunWorkerFactory;
RunWorkerFactory::make<SimpleTargetRunner>(),
{Constants::NORMAL_RUN_MODE},
{m_customExecutableRunConfigFactory.runConfigurationId()}
};
ProjectFileWizardExtension m_projectFileWizardExtension; ProjectFileWizardExtension m_projectFileWizardExtension;

View File

@@ -80,6 +80,11 @@ static QList<RunWorkerFactory *> g_runWorkerFactories;
static QSet<Utils::Id> g_runModes; static QSet<Utils::Id> g_runModes;
static QSet<Utils::Id> g_runConfigs; static QSet<Utils::Id> g_runConfigs;
RunWorkerFactory::RunWorkerFactory()
{
g_runWorkerFactories.append(this);
}
RunWorkerFactory::RunWorkerFactory(const WorkerCreator &producer, RunWorkerFactory::RunWorkerFactory(const WorkerCreator &producer,
const QList<Utils::Id> &runModes, const QList<Utils::Id> &runModes,
const QList<Utils::Id> &runConfigs, const QList<Utils::Id> &runConfigs,
@@ -103,6 +108,26 @@ RunWorkerFactory::~RunWorkerFactory()
g_runWorkerFactories.removeOne(this); 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, bool RunWorkerFactory::canRun(Utils::Id runMode,
Utils::Id deviceType, Utils::Id deviceType,
const QString &runConfigId) const const QString &runConfigId) const

View File

@@ -141,11 +141,12 @@ private:
const std::unique_ptr<Internal::RunWorkerPrivate> d; const std::unique_ptr<Internal::RunWorkerPrivate> d;
}; };
class PROJECTEXPLORER_EXPORT RunWorkerFactory final class PROJECTEXPLORER_EXPORT RunWorkerFactory
{ {
public: public:
using WorkerCreator = std::function<RunWorker *(RunControl *)>; using WorkerCreator = std::function<RunWorker *(RunControl *)>;
RunWorkerFactory();
RunWorkerFactory(const WorkerCreator &producer, RunWorkerFactory(const WorkerCreator &producer,
const QList<Utils::Id> &runModes, const QList<Utils::Id> &runModes,
const QList<Utils::Id> &runConfigs = {}, const QList<Utils::Id> &runConfigs = {},
@@ -165,6 +166,14 @@ public:
// For debugging only. // For debugging only.
static void dumpAll(); static void dumpAll();
protected:
template <typename Worker>
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: private:
WorkerCreator m_producer; WorkerCreator m_producer;
QList<Utils::Id> m_supportedRunModes; QList<Utils::Id> m_supportedRunModes;