forked from qt-creator/qt-creator
iOS: Use stdout of smctl commands
Avoid MessageTracer logs being fed to the device listing json document Change-Id: Ia35b39d787d2df27e6f743e0b6dc401799c383db Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -155,7 +155,7 @@ void IosSettingsWidget::onCreate()
|
|||||||
.arg(name).arg(response.simUdid), Utils::StdOutFormat);
|
.arg(name).arg(response.simUdid), Utils::StdOutFormat);
|
||||||
} else {
|
} else {
|
||||||
statusDialog->addMessage(tr("Simulator device (%1) creation failed.\nError: %2").
|
statusDialog->addMessage(tr("Simulator device (%1) creation failed.\nError: %2").
|
||||||
arg(name).arg(QString::fromUtf8(response.commandOutput)),
|
arg(name).arg(response.commandOutput),
|
||||||
Utils::StdErrFormat);
|
Utils::StdErrFormat);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -926,7 +926,7 @@ void IosSimulatorToolHandlerPrivate::installAppOnSimulator()
|
|||||||
didTransferApp(m_bundlePath, m_deviceId, IosToolHandler::Success);
|
didTransferApp(m_bundlePath, m_deviceId, IosToolHandler::Success);
|
||||||
} else {
|
} else {
|
||||||
errorMsg(IosToolHandler::tr("Application install on simulator failed. %1")
|
errorMsg(IosToolHandler::tr("Application install on simulator failed. %1")
|
||||||
.arg(QString::fromLocal8Bit(response.commandOutput)));
|
.arg(response.commandOutput));
|
||||||
didTransferApp(m_bundlePath, m_deviceId, IosToolHandler::Failure);
|
didTransferApp(m_bundlePath, m_deviceId, IosToolHandler::Failure);
|
||||||
}
|
}
|
||||||
emit q->finished(q);
|
emit q->finished(q);
|
||||||
@@ -990,7 +990,7 @@ void IosSimulatorToolHandlerPrivate::launchAppOnSimulator(const QStringList &ext
|
|||||||
} else {
|
} else {
|
||||||
m_pid = -1;
|
m_pid = -1;
|
||||||
errorMsg(IosToolHandler::tr("Application launch on simulator failed. %1")
|
errorMsg(IosToolHandler::tr("Application launch on simulator failed. %1")
|
||||||
.arg(QString::fromLocal8Bit(response.commandOutput)));
|
.arg(response.commandOutput));
|
||||||
didStartApp(m_bundlePath, m_deviceId, Ios::IosToolHandler::Failure);
|
didStartApp(m_bundlePath, m_deviceId, Ios::IosToolHandler::Failure);
|
||||||
stop(-1);
|
stop(-1);
|
||||||
q->finished(q);
|
q->finished(q);
|
||||||
|
@@ -77,17 +77,17 @@ static bool checkForTimeout(const chrono::high_resolution_clock::time_point &sta
|
|||||||
return timedOut;
|
return timedOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool runCommand(QString command, const QStringList &args, QByteArray *output)
|
static bool runCommand(QString command, const QStringList &args, QString *output)
|
||||||
{
|
{
|
||||||
Utils::SynchronousProcess p;
|
Utils::SynchronousProcess p;
|
||||||
p.setTimeoutS(-1);
|
p.setTimeoutS(-1);
|
||||||
Utils::SynchronousProcessResponse resp = p.runBlocking(command, args);
|
Utils::SynchronousProcessResponse resp = p.runBlocking(command, args);
|
||||||
if (output)
|
if (output)
|
||||||
*output = resp.allRawOutput();
|
*output = resp.stdOut();
|
||||||
return resp.result == Utils::SynchronousProcessResponse::Finished;
|
return resp.result == Utils::SynchronousProcessResponse::Finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool runSimCtlCommand(QStringList args, QByteArray *output)
|
static bool runSimCtlCommand(QStringList args, QString *output)
|
||||||
{
|
{
|
||||||
args.prepend("simctl");
|
args.prepend("simctl");
|
||||||
return runCommand("xcrun", args, output);
|
return runCommand("xcrun", args, output);
|
||||||
@@ -100,11 +100,10 @@ static bool launchSimulator(const QString &simUdid) {
|
|||||||
|
|
||||||
if (IosConfigurations::xcodeVersion() >= QVersionNumber(9)) {
|
if (IosConfigurations::xcodeVersion() >= QVersionNumber(9)) {
|
||||||
// For XCode 9 boot the second device instead of launching simulator app twice.
|
// For XCode 9 boot the second device instead of launching simulator app twice.
|
||||||
QByteArray psOutput;
|
QString psOutput;
|
||||||
if (runCommand("ps", {"-A", "-o", "comm"}, &psOutput)) {
|
if (runCommand("ps", {"-A", "-o", "comm"}, &psOutput)) {
|
||||||
QByteArray simulatorCommand = simulatorAppPath.toLatin1();
|
for (const QString &comm : psOutput.split('\n')) {
|
||||||
for (const QByteArray &comm : psOutput.split('\n')) {
|
if (comm == simulatorAppPath)
|
||||||
if (comm == simulatorCommand)
|
|
||||||
return runSimCtlCommand(QStringList({"boot", simUdid}), nullptr);
|
return runSimCtlCommand(QStringList({"boot", simUdid}), nullptr);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -120,9 +119,9 @@ static bool launchSimulator(const QString &simUdid) {
|
|||||||
static QList<DeviceTypeInfo> getAvailableDeviceTypes()
|
static QList<DeviceTypeInfo> getAvailableDeviceTypes()
|
||||||
{
|
{
|
||||||
QList<DeviceTypeInfo> deviceTypes;
|
QList<DeviceTypeInfo> deviceTypes;
|
||||||
QByteArray output;
|
QString output;
|
||||||
runSimCtlCommand({"list", "-j", deviceTypeTag}, &output);
|
runSimCtlCommand({"list", "-j", deviceTypeTag}, &output);
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(output);
|
QJsonDocument doc = QJsonDocument::fromJson(output.toUtf8());
|
||||||
if (!doc.isNull()) {
|
if (!doc.isNull()) {
|
||||||
const QJsonArray runtimesArray = doc.object().value(deviceTypeTag).toArray();
|
const QJsonArray runtimesArray = doc.object().value(deviceTypeTag).toArray();
|
||||||
foreach (const QJsonValue deviceTypeValue, runtimesArray) {
|
foreach (const QJsonValue deviceTypeValue, runtimesArray) {
|
||||||
@@ -144,9 +143,9 @@ static QList<DeviceTypeInfo> getAvailableDeviceTypes()
|
|||||||
static QList<RuntimeInfo> getAvailableRuntimes()
|
static QList<RuntimeInfo> getAvailableRuntimes()
|
||||||
{
|
{
|
||||||
QList<RuntimeInfo> runtimes;
|
QList<RuntimeInfo> runtimes;
|
||||||
QByteArray output;
|
QString output;
|
||||||
runSimCtlCommand({"list", "-j", runtimesTag}, &output);
|
runSimCtlCommand({"list", "-j", runtimesTag}, &output);
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(output);
|
QJsonDocument doc = QJsonDocument::fromJson(output.toUtf8());
|
||||||
if (!doc.isNull()) {
|
if (!doc.isNull()) {
|
||||||
const QJsonArray runtimesArray = doc.object().value(runtimesTag).toArray();
|
const QJsonArray runtimesArray = doc.object().value(runtimesTag).toArray();
|
||||||
foreach (const QJsonValue runtimeValue, runtimesArray) {
|
foreach (const QJsonValue runtimeValue, runtimesArray) {
|
||||||
@@ -220,9 +219,9 @@ QList<SimulatorInfo> SimulatorControl::availableSimulators()
|
|||||||
static QList<SimulatorInfo> getAllSimulatorDevices()
|
static QList<SimulatorInfo> getAllSimulatorDevices()
|
||||||
{
|
{
|
||||||
QList<SimulatorInfo> simulatorDevices;
|
QList<SimulatorInfo> simulatorDevices;
|
||||||
QByteArray output;
|
QString output;
|
||||||
runSimCtlCommand({"list", "-j", devicesTag}, &output);
|
runSimCtlCommand({"list", "-j", devicesTag}, &output);
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(output);
|
QJsonDocument doc = QJsonDocument::fromJson(output.toUtf8());
|
||||||
if (!doc.isNull()) {
|
if (!doc.isNull()) {
|
||||||
const QJsonObject runtimeObject = doc.object().value(devicesTag).toObject();
|
const QJsonObject runtimeObject = doc.object().value(devicesTag).toObject();
|
||||||
foreach (const QString &runtime, runtimeObject.keys()) {
|
foreach (const QString &runtime, runtimeObject.keys()) {
|
||||||
@@ -512,7 +511,7 @@ void SimulatorControlPrivate::launchApp(QFutureInterface<SimulatorControl::Respo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (runSimCtlCommand(args, &response.commandOutput)) {
|
if (runSimCtlCommand(args, &response.commandOutput)) {
|
||||||
const QByteArray pIdStr = response.commandOutput.trimmed().split(' ').last().trimmed();
|
const QString pIdStr = response.commandOutput.trimmed().split(' ').last().trimmed();
|
||||||
bool validPid = false;
|
bool validPid = false;
|
||||||
response.pID = pIdStr.toLongLong(&validPid);
|
response.pID = pIdStr.toLongLong(&validPid);
|
||||||
response.success = validPid;
|
response.success = validPid;
|
||||||
@@ -566,7 +565,7 @@ void SimulatorControlPrivate::createSimulator(QFutureInterface<SimulatorControl:
|
|||||||
deviceType.identifier,
|
deviceType.identifier,
|
||||||
runtime.identifier},
|
runtime.identifier},
|
||||||
&response.commandOutput);
|
&response.commandOutput);
|
||||||
response.simUdid = response.success ? QString::fromLatin1(response.commandOutput.trimmed())
|
response.simUdid = response.success ? response.commandOutput.trimmed()
|
||||||
: QString();
|
: QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -84,7 +84,7 @@ public:
|
|||||||
QString simUdid;
|
QString simUdid;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
qint64 pID = -1;
|
qint64 pID = -1;
|
||||||
QByteArray commandOutput = "";
|
QString commandOutput = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@@ -98,10 +98,10 @@ void SimulatorOperationDialog::addMessage(const SimulatorInfo &siminfo,
|
|||||||
addMessage(tr("%1, %2\nOperation %3 completed successfully.").arg(siminfo.name)
|
addMessage(tr("%1, %2\nOperation %3 completed successfully.").arg(siminfo.name)
|
||||||
.arg(siminfo.runtimeName).arg(context), Utils::StdOutFormat);
|
.arg(siminfo.runtimeName).arg(context), Utils::StdOutFormat);
|
||||||
} else {
|
} else {
|
||||||
QByteArray erroMsg = response.commandOutput.trimmed();
|
QString erroMsg = response.commandOutput.trimmed();
|
||||||
QString message = tr("%1, %2\nOperation %3 failed.\nUDID: %4\nError: %5").arg(siminfo.name)
|
QString message = tr("%1, %2\nOperation %3 failed.\nUDID: %4\nError: %5").arg(siminfo.name)
|
||||||
.arg(siminfo.runtimeName).arg(context).arg(siminfo.identifier)
|
.arg(siminfo.runtimeName).arg(context).arg(siminfo.identifier)
|
||||||
.arg(erroMsg.isEmpty() ? tr("Unknown") : QString::fromUtf8(erroMsg));
|
.arg(erroMsg.isEmpty() ? tr("Unknown") : erroMsg);
|
||||||
addMessage(message, Utils::StdErrFormat);
|
addMessage(message, Utils::StdErrFormat);
|
||||||
qCDebug(iosCommon) << message;
|
qCDebug(iosCommon) << message;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user