2013-04-25 16:02:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2013-04-25 16:02:17 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** 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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2013-04-25 16:02:17 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2013-04-25 16:02:17 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2013-04-25 16:02:17 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "iosbuildstep.h"
|
|
|
|
|
#include "iosconfigurations.h"
|
|
|
|
|
#include "iosdevice.h"
|
|
|
|
|
#include "iosmanager.h"
|
|
|
|
|
#include "iosrunconfiguration.h"
|
|
|
|
|
#include "iosrunner.h"
|
|
|
|
|
#include "iossimulator.h"
|
2014-03-28 19:05:35 +01:00
|
|
|
#include "iosconstants.h"
|
2013-04-25 16:02:17 +02:00
|
|
|
|
|
|
|
|
#include <projectexplorer/devicesupport/deviceapplicationrunner.h>
|
|
|
|
|
#include <projectexplorer/kitinformation.h>
|
|
|
|
|
#include <projectexplorer/target.h>
|
2013-11-04 22:45:52 +01:00
|
|
|
#include <projectexplorer/taskhub.h>
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2014-02-25 22:48:19 +01:00
|
|
|
#include <debugger/debuggerrunconfigurationaspect.h>
|
2013-04-25 16:02:17 +02:00
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QTime>
|
|
|
|
|
#include <QMessageBox>
|
2014-02-25 22:48:19 +01:00
|
|
|
#include <QRegExp>
|
2013-04-25 16:02:17 +02:00
|
|
|
|
2013-10-28 08:16:05 +01:00
|
|
|
#include <signal.h>
|
|
|
|
|
|
2013-11-04 22:45:52 +01:00
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
namespace Ios {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2014-02-25 22:48:19 +01:00
|
|
|
IosRunner::IosRunner(QObject *parent, IosRunConfiguration *runConfig, bool cppDebug, bool qmlDebug)
|
2014-04-10 11:35:36 +02:00
|
|
|
: QObject(parent), m_toolHandler(0), m_bundleDir(runConfig->bundleDirectory().toString()),
|
2013-04-25 16:02:17 +02:00
|
|
|
m_arguments(runConfig->commandLineArguments()),
|
2015-02-03 23:49:46 +02:00
|
|
|
m_device(DeviceKitInformation::device(runConfig->target()->kit())),
|
2014-02-25 22:48:19 +01:00
|
|
|
m_cppDebug(cppDebug), m_qmlDebug(qmlDebug), m_cleanExit(false),
|
|
|
|
|
m_qmlPort(0), m_pid(0)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2014-03-28 19:05:35 +01:00
|
|
|
m_deviceType = runConfig->deviceType();
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IosRunner::~IosRunner()
|
|
|
|
|
{
|
|
|
|
|
stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString IosRunner::bundlePath()
|
|
|
|
|
{
|
|
|
|
|
return m_bundleDir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList IosRunner::extraArgs()
|
|
|
|
|
{
|
2014-02-25 22:48:19 +01:00
|
|
|
QStringList res = m_arguments;
|
|
|
|
|
if (m_qmlPort != 0)
|
|
|
|
|
res << QString::fromLatin1("-qmljsdebugger=port:%1,block").arg(m_qmlPort);
|
|
|
|
|
return res;
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString IosRunner::deviceId()
|
|
|
|
|
{
|
|
|
|
|
IosDevice::ConstPtr dev = m_device.dynamicCast<const IosDevice>();
|
|
|
|
|
if (!dev)
|
|
|
|
|
return QString();
|
|
|
|
|
return dev->uniqueDeviceID();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IosToolHandler::RunKind IosRunner::runType()
|
|
|
|
|
{
|
2014-02-25 22:48:19 +01:00
|
|
|
if (m_cppDebug)
|
2013-04-25 16:02:17 +02:00
|
|
|
return IosToolHandler::DebugRun;
|
|
|
|
|
return IosToolHandler::NormalRun;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 22:48:19 +01:00
|
|
|
bool IosRunner::cppDebug() const
|
|
|
|
|
{
|
|
|
|
|
return m_cppDebug;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IosRunner::qmlDebug() const
|
|
|
|
|
{
|
|
|
|
|
return m_qmlDebug;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
void IosRunner::start()
|
|
|
|
|
{
|
|
|
|
|
if (m_toolHandler) {
|
|
|
|
|
m_toolHandler->stop();
|
|
|
|
|
emit finished(m_cleanExit);
|
|
|
|
|
}
|
|
|
|
|
m_cleanExit = false;
|
2014-02-25 22:48:19 +01:00
|
|
|
m_qmlPort = 0;
|
2014-10-24 10:28:28 +02:00
|
|
|
if (!QFileInfo::exists(m_bundleDir)) {
|
2014-03-11 11:15:37 +01:00
|
|
|
TaskHub::addTask(Task::Warning,
|
|
|
|
|
tr("Could not find %1.").arg(m_bundleDir),
|
|
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT);
|
|
|
|
|
emit finished(m_cleanExit);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-25 22:48:19 +01:00
|
|
|
if (m_device->type() == Ios::Constants::IOS_DEVICE_TYPE) {
|
|
|
|
|
IosDevice::ConstPtr iosDevice = m_device.dynamicCast<const IosDevice>();
|
|
|
|
|
if (m_device.isNull()) {
|
|
|
|
|
emit finished(m_cleanExit);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (m_qmlDebug)
|
|
|
|
|
m_qmlPort = iosDevice->nextPort();
|
|
|
|
|
} else {
|
2013-04-25 16:02:17 +02:00
|
|
|
IosSimulator::ConstPtr sim = m_device.dynamicCast<const IosSimulator>();
|
|
|
|
|
if (sim.isNull()) {
|
|
|
|
|
emit finished(m_cleanExit);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-25 22:48:19 +01:00
|
|
|
if (m_qmlDebug)
|
|
|
|
|
m_qmlPort = sim->nextPort();
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
2014-02-25 22:48:19 +01:00
|
|
|
|
2014-03-28 19:05:35 +01:00
|
|
|
m_toolHandler = new IosToolHandler(m_deviceType, this);
|
2013-04-25 16:02:17 +02:00
|
|
|
connect(m_toolHandler, SIGNAL(appOutput(Ios::IosToolHandler*,QString)),
|
|
|
|
|
SLOT(handleAppOutput(Ios::IosToolHandler*,QString)));
|
|
|
|
|
connect(m_toolHandler,
|
|
|
|
|
SIGNAL(didStartApp(Ios::IosToolHandler*,QString,QString,Ios::IosToolHandler::OpStatus)),
|
|
|
|
|
SLOT(handleDidStartApp(Ios::IosToolHandler*,QString,QString,Ios::IosToolHandler::OpStatus)));
|
|
|
|
|
connect(m_toolHandler, SIGNAL(errorMsg(Ios::IosToolHandler*,QString)),
|
|
|
|
|
SLOT(handleErrorMsg(Ios::IosToolHandler*,QString)));
|
2014-02-25 22:48:19 +01:00
|
|
|
connect(m_toolHandler, SIGNAL(gotServerPorts(Ios::IosToolHandler*,QString,QString,int,int)),
|
|
|
|
|
SLOT(handleGotServerPorts(Ios::IosToolHandler*,QString,QString,int,int)));
|
2013-10-14 15:23:15 +02:00
|
|
|
connect(m_toolHandler, SIGNAL(gotInferiorPid(Ios::IosToolHandler*,QString,QString,Q_PID)),
|
|
|
|
|
SLOT(handleGotInferiorPid(Ios::IosToolHandler*,QString,QString,Q_PID)));
|
2013-04-25 16:02:17 +02:00
|
|
|
connect(m_toolHandler, SIGNAL(toolExited(Ios::IosToolHandler*,int)),
|
|
|
|
|
SLOT(handleToolExited(Ios::IosToolHandler*,int)));
|
|
|
|
|
connect(m_toolHandler, SIGNAL(finished(Ios::IosToolHandler*)),
|
|
|
|
|
SLOT(handleFinished(Ios::IosToolHandler*)));
|
|
|
|
|
m_toolHandler->requestRunApp(bundlePath(), extraArgs(), runType(), deviceId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosRunner::stop()
|
|
|
|
|
{
|
2013-10-28 08:16:05 +01:00
|
|
|
if (m_toolHandler) {
|
|
|
|
|
#ifdef Q_OS_UNIX
|
|
|
|
|
if (m_pid > 0)
|
|
|
|
|
kill(m_pid, SIGKILL);
|
|
|
|
|
#endif
|
2013-04-25 16:02:17 +02:00
|
|
|
m_toolHandler->stop();
|
2013-10-28 08:16:05 +01:00
|
|
|
}
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosRunner::handleDidStartApp(IosToolHandler *handler, const QString &bundlePath,
|
|
|
|
|
const QString &deviceId, IosToolHandler::OpStatus status)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(bundlePath); Q_UNUSED(deviceId);
|
|
|
|
|
if (m_toolHandler == handler)
|
|
|
|
|
emit didStartApp(status);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 22:48:19 +01:00
|
|
|
void IosRunner::handleGotServerPorts(IosToolHandler *handler, const QString &bundlePath,
|
|
|
|
|
const QString &deviceId, int gdbPort, int qmlPort)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(bundlePath); Q_UNUSED(deviceId);
|
2014-02-25 22:48:19 +01:00
|
|
|
m_qmlPort = qmlPort;
|
2013-04-25 16:02:17 +02:00
|
|
|
if (m_toolHandler == handler)
|
2014-02-25 22:48:19 +01:00
|
|
|
emit gotServerPorts(gdbPort, qmlPort);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosRunner::handleGotInferiorPid(IosToolHandler *handler, const QString &bundlePath,
|
2013-10-14 15:23:15 +02:00
|
|
|
const QString &deviceId, Q_PID pid)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(bundlePath); Q_UNUSED(deviceId);
|
2013-10-28 08:16:05 +01:00
|
|
|
m_pid = pid;
|
2013-04-25 16:02:17 +02:00
|
|
|
if (m_toolHandler == handler)
|
2014-02-25 22:48:19 +01:00
|
|
|
emit gotInferiorPid(pid, m_qmlPort);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosRunner::handleAppOutput(IosToolHandler *handler, const QString &output)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(handler);
|
2014-02-25 22:48:19 +01:00
|
|
|
QRegExp qmlPortRe(QLatin1String("QML Debugger: Waiting for connection on port ([0-9]+)..."));
|
|
|
|
|
int index = qmlPortRe.indexIn(output);
|
|
|
|
|
QString res(output);
|
|
|
|
|
if (index != -1 && m_qmlPort)
|
|
|
|
|
res.replace(qmlPortRe.cap(1), QString::number(m_qmlPort));
|
|
|
|
|
emit appOutput(res);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosRunner::handleErrorMsg(IosToolHandler *handler, const QString &msg)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(handler);
|
2014-03-24 10:53:26 +01:00
|
|
|
QString res(msg);
|
|
|
|
|
QLatin1String lockedErr = QLatin1String("Unexpected reply: ELocked (454c6f636b6564) vs OK (4f4b)");
|
|
|
|
|
if (msg.contains(QLatin1String("AMDeviceStartService returned -402653150"))) {
|
2013-11-04 22:45:52 +01:00
|
|
|
TaskHub::addTask(Task::Warning,
|
|
|
|
|
tr("Run failed. The settings in the Organizer window of Xcode might be incorrect."),
|
|
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT);
|
2014-06-24 14:16:30 +02:00
|
|
|
} else if (res.contains(lockedErr)) {
|
2014-03-24 10:53:26 +01:00
|
|
|
QString message = tr("The device is locked, please unlock.");
|
|
|
|
|
TaskHub::addTask(Task::Error, message,
|
2013-11-04 22:45:52 +01:00
|
|
|
ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT);
|
2014-06-24 14:16:30 +02:00
|
|
|
res.replace(lockedErr, message);
|
2014-03-24 10:53:26 +01:00
|
|
|
}
|
2014-02-25 22:48:19 +01:00
|
|
|
QRegExp qmlPortRe(QLatin1String("QML Debugger: Waiting for connection on port ([0-9]+)..."));
|
|
|
|
|
int index = qmlPortRe.indexIn(msg);
|
|
|
|
|
if (index != -1 && m_qmlPort)
|
|
|
|
|
res.replace(qmlPortRe.cap(1), QString::number(m_qmlPort));
|
|
|
|
|
emit errorMsg(res);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosRunner::handleToolExited(IosToolHandler *handler, int code)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(handler);
|
|
|
|
|
m_cleanExit = (code == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosRunner::handleFinished(IosToolHandler *handler)
|
|
|
|
|
{
|
|
|
|
|
if (m_toolHandler == handler) {
|
|
|
|
|
emit finished(m_cleanExit);
|
|
|
|
|
m_toolHandler = 0;
|
|
|
|
|
}
|
|
|
|
|
handler->deleteLater();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString IosRunner::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return QString::fromLatin1("Run on %1").arg(m_device.isNull() ? QString()
|
|
|
|
|
: m_device->displayName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
2013-10-16 11:02:37 +02:00
|
|
|
} // namespace Ios
|