IosDeployStep: Employ task tree for running

Task-number: QTCREATORBUG-29168
Change-Id: I212aa8cc66d97b84adce9d8acdf8e958989bdc6b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2023-07-14 12:32:06 +02:00
parent 63bc9a2e42
commit 9692ccf352

View File

@@ -106,45 +106,26 @@ namespace Ios::Internal {
class IosDeployStep final : public BuildStep class IosDeployStep final : public BuildStep
{ {
public: public:
enum TransferStatus {
NoTransfer,
TransferInProgress,
TransferOk,
TransferFailed
};
IosDeployStep(BuildStepList *bc, Utils::Id id); IosDeployStep(BuildStepList *bc, Utils::Id id);
private: private:
void cleanup(); void cleanup();
void doRun() final; Tasking::GroupItem runRecipe() final;
void doCancel() final;
void handleIsTransferringApp(IosToolHandler *handler, const FilePath &bundlePath,
const QString &deviceId, int progress, int maxProgress,
const QString &info);
void handleDidTransferApp(IosToolHandler *handler, const FilePath &bundlePath,
const QString &deviceId, IosToolHandler::OpStatus status);
void handleFinished(IosToolHandler *handler);
void handleErrorMsg(IosToolHandler *handler, const QString &msg);
void updateDisplayNames(); void updateDisplayNames();
bool init() final; bool init() final;
QWidget *createConfigWidget() final; QWidget *createConfigWidget() final;
IDevice::ConstPtr device() const;
IosDevice::ConstPtr iosdevice() const; IosDevice::ConstPtr iosdevice() const;
IosSimulator::ConstPtr iossimulator() const; IosSimulator::ConstPtr iossimulator() const;
QString deviceId() const; QString deviceId() const;
bool checkProvisioningProfile(); bool checkProvisioningProfile();
TransferStatus m_transferStatus = NoTransfer;
IosToolHandler *m_toolHandler = nullptr;
IDevice::ConstPtr m_device; IDevice::ConstPtr m_device;
FilePath m_bundlePath; FilePath m_bundlePath;
IosDeviceType m_deviceType; IosDeviceType m_deviceType;
bool m_expectFail = false;
}; };
IosDeployStep::IosDeployStep(BuildStepList *parent, Utils::Id id) IosDeployStep::IosDeployStep(BuildStepList *parent, Utils::Id id)
@@ -167,7 +148,8 @@ void IosDeployStep::updateDisplayNames()
bool IosDeployStep::init() bool IosDeployStep::init()
{ {
QTC_ASSERT(m_transferStatus == NoTransfer, return false); if (!BuildStep::init())
return false;
m_device = DeviceKitAspect::device(kit()); m_device = DeviceKitAspect::device(kit());
auto runConfig = qobject_cast<const IosRunConfiguration *>( auto runConfig = qobject_cast<const IosRunConfiguration *>(
this->target()->activeRunConfiguration()); this->target()->activeRunConfiguration());
@@ -186,96 +168,25 @@ bool IosDeployStep::init()
return true; return true;
} }
void IosDeployStep::doRun() GroupItem IosDeployStep::runRecipe()
{ {
QTC_CHECK(m_transferStatus == NoTransfer); const auto onSetup = [this](IosTransfer &transfer) {
if (m_device.isNull()) { if (m_device.isNull()) {
TaskHub::addTask( TaskHub::addTask(
DeploymentTask(Task::Error, Tr::tr("Deployment failed. No iOS device found."))); DeploymentTask(Task::Error, Tr::tr("Deployment failed. No iOS device found.")));
emit finished(!iossimulator().isNull()); return SetupResult::StopWithError;
cleanup(); }
return; transfer.setDeviceType(m_deviceType);
} transfer.setBundlePath(m_bundlePath);
m_toolHandler = new IosToolHandler(m_deviceType, this); transfer.setExpectSuccess(checkProvisioningProfile());
m_transferStatus = TransferInProgress; emit progress(0, Tr::tr("Transferring application"));
emit progress(0, Tr::tr("Transferring application")); connect(&transfer, &IosTransfer::progressValueChanged, this, &IosDeployStep::progress);
connect(m_toolHandler, &IosToolHandler::isTransferringApp, connect(&transfer, &IosTransfer::errorMessage, this, [this](const QString &message) {
this, &IosDeployStep::handleIsTransferringApp); emit addOutput(message, OutputFormat::ErrorMessage);
connect(m_toolHandler, &IosToolHandler::didTransferApp, });
this, &IosDeployStep::handleDidTransferApp); return SetupResult::Continue;
connect(m_toolHandler, &IosToolHandler::finished, };
this, &IosDeployStep::handleFinished); return IosTransferTask(onSetup);
connect(m_toolHandler, &IosToolHandler::errorMsg,
this, &IosDeployStep::handleErrorMsg);
m_expectFail = !checkProvisioningProfile();
m_toolHandler->requestTransferApp(m_bundlePath, m_deviceType.identifier);
}
void IosDeployStep::doCancel()
{
if (m_toolHandler)
m_toolHandler->stop();
}
void IosDeployStep::cleanup()
{
QTC_CHECK(m_transferStatus != TransferInProgress);
m_transferStatus = NoTransfer;
m_device.clear();
m_toolHandler = nullptr;
m_expectFail = false;
}
void IosDeployStep::handleIsTransferringApp(IosToolHandler *handler, const FilePath &bundlePath,
const QString &deviceId, int progress, int maxProgress,
const QString &info)
{
Q_UNUSED(handler); Q_UNUSED(bundlePath); Q_UNUSED(deviceId)
QTC_CHECK(m_transferStatus == TransferInProgress);
emit this->progress(progress * 100 / maxProgress, info);
}
void IosDeployStep::handleDidTransferApp(IosToolHandler *handler, const FilePath &bundlePath,
const QString &deviceId, IosToolHandler::OpStatus status)
{
Q_UNUSED(handler); Q_UNUSED(bundlePath); Q_UNUSED(deviceId)
QTC_CHECK(m_transferStatus == TransferInProgress);
if (status == IosToolHandler::Success) {
m_transferStatus = TransferOk;
} else {
m_transferStatus = TransferFailed;
if (!m_expectFail)
TaskHub::addTask(DeploymentTask(Task::Error,
Tr::tr("Deployment failed. The settings in the Devices window of Xcode might be incorrect.")));
}
emit finished(status == IosToolHandler::Success);
}
void IosDeployStep::handleFinished(IosToolHandler *handler)
{
switch (m_transferStatus) {
case TransferInProgress:
m_transferStatus = TransferFailed;
TaskHub::addTask(DeploymentTask(Task::Error, Tr::tr("Deployment failed.")));
emit finished(false);
break;
case NoTransfer:
case TransferOk:
case TransferFailed:
break;
}
cleanup();
handler->deleteLater();
// move it when result is reported? (would need care to avoid problems with concurrent runs)
}
void IosDeployStep::handleErrorMsg(IosToolHandler *handler, const QString &msg)
{
Q_UNUSED(handler)
if (msg.contains(QLatin1String("AMDeviceInstallApplication returned -402653103")))
TaskHub::addTask(DeploymentTask(Task::Warning, Tr::tr("The Info.plist might be incorrect.")));
emit addOutput(msg, OutputFormat::ErrorMessage);
} }
QWidget *IosDeployStep::createConfigWidget() QWidget *IosDeployStep::createConfigWidget()