ProjectExplorer: Heed RunControlFactory priorities again

This fixes the regression introduced in 5a848aa188 and uses the
feature to resolve the conflict between ClangStaticAnalyzer and Boot2Qt.

Change-Id: I6cdec8261a457c399c11a4b2078a78088d4c56d1
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2017-07-14 11:22:35 +02:00
parent a7e895166f
commit c8054d9547
3 changed files with 23 additions and 12 deletions

View File

@@ -143,7 +143,7 @@ bool ClangStaticAnalyzerPlugin::initialize(const QStringList &arguments, QString
}; };
RunControl::registerWorker<ClangStaticAnalyzerToolRunner> RunControl::registerWorker<ClangStaticAnalyzerToolRunner>
(Constants::CLANGSTATICANALYZER_RUN_MODE, constraint); (Constants::CLANGSTATICANALYZER_RUN_MODE, constraint, /*priority*/ -1);
return true; return true;
} }

View File

@@ -522,14 +522,24 @@ bool IRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id run
RunControl *IRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id runMode, QString *) RunControl *IRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id runMode, QString *)
{ {
WorkerFactories candidates;
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) { for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
if (factory.canRun(runConfiguration, runMode)) { if (factory.canRun(runConfiguration, runMode))
auto runControl = new RunControl(runConfiguration, runMode); candidates.push_back(factory);
factory.producer(runControl); }
return runControl;
} if (candidates.empty())
}; return nullptr;
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;
} }
/*! /*!

View File

@@ -450,23 +450,24 @@ public:
addWorkerFactory({runMode, constraint, producer}); addWorkerFactory({runMode, constraint, producer});
} }
template <class Worker> template <class Worker>
static void registerWorker(Core::Id runMode, const Constraint &constraint) static void registerWorker(Core::Id runMode, const Constraint &constraint, int priority = 0)
{ {
auto producer = [](RunControl *rc) { return new Worker(rc); }; auto producer = [](RunControl *rc) { return new Worker(rc); };
addWorkerFactory({runMode, constraint, producer}); addWorkerFactory({runMode, constraint, producer, priority});
} }
template <class Config, class Worker> template <class Config, class Worker>
static void registerWorker(Core::Id runMode) static void registerWorker(Core::Id runMode, int priority = 0)
{ {
auto constraint = [](RunConfiguration *runConfig) { return qobject_cast<Config *>(runConfig); }; auto constraint = [](RunConfiguration *runConfig) { return qobject_cast<Config *>(runConfig); };
auto producer = [](RunControl *rc) { return new Worker(rc); }; auto producer = [](RunControl *rc) { return new Worker(rc); };
addWorkerFactory({runMode, constraint, producer}); addWorkerFactory({runMode, constraint, producer, priority});
} }
struct WorkerFactory { struct WorkerFactory {
Core::Id runMode; Core::Id runMode;
Constraint constraint; Constraint constraint;
WorkerCreator producer; WorkerCreator producer;
int priority = 0;
bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const; bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const;
}; };