2010-02-16 13:39:13 +01:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
2012-07-19 12:26:56 +02:00
|
|
|
** Contact: http://www.qt-project.org/
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-02-16 13:39:13 +01:00
|
|
|
**
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "qmlprojectruncontrol.h"
|
|
|
|
|
#include "qmlprojectrunconfiguration.h"
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2011-04-19 16:27:12 +02:00
|
|
|
#include <projectexplorer/target.h>
|
2012-09-03 18:31:44 +02:00
|
|
|
#include <projectexplorer/kit.h>
|
2011-04-19 16:27:12 +02:00
|
|
|
#include <projectexplorer/project.h>
|
2011-07-04 14:09:27 +02:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
2010-02-16 13:39:13 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2010-08-13 14:18:10 +02:00
|
|
|
#include <debugger/debuggerrunner.h>
|
|
|
|
|
#include <debugger/debuggerplugin.h>
|
2010-02-24 11:30:32 +01:00
|
|
|
#include <debugger/debuggerconstants.h>
|
2011-01-10 10:14:23 +01:00
|
|
|
#include <debugger/debuggerstartparameters.h>
|
2012-08-15 13:21:37 +02:00
|
|
|
#include <debugger/debuggerruncontrolfactory.h>
|
2011-07-18 21:07:03 +02:00
|
|
|
#include <qtsupport/baseqtversion.h>
|
2011-05-20 21:40:53 +02:00
|
|
|
#include <qtsupport/qmlobservertool.h>
|
2010-02-24 11:30:32 +01:00
|
|
|
|
2011-07-21 10:40:56 +02:00
|
|
|
#include <qmlprojectmanager/qmlprojectplugin.h>
|
2011-01-24 12:29:48 +01:00
|
|
|
|
2011-01-07 14:52:18 +01:00
|
|
|
using namespace ProjectExplorer;
|
2010-02-16 13:39:13 +01:00
|
|
|
|
|
|
|
|
namespace QmlProjectManager {
|
2011-07-21 10:40:56 +02:00
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2012-01-10 19:17:24 +01:00
|
|
|
QmlProjectRunControl::QmlProjectRunControl(QmlProjectRunConfiguration *runConfiguration, RunMode mode)
|
2010-04-30 13:19:31 +02:00
|
|
|
: RunControl(runConfiguration, mode)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2010-11-29 12:50:44 +01:00
|
|
|
m_applicationLauncher.setEnvironment(runConfiguration->environment());
|
2010-02-16 13:39:13 +01:00
|
|
|
m_applicationLauncher.setWorkingDirectory(runConfiguration->workingDirectory());
|
|
|
|
|
|
2012-01-10 19:17:24 +01:00
|
|
|
if (mode == NormalRunMode) {
|
2010-10-04 15:13:31 +02:00
|
|
|
m_executable = runConfiguration->viewerPath();
|
|
|
|
|
} else {
|
|
|
|
|
m_executable = runConfiguration->observerPath();
|
|
|
|
|
}
|
2010-02-16 13:39:13 +01:00
|
|
|
m_commandLineArguments = runConfiguration->viewerArguments();
|
2011-07-04 14:09:27 +02:00
|
|
|
m_mainQmlFile = runConfiguration->mainScript();
|
2010-02-16 13:39:13 +01:00
|
|
|
|
2011-04-15 12:59:44 +02:00
|
|
|
connect(&m_applicationLauncher, SIGNAL(appendMessage(QString,Utils::OutputFormat)),
|
2012-03-05 22:30:59 +01:00
|
|
|
this, SLOT(slotAppendMessage(QString,Utils::OutputFormat)));
|
2010-02-16 13:39:13 +01:00
|
|
|
connect(&m_applicationLauncher, SIGNAL(processExited(int)),
|
|
|
|
|
this, SLOT(processExited(int)));
|
|
|
|
|
connect(&m_applicationLauncher, SIGNAL(bringToForegroundRequested(qint64)),
|
|
|
|
|
this, SLOT(slotBringApplicationToForeground(qint64)));
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
QmlProjectRunControl::~QmlProjectRunControl()
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2010-10-04 09:44:18 +02:00
|
|
|
stop();
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
void QmlProjectRunControl::start()
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2011-01-07 14:52:18 +01:00
|
|
|
m_applicationLauncher.start(ApplicationLauncher::Gui, m_executable,
|
2010-02-16 13:39:13 +01:00
|
|
|
m_commandLineArguments);
|
2011-05-31 09:48:00 +02:00
|
|
|
setApplicationProcessHandle(ProcessHandle(m_applicationLauncher.applicationPID()));
|
2010-02-16 13:39:13 +01:00
|
|
|
emit started();
|
2011-04-12 19:42:25 +02:00
|
|
|
QString msg = tr("Starting %1 %2\n")
|
2011-01-07 14:52:18 +01:00
|
|
|
.arg(QDir::toNativeSeparators(m_executable), m_commandLineArguments);
|
2011-04-15 12:59:44 +02:00
|
|
|
appendMessage(msg, Utils::NormalMessageFormat);
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
RunControl::StopResult QmlProjectRunControl::stop()
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
|
|
|
|
m_applicationLauncher.stop();
|
2010-08-20 14:19:25 +02:00
|
|
|
return StoppedSynchronously;
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
bool QmlProjectRunControl::isRunning() const
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
|
|
|
|
return m_applicationLauncher.isRunning();
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
QIcon QmlProjectRunControl::icon() const
|
2011-03-28 19:58:13 +02:00
|
|
|
{
|
|
|
|
|
return QIcon(ProjectExplorer::Constants::ICON_RUN_SMALL);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
void QmlProjectRunControl::slotBringApplicationToForeground(qint64 pid)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
|
|
|
|
bringApplicationToForeground(pid);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
void QmlProjectRunControl::slotAppendMessage(const QString &line, Utils::OutputFormat format)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2011-01-07 18:57:54 +01:00
|
|
|
appendMessage(line, format);
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
void QmlProjectRunControl::processExited(int exitCode)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2011-04-12 19:42:25 +02:00
|
|
|
QString msg = tr("%1 exited with code %2\n")
|
2011-01-07 14:52:18 +01:00
|
|
|
.arg(QDir::toNativeSeparators(m_executable)).arg(exitCode);
|
2011-04-15 12:59:44 +02:00
|
|
|
appendMessage(msg, exitCode ? Utils::ErrorMessageFormat : Utils::NormalMessageFormat);
|
2010-02-16 13:39:13 +01:00
|
|
|
emit finished();
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-04 14:09:27 +02:00
|
|
|
QString QmlProjectRunControl::mainQmlFile() const
|
|
|
|
|
{
|
|
|
|
|
return m_mainQmlFile;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
QmlProjectRunControlFactory::QmlProjectRunControlFactory(QObject *parent)
|
2010-02-16 13:39:13 +01:00
|
|
|
: IRunControlFactory(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
QmlProjectRunControlFactory::~QmlProjectRunControlFactory()
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
bool QmlProjectRunControlFactory::canRun(RunConfiguration *runConfiguration,
|
2012-01-10 19:17:24 +01:00
|
|
|
RunMode mode) const
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
2010-11-10 11:39:01 +01:00
|
|
|
QmlProjectRunConfiguration *config =
|
|
|
|
|
qobject_cast<QmlProjectRunConfiguration*>(runConfiguration);
|
2011-07-18 17:23:26 +02:00
|
|
|
if (!config)
|
|
|
|
|
return false;
|
2012-01-10 19:17:24 +01:00
|
|
|
if (mode == NormalRunMode)
|
2011-07-18 17:23:26 +02:00
|
|
|
return !config->viewerPath().isEmpty();
|
2012-01-10 19:17:24 +01:00
|
|
|
if (mode != DebugRunMode)
|
2011-04-13 10:39:47 +02:00
|
|
|
return false;
|
2010-11-10 11:39:01 +01:00
|
|
|
|
2011-07-18 17:23:26 +02:00
|
|
|
if (!Debugger::DebuggerPlugin::isActiveDebugLanguage(Debugger::QmlLanguage))
|
|
|
|
|
return false;
|
2010-08-13 14:18:10 +02:00
|
|
|
|
2011-07-18 17:23:26 +02:00
|
|
|
if (!config->observerPath().isEmpty())
|
|
|
|
|
return true;
|
|
|
|
|
if (!config->qtVersion())
|
|
|
|
|
return false;
|
|
|
|
|
if (!config->qtVersion()->needsQmlDebuggingLibrary())
|
|
|
|
|
return true;
|
|
|
|
|
if (QtSupport::QmlObserverTool::canBuild(config->qtVersion()))
|
|
|
|
|
return true;
|
2010-08-13 14:18:10 +02:00
|
|
|
return false;
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
RunControl *QmlProjectRunControlFactory::create(RunConfiguration *runConfiguration,
|
2012-09-05 12:42:41 +02:00
|
|
|
RunMode mode, QString *errorMessage)
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(canRun(runConfiguration, mode), return 0);
|
2010-08-13 14:18:10 +02:00
|
|
|
QmlProjectRunConfiguration *config = qobject_cast<QmlProjectRunConfiguration *>(runConfiguration);
|
2011-07-04 14:09:27 +02:00
|
|
|
|
|
|
|
|
QList<ProjectExplorer::RunControl *> runcontrols =
|
|
|
|
|
ProjectExplorer::ProjectExplorerPlugin::instance()->runControls();
|
|
|
|
|
foreach (ProjectExplorer::RunControl *rc, runcontrols) {
|
|
|
|
|
if (QmlProjectRunControl *qrc = qobject_cast<QmlProjectRunControl *>(rc)) {
|
|
|
|
|
if (qrc->mainQmlFile() == config->mainScript())
|
|
|
|
|
// Asking the user defeats the purpose
|
|
|
|
|
// Making it configureable might be worth it
|
|
|
|
|
qrc->stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-13 14:18:10 +02:00
|
|
|
RunControl *runControl = 0;
|
2012-01-10 19:17:24 +01:00
|
|
|
if (mode == NormalRunMode)
|
2011-05-02 16:29:13 +02:00
|
|
|
runControl = new QmlProjectRunControl(config, mode);
|
2012-01-10 19:17:24 +01:00
|
|
|
else if (mode == DebugRunMode)
|
2012-09-05 12:42:41 +02:00
|
|
|
runControl = createDebugRunControl(config, errorMessage);
|
2010-08-13 14:18:10 +02:00
|
|
|
return runControl;
|
2010-02-16 13:39:13 +01:00
|
|
|
}
|
|
|
|
|
|
2011-05-02 16:29:13 +02:00
|
|
|
QString QmlProjectRunControlFactory::displayName() const
|
2010-02-16 13:39:13 +01:00
|
|
|
{
|
|
|
|
|
return tr("Run");
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-05 12:42:41 +02:00
|
|
|
RunControl *QmlProjectRunControlFactory::createDebugRunControl(QmlProjectRunConfiguration *runConfig, QString *errorMessage)
|
2010-08-13 14:18:10 +02:00
|
|
|
{
|
|
|
|
|
Debugger::DebuggerStartParameters params;
|
|
|
|
|
params.startMode = Debugger::StartInternal;
|
2010-10-04 15:13:31 +02:00
|
|
|
params.executable = runConfig->observerPath();
|
2010-09-02 17:17:35 +02:00
|
|
|
params.qmlServerAddress = "127.0.0.1";
|
2012-02-17 19:05:11 +01:00
|
|
|
params.qmlServerPort = runConfig->debuggerAspect()->qmlDebugServerPort();
|
|
|
|
|
params.processArgs = QString("-qmljsdebugger=port:%1,block").arg(params.qmlServerPort);
|
2011-02-08 17:23:35 +01:00
|
|
|
params.processArgs += QLatin1Char(' ') + runConfig->viewerArguments();
|
2010-08-13 14:18:10 +02:00
|
|
|
params.workingDirectory = runConfig->workingDirectory();
|
2010-11-29 12:50:44 +01:00
|
|
|
params.environment = runConfig->environment();
|
2010-08-13 14:18:10 +02:00
|
|
|
params.displayName = runConfig->displayName();
|
2011-04-26 09:46:05 +02:00
|
|
|
params.projectSourceDirectory = runConfig->target()->project()->projectDirectory();
|
|
|
|
|
params.projectSourceFiles = runConfig->target()->project()->files(Project::ExcludeGeneratedFiles);
|
2012-02-23 13:36:09 +01:00
|
|
|
if (runConfig->debuggerAspect()->useQmlDebugger())
|
2012-02-16 13:10:46 +01:00
|
|
|
params.languages |= Debugger::QmlLanguage;
|
2012-02-17 19:05:11 +01:00
|
|
|
if (runConfig->debuggerAspect()->useCppDebugger())
|
2012-02-16 13:10:46 +01:00
|
|
|
params.languages |= Debugger::CppLanguage;
|
|
|
|
|
|
2011-08-08 16:26:12 +02:00
|
|
|
// Makes sure that all bindings go through the JavaScript engine, so that
|
|
|
|
|
// breakpoints are actually hit!
|
|
|
|
|
const QString optimizerKey = QLatin1String("QML_DISABLE_OPTIMIZER");
|
|
|
|
|
if (!params.environment.hasKey(optimizerKey)) {
|
|
|
|
|
params.environment.set(optimizerKey, QLatin1String("1"));
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-04 15:13:31 +02:00
|
|
|
if (params.executable.isEmpty()) {
|
2011-07-21 10:40:56 +02:00
|
|
|
QmlProjectPlugin::showQmlObserverToolWarning();
|
2012-09-05 12:42:41 +02:00
|
|
|
*errorMessage = QString(""); // hack, we already showed a error message
|
2010-10-04 15:13:31 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-05 12:42:41 +02:00
|
|
|
return Debugger::DebuggerPlugin::createDebugger(params, runConfig, errorMessage);
|
2010-08-13 14:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 13:39:13 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlProjectManager
|