forked from qt-creator/qt-creator
ProjectExplorer: Move RunWorker priority handling to worker selection
This fixes the temporary regression introduced by 5a848aa1. After
having RunWorker registration in RunControl and RunConfigurationAspect
registration in RunConfiguration, this was effectively the only
remaining code in IRunControlFactory, so this can go now.
Change-Id: I38b51bb00058b90d30f0260660b040f788920008
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -1995,17 +1995,6 @@ static RunControlFactory findRunControlFactory(RunConfiguration *config, Core::I
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
IRunControlFactory *runControlFactory = ExtensionSystem::PluginManager::getObject<IRunControlFactory>(
|
|
||||||
[&config, &mode](IRunControlFactory *factory) {
|
|
||||||
return factory->canRun(config, mode);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (runControlFactory) {
|
|
||||||
return [runControlFactory](RunConfiguration *rc, Id runMode, QString *errorMessage) {
|
|
||||||
return runControlFactory->create(rc, runMode, errorMessage);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ namespace Utils { class ProcessHandle; }
|
|||||||
namespace ProjectExplorer {
|
namespace ProjectExplorer {
|
||||||
class RunControl;
|
class RunControl;
|
||||||
class RunConfiguration;
|
class RunConfiguration;
|
||||||
class IRunControlFactory;
|
|
||||||
class Project;
|
class Project;
|
||||||
class Node;
|
class Node;
|
||||||
class FolderNode;
|
class FolderNode;
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ IRunConfigurationAspect *RunConfiguration::extraAspect(Core::Id id) const
|
|||||||
|
|
||||||
A target specific \l RunConfiguration implementation can specify
|
A target specific \l RunConfiguration implementation can specify
|
||||||
what information it considers necessary to execute a process
|
what information it considers necessary to execute a process
|
||||||
on the target. Target specific) \n IRunControlFactory implementation
|
on the target. Target specific) \n RunWorker implementation
|
||||||
can use that information either unmodified or tweak it or ignore
|
can use that information either unmodified or tweak it or ignore
|
||||||
it when setting up a RunControl.
|
it when setting up a RunControl.
|
||||||
|
|
||||||
@@ -473,29 +473,6 @@ QList<IRunConfigurationFactory *> IRunConfigurationFactory::find(Target *parent)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
\class ProjectExplorer::IRunControlFactory
|
|
||||||
|
|
||||||
\brief The IRunControlFactory class creates RunControl objects matching a
|
|
||||||
run configuration.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\fn RunConfigWidget *ProjectExplorer::IRunConfigurationAspect::createConfigurationWidget()
|
|
||||||
|
|
||||||
Returns a widget used to configure this runner. Ownership is transferred to
|
|
||||||
the caller.
|
|
||||||
|
|
||||||
Returns null if @p \a runConfiguration is not suitable for RunControls from this
|
|
||||||
factory, or no user-accessible
|
|
||||||
configuration is required.
|
|
||||||
*/
|
|
||||||
|
|
||||||
IRunControlFactory::IRunControlFactory(QObject *parent)
|
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
using WorkerFactories = std::vector<RunControl::WorkerFactory>;
|
using WorkerFactories = std::vector<RunControl::WorkerFactory>;
|
||||||
|
|
||||||
static WorkerFactories &theWorkerFactories()
|
static WorkerFactories &theWorkerFactories()
|
||||||
@@ -513,37 +490,6 @@ bool RunControl::WorkerFactory::canRun(RunConfiguration *runConfiguration, Core:
|
|||||||
return constraint(runConfiguration);
|
return constraint(runConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const
|
|
||||||
{
|
|
||||||
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
|
|
||||||
if (factory.canRun(runConfiguration, runMode))
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
RunControl *IRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id runMode, QString *)
|
|
||||||
{
|
|
||||||
WorkerFactories candidates;
|
|
||||||
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
|
|
||||||
if (factory.canRun(runConfiguration, runMode))
|
|
||||||
candidates.push_back(factory);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (candidates.empty())
|
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
RunControl::WorkerFactory bestFactory = *candidates.begin();
|
|
||||||
for (const RunControl::WorkerFactory &factory : candidates) {
|
|
||||||
if (factory.priority > bestFactory.priority)
|
|
||||||
bestFactory = factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto runControl = new RunControl(runConfiguration, runMode);
|
|
||||||
bestFactory.producer(runControl);
|
|
||||||
return runControl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class ProjectExplorer::RunControl
|
\class ProjectExplorer::RunControl
|
||||||
\brief The RunControl class instances represent one item that is run.
|
\brief The RunControl class instances represent one item that is run.
|
||||||
@@ -558,18 +504,6 @@ RunControl *IRunControlFactory::create(RunConfiguration *runConfiguration, Core:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
const char PRIORITY_KEY[] = "RunControlFactoryPriority";
|
|
||||||
|
|
||||||
int ProjectExplorer::IRunControlFactory::priority() const
|
|
||||||
{
|
|
||||||
return property(PRIORITY_KEY).toInt(); // 0 by default.
|
|
||||||
}
|
|
||||||
|
|
||||||
void IRunControlFactory::setPriority(int priority)
|
|
||||||
{
|
|
||||||
setProperty(PRIORITY_KEY, priority);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
enum class RunWorkerState
|
enum class RunWorkerState
|
||||||
@@ -797,12 +731,22 @@ RunWorker *RunControl::createWorker(Core::Id id)
|
|||||||
|
|
||||||
RunControl::WorkerCreator RunControl::producer(RunConfiguration *runConfiguration, Core::Id runMode)
|
RunControl::WorkerCreator RunControl::producer(RunConfiguration *runConfiguration, Core::Id runMode)
|
||||||
{
|
{
|
||||||
for (const auto &factory : theWorkerFactories()) {
|
WorkerFactories candidates;
|
||||||
if (factory.runMode == runMode
|
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
|
||||||
&& (!factory.constraint || factory.constraint(runConfiguration)))
|
if (factory.canRun(runConfiguration, runMode))
|
||||||
return factory.producer;
|
candidates.push_back(factory);
|
||||||
}
|
}
|
||||||
return {};
|
|
||||||
|
if (candidates.empty())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
RunControl::WorkerFactory bestFactory = *candidates.begin();
|
||||||
|
for (const RunControl::WorkerFactory &factory : candidates) {
|
||||||
|
if (factory.priority > bestFactory.priority)
|
||||||
|
bestFactory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bestFactory.producer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunControl::addWorkerFactory(const RunControl::WorkerFactory &workerFactory)
|
void RunControl::addWorkerFactory(const RunControl::WorkerFactory &workerFactory)
|
||||||
|
|||||||
@@ -301,20 +301,6 @@ private:
|
|||||||
virtual RunConfiguration *doRestore(Target *parent, const QVariantMap &map) = 0;
|
virtual RunConfiguration *doRestore(Target *parent, const QVariantMap &map) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT IRunControlFactory : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit IRunControlFactory(QObject *parent = nullptr);
|
|
||||||
|
|
||||||
virtual bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const;
|
|
||||||
virtual RunControl *create(RunConfiguration *runConfiguration, Core::Id runMode, QString *errorMessage);
|
|
||||||
|
|
||||||
int priority() const;
|
|
||||||
protected:
|
|
||||||
void setPriority(int priority); // Higher values will be preferred.
|
|
||||||
};
|
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT RunConfigWidget : public QWidget
|
class PROJECTEXPLORER_EXPORT RunConfigWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
Reference in New Issue
Block a user