2013-04-25 16:02:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://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
|
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.
|
2013-04-25 16:02:17 +02: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.
|
2013-04-25 16:02:17 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "iostoolhandler.h"
|
|
|
|
|
#include "iosconfigurations.h"
|
2014-03-28 19:05:35 +01:00
|
|
|
#include "iosconstants.h"
|
2014-11-12 19:41:59 +01:00
|
|
|
#include "iossimulator.h"
|
2016-09-26 12:40:09 +02:00
|
|
|
#include "simulatorcontrol.h"
|
2013-04-25 16:02:17 +02:00
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
#include "debugger/debuggerconstants.h"
|
2013-10-02 16:09:23 +02:00
|
|
|
#include <coreplugin/icore.h>
|
2013-04-25 16:02:17 +02:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
2014-08-26 15:53:13 +02:00
|
|
|
#include <QFileInfo>
|
2016-09-26 12:40:09 +02:00
|
|
|
#include <QJsonArray>
|
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
#include <QJsonObject>
|
2013-04-25 16:02:17 +02:00
|
|
|
#include <QList>
|
2014-08-26 15:53:13 +02:00
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
#include <QProcess>
|
2013-10-10 15:15:49 +02:00
|
|
|
#include <QProcessEnvironment>
|
2014-08-26 15:53:13 +02:00
|
|
|
#include <QScopedArrayPointer>
|
|
|
|
|
#include <QSocketNotifier>
|
2013-12-04 12:58:29 +01:00
|
|
|
#include <QTimer>
|
2014-08-26 15:53:13 +02:00
|
|
|
#include <QXmlStreamReader>
|
2013-04-25 16:02:17 +02:00
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
2014-08-26 15:53:13 +02:00
|
|
|
static Q_LOGGING_CATEGORY(toolHandlerLog, "qtc.ios.toolhandler")
|
2013-04-25 16:02:17 +02:00
|
|
|
|
|
|
|
|
namespace Ios {
|
|
|
|
|
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
struct ParserState {
|
|
|
|
|
enum Kind {
|
|
|
|
|
Msg,
|
|
|
|
|
DeviceId,
|
|
|
|
|
Key,
|
|
|
|
|
Value,
|
|
|
|
|
QueryResult,
|
|
|
|
|
AppOutput,
|
2014-01-09 15:47:05 +01:00
|
|
|
ControlChar,
|
2013-04-25 16:02:17 +02:00
|
|
|
AppStarted,
|
|
|
|
|
InferiorPid,
|
2014-02-25 22:48:19 +01:00
|
|
|
ServerPorts,
|
2013-04-25 16:02:17 +02:00
|
|
|
Item,
|
|
|
|
|
Status,
|
|
|
|
|
AppTransfer,
|
|
|
|
|
DeviceInfo,
|
|
|
|
|
Exit
|
|
|
|
|
};
|
|
|
|
|
Kind kind;
|
|
|
|
|
QString elName;
|
|
|
|
|
QString chars;
|
|
|
|
|
QString key;
|
|
|
|
|
QString value;
|
|
|
|
|
QMap<QString,QString> info;
|
|
|
|
|
int progress, maxProgress;
|
2014-02-25 22:48:19 +01:00
|
|
|
int gdbPort, qmlPort;
|
2013-04-25 16:02:17 +02:00
|
|
|
bool collectChars() {
|
|
|
|
|
switch (kind) {
|
|
|
|
|
case Msg:
|
|
|
|
|
case DeviceId:
|
|
|
|
|
case Key:
|
|
|
|
|
case Value:
|
|
|
|
|
case Status:
|
|
|
|
|
case InferiorPid:
|
2014-01-09 15:47:05 +01:00
|
|
|
case AppOutput:
|
2013-04-25 16:02:17 +02:00
|
|
|
return true;
|
2014-02-25 22:48:19 +01:00
|
|
|
case ServerPorts:
|
2013-04-25 16:02:17 +02:00
|
|
|
case QueryResult:
|
2014-01-09 15:47:05 +01:00
|
|
|
case ControlChar:
|
2013-04-25 16:02:17 +02:00
|
|
|
case AppStarted:
|
|
|
|
|
case AppTransfer:
|
|
|
|
|
case Item:
|
|
|
|
|
case DeviceInfo:
|
|
|
|
|
case Exit:
|
2013-10-14 15:23:15 +02:00
|
|
|
break;
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
2013-10-14 15:23:15 +02:00
|
|
|
return false;
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ParserState(Kind kind) :
|
2014-02-25 22:48:19 +01:00
|
|
|
kind(kind), gdbPort(0), qmlPort(0) { }
|
2013-04-25 16:02:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class IosToolHandlerPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
enum State {
|
|
|
|
|
NonStarted,
|
|
|
|
|
Starting,
|
|
|
|
|
StartedInferior,
|
|
|
|
|
XmlEndProcessed,
|
|
|
|
|
Stopped
|
|
|
|
|
};
|
|
|
|
|
enum Op {
|
|
|
|
|
OpNone,
|
|
|
|
|
OpAppTransfer,
|
|
|
|
|
OpDeviceInfo,
|
|
|
|
|
OpAppRun
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-12 19:41:59 +01:00
|
|
|
explicit IosToolHandlerPrivate(const IosDeviceType &devType, IosToolHandler *q);
|
2016-09-21 11:10:20 +02:00
|
|
|
virtual ~IosToolHandlerPrivate();
|
2013-04-25 16:02:17 +02:00
|
|
|
virtual void requestTransferApp(const QString &bundlePath, const QString &deviceId,
|
|
|
|
|
int timeout = 1000) = 0;
|
|
|
|
|
virtual void requestRunApp(const QString &bundlePath, const QStringList &extraArgs,
|
|
|
|
|
IosToolHandler::RunKind runKind,
|
|
|
|
|
const QString &deviceId, int timeout = 1000) = 0;
|
|
|
|
|
virtual void requestDeviceInfo(const QString &deviceId, int timeout = 1000) = 0;
|
|
|
|
|
bool isRunning();
|
|
|
|
|
void start(const QString &exe, const QStringList &args);
|
2016-09-26 12:40:09 +02:00
|
|
|
virtual void stop(int errorCode) = 0;
|
|
|
|
|
virtual void debuggerStateChanged(Debugger::DebuggerState state) { Q_UNUSED(state); }
|
2013-04-25 16:02:17 +02:00
|
|
|
|
|
|
|
|
// signals
|
|
|
|
|
void isTransferringApp(const QString &bundlePath, const QString &deviceId, int progress,
|
|
|
|
|
int maxProgress, const QString &info);
|
|
|
|
|
void didTransferApp(const QString &bundlePath, const QString &deviceId,
|
|
|
|
|
IosToolHandler::OpStatus status);
|
|
|
|
|
void didStartApp(const QString &bundlePath, const QString &deviceId,
|
|
|
|
|
IosToolHandler::OpStatus status);
|
2016-04-19 16:43:30 +02:00
|
|
|
void gotServerPorts(const QString &bundlePath, const QString &deviceId, Utils::Port gdbPort,
|
|
|
|
|
Utils::Port qmlPort);
|
2015-09-11 13:13:04 +02:00
|
|
|
void gotInferiorPid(const QString &bundlePath, const QString &deviceId, qint64 pid);
|
2013-04-25 16:02:17 +02:00
|
|
|
void deviceInfo(const QString &deviceId, const IosToolHandler::Dict &info);
|
|
|
|
|
void appOutput(const QString &output);
|
|
|
|
|
void errorMsg(const QString &msg);
|
|
|
|
|
void toolExited(int code);
|
2016-09-26 12:40:09 +02:00
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
protected:
|
2016-09-26 12:40:09 +02:00
|
|
|
void killProcess();
|
|
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
protected:
|
2013-04-25 16:02:17 +02:00
|
|
|
IosToolHandler *q;
|
2016-09-21 11:10:20 +02:00
|
|
|
QProcess *process;
|
2013-12-04 12:58:29 +01:00
|
|
|
QTimer killTimer;
|
2013-04-25 16:02:17 +02:00
|
|
|
QXmlStreamReader outputParser;
|
|
|
|
|
QString deviceId;
|
|
|
|
|
QString bundlePath;
|
|
|
|
|
IosToolHandler::RunKind runKind;
|
|
|
|
|
State state;
|
|
|
|
|
Op op;
|
2014-11-12 19:41:59 +01:00
|
|
|
IosDeviceType devType;
|
2013-04-25 16:02:17 +02:00
|
|
|
static const int lookaheadSize = 67;
|
|
|
|
|
int iBegin, iEnd, gdbSocket;
|
|
|
|
|
QList<ParserState> stack;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class IosDeviceToolHandlerPrivate : public IosToolHandlerPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 19:41:59 +01:00
|
|
|
explicit IosDeviceToolHandlerPrivate(const IosDeviceType &devType, IosToolHandler *q);
|
2016-09-26 12:40:09 +02:00
|
|
|
|
|
|
|
|
// IosToolHandlerPrivate overrides
|
|
|
|
|
public:
|
|
|
|
|
void requestTransferApp(const QString &bundlePath, const QString &deviceId,
|
|
|
|
|
int timeout = 1000) override;
|
|
|
|
|
void requestRunApp(const QString &bundlePath, const QStringList &extraArgs,
|
|
|
|
|
IosToolHandler::RunKind runKind,
|
|
|
|
|
const QString &deviceId, int timeout = 1000) override;
|
|
|
|
|
void requestDeviceInfo(const QString &deviceId, int timeout = 1000) override;
|
|
|
|
|
void stop(int errorCode) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void subprocessError(QProcess::ProcessError error);
|
|
|
|
|
void subprocessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
|
|
|
|
void subprocessHasData();
|
|
|
|
|
void processXml();
|
2013-04-25 16:02:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class IosSimulatorToolHandlerPrivate : public IosToolHandlerPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-11-12 19:41:59 +01:00
|
|
|
explicit IosSimulatorToolHandlerPrivate(const IosDeviceType &devType, IosToolHandler *q);
|
2016-09-26 12:40:09 +02:00
|
|
|
|
|
|
|
|
// IosToolHandlerPrivate overrides
|
|
|
|
|
public:
|
|
|
|
|
void requestTransferApp(const QString &bundlePath, const QString &deviceIdentifier,
|
|
|
|
|
int timeout = 1000) override;
|
|
|
|
|
void requestRunApp(const QString &bundlePath, const QStringList &extraArgs,
|
|
|
|
|
IosToolHandler::RunKind runKind,
|
|
|
|
|
const QString &deviceIdentifier, int timeout = 1000) override;
|
|
|
|
|
void requestDeviceInfo(const QString &deviceId, int timeout = 1000) override;
|
|
|
|
|
void stop(int errorCode) override;
|
|
|
|
|
void debuggerStateChanged(Debugger::DebuggerState state) override;
|
|
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
private:
|
2016-09-26 12:40:09 +02:00
|
|
|
void simAppProcessError(QProcess::ProcessError error);
|
|
|
|
|
void simAppProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
|
|
|
|
void simAppProcessHasData();
|
|
|
|
|
void simAppProcessHasErrorOutput();
|
|
|
|
|
void launchAppOnSimulator();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
qint64 appPId = -1;
|
|
|
|
|
bool appLaunched = false;
|
2013-04-25 16:02:17 +02:00
|
|
|
};
|
|
|
|
|
|
2014-11-12 19:41:59 +01:00
|
|
|
IosToolHandlerPrivate::IosToolHandlerPrivate(const IosDeviceType &devType,
|
2013-04-25 16:02:17 +02:00
|
|
|
Ios::IosToolHandler *q) :
|
2016-09-21 11:10:20 +02:00
|
|
|
q(q),
|
2016-09-26 12:40:09 +02:00
|
|
|
process(nullptr),
|
2016-09-21 11:10:20 +02:00
|
|
|
state(NonStarted),
|
|
|
|
|
devType(devType),
|
|
|
|
|
iBegin(0),
|
|
|
|
|
iEnd(0),
|
2013-04-25 16:02:17 +02:00
|
|
|
gdbSocket(-1)
|
|
|
|
|
{
|
2013-12-04 12:58:29 +01:00
|
|
|
killTimer.setSingleShot(true);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 11:10:20 +02:00
|
|
|
IosToolHandlerPrivate::~IosToolHandlerPrivate()
|
|
|
|
|
{
|
|
|
|
|
if (isRunning()) {
|
|
|
|
|
process->terminate();
|
|
|
|
|
if (!process->waitForFinished(1000))
|
|
|
|
|
process->kill();
|
|
|
|
|
}
|
|
|
|
|
delete process;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
bool IosToolHandlerPrivate::isRunning()
|
|
|
|
|
{
|
2016-09-21 11:10:20 +02:00
|
|
|
return process && (process->state() != QProcess::NotRunning);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosToolHandlerPrivate::start(const QString &exe, const QStringList &args)
|
|
|
|
|
{
|
2016-09-26 12:40:09 +02:00
|
|
|
Q_ASSERT(process);
|
2013-04-25 16:02:17 +02:00
|
|
|
QTC_CHECK(state == NonStarted);
|
|
|
|
|
state = Starting;
|
2014-07-07 09:24:17 +02:00
|
|
|
qCDebug(toolHandlerLog) << "running " << exe << args;
|
2016-09-21 11:10:20 +02:00
|
|
|
process->start(exe, args);
|
2013-04-25 16:02:17 +02:00
|
|
|
state = StartedInferior;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// signals
|
|
|
|
|
void IosToolHandlerPrivate::isTransferringApp(const QString &bundlePath, const QString &deviceId,
|
|
|
|
|
int progress, int maxProgress, const QString &info)
|
|
|
|
|
{
|
|
|
|
|
emit q->isTransferringApp(q, bundlePath, deviceId, progress, maxProgress, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosToolHandlerPrivate::didTransferApp(const QString &bundlePath, const QString &deviceId,
|
|
|
|
|
Ios::IosToolHandler::OpStatus status)
|
|
|
|
|
{
|
|
|
|
|
emit q->didTransferApp(q, bundlePath, deviceId, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosToolHandlerPrivate::didStartApp(const QString &bundlePath, const QString &deviceId,
|
|
|
|
|
IosToolHandler::OpStatus status)
|
|
|
|
|
{
|
|
|
|
|
emit q->didStartApp(q, bundlePath, deviceId, status);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-19 16:43:30 +02:00
|
|
|
void IosToolHandlerPrivate::gotServerPorts(const QString &bundlePath, const QString &deviceId,
|
|
|
|
|
Utils::Port gdbPort, Utils::Port qmlPort)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2014-02-25 22:48:19 +01:00
|
|
|
emit q->gotServerPorts(q, bundlePath, deviceId, gdbPort, qmlPort);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosToolHandlerPrivate::gotInferiorPid(const QString &bundlePath, const QString &deviceId,
|
2015-09-11 13:13:04 +02:00
|
|
|
qint64 pid)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
|
|
|
|
emit q->gotInferiorPid(q, bundlePath, deviceId, pid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosToolHandlerPrivate::deviceInfo(const QString &deviceId,
|
|
|
|
|
const Ios::IosToolHandler::Dict &info)
|
|
|
|
|
{
|
|
|
|
|
emit q->deviceInfo(q, deviceId, info);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosToolHandlerPrivate::appOutput(const QString &output)
|
|
|
|
|
{
|
|
|
|
|
emit q->appOutput(q, output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosToolHandlerPrivate::errorMsg(const QString &msg)
|
|
|
|
|
{
|
|
|
|
|
emit q->errorMsg(q, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosToolHandlerPrivate::toolExited(int code)
|
|
|
|
|
{
|
|
|
|
|
emit q->toolExited(q, code);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
void IosDeviceToolHandlerPrivate::subprocessError(QProcess::ProcessError error)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2013-11-28 14:58:31 +01:00
|
|
|
if (state != Stopped)
|
|
|
|
|
errorMsg(IosToolHandler::tr("iOS tool Error %1").arg(error));
|
|
|
|
|
stop(-1);
|
|
|
|
|
if (error == QProcess::FailedToStart) {
|
2014-07-07 09:24:17 +02:00
|
|
|
qCDebug(toolHandlerLog) << "IosToolHandler::finished(" << this << ")";
|
2013-11-28 14:58:31 +01:00
|
|
|
emit q->finished(q);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
void IosDeviceToolHandlerPrivate::subprocessFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2013-11-28 14:58:31 +01:00
|
|
|
stop((exitStatus == QProcess::NormalExit) ? exitCode : -1 );
|
2014-07-07 09:24:17 +02:00
|
|
|
qCDebug(toolHandlerLog) << "IosToolHandler::finished(" << this << ")";
|
2013-12-04 12:58:29 +01:00
|
|
|
killTimer.stop();
|
2013-11-28 14:58:31 +01:00
|
|
|
emit q->finished(q);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
void IosDeviceToolHandlerPrivate::processXml()
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
|
|
|
|
while (!outputParser.atEnd()) {
|
|
|
|
|
QXmlStreamReader::TokenType tt = outputParser.readNext();
|
2014-07-07 09:24:17 +02:00
|
|
|
//qCDebug(toolHandlerLog) << "processXml, tt=" << tt;
|
2013-04-25 16:02:17 +02:00
|
|
|
switch (tt) {
|
|
|
|
|
case QXmlStreamReader::NoToken:
|
|
|
|
|
// The reader has not yet read anything.
|
|
|
|
|
continue;
|
|
|
|
|
case QXmlStreamReader::Invalid:
|
|
|
|
|
// An error has occurred, reported in error() and errorString().
|
|
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::StartDocument:
|
|
|
|
|
// The reader reports the XML version number in documentVersion(), and the encoding
|
|
|
|
|
// as specified in the XML document in documentEncoding(). If the document is declared
|
|
|
|
|
// standalone, isStandaloneDocument() returns true; otherwise it returns false.
|
|
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::EndDocument:
|
|
|
|
|
// The reader reports the end of the document.
|
|
|
|
|
// state = XmlEndProcessed;
|
|
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::StartElement:
|
|
|
|
|
// The reader reports the start of an element with namespaceUri() and name(). Empty
|
|
|
|
|
// elements are also reported as StartElement, followed directly by EndElement.
|
|
|
|
|
// The convenience function readElementText() can be called to concatenate all content
|
|
|
|
|
// until the corresponding EndElement. Attributes are reported in attributes(),
|
|
|
|
|
// namespace declarations in namespaceDeclarations().
|
|
|
|
|
{
|
|
|
|
|
QStringRef elName = outputParser.name();
|
|
|
|
|
if (elName == QLatin1String("msg")) {
|
|
|
|
|
stack.append(ParserState(ParserState::Msg));
|
|
|
|
|
} else if (elName == QLatin1String("exit")) {
|
|
|
|
|
stack.append(ParserState(ParserState::Exit));
|
|
|
|
|
toolExited(outputParser.attributes().value(QLatin1String("code"))
|
|
|
|
|
.toString().toInt());
|
|
|
|
|
} else if (elName == QLatin1String("device_id")) {
|
|
|
|
|
stack.append(ParserState(ParserState::DeviceId));
|
|
|
|
|
} else if (elName == QLatin1String("key")) {
|
|
|
|
|
stack.append(ParserState(ParserState::Key));
|
|
|
|
|
} else if (elName == QLatin1String("value")) {
|
|
|
|
|
stack.append(ParserState(ParserState::Value));
|
|
|
|
|
} else if (elName == QLatin1String("query_result")) {
|
|
|
|
|
stack.append(ParserState(ParserState::QueryResult));
|
|
|
|
|
} else if (elName == QLatin1String("app_output")) {
|
|
|
|
|
stack.append(ParserState(ParserState::AppOutput));
|
2014-01-09 15:47:05 +01:00
|
|
|
} else if (elName == QLatin1String("control_char")) {
|
|
|
|
|
QXmlStreamAttributes attributes = outputParser.attributes();
|
|
|
|
|
QChar c[1] = { QChar::fromLatin1(static_cast<char>(attributes.value(QLatin1String("code")).toString().toInt())) };
|
|
|
|
|
if (stack.size() > 0 && stack.last().collectChars())
|
|
|
|
|
stack.last().chars.append(c[0]);
|
|
|
|
|
stack.append(ParserState(ParserState::ControlChar));
|
|
|
|
|
break;
|
2013-04-25 16:02:17 +02:00
|
|
|
} else if (elName == QLatin1String("item")) {
|
|
|
|
|
stack.append(ParserState(ParserState::Item));
|
|
|
|
|
} else if (elName == QLatin1String("status")) {
|
|
|
|
|
ParserState pState(ParserState::Status);
|
|
|
|
|
QXmlStreamAttributes attributes = outputParser.attributes();
|
|
|
|
|
pState.progress = attributes.value(QLatin1String("progress")).toString().toInt();
|
|
|
|
|
pState.maxProgress = attributes.value(QLatin1String("max_progress")).toString().toInt();
|
|
|
|
|
stack.append(pState);
|
|
|
|
|
} else if (elName == QLatin1String("app_started")) {
|
|
|
|
|
stack.append(ParserState(ParserState::AppStarted));
|
|
|
|
|
QXmlStreamAttributes attributes = outputParser.attributes();
|
|
|
|
|
QStringRef statusStr = attributes.value(QLatin1String("status"));
|
|
|
|
|
Ios::IosToolHandler::OpStatus status = Ios::IosToolHandler::Unknown;
|
|
|
|
|
if (statusStr.compare(QLatin1String("success"), Qt::CaseInsensitive) == 0)
|
|
|
|
|
status = Ios::IosToolHandler::Success;
|
|
|
|
|
else if (statusStr.compare(QLatin1String("failure"), Qt::CaseInsensitive) == 0)
|
|
|
|
|
status = Ios::IosToolHandler::Failure;
|
|
|
|
|
didStartApp(bundlePath, deviceId, status);
|
|
|
|
|
} else if (elName == QLatin1String("app_transfer")) {
|
|
|
|
|
stack.append(ParserState(ParserState::AppTransfer));
|
|
|
|
|
QXmlStreamAttributes attributes = outputParser.attributes();
|
|
|
|
|
QStringRef statusStr = attributes.value(QLatin1String("status"));
|
|
|
|
|
Ios::IosToolHandler::OpStatus status = Ios::IosToolHandler::Unknown;
|
|
|
|
|
if (statusStr.compare(QLatin1String("success"), Qt::CaseInsensitive) == 0)
|
|
|
|
|
status = Ios::IosToolHandler::Success;
|
|
|
|
|
else if (statusStr.compare(QLatin1String("failure"), Qt::CaseInsensitive) == 0)
|
|
|
|
|
status = Ios::IosToolHandler::Failure;
|
|
|
|
|
emit didTransferApp(bundlePath, deviceId, status);
|
2015-04-21 09:32:14 +02:00
|
|
|
} else if (elName == QLatin1String("device_info") || elName == QLatin1String("deviceinfo")) {
|
2013-04-25 16:02:17 +02:00
|
|
|
stack.append(ParserState(ParserState::DeviceInfo));
|
|
|
|
|
} else if (elName == QLatin1String("inferior_pid")) {
|
|
|
|
|
stack.append(ParserState(ParserState::InferiorPid));
|
2014-02-25 22:48:19 +01:00
|
|
|
} else if (elName == QLatin1String("server_ports")) {
|
|
|
|
|
stack.append(ParserState(ParserState::ServerPorts));
|
|
|
|
|
QXmlStreamAttributes attributes = outputParser.attributes();
|
2016-04-19 16:43:30 +02:00
|
|
|
Utils::Port gdbServerPort(
|
|
|
|
|
attributes.value(QLatin1String("gdb_server")).toString().toInt());
|
|
|
|
|
Utils::Port qmlServerPort(
|
|
|
|
|
attributes.value(QLatin1String("qml_server")).toString().toInt());
|
2014-02-25 22:48:19 +01:00
|
|
|
gotServerPorts(bundlePath, deviceId, gdbServerPort, qmlServerPort);
|
2013-04-25 16:02:17 +02:00
|
|
|
} else {
|
2014-07-07 09:24:17 +02:00
|
|
|
qCWarning(toolHandlerLog) << "unexpected element " << elName;
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case QXmlStreamReader::EndElement:
|
|
|
|
|
// The reader reports the end of an element with namespaceUri() and name().
|
|
|
|
|
{
|
|
|
|
|
ParserState p = stack.last();
|
|
|
|
|
stack.removeLast();
|
|
|
|
|
switch (p.kind) {
|
|
|
|
|
case ParserState::Msg:
|
|
|
|
|
errorMsg(p.chars);
|
|
|
|
|
break;
|
|
|
|
|
case ParserState::DeviceId:
|
|
|
|
|
if (deviceId.isEmpty())
|
|
|
|
|
deviceId = p.chars;
|
|
|
|
|
else
|
|
|
|
|
QTC_CHECK(deviceId.compare(p.chars, Qt::CaseInsensitive) == 0);
|
|
|
|
|
break;
|
|
|
|
|
case ParserState::Key:
|
|
|
|
|
stack.last().key = p.chars;
|
|
|
|
|
break;
|
|
|
|
|
case ParserState::Value:
|
|
|
|
|
stack.last().value = p.chars;
|
|
|
|
|
break;
|
|
|
|
|
case ParserState::Status:
|
|
|
|
|
isTransferringApp(bundlePath, deviceId, p.progress, p.maxProgress, p.chars);
|
|
|
|
|
break;
|
|
|
|
|
case ParserState::QueryResult:
|
|
|
|
|
state = XmlEndProcessed;
|
2013-11-28 14:58:31 +01:00
|
|
|
stop(0);
|
|
|
|
|
return;
|
2013-04-25 16:02:17 +02:00
|
|
|
case ParserState::AppOutput:
|
2014-01-09 15:47:05 +01:00
|
|
|
appOutput(p.chars);
|
|
|
|
|
break;
|
|
|
|
|
case ParserState::ControlChar:
|
2013-04-25 16:02:17 +02:00
|
|
|
break;
|
|
|
|
|
case ParserState::AppStarted:
|
|
|
|
|
break;
|
|
|
|
|
case ParserState::AppTransfer:
|
|
|
|
|
break;
|
|
|
|
|
case ParserState::Item:
|
|
|
|
|
stack.last().info.insert(p.key, p.value);
|
|
|
|
|
break;
|
|
|
|
|
case ParserState::DeviceInfo:
|
|
|
|
|
deviceInfo(deviceId, p.info);
|
|
|
|
|
break;
|
|
|
|
|
case ParserState::Exit:
|
|
|
|
|
break;
|
|
|
|
|
case ParserState::InferiorPid:
|
2015-09-11 13:13:04 +02:00
|
|
|
gotInferiorPid(bundlePath, deviceId, p.chars.toLongLong());
|
2013-04-25 16:02:17 +02:00
|
|
|
break;
|
2014-02-25 22:48:19 +01:00
|
|
|
case ParserState::ServerPorts:
|
2013-10-29 22:25:41 +01:00
|
|
|
break;
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case QXmlStreamReader::Characters:
|
|
|
|
|
// The reader reports characters in text(). If the characters are all white-space,
|
|
|
|
|
// isWhitespace() returns true. If the characters stem from a CDATA section,
|
|
|
|
|
// isCDATA() returns true.
|
|
|
|
|
if (stack.isEmpty())
|
|
|
|
|
break;
|
2014-01-09 15:47:05 +01:00
|
|
|
if (stack.last().collectChars())
|
2013-04-25 16:02:17 +02:00
|
|
|
stack.last().chars.append(outputParser.text());
|
|
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::Comment:
|
|
|
|
|
// The reader reports a comment in text().
|
|
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::DTD:
|
|
|
|
|
// The reader reports a DTD in text(), notation declarations in notationDeclarations(),
|
|
|
|
|
// and entity declarations in entityDeclarations(). Details of the DTD declaration are
|
|
|
|
|
// reported in in dtdName(), dtdPublicId(), and dtdSystemId().
|
|
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::EntityReference:
|
|
|
|
|
// The reader reports an entity reference that could not be resolved. The name of
|
|
|
|
|
// the reference is reported in name(), the replacement text in text().
|
|
|
|
|
break;
|
|
|
|
|
case QXmlStreamReader::ProcessingInstruction:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (outputParser.hasError()
|
|
|
|
|
&& outputParser.error() != QXmlStreamReader::PrematureEndOfDocumentError) {
|
2014-07-07 09:24:17 +02:00
|
|
|
qCWarning(toolHandlerLog) << "error parsing iosTool output:" << outputParser.errorString();
|
2013-11-28 14:58:31 +01:00
|
|
|
stop(-1);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
void IosDeviceToolHandlerPrivate::subprocessHasData()
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2014-07-07 09:24:17 +02:00
|
|
|
qCDebug(toolHandlerLog) << "subprocessHasData, state:" << state;
|
2013-04-25 16:02:17 +02:00
|
|
|
while (true) {
|
|
|
|
|
switch (state) {
|
|
|
|
|
case NonStarted:
|
2014-07-07 09:24:17 +02:00
|
|
|
qCWarning(toolHandlerLog) << "IosToolHandler unexpected state in subprocessHasData: NonStarted";
|
2013-04-25 16:02:17 +02:00
|
|
|
// pass
|
|
|
|
|
case Starting:
|
|
|
|
|
case StartedInferior:
|
|
|
|
|
// read some data
|
|
|
|
|
{
|
2013-10-29 22:25:41 +01:00
|
|
|
char buf[200];
|
2016-09-21 11:10:20 +02:00
|
|
|
while (isRunning()) {
|
|
|
|
|
qint64 rRead = process->read(buf, sizeof(buf));
|
2013-10-29 22:25:41 +01:00
|
|
|
if (rRead == -1) {
|
2013-11-28 14:58:31 +01:00
|
|
|
stop(-1);
|
2013-04-25 16:02:17 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2013-11-06 12:56:51 +01:00
|
|
|
if (rRead == 0)
|
2013-04-25 16:02:17 +02:00
|
|
|
return;
|
2014-07-07 09:24:17 +02:00
|
|
|
qCDebug(toolHandlerLog) << "subprocessHasData read " << QByteArray(buf, rRead);
|
2013-10-29 22:25:41 +01:00
|
|
|
outputParser.addData(QByteArray(buf, rRead));
|
|
|
|
|
processXml();
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
2013-10-29 22:25:41 +01:00
|
|
|
}
|
|
|
|
|
case XmlEndProcessed:
|
2013-11-28 14:58:31 +01:00
|
|
|
stop(0);
|
2013-04-25 16:02:17 +02:00
|
|
|
return;
|
|
|
|
|
case Stopped:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IosDeviceToolHandlerPrivate
|
|
|
|
|
|
2014-11-12 19:41:59 +01:00
|
|
|
IosDeviceToolHandlerPrivate::IosDeviceToolHandlerPrivate(const IosDeviceType &devType,
|
2013-04-25 16:02:17 +02:00
|
|
|
IosToolHandler *q)
|
|
|
|
|
: IosToolHandlerPrivate(devType, q)
|
2016-09-26 12:40:09 +02:00
|
|
|
{
|
|
|
|
|
process = new QProcess;
|
|
|
|
|
|
|
|
|
|
// Prepare & set process Environment.
|
|
|
|
|
QProcessEnvironment env(QProcessEnvironment::systemEnvironment());
|
|
|
|
|
foreach (const QString &k, env.keys())
|
|
|
|
|
if (k.startsWith(QLatin1String("DYLD_")))
|
|
|
|
|
env.remove(k);
|
|
|
|
|
QStringList frameworkPaths;
|
|
|
|
|
Utils::FileName xcPath = IosConfigurations::developerPath();
|
|
|
|
|
QString privateFPath = xcPath.appendPath(QLatin1String("Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks")).toFileInfo().canonicalFilePath();
|
|
|
|
|
if (!privateFPath.isEmpty())
|
|
|
|
|
frameworkPaths << privateFPath;
|
|
|
|
|
QString otherFPath = xcPath.appendPath(QLatin1String("../OtherFrameworks")).toFileInfo().canonicalFilePath();
|
|
|
|
|
if (!otherFPath.isEmpty())
|
|
|
|
|
frameworkPaths << otherFPath;
|
|
|
|
|
QString sharedFPath = xcPath.appendPath(QLatin1String("../SharedFrameworks")).toFileInfo().canonicalFilePath();
|
|
|
|
|
if (!sharedFPath.isEmpty())
|
|
|
|
|
frameworkPaths << sharedFPath;
|
|
|
|
|
frameworkPaths << QLatin1String("/System/Library/Frameworks")
|
|
|
|
|
<< QLatin1String("/System/Library/PrivateFrameworks");
|
|
|
|
|
env.insert(QLatin1String("DYLD_FALLBACK_FRAMEWORK_PATH"), frameworkPaths.join(QLatin1Char(':')));
|
|
|
|
|
qCDebug(toolHandlerLog) << "IosToolHandler runEnv:" << env.toStringList();
|
|
|
|
|
process->setProcessEnvironment(env);
|
|
|
|
|
|
|
|
|
|
QObject::connect(process, &QProcess::readyReadStandardOutput,
|
|
|
|
|
std::bind(&IosDeviceToolHandlerPrivate::subprocessHasData,this));
|
|
|
|
|
|
|
|
|
|
QObject::connect(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
|
|
|
|
std::bind(&IosDeviceToolHandlerPrivate::subprocessFinished,this, _1,_2));
|
|
|
|
|
|
|
|
|
|
QObject::connect(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error),
|
|
|
|
|
std::bind(&IosDeviceToolHandlerPrivate::subprocessError, this, _1));
|
|
|
|
|
|
|
|
|
|
QObject::connect(&killTimer, &QTimer::timeout, std::bind(&IosDeviceToolHandlerPrivate::killProcess, this));
|
|
|
|
|
}
|
2013-04-25 16:02:17 +02:00
|
|
|
|
|
|
|
|
void IosDeviceToolHandlerPrivate::requestTransferApp(const QString &bundlePath,
|
|
|
|
|
const QString &deviceId, int timeout)
|
|
|
|
|
{
|
|
|
|
|
this->bundlePath = bundlePath;
|
|
|
|
|
this->deviceId = deviceId;
|
|
|
|
|
QStringList args;
|
2015-10-20 00:13:21 -07:00
|
|
|
args << QLatin1String("--id") << deviceId << QLatin1String("--bundle")
|
|
|
|
|
<< bundlePath << QLatin1String("--timeout") << QString::number(timeout)
|
|
|
|
|
<< QLatin1String("--install");
|
2013-04-25 16:02:17 +02:00
|
|
|
start(IosToolHandler::iosDeviceToolPath(), args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosDeviceToolHandlerPrivate::requestRunApp(const QString &bundlePath,
|
|
|
|
|
const QStringList &extraArgs,
|
|
|
|
|
IosToolHandler::RunKind runType,
|
|
|
|
|
const QString &deviceId, int timeout)
|
|
|
|
|
{
|
|
|
|
|
this->bundlePath = bundlePath;
|
|
|
|
|
this->deviceId = deviceId;
|
|
|
|
|
this->runKind = runType;
|
|
|
|
|
QStringList args;
|
2015-10-20 00:13:21 -07:00
|
|
|
args << QLatin1String("--id") << deviceId << QLatin1String("--bundle")
|
|
|
|
|
<< bundlePath << QLatin1String("--timeout") << QString::number(timeout);
|
2013-04-25 16:02:17 +02:00
|
|
|
switch (runType) {
|
|
|
|
|
case IosToolHandler::NormalRun:
|
2015-10-20 00:13:21 -07:00
|
|
|
args << QLatin1String("--run");
|
2013-04-25 16:02:17 +02:00
|
|
|
break;
|
|
|
|
|
case IosToolHandler::DebugRun:
|
2015-10-20 00:13:21 -07:00
|
|
|
args << QLatin1String("--debug");
|
2013-04-25 16:02:17 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2015-10-20 00:13:21 -07:00
|
|
|
args << QLatin1String("--args") << extraArgs;
|
2013-04-25 16:02:17 +02:00
|
|
|
op = OpAppRun;
|
|
|
|
|
start(IosToolHandler::iosDeviceToolPath(), args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosDeviceToolHandlerPrivate::requestDeviceInfo(const QString &deviceId, int timeout)
|
|
|
|
|
{
|
|
|
|
|
this->deviceId = deviceId;
|
|
|
|
|
QStringList args;
|
2015-10-20 00:13:21 -07:00
|
|
|
args << QLatin1String("--id") << deviceId << QLatin1String("--device-info")
|
|
|
|
|
<< QLatin1String("--timeout") << QString::number(timeout);
|
2013-04-25 16:02:17 +02:00
|
|
|
op = OpDeviceInfo;
|
|
|
|
|
start(IosToolHandler::iosDeviceToolPath(), args);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
|
|
|
|
|
void IosDeviceToolHandlerPrivate::stop(int errorCode)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2016-09-26 12:40:09 +02:00
|
|
|
qCDebug(toolHandlerLog) << "IosToolHandlerPrivate::stop";
|
|
|
|
|
State oldState = state;
|
|
|
|
|
state = Stopped;
|
|
|
|
|
switch (oldState) {
|
|
|
|
|
case NonStarted:
|
|
|
|
|
qCWarning(toolHandlerLog) << "IosToolHandler::stop() when state was NonStarted";
|
|
|
|
|
// pass
|
|
|
|
|
case Starting:
|
|
|
|
|
switch (op){
|
|
|
|
|
case OpNone:
|
|
|
|
|
qCWarning(toolHandlerLog) << "IosToolHandler::stop() when op was OpNone";
|
|
|
|
|
break;
|
|
|
|
|
case OpAppTransfer:
|
|
|
|
|
didTransferApp(bundlePath, deviceId, IosToolHandler::Failure);
|
|
|
|
|
break;
|
|
|
|
|
case OpAppRun:
|
|
|
|
|
didStartApp(bundlePath, deviceId, IosToolHandler::Failure);
|
|
|
|
|
break;
|
|
|
|
|
case OpDeviceInfo:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// pass
|
|
|
|
|
case StartedInferior:
|
|
|
|
|
case XmlEndProcessed:
|
|
|
|
|
toolExited(errorCode);
|
|
|
|
|
break;
|
|
|
|
|
case Stopped:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (isRunning()) {
|
|
|
|
|
process->write("k\n\r");
|
|
|
|
|
process->closeWriteChannel();
|
|
|
|
|
killTimer.start(1500);
|
|
|
|
|
}
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
// IosSimulatorToolHandlerPrivate
|
|
|
|
|
|
2014-11-12 19:41:59 +01:00
|
|
|
IosSimulatorToolHandlerPrivate::IosSimulatorToolHandlerPrivate(const IosDeviceType &devType,
|
2013-04-25 16:02:17 +02:00
|
|
|
IosToolHandler *q)
|
|
|
|
|
: IosToolHandlerPrivate(devType, q)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
void IosSimulatorToolHandlerPrivate::requestTransferApp(const QString &bundlePath,
|
2016-09-26 12:40:09 +02:00
|
|
|
const QString &deviceIdentifier, int timeout)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(timeout);
|
|
|
|
|
this->bundlePath = bundlePath;
|
2016-09-26 12:40:09 +02:00
|
|
|
this->deviceId = deviceIdentifier;
|
|
|
|
|
isTransferringApp(bundlePath, deviceId, 0, 100, "");
|
|
|
|
|
if (SimulatorControl::startSimulator(deviceId)) {
|
|
|
|
|
isTransferringApp(bundlePath, deviceId, 20, 100, "");
|
|
|
|
|
QByteArray cmdOutput;
|
|
|
|
|
if (SimulatorControl::installApp(deviceId, Utils::FileName::fromString(bundlePath), cmdOutput)) {
|
|
|
|
|
isTransferringApp(bundlePath, deviceId, 100, 100, "");
|
|
|
|
|
didTransferApp(bundlePath, deviceId, IosToolHandler::Success);
|
|
|
|
|
} else {
|
|
|
|
|
errorMsg(IosToolHandler::tr("Application install on Simulator failed. %1").arg(QString::fromLocal8Bit(cmdOutput)));
|
|
|
|
|
didTransferApp(bundlePath, deviceId, IosToolHandler::Failure);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
errorMsg(IosToolHandler::tr("Application install on Simulator failed. Simulator not running."));
|
|
|
|
|
didTransferApp(bundlePath, deviceId, IosToolHandler::Failure);
|
|
|
|
|
}
|
|
|
|
|
emit q->finished(q);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
void IosSimulatorToolHandlerPrivate::requestRunApp(const QString &bundlePath,
|
|
|
|
|
const QStringList &extraArgs,
|
|
|
|
|
IosToolHandler::RunKind runType,
|
2016-09-26 12:40:09 +02:00
|
|
|
const QString &deviceIdentifier, int timeout)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
|
|
|
|
Q_UNUSED(timeout);
|
2016-09-26 12:40:09 +02:00
|
|
|
Q_UNUSED(deviceIdentifier);
|
2013-04-25 16:02:17 +02:00
|
|
|
this->bundlePath = bundlePath;
|
2016-09-26 12:40:09 +02:00
|
|
|
this->deviceId = devType.identifier;
|
2013-04-25 16:02:17 +02:00
|
|
|
this->runKind = runType;
|
2016-09-26 12:40:09 +02:00
|
|
|
op = OpAppRun;
|
2013-04-25 16:02:17 +02:00
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
Utils::FileName appBundle = Utils::FileName::fromString(bundlePath);
|
|
|
|
|
if (!appBundle.exists()) {
|
|
|
|
|
errorMsg(IosToolHandler::tr("Application launch on Simulator failed. Invalid Bundle path %1")
|
|
|
|
|
.arg(bundlePath));
|
|
|
|
|
didStartApp(bundlePath, deviceId, Ios::IosToolHandler::Failure);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (SimulatorControl::startSimulator(deviceId)) {
|
|
|
|
|
qint64 pId = -1;
|
|
|
|
|
bool debugRun = runType == IosToolHandler::DebugRun;
|
|
|
|
|
QProcess* controlProcess = SimulatorControl::spawnAppProcess(deviceId, appBundle, pId, debugRun, extraArgs);
|
|
|
|
|
if (controlProcess) {
|
|
|
|
|
Q_ASSERT(!process || !isRunning());
|
|
|
|
|
if (process) {
|
|
|
|
|
delete process;
|
|
|
|
|
process = nullptr;
|
|
|
|
|
}
|
|
|
|
|
process = controlProcess;
|
|
|
|
|
QObject::connect(process, &QProcess::readyReadStandardOutput,
|
|
|
|
|
std::bind(&IosSimulatorToolHandlerPrivate::simAppProcessHasData,this));
|
|
|
|
|
QObject::connect(process, &QProcess::readyReadStandardError,
|
|
|
|
|
std::bind(&IosSimulatorToolHandlerPrivate::simAppProcessHasErrorOutput,this));
|
|
|
|
|
QObject::connect(process, static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
|
|
|
|
|
std::bind(&IosSimulatorToolHandlerPrivate::simAppProcessFinished,this, _1,_2));
|
|
|
|
|
QObject::connect(process, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error),
|
|
|
|
|
std::bind(&IosSimulatorToolHandlerPrivate::simAppProcessError, this, _1));
|
|
|
|
|
|
|
|
|
|
appPId = pId;
|
|
|
|
|
gotInferiorPid(bundlePath,deviceId,pId);
|
|
|
|
|
|
|
|
|
|
// For debug run, wait for the debugger to attach and then launch the app.
|
|
|
|
|
if (!debugRun) {
|
|
|
|
|
launchAppOnSimulator();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
errorMsg(IosToolHandler::tr("Spawning the Application process on Simulator failed."));
|
|
|
|
|
didStartApp(bundlePath, deviceId, Ios::IosToolHandler::Failure);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
errorMsg(IosToolHandler::tr("Application launch on Simulator failed. Simulator not running.")
|
|
|
|
|
.arg(bundlePath));
|
|
|
|
|
didStartApp(bundlePath, deviceId, Ios::IosToolHandler::Failure);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosSimulatorToolHandlerPrivate::launchAppOnSimulator()
|
|
|
|
|
{
|
|
|
|
|
// Wait for the app to reach a state when we can launch it on the simulator.
|
|
|
|
|
if (appPId != -1 && SimulatorControl::waitForProcessSpawn(appPId)) {
|
|
|
|
|
QByteArray commandOutput;
|
|
|
|
|
Utils::FileName appBundle = Utils::FileName::fromString(bundlePath);
|
|
|
|
|
if (SimulatorControl::launchApp(deviceId, SimulatorControl::bundleIdentifier(appBundle), &commandOutput) != -1) {
|
|
|
|
|
appLaunched = true;
|
|
|
|
|
didStartApp(bundlePath, deviceId, Ios::IosToolHandler::Success);
|
|
|
|
|
} else {
|
|
|
|
|
errorMsg(IosToolHandler::tr("Application launch on Simulator failed. %1")
|
|
|
|
|
.arg(QString::fromLocal8Bit(commandOutput)));
|
|
|
|
|
didStartApp(bundlePath, deviceId, Ios::IosToolHandler::Failure);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
errorMsg(IosToolHandler::tr("Spawning the Application process on Simulator failed. Spawning timed out."));
|
|
|
|
|
didStartApp(bundlePath, deviceId, Ios::IosToolHandler::Failure);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosSimulatorToolHandlerPrivate::requestDeviceInfo(const QString &deviceId, int timeout)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(timeout);
|
2016-09-26 12:40:09 +02:00
|
|
|
Q_UNUSED(deviceId);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
void IosSimulatorToolHandlerPrivate::stop(int errorCode)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2016-09-26 12:40:09 +02:00
|
|
|
if (process) {
|
|
|
|
|
if (isRunning()) {
|
|
|
|
|
process->terminate();
|
|
|
|
|
if (!process->waitForFinished(1000))
|
|
|
|
|
process->kill();
|
|
|
|
|
}
|
|
|
|
|
process->deleteLater();
|
|
|
|
|
process = nullptr;
|
|
|
|
|
appPId = -1;
|
|
|
|
|
appLaunched = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toolExited(errorCode);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
void IosSimulatorToolHandlerPrivate::debuggerStateChanged(Debugger::DebuggerState state)
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2016-09-26 12:40:09 +02:00
|
|
|
if (!appLaunched && state == Debugger::DebuggerState::InferiorRunOk) {
|
|
|
|
|
// Debugger attached. Launch it on the simulator.
|
|
|
|
|
launchAppOnSimulator();
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
2016-09-26 12:40:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosSimulatorToolHandlerPrivate::simAppProcessError(QProcess::ProcessError error)
|
|
|
|
|
{
|
|
|
|
|
errorMsg(IosToolHandler::tr("Simulator application process error %1").arg(error));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosSimulatorToolHandlerPrivate::simAppProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
|
|
|
|
{
|
|
|
|
|
stop((exitStatus == QProcess::NormalExit) ? exitCode : -1 );
|
|
|
|
|
qCDebug(toolHandlerLog) << "IosToolHandler::finished(" << this << ")";
|
|
|
|
|
q->finished(q);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosSimulatorToolHandlerPrivate::simAppProcessHasData()
|
|
|
|
|
{
|
|
|
|
|
appOutput(QString::fromLocal8Bit(process->readAllStandardOutput()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosSimulatorToolHandlerPrivate::simAppProcessHasErrorOutput()
|
|
|
|
|
{
|
|
|
|
|
errorMsg(QString::fromLocal8Bit(process->readAllStandardError()));
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
2013-12-04 12:58:29 +01:00
|
|
|
void IosToolHandlerPrivate::killProcess()
|
|
|
|
|
{
|
2016-09-21 11:10:20 +02:00
|
|
|
if (isRunning())
|
|
|
|
|
process->kill();
|
2013-12-04 12:58:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
QString IosToolHandler::iosDeviceToolPath()
|
|
|
|
|
{
|
2013-10-02 16:09:23 +02:00
|
|
|
QString res = Core::ICore::libexecPath() + QLatin1String("/ios/iostool");
|
2013-04-25 16:02:17 +02:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-12 19:41:59 +01:00
|
|
|
IosToolHandler::IosToolHandler(const Internal::IosDeviceType &devType, QObject *parent) :
|
2013-04-25 16:02:17 +02:00
|
|
|
QObject(parent)
|
|
|
|
|
{
|
2014-11-12 19:41:59 +01:00
|
|
|
if (devType.type == Internal::IosDeviceType::IosDevice)
|
2013-04-25 16:02:17 +02:00
|
|
|
d = new Internal::IosDeviceToolHandlerPrivate(devType, this);
|
|
|
|
|
else
|
|
|
|
|
d = new Internal::IosSimulatorToolHandlerPrivate(devType, this);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-08 15:27:45 +02:00
|
|
|
IosToolHandler::~IosToolHandler()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
void IosToolHandler::stop()
|
|
|
|
|
{
|
2013-11-28 14:58:31 +01:00
|
|
|
d->stop(-1);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-26 12:40:09 +02:00
|
|
|
void IosToolHandler::debuggerStateChanged(int state)
|
|
|
|
|
{
|
|
|
|
|
d->debuggerStateChanged((Debugger::DebuggerState)state);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
void IosToolHandler::requestTransferApp(const QString &bundlePath, const QString &deviceId,
|
|
|
|
|
int timeout)
|
|
|
|
|
{
|
|
|
|
|
d->requestTransferApp(bundlePath, deviceId, timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosToolHandler::requestRunApp(const QString &bundlePath, const QStringList &extraArgs,
|
|
|
|
|
RunKind runType, const QString &deviceId, int timeout)
|
|
|
|
|
{
|
|
|
|
|
d->requestRunApp(bundlePath, extraArgs, runType, deviceId, timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosToolHandler::requestDeviceInfo(const QString &deviceId, int timeout)
|
|
|
|
|
{
|
|
|
|
|
d->requestDeviceInfo(deviceId, timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IosToolHandler::isRunning()
|
|
|
|
|
{
|
|
|
|
|
return d->isRunning();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Ios
|