forked from qt-creator/qt-creator
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:
@@ -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<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
|
||||
|
@@ -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
|
||||
|
@@ -631,11 +631,7 @@ public:
|
||||
CurrentProjectFind m_curretProjectFind;
|
||||
|
||||
CustomExecutableRunConfigurationFactory m_customExecutableRunConfigFactory;
|
||||
RunWorkerFactory m_customExecutableRunWorkerFactory{
|
||||
RunWorkerFactory::make<SimpleTargetRunner>(),
|
||||
{Constants::NORMAL_RUN_MODE},
|
||||
{m_customExecutableRunConfigFactory.runConfigurationId()}
|
||||
};
|
||||
CustomExecutableRunWorkerFactory m_customExecutableRunWorkerFactory;
|
||||
|
||||
ProjectFileWizardExtension m_projectFileWizardExtension;
|
||||
|
||||
|
@@ -80,6 +80,11 @@ static QList<RunWorkerFactory *> g_runWorkerFactories;
|
||||
static QSet<Utils::Id> g_runModes;
|
||||
static QSet<Utils::Id> g_runConfigs;
|
||||
|
||||
RunWorkerFactory::RunWorkerFactory()
|
||||
{
|
||||
g_runWorkerFactories.append(this);
|
||||
}
|
||||
|
||||
RunWorkerFactory::RunWorkerFactory(const WorkerCreator &producer,
|
||||
const QList<Utils::Id> &runModes,
|
||||
const QList<Utils::Id> &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
|
||||
|
@@ -141,11 +141,12 @@ private:
|
||||
const std::unique_ptr<Internal::RunWorkerPrivate> d;
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT RunWorkerFactory final
|
||||
class PROJECTEXPLORER_EXPORT RunWorkerFactory
|
||||
{
|
||||
public:
|
||||
using WorkerCreator = std::function<RunWorker *(RunControl *)>;
|
||||
|
||||
RunWorkerFactory();
|
||||
RunWorkerFactory(const WorkerCreator &producer,
|
||||
const QList<Utils::Id> &runModes,
|
||||
const QList<Utils::Id> &runConfigs = {},
|
||||
@@ -165,6 +166,14 @@ public:
|
||||
// For debugging only.
|
||||
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:
|
||||
WorkerCreator m_producer;
|
||||
QList<Utils::Id> m_supportedRunModes;
|
||||
|
Reference in New Issue
Block a user