2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "runconfiguration.h"
|
2010-01-07 18:17:24 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "project.h"
|
2010-02-08 15:50:06 +01:00
|
|
|
#include "target.h"
|
2011-02-01 18:36:00 +01:00
|
|
|
#include "toolchain.h"
|
2011-08-18 13:46:52 +02:00
|
|
|
#include "abi.h"
|
2009-10-28 17:21:27 +01:00
|
|
|
#include "buildconfiguration.h"
|
2017-01-25 16:18:30 +01:00
|
|
|
#include "environmentaspect.h"
|
2012-09-03 18:31:44 +02:00
|
|
|
#include "kitinformation.h"
|
2017-03-10 09:05:52 +01:00
|
|
|
#include "runnables.h"
|
2017-06-30 08:41:08 +02:00
|
|
|
#include "session.h"
|
2017-03-10 09:05:52 +01:00
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2011-01-17 13:52:14 +01:00
|
|
|
|
2017-01-05 12:49:45 +01:00
|
|
|
#include <utils/algorithm.h>
|
2011-01-17 13:52:14 +01:00
|
|
|
#include <utils/checkablemessagebox.h>
|
2017-03-10 09:05:52 +01:00
|
|
|
#include <utils/outputformatter.h>
|
2017-02-27 17:25:58 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2017-03-10 09:05:52 +01:00
|
|
|
#include <utils/utilsicons.h>
|
2011-01-17 13:52:14 +01:00
|
|
|
|
|
|
|
|
#include <coreplugin/icore.h>
|
2013-03-26 11:32:14 +01:00
|
|
|
#include <coreplugin/icontext.h>
|
2010-02-08 15:50:06 +01:00
|
|
|
|
2017-03-10 09:05:52 +01:00
|
|
|
#include <QDir>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPushButton>
|
2017-03-10 09:05:52 +01:00
|
|
|
#include <QTimer>
|
2017-05-09 10:25:11 +02:00
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
#include <QSettings>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-02-01 12:15:44 +01:00
|
|
|
#ifdef Q_OS_OSX
|
2012-02-23 17:40:48 +01:00
|
|
|
#include <ApplicationServices/ApplicationServices.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#endif
|
|
|
|
|
|
2017-02-27 11:49:00 +01:00
|
|
|
#if defined (WITH_JOURNALD)
|
|
|
|
|
#include "journaldwatcher.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-01-16 15:53:53 +01:00
|
|
|
using namespace Utils;
|
2017-03-29 14:08:44 +02:00
|
|
|
using namespace ProjectExplorer::Internal;
|
2011-07-06 10:25:18 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
namespace {
|
|
|
|
|
Q_LOGGING_CATEGORY(statesLog, "qtc.projectmanager.states")
|
|
|
|
|
}
|
2017-05-04 12:12:27 +02:00
|
|
|
|
2017-01-16 15:53:53 +01:00
|
|
|
namespace ProjectExplorer {
|
2011-07-06 10:25:18 +02:00
|
|
|
|
2013-08-12 17:04:10 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// ISettingsAspect
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
ISettingsAspect *ISettingsAspect::clone() const
|
|
|
|
|
{
|
|
|
|
|
ISettingsAspect *other = create();
|
|
|
|
|
QVariantMap data;
|
|
|
|
|
toMap(data);
|
|
|
|
|
other->fromMap(data);
|
|
|
|
|
return other;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// IRunConfigurationAspect
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2016-04-13 15:52:14 +02:00
|
|
|
IRunConfigurationAspect::IRunConfigurationAspect(RunConfiguration *runConfig) :
|
|
|
|
|
m_runConfiguration(runConfig)
|
|
|
|
|
{ }
|
2013-08-12 17:04:10 +02:00
|
|
|
|
|
|
|
|
IRunConfigurationAspect::~IRunConfigurationAspect()
|
|
|
|
|
{
|
|
|
|
|
delete m_projectSettings;
|
|
|
|
|
}
|
2012-02-17 19:05:11 +01:00
|
|
|
|
2013-06-05 08:43:52 +03:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Returns the widget used to configure this run configuration. Ownership is
|
|
|
|
|
transferred to the caller.
|
2013-06-05 08:43:52 +03:00
|
|
|
*/
|
2013-08-12 17:04:10 +02:00
|
|
|
|
2016-04-21 19:07:07 +02:00
|
|
|
RunConfigWidget *IRunConfigurationAspect::createConfigurationWidget() const
|
2013-03-27 17:17:24 +01:00
|
|
|
{
|
2016-04-21 19:07:07 +02:00
|
|
|
return m_runConfigWidgetCreator ? m_runConfigWidgetCreator() : nullptr;
|
2013-03-27 17:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
2013-08-12 17:04:10 +02:00
|
|
|
void IRunConfigurationAspect::setProjectSettings(ISettingsAspect *settings)
|
|
|
|
|
{
|
|
|
|
|
m_projectSettings = settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IRunConfigurationAspect::setGlobalSettings(ISettingsAspect *settings)
|
|
|
|
|
{
|
|
|
|
|
m_globalSettings = settings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IRunConfigurationAspect::setUsingGlobalSettings(bool value)
|
|
|
|
|
{
|
|
|
|
|
m_useGlobalSettings = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ISettingsAspect *IRunConfigurationAspect::currentSettings() const
|
|
|
|
|
{
|
|
|
|
|
return m_useGlobalSettings ? m_globalSettings : m_projectSettings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IRunConfigurationAspect::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
m_projectSettings->fromMap(map);
|
|
|
|
|
m_useGlobalSettings = map.value(m_id.toString() + QLatin1String(".UseGlobalSettings"), true).toBool();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IRunConfigurationAspect::toMap(QVariantMap &map) const
|
|
|
|
|
{
|
|
|
|
|
m_projectSettings->toMap(map);
|
|
|
|
|
map.insert(m_id.toString() + QLatin1String(".UseGlobalSettings"), m_useGlobalSettings);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-21 19:07:07 +02:00
|
|
|
void IRunConfigurationAspect::setRunConfigWidgetCreator(const RunConfigWidgetCreator &runConfigWidgetCreator)
|
|
|
|
|
{
|
|
|
|
|
m_runConfigWidgetCreator = runConfigWidgetCreator;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-12 16:41:29 +01:00
|
|
|
IRunConfigurationAspect *IRunConfigurationAspect::clone(RunConfiguration *runConfig) const
|
2013-08-12 17:04:10 +02:00
|
|
|
{
|
2014-12-12 16:41:29 +01:00
|
|
|
IRunConfigurationAspect *other = create(runConfig);
|
2013-08-24 23:39:47 +03:00
|
|
|
if (m_projectSettings)
|
|
|
|
|
other->m_projectSettings = m_projectSettings->clone();
|
2013-08-12 17:04:10 +02:00
|
|
|
other->m_globalSettings = m_globalSettings;
|
|
|
|
|
other->m_useGlobalSettings = m_useGlobalSettings;
|
|
|
|
|
return other;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IRunConfigurationAspect::resetProjectToGlobalSettings()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_globalSettings, return);
|
|
|
|
|
QVariantMap map;
|
|
|
|
|
m_globalSettings->toMap(map);
|
|
|
|
|
m_projectSettings->fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 17:17:24 +01:00
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
|
|
|
|
\class ProjectExplorer::RunConfiguration
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The RunConfiguration class is the base class for a run configuration.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
A run configuration specifies how a target should be run, while a runner
|
|
|
|
|
does the actual running.
|
|
|
|
|
|
|
|
|
|
All RunControls and the target hold a shared pointer to the run
|
|
|
|
|
configuration. That is, the lifetime of the run configuration might exceed
|
|
|
|
|
the life of the target.
|
2011-04-14 12:58:14 +02:00
|
|
|
The user might still have a RunControl running (or output tab of that RunControl open)
|
|
|
|
|
and yet unloaded the target.
|
|
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
Also, a run configuration might be already removed from the list of run
|
|
|
|
|
configurations
|
2011-04-14 12:58:14 +02:00
|
|
|
for a target, but still be runnable via the output tab.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-14 09:36:09 +02:00
|
|
|
static std::vector<RunConfiguration::AspectFactory> theAspectFactories;
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
RunConfiguration::RunConfiguration(Target *target, Core::Id id) :
|
2017-01-05 12:49:45 +01:00
|
|
|
ProjectConfiguration(target, id)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-16 14:00:41 +02:00
|
|
|
Q_ASSERT(target);
|
2013-03-27 13:03:15 +01:00
|
|
|
ctor();
|
2017-01-05 12:49:45 +01:00
|
|
|
|
2017-07-14 09:36:09 +02:00
|
|
|
for (const AspectFactory &factory : theAspectFactories)
|
|
|
|
|
addExtraAspect(factory(this));
|
2010-01-19 13:41:02 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
RunConfiguration::RunConfiguration(Target *target, RunConfiguration *source) :
|
2017-01-05 12:49:45 +01:00
|
|
|
ProjectConfiguration(target, source)
|
2010-01-19 13:41:02 +01:00
|
|
|
{
|
2010-07-16 14:00:41 +02:00
|
|
|
Q_ASSERT(target);
|
2013-03-27 13:03:15 +01:00
|
|
|
ctor();
|
2012-09-20 14:42:57 +02:00
|
|
|
foreach (IRunConfigurationAspect *aspect, source->m_aspects) {
|
2013-03-22 15:18:52 +01:00
|
|
|
IRunConfigurationAspect *clone = aspect->clone(this);
|
|
|
|
|
if (clone)
|
|
|
|
|
m_aspects.append(clone);
|
2012-09-20 14:42:57 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RunConfiguration::~RunConfiguration()
|
|
|
|
|
{
|
2011-02-28 12:23:12 +01:00
|
|
|
qDeleteAll(m_aspects);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-14 09:36:09 +02:00
|
|
|
void RunConfiguration::addAspectFactory(const AspectFactory &aspectFactory)
|
2011-02-28 12:23:12 +01:00
|
|
|
{
|
2017-07-14 09:36:09 +02:00
|
|
|
theAspectFactories.push_back(aspectFactory);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-05 17:27:45 +02:00
|
|
|
void RunConfiguration::addExtraAspect(IRunConfigurationAspect *aspect)
|
|
|
|
|
{
|
|
|
|
|
if (aspect)
|
|
|
|
|
m_aspects += aspect;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 13:03:15 +01:00
|
|
|
void RunConfiguration::ctor()
|
|
|
|
|
{
|
2016-01-29 16:38:37 +02:00
|
|
|
connect(this, &RunConfiguration::enabledChanged,
|
|
|
|
|
this, &RunConfiguration::requestRunActionsUpdate);
|
2014-11-05 14:01:26 +01:00
|
|
|
|
2014-11-05 15:45:56 +01:00
|
|
|
Utils::MacroExpander *expander = macroExpander();
|
|
|
|
|
expander->setDisplayName(tr("Run Settings"));
|
|
|
|
|
expander->setAccumulating(true);
|
|
|
|
|
expander->registerSubProvider([this]() -> Utils::MacroExpander * {
|
|
|
|
|
BuildConfiguration *bc = target()->activeBuildConfiguration();
|
|
|
|
|
return bc ? bc->macroExpander() : target()->macroExpander();
|
|
|
|
|
});
|
2017-03-17 15:33:07 +02:00
|
|
|
expander->registerPrefix("CurrentRun:Env", tr("Variables in the current run environment"),
|
2017-01-25 16:18:30 +01:00
|
|
|
[this](const QString &var) {
|
|
|
|
|
const auto envAspect = extraAspect<EnvironmentAspect>();
|
|
|
|
|
return envAspect ? envAspect->environment().value(var) : QString();
|
|
|
|
|
});
|
2016-03-31 17:09:56 +03:00
|
|
|
expander->registerVariable(Constants::VAR_CURRENTRUN_NAME,
|
|
|
|
|
QCoreApplication::translate("ProjectExplorer", "The currently active run configuration's name."),
|
|
|
|
|
[this] { return displayName(); }, false);
|
2013-03-27 13:03:15 +01:00
|
|
|
}
|
|
|
|
|
|
2017-06-30 08:41:08 +02:00
|
|
|
/*!
|
|
|
|
|
* Returns the RunConfiguration of the currently active target
|
|
|
|
|
* of the startup project, if such exists, or \c nullptr otherwise.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
RunConfiguration *RunConfiguration::startupRunConfiguration()
|
|
|
|
|
{
|
|
|
|
|
if (Project *pro = SessionManager::startupProject()) {
|
|
|
|
|
if (const Target *target = pro->activeTarget())
|
|
|
|
|
return target->activeRunConfiguration();
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Checks whether a run configuration is enabled.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2011-05-26 15:33:24 +02:00
|
|
|
bool RunConfiguration::isEnabled() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-01-19 13:41:02 +01:00
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-26 16:30:35 +02:00
|
|
|
QString RunConfiguration::disabledReason() const
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
bool RunConfiguration::isConfigured() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 17:31:49 +02:00
|
|
|
RunConfiguration::ConfigurationState RunConfiguration::ensureConfigured(QString *errorMessage)
|
2012-09-13 11:27:15 +02:00
|
|
|
{
|
|
|
|
|
if (isConfigured())
|
2014-07-30 17:31:49 +02:00
|
|
|
return Configured;
|
2012-09-13 11:27:15 +02:00
|
|
|
if (errorMessage)
|
|
|
|
|
*errorMessage = tr("Unknown error.");
|
2014-07-30 17:31:49 +02:00
|
|
|
return UnConfigured;
|
2012-09-13 11:27:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
BuildConfiguration *RunConfiguration::activeBuildConfiguration() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-08 15:50:06 +01:00
|
|
|
if (!target())
|
2016-04-13 15:52:14 +02:00
|
|
|
return nullptr;
|
2010-02-08 15:50:06 +01:00
|
|
|
return target()->activeBuildConfiguration();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-08 15:50:06 +01:00
|
|
|
Target *RunConfiguration::target() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-07-16 14:00:41 +02:00
|
|
|
return static_cast<Target *>(parent());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-01 11:34:34 +02:00
|
|
|
QVariantMap RunConfiguration::toMap() const
|
|
|
|
|
{
|
2012-02-22 11:56:08 +01:00
|
|
|
QVariantMap map = ProjectConfiguration::toMap();
|
|
|
|
|
|
2011-02-28 12:23:12 +01:00
|
|
|
foreach (IRunConfigurationAspect *aspect, m_aspects)
|
2013-08-12 17:05:52 +02:00
|
|
|
aspect->toMap(map);
|
2011-02-28 12:23:12 +01:00
|
|
|
|
2010-09-01 11:34:34 +02:00
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-03 23:59:04 +02:00
|
|
|
Abi RunConfiguration::abi() const
|
2011-02-01 18:36:00 +01:00
|
|
|
{
|
|
|
|
|
BuildConfiguration *bc = target()->activeBuildConfiguration();
|
|
|
|
|
if (!bc)
|
|
|
|
|
return Abi::hostAbi();
|
2016-12-16 00:43:14 +01:00
|
|
|
ToolChain *tc = ToolChainKitInformation::toolChain(target()->kit(), Constants::CXX_LANGUAGE_ID);
|
2011-02-01 18:36:00 +01:00
|
|
|
if (!tc)
|
|
|
|
|
return Abi::hostAbi();
|
|
|
|
|
return tc->targetAbi();
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-01 11:34:34 +02:00
|
|
|
bool RunConfiguration::fromMap(const QVariantMap &map)
|
|
|
|
|
{
|
2011-02-28 12:23:12 +01:00
|
|
|
foreach (IRunConfigurationAspect *aspect, m_aspects)
|
2012-02-22 12:36:39 +01:00
|
|
|
aspect->fromMap(map);
|
2011-02-28 12:23:12 +01:00
|
|
|
|
2010-09-01 11:34:34 +02:00
|
|
|
return ProjectConfiguration::fromMap(map);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
|
|
|
|
\class ProjectExplorer::IRunConfigurationAspect
|
|
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The IRunConfigurationAspect class provides an additional
|
|
|
|
|
configuration aspect.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
Aspects are a mechanism to add RunControl-specific options to a run
|
|
|
|
|
configuration without subclassing the run configuration for every addition.
|
|
|
|
|
This prevents a combinatorial explosion of subclasses and eliminates
|
|
|
|
|
the need to add all options to the base class.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Returns extra aspects.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
|
|
|
|
\sa ProjectExplorer::IRunConfigurationAspect
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-28 12:23:12 +01:00
|
|
|
QList<IRunConfigurationAspect *> RunConfiguration::extraAspects() const
|
|
|
|
|
{
|
|
|
|
|
return m_aspects;
|
|
|
|
|
}
|
2017-01-05 12:49:45 +01:00
|
|
|
|
2013-08-12 17:04:10 +02:00
|
|
|
IRunConfigurationAspect *RunConfiguration::extraAspect(Core::Id id) const
|
|
|
|
|
{
|
2017-01-05 12:49:45 +01:00
|
|
|
return Utils::findOrDefault(m_aspects, Utils::equal(&IRunConfigurationAspect::id, id));
|
2013-08-12 17:04:10 +02:00
|
|
|
}
|
2011-02-28 12:23:12 +01:00
|
|
|
|
2016-01-20 14:50:34 +01:00
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
|
|
|
|
|
\class ProjectExplorer::Runnable
|
|
|
|
|
|
|
|
|
|
\brief The ProjectExplorer::Runnable class wraps information needed
|
|
|
|
|
to execute a process on a target device.
|
|
|
|
|
|
|
|
|
|
A target specific \l RunConfiguration implementation can specify
|
|
|
|
|
what information it considers necessary to execute a process
|
2017-07-18 10:39:03 +02:00
|
|
|
on the target. Target specific) \n RunWorker implementation
|
2016-01-20 14:50:34 +01:00
|
|
|
can use that information either unmodified or tweak it or ignore
|
|
|
|
|
it when setting up a RunControl.
|
|
|
|
|
|
|
|
|
|
From Qt Creator's core perspective a Runnable object is opaque.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\internal
|
|
|
|
|
|
|
|
|
|
\brief Returns a \l Runnable described by this RunConfiguration.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
Runnable RunConfiguration::runnable() const
|
|
|
|
|
{
|
|
|
|
|
return Runnable();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-15 12:59:44 +02:00
|
|
|
Utils::OutputFormatter *RunConfiguration::createOutputFormatter() const
|
2010-07-13 15:02:37 +02:00
|
|
|
{
|
2011-04-15 12:59:44 +02:00
|
|
|
return new Utils::OutputFormatter();
|
2010-07-13 15:02:37 +02:00
|
|
|
}
|
|
|
|
|
|
2011-05-31 09:48:00 +02:00
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
|
|
|
|
\class ProjectExplorer::IRunConfigurationFactory
|
|
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The IRunConfigurationFactory class restores run configurations from
|
|
|
|
|
settings.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
|
|
|
|
The run configuration factory is used for restoring run configurations from
|
2013-09-10 17:16:10 +02:00
|
|
|
settings and for creating new run configurations in the \gui {Run Settings}
|
|
|
|
|
dialog.
|
|
|
|
|
To restore run configurations, use the
|
|
|
|
|
\c {bool canRestore(Target *parent, const QString &id)}
|
|
|
|
|
and \c {RunConfiguration* create(Target *parent, const QString &id)}
|
|
|
|
|
functions.
|
|
|
|
|
|
|
|
|
|
To generate a list of creatable run configurations, use the
|
|
|
|
|
\c {QStringList availableCreationIds(Target *parent)} and
|
|
|
|
|
\c {QString displayNameForType(const QString&)} functions. To create a
|
|
|
|
|
run configuration, use \c create().
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn QStringList ProjectExplorer::IRunConfigurationFactory::availableCreationIds(Target *parent) const
|
|
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
Shows the list of possible additions to a target. Returns a list of types.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
2014-07-01 11:08:26 +02:00
|
|
|
\fn QString ProjectExplorer::IRunConfigurationFactory::displayNameForId(Core::Id id) const
|
2013-09-10 17:16:10 +02:00
|
|
|
Translates the types to names to display to the user.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2010-01-19 13:41:02 +01:00
|
|
|
IRunConfigurationFactory::IRunConfigurationFactory(QObject *parent) :
|
|
|
|
|
QObject(parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
RunConfiguration *IRunConfigurationFactory::create(Target *parent, Core::Id id)
|
2013-03-26 16:39:41 +01:00
|
|
|
{
|
|
|
|
|
if (!canCreate(parent, id))
|
2016-04-13 15:52:14 +02:00
|
|
|
return nullptr;
|
2013-03-26 16:39:41 +01:00
|
|
|
RunConfiguration *rc = doCreate(parent, id);
|
|
|
|
|
if (!rc)
|
2016-04-13 15:52:14 +02:00
|
|
|
return nullptr;
|
2013-03-26 16:39:41 +01:00
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-28 14:53:12 +01:00
|
|
|
RunConfiguration *IRunConfigurationFactory::restore(Target *parent, const QVariantMap &map)
|
|
|
|
|
{
|
|
|
|
|
if (!canRestore(parent, map))
|
2016-04-13 15:52:14 +02:00
|
|
|
return nullptr;
|
2013-03-28 14:53:12 +01:00
|
|
|
RunConfiguration *rc = doRestore(parent, map);
|
|
|
|
|
if (!rc->fromMap(map)) {
|
|
|
|
|
delete rc;
|
2016-04-13 15:52:14 +02:00
|
|
|
rc = nullptr;
|
2013-03-28 14:53:12 +01:00
|
|
|
}
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
IRunConfigurationFactory *IRunConfigurationFactory::find(Target *parent, const QVariantMap &map)
|
2010-02-08 15:50:06 +01:00
|
|
|
{
|
2014-05-08 11:58:23 +02:00
|
|
|
return ExtensionSystem::PluginManager::getObject<IRunConfigurationFactory>(
|
|
|
|
|
[&parent, &map](IRunConfigurationFactory *factory) {
|
|
|
|
|
return factory->canRestore(parent, map);
|
|
|
|
|
});
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
2012-09-20 14:42:57 +02:00
|
|
|
IRunConfigurationFactory *IRunConfigurationFactory::find(Target *parent, RunConfiguration *rc)
|
|
|
|
|
{
|
2014-05-08 11:58:23 +02:00
|
|
|
return ExtensionSystem::PluginManager::getObject<IRunConfigurationFactory>(
|
|
|
|
|
[&parent, rc](IRunConfigurationFactory *factory) {
|
|
|
|
|
return factory->canClone(parent, rc);
|
|
|
|
|
});
|
2012-09-20 14:42:57 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-24 15:49:09 +02:00
|
|
|
QList<IRunConfigurationFactory *> IRunConfigurationFactory::find(Target *parent)
|
2010-02-08 15:50:06 +01:00
|
|
|
{
|
2014-05-08 11:58:23 +02:00
|
|
|
return ExtensionSystem::PluginManager::getObjects<IRunConfigurationFactory>(
|
|
|
|
|
[&parent](IRunConfigurationFactory *factory) {
|
|
|
|
|
return !factory->availableCreationIds(parent).isEmpty();
|
|
|
|
|
});
|
2010-02-08 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
|
2017-06-19 13:27:59 +02:00
|
|
|
using WorkerFactories = std::vector<RunControl::WorkerFactory>;
|
|
|
|
|
|
|
|
|
|
static WorkerFactories &theWorkerFactories()
|
|
|
|
|
{
|
|
|
|
|
static WorkerFactories factories;
|
|
|
|
|
return factories;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-03 13:55:25 +02:00
|
|
|
bool RunControl::WorkerFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const
|
|
|
|
|
{
|
2017-07-18 14:56:59 +02:00
|
|
|
if (runMode != this->runMode)
|
2017-07-03 13:55:25 +02:00
|
|
|
return false;
|
|
|
|
|
if (!constraint)
|
|
|
|
|
return true;
|
|
|
|
|
return constraint(runConfiguration);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
|
|
|
|
\class ProjectExplorer::RunControl
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The RunControl class instances represent one item that is run.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\fn QIcon ProjectExplorer::RunControl::icon() const
|
2013-09-10 17:16:10 +02:00
|
|
|
Returns the icon to be shown in the Outputwindow.
|
2011-04-14 12:58:14 +02:00
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
TODO the icon differs currently only per "mode", so this is more flexible
|
|
|
|
|
than it needs to be.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2017-06-26 12:57:33 +02:00
|
|
|
|
2016-02-01 12:15:44 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
enum class RunWorkerState
|
|
|
|
|
{
|
2017-08-09 08:43:51 +02:00
|
|
|
Initialized, Starting, Running, Stopping, Done
|
2017-05-09 10:25:11 +02:00
|
|
|
};
|
|
|
|
|
|
2017-05-23 16:40:49 +02:00
|
|
|
static QString stateName(RunWorkerState s)
|
|
|
|
|
{
|
|
|
|
|
# define SN(x) case x: return QLatin1String(#x);
|
|
|
|
|
switch (s) {
|
|
|
|
|
SN(RunWorkerState::Initialized)
|
|
|
|
|
SN(RunWorkerState::Starting)
|
|
|
|
|
SN(RunWorkerState::Running)
|
|
|
|
|
SN(RunWorkerState::Stopping)
|
|
|
|
|
SN(RunWorkerState::Done)
|
|
|
|
|
}
|
2017-07-13 15:24:04 +02:00
|
|
|
return QString("<unknown: %1>").arg(int(s));
|
2017-05-23 16:40:49 +02:00
|
|
|
# undef SN
|
|
|
|
|
}
|
2017-05-09 10:25:11 +02:00
|
|
|
|
|
|
|
|
class RunWorkerPrivate : public QObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
RunWorkerPrivate(RunWorker *runWorker, RunControl *runControl);
|
|
|
|
|
|
|
|
|
|
bool canStart() const;
|
2017-08-08 14:49:49 +02:00
|
|
|
bool canStop() const;
|
2017-05-09 10:25:11 +02:00
|
|
|
void timerEvent(QTimerEvent *ev) override;
|
|
|
|
|
|
|
|
|
|
RunWorker *q;
|
|
|
|
|
RunWorkerState state = RunWorkerState::Initialized;
|
2017-07-13 15:24:04 +02:00
|
|
|
QPointer<RunControl> runControl;
|
2017-08-08 14:09:50 +02:00
|
|
|
QList<RunWorker *> startDependencies;
|
2017-08-08 14:49:49 +02:00
|
|
|
QList<RunWorker *> stopDependencies;
|
2017-06-26 18:01:59 +02:00
|
|
|
QString id;
|
2017-05-09 10:25:11 +02:00
|
|
|
|
|
|
|
|
QVariantMap data;
|
|
|
|
|
int startWatchdogInterval = 0;
|
|
|
|
|
int startWatchdogTimerId = -1;
|
|
|
|
|
int stopWatchdogInterval = 0; // 5000;
|
|
|
|
|
int stopWatchdogTimerId = -1;
|
2017-07-05 15:17:38 +02:00
|
|
|
bool supportsReRunning = true;
|
2017-08-09 13:44:49 +02:00
|
|
|
bool essential = false;
|
2017-05-09 10:25:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum class RunControlState
|
|
|
|
|
{
|
|
|
|
|
Initialized, // Default value after creation.
|
|
|
|
|
Starting, // Actual process/tool starts.
|
|
|
|
|
Running, // All good and running.
|
|
|
|
|
Stopping, // initiateStop() was called, stop application/tool
|
|
|
|
|
Stopped, // all good, but stopped. Can possibly be re-started
|
2017-07-13 15:24:04 +02:00
|
|
|
Finishing, // Application tab manually closed
|
|
|
|
|
Finished // Final state, will self-destruct with deleteLater()
|
2017-05-09 10:25:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static QString stateName(RunControlState s)
|
|
|
|
|
{
|
|
|
|
|
# define SN(x) case x: return QLatin1String(#x);
|
|
|
|
|
switch (s) {
|
|
|
|
|
SN(RunControlState::Initialized)
|
|
|
|
|
SN(RunControlState::Starting)
|
|
|
|
|
SN(RunControlState::Running)
|
|
|
|
|
SN(RunControlState::Stopping)
|
|
|
|
|
SN(RunControlState::Stopped)
|
2017-07-13 15:24:04 +02:00
|
|
|
SN(RunControlState::Finishing)
|
|
|
|
|
SN(RunControlState::Finished)
|
2017-05-09 10:25:11 +02:00
|
|
|
}
|
2017-07-13 15:24:04 +02:00
|
|
|
return QString("<unknown: %1>").arg(int(s));
|
2017-05-09 10:25:11 +02:00
|
|
|
# undef SN
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-29 14:08:44 +02:00
|
|
|
class RunControlPrivate : public QObject
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
public:
|
2017-03-29 14:08:44 +02:00
|
|
|
RunControlPrivate(RunControl *parent, RunConfiguration *runConfiguration, Core::Id mode)
|
|
|
|
|
: q(parent), runMode(mode), runConfiguration(runConfiguration)
|
2016-02-01 12:15:44 +01:00
|
|
|
{
|
2017-04-13 09:01:54 +02:00
|
|
|
icon = Icons::RUN_SMALL_TOOLBAR;
|
2016-02-01 12:15:44 +01:00
|
|
|
if (runConfiguration) {
|
2017-04-11 13:34:33 +02:00
|
|
|
runnable = runConfiguration->runnable();
|
2016-02-01 12:15:44 +01:00
|
|
|
displayName = runConfiguration->displayName();
|
|
|
|
|
outputFormatter = runConfiguration->createOutputFormatter();
|
2016-02-01 12:37:35 +01:00
|
|
|
device = DeviceKitInformation::device(runConfiguration->target()->kit());
|
|
|
|
|
project = runConfiguration->target()->project();
|
2016-02-01 12:15:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
2015-09-17 15:24:32 +02:00
|
|
|
|
2016-02-01 12:15:44 +01:00
|
|
|
~RunControlPrivate()
|
|
|
|
|
{
|
2017-07-13 15:24:04 +02:00
|
|
|
QTC_CHECK(state == RunControlState::Finished || state == RunControlState::Initialized);
|
|
|
|
|
disconnect();
|
|
|
|
|
q = nullptr;
|
2017-05-09 10:25:11 +02:00
|
|
|
qDeleteAll(m_workers);
|
2017-07-13 15:24:04 +02:00
|
|
|
m_workers.clear();
|
2016-02-01 12:15:44 +01:00
|
|
|
delete outputFormatter;
|
2010-07-13 15:02:37 +02:00
|
|
|
}
|
2015-09-17 15:24:32 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
Q_ENUM(RunControlState)
|
|
|
|
|
|
|
|
|
|
void checkState(RunControlState expectedState);
|
|
|
|
|
void setState(RunControlState state);
|
2017-03-29 14:08:44 +02:00
|
|
|
|
2017-05-04 12:12:27 +02:00
|
|
|
void debugMessage(const QString &msg);
|
|
|
|
|
|
2017-03-29 14:08:44 +02:00
|
|
|
void initiateStart();
|
2017-07-05 15:17:38 +02:00
|
|
|
void initiateReStart();
|
2017-05-09 10:25:11 +02:00
|
|
|
void continueStart();
|
2017-03-29 14:08:44 +02:00
|
|
|
void initiateStop();
|
2017-08-08 14:49:49 +02:00
|
|
|
void continueStopOrFinish();
|
2017-07-13 15:24:04 +02:00
|
|
|
void initiateFinish();
|
2017-05-04 12:12:27 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void onWorkerStarted(RunWorker *worker);
|
|
|
|
|
void onWorkerStopped(RunWorker *worker);
|
|
|
|
|
void onWorkerFailed(RunWorker *worker, const QString &msg);
|
2017-03-29 14:08:44 +02:00
|
|
|
|
2017-05-02 15:03:56 +02:00
|
|
|
void showError(const QString &msg);
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
static bool isAllowedTransition(RunControlState from, RunControlState to);
|
2017-07-05 15:17:38 +02:00
|
|
|
bool supportsReRunning() const;
|
2017-03-29 14:08:44 +02:00
|
|
|
|
|
|
|
|
RunControl *q;
|
2016-02-01 12:15:44 +01:00
|
|
|
QString displayName;
|
|
|
|
|
Runnable runnable;
|
2016-02-01 12:37:35 +01:00
|
|
|
IDevice::ConstPtr device;
|
2016-02-01 12:15:44 +01:00
|
|
|
Core::Id runMode;
|
|
|
|
|
Utils::Icon icon;
|
2017-03-24 17:06:13 +01:00
|
|
|
const QPointer<RunConfiguration> runConfiguration; // Not owned.
|
|
|
|
|
QPointer<Project> project; // Not owned.
|
2017-07-13 15:24:04 +02:00
|
|
|
QPointer<Utils::OutputFormatter> outputFormatter = nullptr;
|
2017-04-11 12:40:45 +02:00
|
|
|
std::function<bool(bool*)> promptToStop;
|
2017-06-19 13:27:59 +02:00
|
|
|
std::vector<RunControl::WorkerFactory> m_factories;
|
2016-02-01 12:15:44 +01:00
|
|
|
|
|
|
|
|
// A handle to the actual application process.
|
2017-01-16 15:53:53 +01:00
|
|
|
Utils::ProcessHandle applicationProcessHandle;
|
2016-02-01 12:15:44 +01:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
RunControlState state = RunControlState::Initialized;
|
2017-02-27 17:25:58 +01:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
QList<QPointer<RunWorker>> m_workers;
|
2016-02-01 12:15:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // Internal
|
|
|
|
|
|
2017-03-29 14:08:44 +02:00
|
|
|
using namespace Internal;
|
|
|
|
|
|
2016-04-13 15:52:14 +02:00
|
|
|
RunControl::RunControl(RunConfiguration *runConfiguration, Core::Id mode) :
|
2017-03-29 14:08:44 +02:00
|
|
|
d(new RunControlPrivate(this, runConfiguration, mode))
|
2017-02-27 11:49:00 +01:00
|
|
|
{
|
|
|
|
|
#ifdef WITH_JOURNALD
|
|
|
|
|
JournaldWatcher::instance()->subscribe(this, [this](const JournaldWatcher::LogEntry &entry) {
|
|
|
|
|
if (entry.value("_MACHINE_ID") != JournaldWatcher::instance()->machineId())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QByteArray pid = entry.value("_PID");
|
|
|
|
|
if (pid.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const qint64 pidNum = static_cast<qint64>(QString::fromLatin1(pid).toInt());
|
|
|
|
|
if (pidNum != d->applicationProcessHandle.pid())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const QString message = QString::fromUtf8(entry.value("MESSAGE")) + "\n";
|
|
|
|
|
appendMessageRequested(this, message, Utils::OutputFormat::LogMessageFormat);
|
|
|
|
|
});
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-10-08 18:37:18 +02:00
|
|
|
RunControl::~RunControl()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2017-02-27 11:49:00 +01:00
|
|
|
#ifdef WITH_JOURNALD
|
|
|
|
|
JournaldWatcher::instance()->unsubscribe(this);
|
|
|
|
|
#endif
|
2016-02-01 12:15:44 +01:00
|
|
|
delete d;
|
2017-05-02 15:03:56 +02:00
|
|
|
d = nullptr;
|
2010-07-13 15:02:37 +02:00
|
|
|
}
|
2009-10-08 18:37:18 +02:00
|
|
|
|
2017-03-13 13:48:55 +01:00
|
|
|
void RunControl::initiateStart()
|
|
|
|
|
{
|
2017-03-29 14:08:44 +02:00
|
|
|
emit aboutToStart();
|
|
|
|
|
d->initiateStart();
|
2017-03-13 13:48:55 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-05 15:17:38 +02:00
|
|
|
void RunControl::initiateReStart()
|
|
|
|
|
{
|
|
|
|
|
emit aboutToStart();
|
|
|
|
|
d->initiateReStart();
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-13 13:48:55 +01:00
|
|
|
void RunControl::initiateStop()
|
2017-03-29 14:08:44 +02:00
|
|
|
{
|
|
|
|
|
d->initiateStop();
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 15:24:04 +02:00
|
|
|
void RunControl::initiateFinish()
|
|
|
|
|
{
|
2017-07-20 14:43:24 +02:00
|
|
|
QTimer::singleShot(0, d, &RunControlPrivate::initiateFinish);
|
2017-07-13 15:24:04 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
using WorkerCreators = QHash<Core::Id, RunControl::WorkerCreator>;
|
2017-03-29 14:08:44 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
static WorkerCreators &theWorkerCreators()
|
2017-05-02 15:03:56 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
static WorkerCreators creators;
|
|
|
|
|
return creators;
|
2017-05-02 15:03:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunControl::registerWorkerCreator(Core::Id id, const WorkerCreator &workerCreator)
|
2017-03-29 14:08:44 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
theWorkerCreators().insert(id, workerCreator);
|
|
|
|
|
auto keys = theWorkerCreators().keys();
|
|
|
|
|
Q_UNUSED(keys);
|
2017-03-29 14:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
RunWorker *RunControl::createWorker(Core::Id id)
|
2017-03-29 14:08:44 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
auto keys = theWorkerCreators().keys();
|
|
|
|
|
Q_UNUSED(keys);
|
2017-07-03 13:55:25 +02:00
|
|
|
WorkerCreator creator = theWorkerCreators().value(id);
|
2017-05-09 10:25:11 +02:00
|
|
|
if (creator)
|
|
|
|
|
return creator(this);
|
|
|
|
|
creator = device()->workerCreator(id);
|
|
|
|
|
if (creator)
|
|
|
|
|
return creator(this);
|
|
|
|
|
return nullptr;
|
2017-03-29 14:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-03 13:55:25 +02:00
|
|
|
RunControl::WorkerCreator RunControl::producer(RunConfiguration *runConfiguration, Core::Id runMode)
|
2017-06-19 13:27:59 +02:00
|
|
|
{
|
2017-07-18 10:39:03 +02:00
|
|
|
WorkerFactories candidates;
|
|
|
|
|
for (const RunControl::WorkerFactory &factory : theWorkerFactories()) {
|
|
|
|
|
if (factory.canRun(runConfiguration, runMode))
|
|
|
|
|
candidates.push_back(factory);
|
2017-06-19 13:27:59 +02:00
|
|
|
}
|
2017-07-18 10:39:03 +02:00
|
|
|
|
|
|
|
|
if (candidates.empty())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
RunControl::WorkerFactory bestFactory = *candidates.begin();
|
|
|
|
|
for (const RunControl::WorkerFactory &factory : candidates) {
|
|
|
|
|
if (factory.priority > bestFactory.priority)
|
|
|
|
|
bestFactory = factory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bestFactory.producer;
|
2017-06-19 13:27:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunControl::addWorkerFactory(const RunControl::WorkerFactory &workerFactory)
|
|
|
|
|
{
|
|
|
|
|
theWorkerFactories().push_back(workerFactory);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunControlPrivate::initiateStart()
|
2017-05-02 15:03:56 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
checkState(RunControlState::Initialized);
|
|
|
|
|
setState(RunControlState::Starting);
|
|
|
|
|
debugMessage("Queue: Starting");
|
|
|
|
|
|
|
|
|
|
continueStart();
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-05 15:17:38 +02:00
|
|
|
void RunControlPrivate::initiateReStart()
|
|
|
|
|
{
|
|
|
|
|
checkState(RunControlState::Stopped);
|
|
|
|
|
|
|
|
|
|
// Re-set worked on re-runs.
|
|
|
|
|
for (RunWorker *worker : m_workers) {
|
|
|
|
|
if (worker->d->state == RunWorkerState::Done)
|
|
|
|
|
worker->d->state = RunWorkerState::Initialized;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setState(RunControlState::Starting);
|
|
|
|
|
debugMessage("Queue: ReStarting");
|
|
|
|
|
|
|
|
|
|
continueStart();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunControlPrivate::continueStart()
|
|
|
|
|
{
|
|
|
|
|
checkState(RunControlState::Starting);
|
|
|
|
|
bool allDone = true;
|
|
|
|
|
debugMessage("Looking for next worker");
|
|
|
|
|
for (RunWorker *worker : m_workers) {
|
|
|
|
|
if (worker) {
|
2017-06-26 18:01:59 +02:00
|
|
|
const QString &workerId = worker->d->id;
|
|
|
|
|
debugMessage(" Examining worker " + workerId);
|
2017-05-09 10:25:11 +02:00
|
|
|
switch (worker->d->state) {
|
|
|
|
|
case RunWorkerState::Initialized:
|
2017-06-26 18:01:59 +02:00
|
|
|
debugMessage(" " + workerId + " is not done yet.");
|
2017-05-09 10:25:11 +02:00
|
|
|
if (worker->d->canStart()) {
|
2017-06-26 18:01:59 +02:00
|
|
|
debugMessage("Starting " + workerId);
|
2017-05-09 10:25:11 +02:00
|
|
|
worker->d->state = RunWorkerState::Starting;
|
|
|
|
|
QTimer::singleShot(0, worker, &RunWorker::initiateStart);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
allDone = false;
|
2017-06-26 18:01:59 +02:00
|
|
|
debugMessage(" " + workerId + " cannot start.");
|
2017-05-09 10:25:11 +02:00
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Starting:
|
2017-06-26 18:01:59 +02:00
|
|
|
debugMessage(" " + workerId + " currently starting");
|
2017-05-09 10:25:11 +02:00
|
|
|
allDone = false;
|
|
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Running:
|
2017-06-26 18:01:59 +02:00
|
|
|
debugMessage(" " + workerId + " currently running");
|
2017-05-09 10:25:11 +02:00
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Stopping:
|
2017-06-26 18:01:59 +02:00
|
|
|
debugMessage(" " + workerId + " currently stopping");
|
2017-05-09 10:25:11 +02:00
|
|
|
continue;
|
|
|
|
|
case RunWorkerState::Done:
|
2017-06-26 18:01:59 +02:00
|
|
|
debugMessage(" " + workerId + " was done before");
|
2017-05-09 10:25:11 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
debugMessage("Found unknown deleted worker while starting");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (allDone)
|
|
|
|
|
setState(RunControlState::Running);
|
2017-05-02 15:03:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-03-29 14:08:44 +02:00
|
|
|
void RunControlPrivate::initiateStop()
|
|
|
|
|
{
|
2017-08-09 12:06:05 +02:00
|
|
|
if (state != RunControlState::Starting && state != RunControlState::Running)
|
|
|
|
|
qDebug() << "Unexpected initiateStop() in state" << stateName(state);
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
setState(RunControlState::Stopping);
|
2017-07-13 15:24:04 +02:00
|
|
|
debugMessage("Queue: Stopping for all workers");
|
2017-05-09 10:25:11 +02:00
|
|
|
|
2017-08-08 14:49:49 +02:00
|
|
|
continueStopOrFinish();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunControlPrivate::continueStopOrFinish()
|
|
|
|
|
{
|
2017-07-13 15:24:04 +02:00
|
|
|
bool allDone = true;
|
2017-08-08 14:49:49 +02:00
|
|
|
|
|
|
|
|
auto queueStop = [this](RunWorker *worker, const QString &message) {
|
|
|
|
|
if (worker->d->canStop()) {
|
|
|
|
|
debugMessage(message);
|
|
|
|
|
worker->d->state = RunWorkerState::Stopping;
|
|
|
|
|
QTimer::singleShot(0, worker, &RunWorker::initiateStop);
|
|
|
|
|
} else {
|
|
|
|
|
debugMessage(" " + worker->d->id + " is waiting for dependent workers to stop");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-13 15:24:04 +02:00
|
|
|
for (RunWorker *worker : m_workers) {
|
|
|
|
|
if (worker) {
|
|
|
|
|
const QString &workerId = worker->d->id;
|
|
|
|
|
debugMessage(" Examining worker " + workerId);
|
|
|
|
|
switch (worker->d->state) {
|
|
|
|
|
case RunWorkerState::Initialized:
|
|
|
|
|
debugMessage(" " + workerId + " was Initialized, setting to Done");
|
|
|
|
|
worker->d->state = RunWorkerState::Done;
|
|
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Stopping:
|
|
|
|
|
debugMessage(" " + workerId + " was already Stopping. Keeping it that way");
|
|
|
|
|
allDone = false;
|
|
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Starting:
|
2017-08-08 14:49:49 +02:00
|
|
|
queueStop(worker, " " + workerId + " was Starting, queuing stop");
|
2017-07-13 15:24:04 +02:00
|
|
|
allDone = false;
|
|
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Running:
|
2017-08-08 14:49:49 +02:00
|
|
|
queueStop(worker, " " + workerId + " was Running, queuing stop");
|
2017-07-13 15:24:04 +02:00
|
|
|
allDone = false;
|
|
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Done:
|
|
|
|
|
debugMessage(" " + workerId + " was Done. Good.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
debugMessage("Found unknown deleted worker");
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-08 14:49:49 +02:00
|
|
|
|
|
|
|
|
RunControlState targetState;
|
|
|
|
|
if (state == RunControlState::Finishing) {
|
|
|
|
|
targetState = RunControlState::Finished;
|
|
|
|
|
} else {
|
|
|
|
|
checkState(RunControlState::Stopping);
|
|
|
|
|
targetState = RunControlState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 15:24:04 +02:00
|
|
|
if (allDone) {
|
2017-08-08 14:49:49 +02:00
|
|
|
debugMessage("All Stopped");
|
|
|
|
|
setState(targetState);
|
2017-07-13 15:24:04 +02:00
|
|
|
} else {
|
2017-08-08 14:49:49 +02:00
|
|
|
debugMessage("Not all workers Stopped. Waiting...");
|
2017-07-13 15:24:04 +02:00
|
|
|
}
|
2017-05-09 10:25:11 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-13 15:24:04 +02:00
|
|
|
void RunControlPrivate::initiateFinish()
|
2017-05-09 10:25:11 +02:00
|
|
|
{
|
2017-07-13 15:24:04 +02:00
|
|
|
setState(RunControlState::Finishing);
|
|
|
|
|
debugMessage("Ramping down");
|
|
|
|
|
|
2017-08-08 14:49:49 +02:00
|
|
|
continueStopOrFinish();
|
2017-05-04 12:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunControlPrivate::onWorkerStarted(RunWorker *worker)
|
2017-05-04 12:12:27 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
worker->d->state = RunWorkerState::Running;
|
2017-03-29 14:08:44 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
if (state == RunControlState::Starting) {
|
2017-06-26 18:01:59 +02:00
|
|
|
debugMessage(worker->d->id + " start succeeded");
|
2017-05-09 10:25:11 +02:00
|
|
|
continueStart();
|
|
|
|
|
return;
|
2017-05-04 12:12:27 +02:00
|
|
|
}
|
2017-07-28 10:19:05 +02:00
|
|
|
showError(tr("Unexpected run control state %1 when worker %2 started.")
|
2017-05-09 10:25:11 +02:00
|
|
|
.arg(stateName(state))
|
2017-06-26 18:01:59 +02:00
|
|
|
.arg(worker->d->id));
|
2017-05-04 12:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunControlPrivate::onWorkerFailed(RunWorker *worker, const QString &msg)
|
2017-05-04 12:12:27 +02:00
|
|
|
{
|
2017-08-09 08:43:51 +02:00
|
|
|
worker->d->state = RunWorkerState::Done;
|
2017-03-29 14:08:44 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
showError(msg);
|
2017-08-09 13:44:00 +02:00
|
|
|
if (state == RunControlState::Running || state == RunControlState::Starting)
|
|
|
|
|
initiateStop();
|
|
|
|
|
else
|
|
|
|
|
continueStopOrFinish();
|
2017-05-09 10:25:11 +02:00
|
|
|
}
|
2017-05-04 12:12:27 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunControlPrivate::onWorkerStopped(RunWorker *worker)
|
2017-03-29 14:08:44 +02:00
|
|
|
{
|
2017-06-26 18:01:59 +02:00
|
|
|
const QString &workerId = worker->d->id;
|
2017-05-23 16:40:49 +02:00
|
|
|
switch (worker->d->state) {
|
|
|
|
|
case RunWorkerState::Running:
|
|
|
|
|
// That was a spontaneous stop.
|
|
|
|
|
worker->d->state = RunWorkerState::Done;
|
2017-06-26 18:01:59 +02:00
|
|
|
debugMessage(workerId + " stopped spontaneously.");
|
2017-05-23 16:40:49 +02:00
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Stopping:
|
|
|
|
|
worker->d->state = RunWorkerState::Done;
|
2017-06-26 18:01:59 +02:00
|
|
|
debugMessage(workerId + " stopped expectedly.");
|
2017-05-23 16:40:49 +02:00
|
|
|
break;
|
2017-07-13 15:24:04 +02:00
|
|
|
case RunWorkerState::Done:
|
|
|
|
|
worker->d->state = RunWorkerState::Done;
|
|
|
|
|
debugMessage(workerId + " stopped twice. Huh? But harmless.");
|
|
|
|
|
return; // Sic!
|
2017-05-23 16:40:49 +02:00
|
|
|
default:
|
2017-06-26 18:01:59 +02:00
|
|
|
debugMessage(workerId + " stopped unexpectedly in state"
|
2017-05-23 16:40:49 +02:00
|
|
|
+ stateName(worker->d->state));
|
2017-08-09 08:43:51 +02:00
|
|
|
worker->d->state = RunWorkerState::Done;
|
2017-05-23 16:40:49 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2017-07-13 15:24:04 +02:00
|
|
|
|
2017-08-08 14:49:49 +02:00
|
|
|
if (state == RunControlState::Finishing || state == RunControlState::Stopping) {
|
|
|
|
|
continueStopOrFinish();
|
|
|
|
|
return;
|
2017-08-09 13:44:49 +02:00
|
|
|
} else if (worker->isEssential()) {
|
|
|
|
|
debugMessage(workerId + " is essential. Stopping all others.");
|
|
|
|
|
initiateStop();
|
|
|
|
|
return;
|
2017-08-08 14:49:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-08 15:27:15 +02:00
|
|
|
for (RunWorker *dependent : worker->d->stopDependencies) {
|
|
|
|
|
switch (dependent->d->state) {
|
|
|
|
|
case RunWorkerState::Done:
|
|
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Initialized:
|
|
|
|
|
dependent->d->state = RunWorkerState::Done;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
debugMessage("Killing " + dependent->d->id + " as it depends on stopped " + workerId);
|
|
|
|
|
dependent->d->state = RunWorkerState::Stopping;
|
|
|
|
|
QTimer::singleShot(0, dependent, &RunWorker::initiateStop);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-13 15:24:04 +02:00
|
|
|
debugMessage("Checking whether all stopped");
|
|
|
|
|
bool allDone = true;
|
|
|
|
|
for (RunWorker *worker : m_workers) {
|
|
|
|
|
if (worker) {
|
|
|
|
|
const QString &workerId = worker->d->id;
|
|
|
|
|
debugMessage(" Examining worker " + workerId);
|
|
|
|
|
switch (worker->d->state) {
|
|
|
|
|
case RunWorkerState::Initialized:
|
2017-07-19 10:35:08 +02:00
|
|
|
debugMessage(" " + workerId + " was Initialized.");
|
2017-07-13 15:24:04 +02:00
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Starting:
|
2017-07-19 10:35:08 +02:00
|
|
|
debugMessage(" " + workerId + " was Starting, waiting for its response");
|
2017-07-13 15:24:04 +02:00
|
|
|
allDone = false;
|
|
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Running:
|
2017-07-19 10:35:08 +02:00
|
|
|
debugMessage(" " + workerId + " was Running, waiting for its response");
|
2017-07-13 15:24:04 +02:00
|
|
|
allDone = false;
|
|
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Stopping:
|
|
|
|
|
debugMessage(" " + workerId + " was already Stopping. Keeping it that way");
|
|
|
|
|
allDone = false;
|
|
|
|
|
break;
|
|
|
|
|
case RunWorkerState::Done:
|
|
|
|
|
debugMessage(" " + workerId + " was Done. Good.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
debugMessage("Found unknown deleted worker");
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-08 14:49:49 +02:00
|
|
|
|
|
|
|
|
if (allDone) {
|
|
|
|
|
if (state == RunControlState::Stopped) {
|
|
|
|
|
debugMessage("All workers stopped, but runControl was already stopped.");
|
2017-07-13 15:24:04 +02:00
|
|
|
} else {
|
2017-08-08 14:49:49 +02:00
|
|
|
debugMessage("All workers stopped. Set runControl to Stopped");
|
|
|
|
|
setState(RunControlState::Stopped);
|
2017-07-13 15:24:04 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2017-08-08 14:49:49 +02:00
|
|
|
debugMessage("Not all workers stopped. Waiting...");
|
2017-07-13 15:24:04 +02:00
|
|
|
}
|
2017-03-13 13:48:55 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-02 15:03:56 +02:00
|
|
|
void RunControlPrivate::showError(const QString &msg)
|
|
|
|
|
{
|
|
|
|
|
if (!msg.isEmpty())
|
2017-05-09 10:25:11 +02:00
|
|
|
q->appendMessage(msg + '\n', ErrorMessageFormat);
|
2017-05-02 15:03:56 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-10 15:43:22 +03:00
|
|
|
Utils::OutputFormatter *RunControl::outputFormatter() const
|
2010-07-13 15:02:37 +02:00
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
return d->outputFormatter;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-29 10:36:29 +03:00
|
|
|
Core::Id RunControl::runMode() const
|
2010-04-30 13:19:31 +02:00
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
return d->runMode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Runnable &RunControl::runnable() const
|
|
|
|
|
{
|
|
|
|
|
return d->runnable;
|
2010-04-30 13:19:31 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-18 17:11:31 +01:00
|
|
|
void RunControl::setRunnable(const Runnable &runnable)
|
|
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
d->runnable = runnable;
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-08 18:37:18 +02:00
|
|
|
QString RunControl::displayName() const
|
|
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
return d->displayName;
|
2009-10-08 18:37:18 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-21 18:19:23 +01:00
|
|
|
void RunControl::setDisplayName(const QString &displayName)
|
|
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
d->displayName = displayName;
|
2016-01-21 18:19:23 +01:00
|
|
|
}
|
|
|
|
|
|
2015-11-23 16:41:54 +01:00
|
|
|
void RunControl::setIcon(const Utils::Icon &icon)
|
|
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
d->icon = icon;
|
2015-11-23 16:41:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils::Icon RunControl::icon() const
|
|
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
return d->icon;
|
2015-11-23 16:41:54 +01:00
|
|
|
}
|
|
|
|
|
|
2011-08-17 09:06:59 +02:00
|
|
|
Abi RunControl::abi() const
|
|
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
if (const RunConfiguration *rc = d->runConfiguration.data())
|
2011-08-17 09:06:59 +02:00
|
|
|
return rc->abi();
|
|
|
|
|
return Abi();
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 12:37:35 +01:00
|
|
|
IDevice::ConstPtr RunControl::device() const
|
|
|
|
|
{
|
|
|
|
|
return d->device;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-31 15:06:07 +02:00
|
|
|
RunConfiguration *RunControl::runConfiguration() const
|
|
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
return d->runConfiguration.data();
|
2012-08-31 15:06:07 +02:00
|
|
|
}
|
|
|
|
|
|
2015-09-17 15:24:32 +02:00
|
|
|
Project *RunControl::project() const
|
|
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
return d->project.data();
|
2015-09-17 15:24:32 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-01 14:30:13 +01:00
|
|
|
bool RunControl::canReUseOutputPane(const RunControl *other) const
|
|
|
|
|
{
|
|
|
|
|
if (other->isRunning())
|
|
|
|
|
return false;
|
|
|
|
|
|
2016-05-11 16:29:03 +02:00
|
|
|
return d->runnable.canReUseOutputPane(other->d->runnable);
|
2016-02-01 14:30:13 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-01 09:55:32 +01:00
|
|
|
/*!
|
|
|
|
|
A handle to the application process.
|
|
|
|
|
|
|
|
|
|
This is typically a process id, but should be treated as
|
|
|
|
|
opaque handle to the process controled by this \c RunControl.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-05-31 09:48:00 +02:00
|
|
|
ProcessHandle RunControl::applicationProcessHandle() const
|
|
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
return d->applicationProcessHandle;
|
2011-05-31 09:48:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunControl::setApplicationProcessHandle(const ProcessHandle &handle)
|
|
|
|
|
{
|
2016-02-01 12:15:44 +01:00
|
|
|
if (d->applicationProcessHandle != handle) {
|
|
|
|
|
d->applicationProcessHandle = handle;
|
2017-02-27 17:25:58 +01:00
|
|
|
emit applicationProcessHandleChanged(QPrivateSignal());
|
2011-07-06 10:25:18 +02:00
|
|
|
}
|
2011-05-31 09:48:00 +02:00
|
|
|
}
|
|
|
|
|
|
2013-09-10 17:16:10 +02:00
|
|
|
/*!
|
|
|
|
|
Prompts to stop. If \a optionalPrompt is passed, a \gui {Do not ask again}
|
|
|
|
|
checkbox is displayed and the result is returned in \a *optionalPrompt.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-01-17 13:52:14 +01:00
|
|
|
bool RunControl::promptToStop(bool *optionalPrompt) const
|
2010-08-20 14:19:25 +02:00
|
|
|
{
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(isRunning(), return true);
|
2011-01-17 13:52:14 +01:00
|
|
|
if (optionalPrompt && !*optionalPrompt)
|
|
|
|
|
return true;
|
|
|
|
|
|
2017-04-11 12:40:45 +02:00
|
|
|
// Overridden.
|
|
|
|
|
if (d->promptToStop)
|
|
|
|
|
return d->promptToStop(optionalPrompt);
|
|
|
|
|
|
2011-01-17 13:52:14 +01:00
|
|
|
const QString msg = tr("<html><head/><body><center><i>%1</i> is still running.<center/>"
|
|
|
|
|
"<center>Force it to quit?</center></body></html>").arg(displayName());
|
|
|
|
|
return showPromptToStopDialog(tr("Application Still Running"), msg,
|
2017-01-11 21:48:46 +02:00
|
|
|
tr("Force &Quit"), tr("&Keep Running"),
|
2011-01-17 13:52:14 +01:00
|
|
|
optionalPrompt);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-11 12:40:45 +02:00
|
|
|
void RunControl::setPromptToStop(const std::function<bool (bool *)> &promptToStop)
|
|
|
|
|
{
|
|
|
|
|
d->promptToStop = promptToStop;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-07 11:09:12 +02:00
|
|
|
bool RunControl::supportsReRunning() const
|
|
|
|
|
{
|
2017-07-05 15:17:38 +02:00
|
|
|
return d->supportsReRunning();
|
2017-04-07 11:09:12 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-05 15:17:38 +02:00
|
|
|
bool RunControlPrivate::supportsReRunning() const
|
2017-04-07 11:09:12 +02:00
|
|
|
{
|
2017-07-05 15:17:38 +02:00
|
|
|
for (RunWorker *worker : m_workers) {
|
|
|
|
|
if (!worker->d->supportsReRunning)
|
|
|
|
|
return false;
|
|
|
|
|
if (worker->d->state != RunWorkerState::Done)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2017-04-07 11:09:12 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-27 17:25:58 +01:00
|
|
|
bool RunControl::isRunning() const
|
|
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
return d->state == RunControlState::Running;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RunControl::isStarting() const
|
|
|
|
|
{
|
|
|
|
|
return d->state == RunControlState::Starting;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RunControl::isStopping() const
|
|
|
|
|
{
|
|
|
|
|
return d->state == RunControlState::Stopping;
|
2017-02-27 17:25:58 +01:00
|
|
|
}
|
|
|
|
|
|
2017-07-05 14:25:42 +02:00
|
|
|
bool RunControl::isStopped() const
|
|
|
|
|
{
|
|
|
|
|
return d->state == RunControlState::Stopped;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-14 12:58:14 +02:00
|
|
|
/*!
|
2013-09-10 17:16:10 +02:00
|
|
|
Prompts to terminate the application with the \gui {Do not ask again}
|
|
|
|
|
checkbox.
|
2011-04-14 12:58:14 +02:00
|
|
|
*/
|
|
|
|
|
|
2011-01-17 13:52:14 +01:00
|
|
|
bool RunControl::showPromptToStopDialog(const QString &title,
|
|
|
|
|
const QString &text,
|
|
|
|
|
const QString &stopButtonText,
|
|
|
|
|
const QString &cancelButtonText,
|
2017-05-02 10:06:09 +02:00
|
|
|
bool *prompt)
|
2011-01-17 13:52:14 +01:00
|
|
|
{
|
|
|
|
|
// Show a question message box where user can uncheck this
|
|
|
|
|
// question for this class.
|
2012-01-24 15:36:40 +01:00
|
|
|
Utils::CheckableMessageBox messageBox(Core::ICore::mainWindow());
|
2011-01-17 13:52:14 +01:00
|
|
|
messageBox.setWindowTitle(title);
|
|
|
|
|
messageBox.setText(text);
|
|
|
|
|
messageBox.setStandardButtons(QDialogButtonBox::Yes|QDialogButtonBox::Cancel);
|
|
|
|
|
if (!stopButtonText.isEmpty())
|
|
|
|
|
messageBox.button(QDialogButtonBox::Yes)->setText(stopButtonText);
|
|
|
|
|
if (!cancelButtonText.isEmpty())
|
|
|
|
|
messageBox.button(QDialogButtonBox::Cancel)->setText(cancelButtonText);
|
|
|
|
|
messageBox.setDefaultButton(QDialogButtonBox::Yes);
|
|
|
|
|
if (prompt) {
|
2013-10-31 15:39:49 +01:00
|
|
|
messageBox.setCheckBoxText(Utils::CheckableMessageBox::msgDoNotAskAgain());
|
2011-01-17 13:52:14 +01:00
|
|
|
messageBox.setChecked(false);
|
|
|
|
|
} else {
|
|
|
|
|
messageBox.setCheckBoxVisible(false);
|
|
|
|
|
}
|
|
|
|
|
messageBox.exec();
|
|
|
|
|
const bool close = messageBox.clickedStandardButton() == QDialogButtonBox::Yes;
|
|
|
|
|
if (close && prompt && messageBox.isChecked())
|
|
|
|
|
*prompt = false;
|
|
|
|
|
return close;
|
2010-08-20 14:19:25 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
bool RunControlPrivate::isAllowedTransition(RunControlState from, RunControlState to)
|
2017-03-13 13:48:55 +01:00
|
|
|
{
|
|
|
|
|
switch (from) {
|
2017-05-09 10:25:11 +02:00
|
|
|
case RunControlState::Initialized:
|
2017-07-13 15:24:04 +02:00
|
|
|
return to == RunControlState::Starting
|
|
|
|
|
|| to == RunControlState::Finishing;
|
2017-05-09 10:25:11 +02:00
|
|
|
case RunControlState::Starting:
|
2017-07-13 15:24:04 +02:00
|
|
|
return to == RunControlState::Running
|
2017-08-09 12:06:05 +02:00
|
|
|
|| to == RunControlState::Stopping
|
2017-07-13 15:24:04 +02:00
|
|
|
|| to == RunControlState::Finishing;
|
2017-05-09 10:25:11 +02:00
|
|
|
case RunControlState::Running:
|
|
|
|
|
return to == RunControlState::Stopping
|
2017-07-13 15:24:04 +02:00
|
|
|
|| to == RunControlState::Stopped
|
|
|
|
|
|| to == RunControlState::Finishing;
|
2017-05-09 10:25:11 +02:00
|
|
|
case RunControlState::Stopping:
|
2017-07-13 15:24:04 +02:00
|
|
|
return to == RunControlState::Stopped
|
|
|
|
|
|| to == RunControlState::Finishing;
|
2017-05-09 10:25:11 +02:00
|
|
|
case RunControlState::Stopped:
|
2017-07-13 15:24:04 +02:00
|
|
|
return to == RunControlState::Finishing;
|
|
|
|
|
case RunControlState::Finishing:
|
|
|
|
|
return to == RunControlState::Finished;
|
|
|
|
|
case RunControlState::Finished:
|
2017-03-13 13:48:55 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunControlPrivate::checkState(RunControlState expectedState)
|
2017-03-29 14:08:44 +02:00
|
|
|
{
|
|
|
|
|
if (state != expectedState)
|
2017-05-09 10:25:11 +02:00
|
|
|
qDebug() << "Unexpected run control state " << stateName(expectedState)
|
|
|
|
|
<< " have: " << stateName(state);
|
2017-03-29 14:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunControlPrivate::setState(RunControlState newState)
|
2017-03-13 13:48:55 +01:00
|
|
|
{
|
2017-03-29 14:08:44 +02:00
|
|
|
if (!isAllowedTransition(state, newState))
|
2017-05-09 10:25:11 +02:00
|
|
|
qDebug() << "Invalid run control state transition from " << stateName(state)
|
|
|
|
|
<< " to " << stateName(newState);
|
2017-03-29 14:08:44 +02:00
|
|
|
|
|
|
|
|
state = newState;
|
|
|
|
|
|
2017-05-04 12:12:27 +02:00
|
|
|
debugMessage("Entering state " + stateName(newState));
|
|
|
|
|
|
2017-03-29 14:08:44 +02:00
|
|
|
// Extra reporting.
|
|
|
|
|
switch (state) {
|
2017-05-09 10:25:11 +02:00
|
|
|
case RunControlState::Running:
|
2017-03-29 14:08:44 +02:00
|
|
|
emit q->started();
|
|
|
|
|
break;
|
2017-05-09 10:25:11 +02:00
|
|
|
case RunControlState::Stopped:
|
2017-05-04 12:12:27 +02:00
|
|
|
q->setApplicationProcessHandle(Utils::ProcessHandle());
|
2017-07-11 17:25:33 +02:00
|
|
|
emit q->stopped();
|
2017-03-29 14:08:44 +02:00
|
|
|
break;
|
2017-07-13 15:24:04 +02:00
|
|
|
case RunControlState::Finished:
|
|
|
|
|
emit q->finished();
|
|
|
|
|
debugMessage("All finished. Deleting myself");
|
2017-07-20 14:43:24 +02:00
|
|
|
q->deleteLater();
|
2017-07-13 15:24:04 +02:00
|
|
|
break;
|
2017-03-29 14:08:44 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2017-03-13 13:48:55 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-04 12:12:27 +02:00
|
|
|
void RunControlPrivate::debugMessage(const QString &msg)
|
|
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
qCDebug(statesLog()) << msg;
|
2017-05-04 12:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-15 12:59:44 +02:00
|
|
|
void RunControl::appendMessage(const QString &msg, Utils::OutputFormat format)
|
2011-01-07 18:57:54 +01:00
|
|
|
{
|
2016-05-13 11:27:51 +02:00
|
|
|
emit appendMessageRequested(this, msg, format);
|
2011-01-07 18:57:54 +01:00
|
|
|
}
|
2015-06-29 10:36:29 +03:00
|
|
|
|
2016-05-11 16:29:03 +02:00
|
|
|
bool Runnable::canReUseOutputPane(const Runnable &other) const
|
2016-02-01 14:30:13 +01:00
|
|
|
{
|
2016-05-11 16:29:03 +02:00
|
|
|
return d ? d->canReUseOutputPane(other.d) : (other.d.get() == 0);
|
2016-02-01 14:30:13 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-10 09:05:52 +01:00
|
|
|
|
2017-03-13 17:01:59 +01:00
|
|
|
// FIXME: Remove once ApplicationLauncher signalling does not depend on device.
|
|
|
|
|
static bool isSynchronousLauncher(RunControl *runControl)
|
|
|
|
|
{
|
|
|
|
|
RunConfiguration *runConfig = runControl->runConfiguration();
|
|
|
|
|
Target *target = runConfig ? runConfig->target() : nullptr;
|
|
|
|
|
Kit *kit = target ? target->kit() : nullptr;
|
|
|
|
|
Core::Id deviceId = DeviceTypeKitInformation::deviceTypeId(kit);
|
|
|
|
|
return !deviceId.isValid() || deviceId == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-29 14:08:44 +02:00
|
|
|
|
|
|
|
|
// SimpleTargetRunner
|
|
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
SimpleTargetRunner::SimpleTargetRunner(RunControl *runControl)
|
2017-05-09 10:25:11 +02:00
|
|
|
: RunWorker(runControl)
|
2017-03-10 09:05:52 +01:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
setDisplayName("SimpleTargetRunner");
|
2017-06-14 11:13:16 +02:00
|
|
|
m_runnable = runControl->runnable();
|
2017-03-10 09:05:52 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
void SimpleTargetRunner::start()
|
2017-03-10 09:05:52 +01:00
|
|
|
{
|
2017-07-05 15:17:38 +02:00
|
|
|
m_stopReported = false;
|
2017-03-29 11:01:16 +02:00
|
|
|
m_launcher.disconnect(this);
|
2017-03-10 09:05:52 +01:00
|
|
|
|
2017-06-14 11:13:16 +02:00
|
|
|
QString msg = RunControl::tr("Starting %1...").arg(m_runnable.displayName());
|
2017-05-09 10:25:11 +02:00
|
|
|
appendMessage(msg, Utils::NormalMessageFormat);
|
2017-03-10 09:05:52 +01:00
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
if (isSynchronousLauncher(runControl())) {
|
2017-03-13 17:01:59 +01:00
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
connect(&m_launcher, &ApplicationLauncher::appendMessage,
|
2017-05-09 10:25:11 +02:00
|
|
|
this, &SimpleTargetRunner::appendMessage);
|
2017-03-29 11:01:16 +02:00
|
|
|
connect(&m_launcher, &ApplicationLauncher::processStarted,
|
|
|
|
|
this, &SimpleTargetRunner::onProcessStarted);
|
|
|
|
|
connect(&m_launcher, &ApplicationLauncher::processExited,
|
|
|
|
|
this, &SimpleTargetRunner::onProcessFinished);
|
2017-05-23 16:40:49 +02:00
|
|
|
connect(&m_launcher, &ApplicationLauncher::error,
|
|
|
|
|
this, &SimpleTargetRunner::onProcessError);
|
2017-03-13 17:01:59 +01:00
|
|
|
|
2017-06-14 11:13:16 +02:00
|
|
|
QTC_ASSERT(m_runnable.is<StandardRunnable>(), return);
|
|
|
|
|
const QString executable = m_runnable.as<StandardRunnable>().executable;
|
2017-03-13 17:01:59 +01:00
|
|
|
if (executable.isEmpty()) {
|
2017-05-04 12:12:27 +02:00
|
|
|
reportFailure(RunControl::tr("No executable specified."));
|
2017-03-13 17:01:59 +01:00
|
|
|
} else if (!QFileInfo::exists(executable)) {
|
2017-05-04 12:12:27 +02:00
|
|
|
reportFailure(RunControl::tr("Executable %1 does not exist.")
|
2017-05-02 15:03:56 +02:00
|
|
|
.arg(QDir::toNativeSeparators(executable)));
|
2017-03-13 17:01:59 +01:00
|
|
|
} else {
|
2017-06-14 11:13:16 +02:00
|
|
|
m_launcher.start(m_runnable);
|
2017-03-13 17:01:59 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-10 09:05:52 +01:00
|
|
|
} else {
|
2017-03-13 17:01:59 +01:00
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
connect(&m_launcher, &ApplicationLauncher::reportError,
|
2017-05-09 10:25:11 +02:00
|
|
|
this, [this](const QString &msg) {
|
|
|
|
|
reportFailure(msg);
|
|
|
|
|
});
|
2017-03-13 17:01:59 +01:00
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
connect(&m_launcher, &ApplicationLauncher::remoteStderr,
|
2017-07-13 17:59:53 +02:00
|
|
|
this, [this](const QString &output) {
|
|
|
|
|
appendMessage(output, Utils::StdErrFormatSameLine);
|
2017-03-13 17:01:59 +01:00
|
|
|
});
|
|
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
connect(&m_launcher, &ApplicationLauncher::remoteStdout,
|
2017-07-13 17:59:53 +02:00
|
|
|
this, [this](const QString &output) {
|
|
|
|
|
appendMessage(output, Utils::StdOutFormatSameLine);
|
2017-03-13 17:01:59 +01:00
|
|
|
});
|
|
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
connect(&m_launcher, &ApplicationLauncher::finished,
|
2017-03-13 17:01:59 +01:00
|
|
|
this, [this] {
|
2017-03-29 11:01:16 +02:00
|
|
|
m_launcher.disconnect(this);
|
2017-05-09 10:25:11 +02:00
|
|
|
reportStopped();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(&m_launcher, &ApplicationLauncher::processStarted,
|
|
|
|
|
this, [this] {
|
|
|
|
|
appendMessage("Application launcher started", Utils::NormalMessageFormat);
|
|
|
|
|
// reportStarted();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(&m_launcher, &ApplicationLauncher::processExited,
|
|
|
|
|
this, [this] {
|
|
|
|
|
m_launcher.disconnect(this);
|
|
|
|
|
reportStopped();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
connect(&m_launcher, &ApplicationLauncher::remoteProcessStarted,
|
|
|
|
|
this, [this] {
|
|
|
|
|
reportStarted();
|
2017-03-13 17:01:59 +01:00
|
|
|
});
|
|
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
connect(&m_launcher, &ApplicationLauncher::reportProgress,
|
2017-03-13 17:01:59 +01:00
|
|
|
this, [this](const QString &progressString) {
|
2017-05-09 10:25:11 +02:00
|
|
|
appendMessage(progressString, Utils::NormalMessageFormat);
|
2017-03-13 17:01:59 +01:00
|
|
|
});
|
|
|
|
|
|
2017-06-14 11:13:16 +02:00
|
|
|
m_launcher.start(m_runnable, device());
|
2017-03-10 09:05:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
void SimpleTargetRunner::stop()
|
2017-03-10 09:05:52 +01:00
|
|
|
{
|
2017-03-29 11:01:16 +02:00
|
|
|
m_launcher.stop();
|
2017-03-10 09:05:52 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
void SimpleTargetRunner::onProcessStarted()
|
2017-03-10 09:05:52 +01:00
|
|
|
{
|
|
|
|
|
// Console processes only know their pid after being started
|
2017-07-13 17:39:42 +02:00
|
|
|
ProcessHandle pid = m_launcher.applicationPID();
|
|
|
|
|
runControl()->setApplicationProcessHandle(pid);
|
|
|
|
|
pid.activate();
|
2017-05-09 10:25:11 +02:00
|
|
|
reportStarted();
|
2017-03-10 09:05:52 +01:00
|
|
|
}
|
|
|
|
|
|
2017-03-29 11:01:16 +02:00
|
|
|
void SimpleTargetRunner::onProcessFinished(int exitCode, QProcess::ExitStatus status)
|
2017-03-10 09:05:52 +01:00
|
|
|
{
|
|
|
|
|
QString msg;
|
|
|
|
|
if (status == QProcess::CrashExit)
|
2017-05-09 10:25:11 +02:00
|
|
|
msg = tr("%1 crashed.");
|
2017-03-10 09:05:52 +01:00
|
|
|
else
|
2017-05-09 10:25:11 +02:00
|
|
|
msg = tr("%2 exited with code %1").arg(exitCode);
|
2017-06-14 11:13:16 +02:00
|
|
|
appendMessage(msg.arg(m_runnable.displayName()), Utils::NormalMessageFormat);
|
2017-07-05 15:17:38 +02:00
|
|
|
if (!m_stopReported) {
|
|
|
|
|
m_stopReported = true;
|
|
|
|
|
reportStopped();
|
|
|
|
|
}
|
2017-03-29 11:01:16 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-05 15:17:38 +02:00
|
|
|
void SimpleTargetRunner::onProcessError(QProcess::ProcessError error)
|
2017-05-23 16:40:49 +02:00
|
|
|
{
|
2017-07-05 15:17:38 +02:00
|
|
|
if (error == QProcess::Timedout)
|
|
|
|
|
return; // No actual change on the process side.
|
|
|
|
|
QString msg = userMessageForProcessError(error, m_runnable.displayName());
|
|
|
|
|
appendMessage(msg, Utils::NormalMessageFormat);
|
|
|
|
|
if (!m_stopReported) {
|
|
|
|
|
m_stopReported = true;
|
|
|
|
|
reportStopped();
|
|
|
|
|
}
|
2017-05-23 16:40:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-14 11:13:16 +02:00
|
|
|
void SimpleTargetRunner::setRunnable(const Runnable &runnable)
|
|
|
|
|
{
|
|
|
|
|
m_runnable = runnable;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
// RunWorkerPrivate
|
2017-03-29 11:01:16 +02:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
RunWorkerPrivate::RunWorkerPrivate(RunWorker *runWorker, RunControl *runControl)
|
|
|
|
|
: q(runWorker), runControl(runControl)
|
2017-03-29 11:01:16 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
runControl->d->m_workers.append(runWorker);
|
2017-03-29 11:01:16 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
bool RunWorkerPrivate::canStart() const
|
2017-05-04 12:12:27 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
if (state != RunWorkerState::Initialized)
|
|
|
|
|
return false;
|
2017-08-08 14:09:50 +02:00
|
|
|
for (RunWorker *worker : startDependencies) {
|
2017-08-08 14:49:49 +02:00
|
|
|
QTC_ASSERT(worker, continue);
|
2017-05-09 10:25:11 +02:00
|
|
|
if (worker->d->state != RunWorkerState::Done
|
|
|
|
|
&& worker->d->state != RunWorkerState::Running)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2017-05-04 12:12:27 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-08 14:49:49 +02:00
|
|
|
bool RunWorkerPrivate::canStop() const
|
|
|
|
|
{
|
|
|
|
|
if (state != RunWorkerState::Starting && state != RunWorkerState::Running)
|
|
|
|
|
return false;
|
|
|
|
|
for (RunWorker *worker : stopDependencies) {
|
|
|
|
|
QTC_ASSERT(worker, continue);
|
2017-08-09 08:43:51 +02:00
|
|
|
if (worker->d->state != RunWorkerState::Done)
|
2017-08-08 14:49:49 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunWorkerPrivate::timerEvent(QTimerEvent *ev)
|
2017-03-29 11:01:16 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
if (ev->timerId() == startWatchdogTimerId) {
|
2017-07-28 10:19:05 +02:00
|
|
|
q->reportFailure(tr("Worker start timed out."));
|
2017-05-09 10:25:11 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (ev->timerId() == stopWatchdogTimerId) {
|
2017-07-28 10:19:05 +02:00
|
|
|
q->reportFailure(tr("Worker stop timed out."));
|
2017-05-09 10:25:11 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2017-03-29 11:01:16 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 11:23:36 +02:00
|
|
|
/*!
|
|
|
|
|
\class ProjectExplorer::RunWorker
|
|
|
|
|
|
|
|
|
|
\brief The RunWorker class encapsulates a task that forms part, or
|
|
|
|
|
the whole of the operation of a tool for a certain \c RunConfiguration
|
|
|
|
|
according to some \c RunMode.
|
|
|
|
|
|
|
|
|
|
A typical example for a \c RunWorker is a process, either the
|
|
|
|
|
application process itself, or a helper process, such as a watchdog
|
|
|
|
|
or a log parser.
|
|
|
|
|
|
|
|
|
|
A \c RunWorker has a simple state model covering the \c Initialized,
|
2017-08-09 08:43:51 +02:00
|
|
|
\c Starting, \c Running, \c Stopping, and \c Done states.
|
2017-07-19 11:23:36 +02:00
|
|
|
|
|
|
|
|
In the course of the operation of tools several \c RunWorkers
|
|
|
|
|
may co-operate and form a combined state that is presented
|
|
|
|
|
to the user as \c RunControl, with direct interaction made
|
|
|
|
|
possible through the buttons in the \uicontrol{Application Output}
|
|
|
|
|
pane.
|
|
|
|
|
|
|
|
|
|
RunWorkers are typically created together with their RunControl.
|
|
|
|
|
The startup order of RunWorkers under a RunControl can be
|
|
|
|
|
specified by making a RunWorker dependent on others.
|
|
|
|
|
|
|
|
|
|
When a RunControl starts, it calls \c initiateStart() on RunWorkers
|
|
|
|
|
with fulfilled dependencies until all workers are \c Running, or in case
|
|
|
|
|
of short-lived helper tasks, \c Done.
|
|
|
|
|
|
|
|
|
|
A RunWorker can stop spontaneously, for example when the main application
|
|
|
|
|
process ends. In this case, it typically calls \c initiateStop()
|
|
|
|
|
on its RunControl, which in turn passes this to all sibling
|
|
|
|
|
RunWorkers.
|
|
|
|
|
|
|
|
|
|
Pressing the stop button in the \uicontrol{Application Output} pane
|
|
|
|
|
also calls \c initiateStop on the RunControl.
|
|
|
|
|
*/
|
2017-05-09 10:25:11 +02:00
|
|
|
|
|
|
|
|
RunWorker::RunWorker(RunControl *runControl)
|
|
|
|
|
: d(new RunWorkerPrivate(this, runControl))
|
2017-03-29 11:01:16 +02:00
|
|
|
{
|
2017-03-10 09:05:52 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
RunWorker::~RunWorker()
|
2017-04-21 11:39:01 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
delete d;
|
2017-04-21 11:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 11:23:36 +02:00
|
|
|
/*!
|
|
|
|
|
* This function is called by the RunControl once all dependencies
|
|
|
|
|
* are fulfilled.
|
|
|
|
|
*/
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunWorker::initiateStart()
|
2017-05-02 15:03:56 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
if (d->startWatchdogInterval != 0)
|
|
|
|
|
d->startWatchdogTimerId = d->startTimer(d->startWatchdogInterval);
|
|
|
|
|
|
|
|
|
|
start();
|
2017-04-27 16:32:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 11:23:36 +02:00
|
|
|
/*!
|
|
|
|
|
* This function has to be called by a RunWorker implementation
|
|
|
|
|
* to notify its RunControl about the successful start of this RunWorker.
|
|
|
|
|
*
|
|
|
|
|
* The RunControl may start other RunWorkers in response.
|
|
|
|
|
*/
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunWorker::reportStarted()
|
2017-05-02 15:03:56 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
if (d->startWatchdogInterval != 0)
|
|
|
|
|
d->killTimer(d->startWatchdogTimerId);
|
|
|
|
|
d->runControl->d->onWorkerStarted(this);
|
|
|
|
|
emit started();
|
2017-05-02 15:03:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 11:23:36 +02:00
|
|
|
/*!
|
|
|
|
|
* This function is called by the RunControl in its own \c initiateStop
|
|
|
|
|
* implementation, which is triggered in response to pressing the
|
|
|
|
|
* stop button in the \uicontrol{Application Output} pane or on direct
|
|
|
|
|
* request of one of the sibling RunWorkers.
|
|
|
|
|
*/
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunWorker::initiateStop()
|
2017-05-02 15:03:56 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
if (d->stopWatchdogInterval != 0)
|
|
|
|
|
d->stopWatchdogTimerId = d->startTimer(d->stopWatchdogInterval);
|
|
|
|
|
|
2017-06-26 18:01:59 +02:00
|
|
|
d->runControl->d->debugMessage("Initiate stop for " + d->id);
|
2017-05-09 10:25:11 +02:00
|
|
|
stop();
|
2017-05-02 15:03:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 11:23:36 +02:00
|
|
|
/*!
|
|
|
|
|
* This function has to be called by a RunWorker implementation
|
|
|
|
|
* to notify its RunControl about this RunWorker having stopped.
|
|
|
|
|
*
|
|
|
|
|
* The stop can be spontaneous, or in response to an initiateStop()
|
|
|
|
|
* or an initiateFinish() call.
|
|
|
|
|
*
|
|
|
|
|
* The RunControl will adjust its global state in response.
|
|
|
|
|
*/
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunWorker::reportStopped()
|
2017-04-27 16:32:49 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
if (d->stopWatchdogInterval != 0)
|
|
|
|
|
d->killTimer(d->stopWatchdogTimerId);
|
|
|
|
|
d->runControl->d->onWorkerStopped(this);
|
|
|
|
|
emit stopped();
|
2017-04-27 16:32:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 11:23:36 +02:00
|
|
|
/*!
|
|
|
|
|
* This function can be called by a RunWorker implementation to
|
|
|
|
|
* signal a problem in the operation in this worker. The
|
|
|
|
|
* RunControl will start to ramp down through initiateStop().
|
|
|
|
|
*/
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunWorker::reportFailure(const QString &msg)
|
2017-04-27 16:32:49 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
d->runControl->d->onWorkerFailed(this, msg);
|
2017-04-27 16:32:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 11:23:36 +02:00
|
|
|
/*!
|
|
|
|
|
* Appends a message in the specified \a format to
|
|
|
|
|
* the owning RunControl's \uicontrol{Application Output} pane.
|
|
|
|
|
*/
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunWorker::appendMessage(const QString &msg, OutputFormat format)
|
2017-04-27 16:32:49 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
if (msg.endsWith('\n'))
|
|
|
|
|
d->runControl->appendMessage(msg, format);
|
|
|
|
|
else
|
|
|
|
|
d->runControl->appendMessage(msg + '\n', format);
|
2017-04-27 16:32:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
IDevice::ConstPtr RunWorker::device() const
|
|
|
|
|
{
|
|
|
|
|
return d->runControl->device();
|
|
|
|
|
}
|
2017-03-24 17:06:13 +01:00
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
const Runnable &RunWorker::runnable() const
|
2017-03-24 17:06:13 +01:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
return d->runControl->runnable();
|
2017-03-24 17:06:13 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
Core::Id RunWorker::runMode() const
|
2017-03-24 17:06:13 +01:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
return d->runControl->runMode();
|
2017-03-24 17:06:13 +01:00
|
|
|
}
|
|
|
|
|
|
2017-08-08 14:09:50 +02:00
|
|
|
void RunWorker::addStartDependency(RunWorker *dependency)
|
2017-03-28 09:07:29 +02:00
|
|
|
{
|
2017-08-08 14:09:50 +02:00
|
|
|
d->startDependencies.append(dependency);
|
2017-03-28 09:07:29 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-08 14:49:49 +02:00
|
|
|
void RunWorker::addStopDependency(RunWorker *dependency)
|
|
|
|
|
{
|
|
|
|
|
d->stopDependencies.append(dependency);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
RunControl *RunWorker::runControl() const
|
2017-04-05 16:14:58 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
return d->runControl;
|
2017-04-05 16:14:58 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-26 18:01:59 +02:00
|
|
|
void RunWorker::setId(const QString &id)
|
2017-05-04 08:44:28 +02:00
|
|
|
{
|
2017-06-26 18:01:59 +02:00
|
|
|
d->id = id;
|
2017-05-04 08:44:28 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunWorker::setStartTimeout(int ms)
|
2017-05-02 15:03:56 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
d->startWatchdogInterval = ms;
|
2017-04-27 16:32:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunWorker::setStopTimeout(int ms)
|
2017-05-02 15:03:56 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
d->stopWatchdogInterval = ms;
|
2017-04-27 16:32:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunWorker::recordData(const QString &channel, const QVariant &data)
|
2017-05-02 15:03:56 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
d->data[channel] = data;
|
2017-05-02 15:03:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-14 11:13:16 +02:00
|
|
|
QVariant RunWorker::recordedData(const QString &channel) const
|
2017-04-27 16:32:49 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
return d->data[channel];
|
2017-04-27 16:32:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-07-05 15:17:38 +02:00
|
|
|
void RunWorker::setSupportsReRunning(bool reRunningSupported)
|
|
|
|
|
{
|
|
|
|
|
d->supportsReRunning = reRunningSupported;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RunWorker::supportsReRunning() const
|
|
|
|
|
{
|
2017-07-07 17:20:16 +02:00
|
|
|
return d->supportsReRunning;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-05 15:17:38 +02:00
|
|
|
QString RunWorker::userMessageForProcessError(QProcess::ProcessError error, const QString &program)
|
|
|
|
|
{
|
|
|
|
|
QString failedToStart = tr("The process failed to start.");
|
|
|
|
|
QString msg = tr("An unknown error in the process occurred.");
|
|
|
|
|
switch (error) {
|
|
|
|
|
case QProcess::FailedToStart:
|
|
|
|
|
msg = failedToStart + ' ' + tr("Either the "
|
|
|
|
|
"invoked program \"%1\" is missing, or you may have insufficient "
|
|
|
|
|
"permissions to invoke the program.").arg(program);
|
|
|
|
|
break;
|
|
|
|
|
case QProcess::Crashed:
|
2017-07-28 10:19:05 +02:00
|
|
|
msg = tr("The process was ended forcefully.");
|
2017-07-05 15:17:38 +02:00
|
|
|
break;
|
|
|
|
|
case QProcess::Timedout:
|
|
|
|
|
// "The last waitFor...() function timed out. "
|
|
|
|
|
// "The state of QProcess is unchanged, and you can try calling "
|
|
|
|
|
// "waitFor...() again."
|
|
|
|
|
return QString(); // sic!
|
|
|
|
|
case QProcess::WriteError:
|
|
|
|
|
msg = tr("An error occurred when attempting to write "
|
|
|
|
|
"to the process. For example, the process may not be running, "
|
|
|
|
|
"or it may have closed its input channel.");
|
|
|
|
|
break;
|
|
|
|
|
case QProcess::ReadError:
|
|
|
|
|
msg = tr("An error occurred when attempting to read from "
|
|
|
|
|
"the process. For example, the process may not be running.");
|
|
|
|
|
break;
|
|
|
|
|
case QProcess::UnknownError:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 13:44:49 +02:00
|
|
|
bool RunWorker::isEssential() const
|
|
|
|
|
{
|
|
|
|
|
return d->essential;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunWorker::setEssential(bool essential)
|
|
|
|
|
{
|
|
|
|
|
d->essential = essential;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-09 10:25:11 +02:00
|
|
|
void RunWorker::start()
|
2017-04-27 16:32:49 +02:00
|
|
|
{
|
2017-05-09 10:25:11 +02:00
|
|
|
reportStarted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunWorker::stop()
|
|
|
|
|
{
|
|
|
|
|
reportStopped();
|
2017-04-27 16:32:49 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-29 10:36:29 +03:00
|
|
|
} // namespace ProjectExplorer
|