forked from qt-creator/qt-creator
Project: Push direct RunConfiguration use out of RunWorker factories
Change-Id: Ie5a5771bcaed7085494d5875b42668ee8d6dc157 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -3029,7 +3029,9 @@ bool ProjectExplorerPlugin::canRunStartupProject(Core::Id runMode, QString *whyN
|
|||||||
}
|
}
|
||||||
|
|
||||||
// shouldn't actually be shown to the user...
|
// 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)
|
if (whyNot)
|
||||||
*whyNot = tr("Cannot run \"%1\".").arg(activeRC->displayName());
|
*whyNot = tr("Cannot run \"%1\".").arg(activeRC->displayName());
|
||||||
return false;
|
return false;
|
||||||
|
@@ -90,19 +90,20 @@ RunWorkerFactory::~RunWorkerFactory()
|
|||||||
g_runWorkerFactories.removeOne(this);
|
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))
|
if (!m_supportedRunModes.contains(runMode))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!m_supportedRunConfigurations.isEmpty()) {
|
if (!m_supportedRunConfigurations.isEmpty()) {
|
||||||
// FIXME: That's to be used after mangled ids are gone.
|
// FIXME: That's to be used after mangled ids are gone.
|
||||||
//if (!m_supportedRunConfigurations.contains(runConfiguration->id()))
|
//if (!m_supportedRunConfigurations.contains(runConfigId)
|
||||||
// return false;
|
// return false;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
const QString rcid = runConfiguration->id().toString();
|
|
||||||
for (const Core::Id &id : m_supportedRunConfigurations) {
|
for (const Core::Id &id : m_supportedRunConfigurations) {
|
||||||
if (rcid.startsWith(id.toString())) {
|
if (runConfigId.startsWith(id.toString())) {
|
||||||
ok = true;
|
ok = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -112,12 +113,8 @@ bool RunWorkerFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMo
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!m_supportedDeviceTypes.isEmpty()) {
|
if (!m_supportedDeviceTypes.isEmpty())
|
||||||
Target *target = runConfiguration ? runConfiguration->target() : nullptr;
|
return m_supportedDeviceTypes.contains(deviceType);
|
||||||
Kit *kit = target ? target->kit() : nullptr;
|
|
||||||
const Core::Id devid = DeviceTypeKitAspect::deviceTypeId(kit);
|
|
||||||
return m_supportedDeviceTypes.contains(devid);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -297,6 +294,7 @@ public:
|
|||||||
Utils::Icon icon;
|
Utils::Icon icon;
|
||||||
MacroExpander *macroExpander;
|
MacroExpander *macroExpander;
|
||||||
QPointer<RunConfiguration> runConfiguration; // Not owned. Avoid use.
|
QPointer<RunConfiguration> runConfiguration; // Not owned. Avoid use.
|
||||||
|
Core::Id runConfigId;
|
||||||
Kit *kit = nullptr; // Not owned.
|
Kit *kit = nullptr; // Not owned.
|
||||||
QPointer<Target> target; // Not owned.
|
QPointer<Target> target; // Not owned.
|
||||||
QPointer<Project> project; // Not owned.
|
QPointer<Project> project; // Not owned.
|
||||||
@@ -326,6 +324,7 @@ void RunControl::setRunConfiguration(RunConfiguration *runConfig)
|
|||||||
QTC_ASSERT(runConfig, return);
|
QTC_ASSERT(runConfig, return);
|
||||||
QTC_CHECK(!d->runConfiguration);
|
QTC_CHECK(!d->runConfiguration);
|
||||||
d->runConfiguration = runConfig;
|
d->runConfiguration = runConfig;
|
||||||
|
d->runConfigId = runConfig->id();
|
||||||
d->runnable = runConfig->runnable();
|
d->runnable = runConfig->runnable();
|
||||||
d->displayName = runConfig->displayName();
|
d->displayName = runConfig->displayName();
|
||||||
if (auto outputFormatter = runConfig->createOutputFormatter()) {
|
if (auto outputFormatter = runConfig->createOutputFormatter()) {
|
||||||
@@ -447,8 +446,12 @@ RunWorker *RunControl::createWorker(Core::Id id)
|
|||||||
|
|
||||||
bool RunControl::createMainWorker()
|
bool RunControl::createMainWorker()
|
||||||
{
|
{
|
||||||
const auto canRun = std::bind(&RunWorkerFactory::canRun, std::placeholders::_1,
|
const auto canRun = std::bind(&RunWorkerFactory::canRun,
|
||||||
d->runConfiguration, d->runMode);
|
std::placeholders::_1,
|
||||||
|
d->runMode,
|
||||||
|
DeviceTypeKitAspect::deviceTypeId(d->kit),
|
||||||
|
d->runConfigId.toString());
|
||||||
|
|
||||||
const QList<RunWorkerFactory *> candidates = Utils::filtered(g_runWorkerFactories, canRun);
|
const QList<RunWorkerFactory *> candidates = Utils::filtered(g_runWorkerFactories, canRun);
|
||||||
// There might be combinations that cannot run. But that should have been checked
|
// There might be combinations that cannot run. But that should have been checked
|
||||||
// with canRun below.
|
// with canRun below.
|
||||||
@@ -460,9 +463,13 @@ bool RunControl::createMainWorker()
|
|||||||
return candidates.front()->producer()(this) != nullptr;
|
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);
|
return Utils::contains(g_runWorkerFactories, check);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -151,7 +151,7 @@ public:
|
|||||||
|
|
||||||
~RunWorkerFactory();
|
~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; }
|
WorkerCreator producer() const { return m_producer; }
|
||||||
|
|
||||||
template <typename Worker>
|
template <typename Worker>
|
||||||
@@ -256,7 +256,7 @@ public:
|
|||||||
static void registerWorkerCreator(Core::Id id, const WorkerCreator &workerCreator);
|
static void registerWorkerCreator(Core::Id id, const WorkerCreator &workerCreator);
|
||||||
|
|
||||||
bool createMainWorker();
|
bool createMainWorker();
|
||||||
static bool canRun(RunConfiguration *runConfig, Core::Id runMode);
|
static bool canRun(Core::Id runMode, Core::Id deviceType, Core::Id runConfigId);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void appendMessage(const QString &msg, Utils::OutputFormat format);
|
void appendMessage(const QString &msg, Utils::OutputFormat format);
|
||||||
|
Reference in New Issue
Block a user