iOS: Fix run without deploy on iOS simulator

Task-number: QTCREATORBUG-18107
Change-Id: Ie847cdab672ff2df7af0c2fee742901de0783861
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Vikas Pachdha
2017-04-28 08:27:10 +02:00
parent f2e296f7c7
commit a4a78ae8b1
3 changed files with 43 additions and 7 deletions

View File

@@ -848,13 +848,12 @@ void IosSimulatorToolHandlerPrivate::requestRunApp(const QString &appBundlePath,
} }
auto onSimulatorStart = [this, extraArgs] (const SimulatorControl::ResponseData &response) { auto onSimulatorStart = [this, extraArgs] (const SimulatorControl::ResponseData &response) {
if (isResponseValid(response)) if (!isResponseValid(response))
return; return;
if (response.success) { if (response.success) {
launchAppOnSimulator(extraArgs); launchAppOnSimulator(extraArgs);
} else { } else {
errorMsg(IosToolHandler::tr("Application launch on Simulator failed. Simulator not running.") errorMsg(IosToolHandler::tr("Application launch on Simulator failed. Simulator not running."));
.arg(bundlePath));
didStartApp(bundlePath, deviceId, Ios::IosToolHandler::Failure); didStartApp(bundlePath, deviceId, Ios::IosToolHandler::Failure);
} }
}; };

View File

@@ -398,7 +398,29 @@ void SimulatorControlPrivate::startSimulator(QFutureInterface<SimulatorControl::
{ {
SimulatorControl::ResponseData response(simUdid); SimulatorControl::ResponseData response(simUdid);
SimulatorInfo simInfo = deviceInfo(simUdid); SimulatorInfo simInfo = deviceInfo(simUdid);
if (simInfo.available && simInfo.isShutdown()) {
if (!simInfo.available) {
qCDebug(simulatorLog) << "Simulator device is not available." << simUdid;
return;
}
// Shutting down state checks are for the case when simulator start is called within a short
// interval of closing the previous interval of the simulator. We wait untill the shutdown
// process is complete.
auto start = chrono::high_resolution_clock::now();
while (simInfo.isShuttingDown() && !checkForTimeout(start, SIMULATOR_START_TIMEOUT)) {
// Wait till the simulator shuts down, if doing so.
QThread::currentThread()->msleep(100);
simInfo = deviceInfo(simUdid);
}
if (simInfo.isShuttingDown()) {
qCDebug(simulatorLog) << "Can not start Simulator device. "
<< "Previous instance taking too long to shutdown." << simInfo;
return;
}
if (simInfo.isShutdown()) {
const QString cmd = IosConfigurations::developerPath() const QString cmd = IosConfigurations::developerPath()
.appendPath(QStringLiteral("/Applications/Simulator.app/Contents/MacOS/Simulator")) .appendPath(QStringLiteral("/Applications/Simulator.app/Contents/MacOS/Simulator"))
.toString(); .toString();
@@ -410,7 +432,7 @@ void SimulatorControlPrivate::startSimulator(QFutureInterface<SimulatorControl::
// At this point the sim device exists, available and was not running. // At this point the sim device exists, available and was not running.
// So the simulator is started and we'll wait for it to reach to a state // So the simulator is started and we'll wait for it to reach to a state
// where we can interact with it. // where we can interact with it.
auto start = chrono::high_resolution_clock::now(); start = chrono::high_resolution_clock::now();
SimulatorInfo info; SimulatorInfo info;
do { do {
info = deviceInfo(simUdid); info = deviceInfo(simUdid);
@@ -424,6 +446,9 @@ void SimulatorControlPrivate::startSimulator(QFutureInterface<SimulatorControl::
} else { } else {
qCDebug(simulatorLog) << "Error starting simulator."; qCDebug(simulatorLog) << "Error starting simulator.";
} }
} else {
qCDebug(simulatorLog) << "Can not start Simulator device. Simulator not in shutdown state."
<< simInfo;
} }
if (!fi.isCanceled()) { if (!fi.isCanceled()) {
@@ -541,5 +566,13 @@ void SimulatorControlPrivate::takeSceenshot(QFutureInterface<SimulatorControl::R
fi.reportResult(response); fi.reportResult(response);
} }
QDebug &operator<<(QDebug &stream, const SimulatorInfo &info)
{
stream << "Name: " << info.name << "UDID: " << info.identifier
<< "Availability: " << info.available << "State: " << info.state
<< "Runtime: " << info.runtimeName;
return stream;
}
} // namespace Internal } // namespace Internal
} // namespace Ios } // namespace Ios

View File

@@ -27,7 +27,7 @@
#include <QObject> #include <QObject>
#include <QFuture> #include <QFuture>
#include "utils/fileutils.h" #include "utils/fileutils.h"
#include <QDebug>
#include <memory> #include <memory>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@@ -50,10 +50,14 @@ public:
} }
}; };
class SimulatorInfo : public SimulatorEntity { class SimulatorInfo : public SimulatorEntity
{
friend QDebug &operator<<(QDebug &, const SimulatorInfo &info);
public: public:
bool isBooted() const { return state.compare(QStringLiteral("Booted")) == 0; } bool isBooted() const { return state.compare(QStringLiteral("Booted")) == 0; }
bool isShutdown() const { return state.compare(QStringLiteral("Shutdown")) == 0; } bool isShutdown() const { return state.compare(QStringLiteral("Shutdown")) == 0; }
bool isShuttingDown() const { return state == "Shutting Down"; }
bool available; bool available;
QString state; QString state;
QString runtimeName; QString runtimeName;