From 86e9c42c9076dee16780842f2467ffc885cb9dd3 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 8 Aug 2019 15:52:41 +0200 Subject: [PATCH] Project: Push direct RunConfiguration use out of RunWorker factories Change-Id: Ie5a5771bcaed7085494d5875b42668ee8d6dc157 Reviewed-by: Christian Stenger --- .../projectexplorer/projectexplorer.cpp | 4 ++- src/plugins/projectexplorer/runcontrol.cpp | 35 +++++++++++-------- src/plugins/projectexplorer/runcontrol.h | 4 +-- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index a101015df2f..866bb0da87b 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -3029,7 +3029,9 @@ bool ProjectExplorerPlugin::canRunStartupProject(Core::Id runMode, QString *whyN } // shouldn't actually be shown to the user... - if (!RunControl::canRun(activeRC, runMode)) { + if (!RunControl::canRun(runMode, + DeviceTypeKitAspect::deviceTypeId(target->kit()), + activeRC->id())) { if (whyNot) *whyNot = tr("Cannot run \"%1\".").arg(activeRC->displayName()); return false; diff --git a/src/plugins/projectexplorer/runcontrol.cpp b/src/plugins/projectexplorer/runcontrol.cpp index f207eb9c8b6..7d1ce1196e5 100644 --- a/src/plugins/projectexplorer/runcontrol.cpp +++ b/src/plugins/projectexplorer/runcontrol.cpp @@ -90,19 +90,20 @@ RunWorkerFactory::~RunWorkerFactory() g_runWorkerFactories.removeOne(this); } -bool RunWorkerFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const +bool RunWorkerFactory::canRun(Core::Id runMode, + Core::Id deviceType, + const QString &runConfigId) const { if (!m_supportedRunModes.contains(runMode)) return false; if (!m_supportedRunConfigurations.isEmpty()) { // FIXME: That's to be used after mangled ids are gone. - //if (!m_supportedRunConfigurations.contains(runConfiguration->id())) + //if (!m_supportedRunConfigurations.contains(runConfigId) // return false; bool ok = false; - const QString rcid = runConfiguration->id().toString(); for (const Core::Id &id : m_supportedRunConfigurations) { - if (rcid.startsWith(id.toString())) { + if (runConfigId.startsWith(id.toString())) { ok = true; break; } @@ -112,12 +113,8 @@ bool RunWorkerFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMo return false; } - if (!m_supportedDeviceTypes.isEmpty()) { - Target *target = runConfiguration ? runConfiguration->target() : nullptr; - Kit *kit = target ? target->kit() : nullptr; - const Core::Id devid = DeviceTypeKitAspect::deviceTypeId(kit); - return m_supportedDeviceTypes.contains(devid); - } + if (!m_supportedDeviceTypes.isEmpty()) + return m_supportedDeviceTypes.contains(deviceType); return true; } @@ -297,6 +294,7 @@ public: Utils::Icon icon; MacroExpander *macroExpander; QPointer runConfiguration; // Not owned. Avoid use. + Core::Id runConfigId; Kit *kit = nullptr; // Not owned. QPointer target; // Not owned. QPointer project; // Not owned. @@ -326,6 +324,7 @@ void RunControl::setRunConfiguration(RunConfiguration *runConfig) QTC_ASSERT(runConfig, return); QTC_CHECK(!d->runConfiguration); d->runConfiguration = runConfig; + d->runConfigId = runConfig->id(); d->runnable = runConfig->runnable(); d->displayName = runConfig->displayName(); if (auto outputFormatter = runConfig->createOutputFormatter()) { @@ -447,8 +446,12 @@ RunWorker *RunControl::createWorker(Core::Id id) bool RunControl::createMainWorker() { - const auto canRun = std::bind(&RunWorkerFactory::canRun, std::placeholders::_1, - d->runConfiguration, d->runMode); + const auto canRun = std::bind(&RunWorkerFactory::canRun, + std::placeholders::_1, + d->runMode, + DeviceTypeKitAspect::deviceTypeId(d->kit), + d->runConfigId.toString()); + const QList candidates = Utils::filtered(g_runWorkerFactories, canRun); // There might be combinations that cannot run. But that should have been checked // with canRun below. @@ -460,9 +463,13 @@ bool RunControl::createMainWorker() return candidates.front()->producer()(this) != nullptr; } -bool RunControl::canRun(RunConfiguration *runConfig, Core::Id runMode) +bool RunControl::canRun(Core::Id runMode, Core::Id deviceType, Core::Id runConfigId) { - const auto check = std::bind(&RunWorkerFactory::canRun, std::placeholders::_1, runConfig, runMode); + const auto check = std::bind(&RunWorkerFactory::canRun, + std::placeholders::_1, + runMode, + deviceType, + runConfigId.toString()); return Utils::contains(g_runWorkerFactories, check); } diff --git a/src/plugins/projectexplorer/runcontrol.h b/src/plugins/projectexplorer/runcontrol.h index b7946347429..67f06fcea1c 100644 --- a/src/plugins/projectexplorer/runcontrol.h +++ b/src/plugins/projectexplorer/runcontrol.h @@ -151,7 +151,7 @@ public: ~RunWorkerFactory(); - bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const; + bool canRun(Core::Id runMode, Core::Id deviceType, const QString &runConfigId) const; WorkerCreator producer() const { return m_producer; } template @@ -256,7 +256,7 @@ public: static void registerWorkerCreator(Core::Id id, const WorkerCreator &workerCreator); bool createMainWorker(); - static bool canRun(RunConfiguration *runConfig, Core::Id runMode); + static bool canRun(Core::Id runMode, Core::Id deviceType, Core::Id runConfigId); signals: void appendMessage(const QString &msg, Utils::OutputFormat format);