forked from qt-creator/qt-creator
AndroidDeployQtStep: Employ task tree for running
Task-number: QTCREATORBUG-29168 Change-Id: Icb38b0036025cc4fe7ab7a6c8086f51922630730 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -89,13 +89,12 @@ private:
|
|||||||
void runCommand(const CommandLine &command);
|
void runCommand(const CommandLine &command);
|
||||||
|
|
||||||
bool init() override;
|
bool init() override;
|
||||||
void doRun() override;
|
Tasking::GroupItem runRecipe() final;
|
||||||
void doCancel() override;
|
|
||||||
void gatherFilesToPull();
|
void gatherFilesToPull();
|
||||||
DeployErrorCode runDeploy();
|
DeployErrorCode runDeploy();
|
||||||
void slotAskForUninstall(DeployErrorCode errorCode);
|
void slotAskForUninstall(DeployErrorCode errorCode);
|
||||||
|
|
||||||
void runImpl(QPromise<bool> &promise);
|
void runImpl(QPromise<void> &promise);
|
||||||
|
|
||||||
QWidget *createConfigWidget() override;
|
QWidget *createConfigWidget() override;
|
||||||
|
|
||||||
@@ -132,8 +131,6 @@ private:
|
|||||||
FilePath m_workingDirectory;
|
FilePath m_workingDirectory;
|
||||||
Environment m_environment;
|
Environment m_environment;
|
||||||
AndroidDeviceInfo m_deviceInfo;
|
AndroidDeviceInfo m_deviceInfo;
|
||||||
|
|
||||||
// The synchronizer has cancelOnWait set to true by default.
|
|
||||||
FutureSynchronizer m_synchronizer;
|
FutureSynchronizer m_synchronizer;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -162,6 +159,9 @@ AndroidDeployQtStep::AndroidDeployQtStep(BuildStepList *parent, Id id)
|
|||||||
|
|
||||||
bool AndroidDeployQtStep::init()
|
bool AndroidDeployQtStep::init()
|
||||||
{
|
{
|
||||||
|
if (!BuildStep::init())
|
||||||
|
return false;
|
||||||
|
|
||||||
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit());
|
QtSupport::QtVersion *version = QtSupport::QtKitAspect::qtVersion(kit());
|
||||||
if (!version) {
|
if (!version) {
|
||||||
reportWarningOrError(Tr::tr("The Qt version for kit %1 is invalid.").arg(kit()->displayName()),
|
reportWarningOrError(Tr::tr("The Qt version for kit %1 is invalid.").arg(kit()->displayName()),
|
||||||
@@ -477,16 +477,16 @@ void AndroidDeployQtStep::slotAskForUninstall(DeployErrorCode errorCode)
|
|||||||
m_askForUninstall = button == QMessageBox::Yes;
|
m_askForUninstall = button == QMessageBox::Yes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidDeployQtStep::runImpl(QPromise<bool> &promise)
|
// TODO: This implementation is not thread safe.
|
||||||
|
void AndroidDeployQtStep::runImpl(QPromise<void> &promise)
|
||||||
{
|
{
|
||||||
if (!m_avdName.isEmpty()) {
|
if (!m_avdName.isEmpty()) {
|
||||||
const QString serialNumber = AndroidAvdManager().waitForAvd(m_avdName,
|
const QString serialNumber = AndroidAvdManager().waitForAvd(m_avdName, promise.future());
|
||||||
QFuture<void>(promise.future()));
|
|
||||||
qCDebug(deployStepLog) << "Deploying to AVD:" << m_avdName << serialNumber;
|
qCDebug(deployStepLog) << "Deploying to AVD:" << m_avdName << serialNumber;
|
||||||
if (serialNumber.isEmpty()) {
|
if (serialNumber.isEmpty()) {
|
||||||
reportWarningOrError(Tr::tr("The deployment AVD \"%1\" cannot be started.")
|
reportWarningOrError(Tr::tr("The deployment AVD \"%1\" cannot be started.")
|
||||||
.arg(m_avdName), Task::Error);
|
.arg(m_avdName), Task::Error);
|
||||||
promise.addResult(false);
|
promise.future().cancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_serialNumber = serialNumber;
|
m_serialNumber = serialNumber;
|
||||||
@@ -529,7 +529,8 @@ void AndroidDeployQtStep::runImpl(QPromise<bool> &promise)
|
|||||||
reportWarningOrError(error, Task::Error);
|
reportWarningOrError(error, Task::Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
promise.addResult(returnValue == NoError);
|
if (returnValue != NoError)
|
||||||
|
promise.future().cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidDeployQtStep::gatherFilesToPull()
|
void AndroidDeployQtStep::gatherFilesToPull()
|
||||||
@@ -561,22 +562,13 @@ void AndroidDeployQtStep::gatherFilesToPull()
|
|||||||
<< "to:" << itr.value();
|
<< "to:" << itr.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidDeployQtStep::doRun()
|
Tasking::GroupItem AndroidDeployQtStep::runRecipe()
|
||||||
{
|
{
|
||||||
auto * const watcher = new QFutureWatcher<bool>(this);
|
const auto onSetup = [this](Async<void> &async) {
|
||||||
connect(watcher, &QFutureWatcher<bool>::finished, this, [this, watcher] {
|
async.setConcurrentCallData(&AndroidDeployQtStep::runImpl, this);
|
||||||
const bool success = !watcher->isCanceled() && watcher->result();
|
async.setFutureSynchronizer(&m_synchronizer);
|
||||||
emit finished(success);
|
};
|
||||||
watcher->deleteLater();
|
return Tasking::AsyncTask<void>(onSetup);
|
||||||
});
|
|
||||||
auto future = Utils::asyncRun(&AndroidDeployQtStep::runImpl, this);
|
|
||||||
watcher->setFuture(future);
|
|
||||||
m_synchronizer.addFuture(future);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AndroidDeployQtStep::doCancel()
|
|
||||||
{
|
|
||||||
m_synchronizer.cancelAllFutures();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AndroidDeployQtStep::runCommand(const CommandLine &command)
|
void AndroidDeployQtStep::runCommand(const CommandLine &command)
|
||||||
|
Reference in New Issue
Block a user