From c8054d9547ffffd9300340d48033e9f75f3f3e7b Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 14 Jul 2017 11:22:35 +0200 Subject: [PATCH] ProjectExplorer: Heed RunControlFactory priorities again This fixes the regression introduced in 5a848aa18872f and uses the feature to resolve the conflict between ClangStaticAnalyzer and Boot2Qt. Change-Id: I6cdec8261a457c399c11a4b2078a78088d4c56d1 Reviewed-by: Christian Kandeler --- .../clangstaticanalyzerplugin.cpp | 2 +- .../projectexplorer/runconfiguration.cpp | 24 +++++++++++++------ .../projectexplorer/runconfiguration.h | 9 +++---- 3 files changed, 23 insertions(+), 12 deletions(-) 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; };