diff --git a/src/plugins/clangstaticanalyzer/clangstaticanalyzerplugin.cpp b/src/plugins/clangstaticanalyzer/clangstaticanalyzerplugin.cpp index f10b2784bb8..e18b9747b81 100644 --- a/src/plugins/clangstaticanalyzer/clangstaticanalyzerplugin.cpp +++ b/src/plugins/clangstaticanalyzer/clangstaticanalyzerplugin.cpp @@ -143,7 +143,7 @@ bool ClangStaticAnalyzerPlugin::initialize(const QStringList &arguments, QString }; RunControl::registerWorker - (Constants::CLANGSTATICANALYZER_RUN_MODE, constraint); + (Constants::CLANGSTATICANALYZER_RUN_MODE, constraint, /*priority*/ -1); return true; } diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index d0984117068..093c261ad22 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -522,14 +522,24 @@ bool IRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id run RunControl *IRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id runMode, QString *) { + WorkerFactories candidates; for (const RunControl::WorkerFactory &factory : theWorkerFactories()) { - if (factory.canRun(runConfiguration, runMode)) { - auto runControl = new RunControl(runConfiguration, runMode); - factory.producer(runControl); - return runControl; - } - }; - return nullptr; + 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; } /*! diff --git a/src/plugins/projectexplorer/runconfiguration.h b/src/plugins/projectexplorer/runconfiguration.h index eb408c204a0..264ec4fd50a 100644 --- a/src/plugins/projectexplorer/runconfiguration.h +++ b/src/plugins/projectexplorer/runconfiguration.h @@ -450,23 +450,24 @@ public: addWorkerFactory({runMode, constraint, producer}); } template - 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); }; - addWorkerFactory({runMode, constraint, producer}); + addWorkerFactory({runMode, constraint, producer, priority}); } template - static void registerWorker(Core::Id runMode) + static void registerWorker(Core::Id runMode, int priority = 0) { auto constraint = [](RunConfiguration *runConfig) { return qobject_cast(runConfig); }; auto producer = [](RunControl *rc) { return new Worker(rc); }; - addWorkerFactory({runMode, constraint, producer}); + addWorkerFactory({runMode, constraint, producer, priority}); } struct WorkerFactory { Core::Id runMode; Constraint constraint; WorkerCreator producer; + int priority = 0; bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const; };