Android: Use QtConcurrent invocation for async run

Change-Id: I275af7c52197ecdb0c02e2e1039b37bd8c9bb1c1
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2023-03-03 23:59:37 +01:00
parent c2d6501e64
commit 2f5aad0cdb
7 changed files with 61 additions and 59 deletions

View File

@@ -10,9 +10,9 @@
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/algorithm.h>
#include <utils/asynctask.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/runextensions.h>
#include <QLoggingCategory>
#include <QMainWindow>
@@ -139,7 +139,7 @@ AndroidAvdManager::~AndroidAvdManager() = default;
QFuture<CreateAvdInfo> AndroidAvdManager::createAvd(CreateAvdInfo info) const
{
return runAsync(&createAvdCommand, m_config, info);
return Utils::asyncRun(&createAvdCommand, m_config, info);
}
bool AndroidAvdManager::removeAvd(const QString &name) const
@@ -217,7 +217,7 @@ static AndroidDeviceInfoList listVirtualDevices(const AndroidConfig &config)
QFuture<AndroidDeviceInfoList> AndroidAvdManager::avdList() const
{
return runAsync(listVirtualDevices, m_config);
return Utils::asyncRun(listVirtualDevices, m_config);
}
QString AndroidAvdManager::startAvd(const QString &name) const

View File

@@ -30,10 +30,10 @@
#include <qtsupport/qtkitinformation.h>
#include <utils/algorithm.h>
#include <utils/asynctask.h>
#include <utils/layoutbuilder.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/runextensions.h>
#include <QCheckBox>
#include <QFileDialog>
@@ -401,16 +401,16 @@ void AndroidDeployQtStep::slotAskForUninstall(DeployErrorCode errorCode)
m_askForUninstall = button == QMessageBox::Yes;
}
void AndroidDeployQtStep::runImpl(QFutureInterface<bool> &fi)
void AndroidDeployQtStep::runImpl(QPromise<bool> &promise)
{
if (!m_avdName.isEmpty()) {
const QString serialNumber = AndroidAvdManager().waitForAvd(m_avdName,
QFuture<void>(fi.future()));
QFuture<void>(promise.future()));
qCDebug(deployStepLog) << "Deploying to AVD:" << m_avdName << serialNumber;
if (serialNumber.isEmpty()) {
reportWarningOrError(Tr::tr("The deployment AVD \"%1\" cannot be started.")
.arg(m_avdName), Task::Error);
fi.reportResult(false);
promise.addResult(false);
return;
}
m_serialNumber = serialNumber;
@@ -446,7 +446,7 @@ void AndroidDeployQtStep::runImpl(QFutureInterface<bool> &fi)
reportWarningOrError(error, Task::Error);
}
}
fi.reportResult(returnValue == NoError);
promise.addResult(returnValue == NoError);
}
void AndroidDeployQtStep::gatherFilesToPull()
@@ -486,7 +486,7 @@ void AndroidDeployQtStep::doRun()
emit finished(success);
watcher->deleteLater();
});
auto future = Utils::runAsync(&AndroidDeployQtStep::runImpl, this);
auto future = Utils::asyncRun(&AndroidDeployQtStep::runImpl, this);
watcher->setFuture(future);
m_synchronizer.addFuture(future);
}

View File

@@ -53,7 +53,7 @@ private:
DeployErrorCode runDeploy();
void slotAskForUninstall(DeployErrorCode errorCode);
void runImpl(QFutureInterface<bool> &fi);
void runImpl(QPromise<bool> &promise);
QWidget *createConfigWidget() override;

View File

@@ -21,9 +21,9 @@
#include <projectexplorer/projectmanager.h>
#include <projectexplorer/target.h>
#include <utils/asynctask.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/runextensions.h>
#include <utils/url.h>
#include <QEventLoop>
@@ -454,7 +454,7 @@ void AndroidDeviceManager::startAvd(const ProjectExplorer::IDevice::Ptr &device,
const AndroidDevice *androidDev = static_cast<const AndroidDevice *>(device.data());
const QString name = androidDev->avdName();
qCDebug(androidDeviceLog, "Starting Android AVD id \"%s\".", qPrintable(name));
runAsync([this, name, device] {
auto future = Utils::asyncRun([this, name, device] {
const QString serialNumber = m_avdManager.startAvd(name);
// Mark the AVD as ReadyToUse once we know it's started
if (!serialNumber.isEmpty()) {
@@ -462,6 +462,7 @@ void AndroidDeviceManager::startAvd(const ProjectExplorer::IDevice::Ptr &device,
devMgr->setDeviceState(device->id(), IDevice::DeviceReadyToUse);
}
});
// TODO: use future!
}
void AndroidDeviceManager::eraseAvd(const IDevice::Ptr &device, QWidget *parent)
@@ -479,7 +480,7 @@ void AndroidDeviceManager::eraseAvd(const IDevice::Ptr &device, QWidget *parent)
return;
qCDebug(androidDeviceLog) << QString("Erasing Android AVD \"%1\" from the system.").arg(name);
m_removeAvdFutureWatcher.setFuture(runAsync([this, name, device] {
m_removeAvdFutureWatcher.setFuture(Utils::asyncRun([this, name, device] {
QPair<IDevice::ConstPtr, bool> pair;
pair.first = device;
pair.second = false;

View File

@@ -27,8 +27,8 @@
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
#include <utils/asynctask.h>
#include <utils/qtcprocess.h>
#include <utils/runextensions.h>
#include <QDateTime>
#include <QDeadlineTimer>
@@ -163,7 +163,7 @@ bool AndroidQmlPreviewWorker::isPreviewRunning(int lastKnownPid) const
void AndroidQmlPreviewWorker::startPidWatcher()
{
m_pidFutureWatcher.setFuture(runAsync([this] {
m_pidFutureWatcher.setFuture(Utils::asyncRun([this] {
// wait for started
const int sleepTimeMs = 2000;
QDeadlineTimer deadline(20000);

View File

@@ -11,8 +11,8 @@
#include <debugger/debuggerrunconfigurationaspect.h>
#include <projectexplorer/buildconfiguration.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/environmentaspect.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/runconfigurationaspects.h>
#include <projectexplorer/runcontrol.h>
#include <projectexplorer/target.h>
@@ -20,6 +20,7 @@
#include <qtsupport/baseqtversion.h>
#include <qtsupport/qtkitinformation.h>
#include <utils/asynctask.h>
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
#include <utils/qtcprocess.h>
@@ -77,7 +78,7 @@ static qint64 extractPID(const QString &output, const QString &packageName)
return pid;
}
static void findProcessPID(QFutureInterface<qint64> &fi, QStringList selector,
static void findProcessPID(QPromise<qint64> &promise, QStringList selector,
const QString &packageName, bool preNougat)
{
if (packageName.isEmpty())
@@ -105,11 +106,11 @@ static void findProcessPID(QFutureInterface<qint64> &fi, QStringList selector,
if (!out.isEmpty())
processPID = out.trimmed().toLongLong();
}
} while ((processPID == -1 || processPID == 0) && !isTimedOut(start) && !fi.isCanceled());
} while ((processPID == -1 || processPID == 0) && !isTimedOut(start) && !promise.isCanceled());
qCDebug(androidRunWorkerLog) << "PID found:" << processPID << ", PreNougat:" << preNougat;
if (!fi.isCanceled())
fi.reportResult(processPID);
if (!promise.isCanceled())
promise.addResult(processPID);
}
static void deleter(QProcess *p)
@@ -683,7 +684,7 @@ void AndroidRunnerWorker::asyncStart()
{
asyncStartHelper();
m_pidFinder = Utils::onResultReady(Utils::runAsync(findProcessPID, selector(),
m_pidFinder = Utils::onResultReady(Utils::asyncRun(findProcessPID, selector(),
m_packageName, m_isPreNougat),
bind(&AndroidRunnerWorker::onProcessIdChanged, this, _1));
}

View File

@@ -8,9 +8,9 @@
#include "sdkmanageroutputparser.h"
#include <utils/algorithm.h>
#include <utils/asynctask.h>
#include <utils/qtcassert.h>
#include <utils/qtcprocess.h>
#include <utils/runextensions.h>
#include <utils/stringutils.h>
#include <QFutureWatcher>
@@ -34,7 +34,7 @@ namespace Internal {
const int sdkManagerCmdTimeoutS = 60;
const int sdkManagerOperationTimeoutS = 600;
using SdkCmdFutureInterface = QFutureInterface<AndroidSdkManager::OperationOutput>;
using SdkCmdPromise = QPromise<AndroidSdkManager::OperationOutput>;
static const QRegularExpression &assertionRegExp()
{
@@ -111,7 +111,7 @@ static bool sdkManagerCommand(const AndroidConfig &config, const QStringList &ar
after the lapse of \a timeout seconds. The function blocks the calling thread.
*/
static void sdkManagerCommand(const AndroidConfig &config, const QStringList &args,
AndroidSdkManager &sdkManager, SdkCmdFutureInterface &fi,
AndroidSdkManager &sdkManager, SdkCmdPromise &promise,
AndroidSdkManager::OperationOutput &output, double progressQuota,
bool interruptible = true, int timeout = sdkManagerOperationTimeoutS)
{
@@ -120,19 +120,19 @@ static void sdkManagerCommand(const AndroidConfig &config, const QStringList &ar
qCDebug(sdkManagerLog).noquote() << "Running SDK Manager command (async):"
<< CommandLine(config.sdkManagerToolPath(), newArgs)
.toUserOutput();
int offset = fi.progressValue();
int offset = promise.future().progressValue();
QtcProcess proc;
proc.setEnvironment(AndroidConfigurations::toolsEnvironment(config));
bool assertionFound = false;
proc.setTimeoutS(timeout);
proc.setStdOutCallback([offset, progressQuota, &proc, &assertionFound, &fi](const QString &out) {
proc.setStdOutCallback([offset, progressQuota, &proc, &assertionFound, &promise](const QString &out) {
int progressPercent = parseProgress(out, assertionFound);
if (assertionFound) {
proc.stop();
proc.waitForFinished();
}
if (progressPercent != -1)
fi.setProgressValue(offset + qRound((progressPercent / 100.0) * progressQuota));
promise.setProgressValue(offset + qRound((progressPercent / 100.0) * progressQuota));
});
proc.setStdErrCallback([&output](const QString &err) {
output.stdError = err;
@@ -168,12 +168,12 @@ public:
const AndroidSdkPackageList &allPackages(bool forceUpdate = false);
void refreshSdkPackages(bool forceReload = false);
void parseCommonArguments(QFutureInterface<QString> &fi);
void updateInstalled(SdkCmdFutureInterface &fi);
void update(SdkCmdFutureInterface &fi, const QStringList &install,
void parseCommonArguments(QPromise<QString> &promise);
void updateInstalled(SdkCmdPromise &fi);
void update(SdkCmdPromise &fi, const QStringList &install,
const QStringList &uninstall);
void checkPendingLicense(SdkCmdFutureInterface &fi);
void getPendingLicense(SdkCmdFutureInterface &fi);
void checkPendingLicense(SdkCmdPromise &fi);
void getPendingLicense(SdkCmdPromise &fi);
void addWatcher(const QFuture<AndroidSdkManager::OperationOutput> &future);
void setLicenseInput(bool acceptLicense);
@@ -186,7 +186,7 @@ private:
void reloadSdkPackages();
void clearPackages();
bool onLicenseStdOut(const QString &output, bool notify,
AndroidSdkManager::OperationOutput &result, SdkCmdFutureInterface &fi);
AndroidSdkManager::OperationOutput &result, SdkCmdPromise &fi);
AndroidSdkManager &m_sdkManager;
const AndroidConfig &m_config;
@@ -308,7 +308,7 @@ bool AndroidSdkManager::packageListingSuccessful() const
QFuture<QString> AndroidSdkManager::availableArguments() const
{
return Utils::runAsync(&AndroidSdkManagerPrivate::parseCommonArguments, m_d.get());
return Utils::asyncRun(&AndroidSdkManagerPrivate::parseCommonArguments, m_d.get());
}
QFuture<AndroidSdkManager::OperationOutput> AndroidSdkManager::updateAll()
@@ -316,7 +316,7 @@ QFuture<AndroidSdkManager::OperationOutput> AndroidSdkManager::updateAll()
if (isBusy()) {
return QFuture<AndroidSdkManager::OperationOutput>();
}
auto future = Utils::runAsync(&AndroidSdkManagerPrivate::updateInstalled, m_d.get());
auto future = Utils::asyncRun(&AndroidSdkManagerPrivate::updateInstalled, m_d.get());
m_d->addWatcher(future);
return future;
}
@@ -326,7 +326,7 @@ AndroidSdkManager::update(const QStringList &install, const QStringList &uninsta
{
if (isBusy())
return QFuture<AndroidSdkManager::OperationOutput>();
auto future = Utils::runAsync(&AndroidSdkManagerPrivate::update, m_d.get(), install, uninstall);
auto future = Utils::asyncRun(&AndroidSdkManagerPrivate::update, m_d.get(), install, uninstall);
m_d->addWatcher(future);
return future;
}
@@ -335,7 +335,7 @@ QFuture<AndroidSdkManager::OperationOutput> AndroidSdkManager::checkPendingLicen
{
if (isBusy())
return QFuture<AndroidSdkManager::OperationOutput>();
auto future = Utils::runAsync(&AndroidSdkManagerPrivate::checkPendingLicense, m_d.get());
auto future = Utils::asyncRun(&AndroidSdkManagerPrivate::checkPendingLicense, m_d.get());
m_d->addWatcher(future);
return future;
}
@@ -344,7 +344,7 @@ QFuture<AndroidSdkManager::OperationOutput> AndroidSdkManager::runLicenseCommand
{
if (isBusy())
return QFuture<AndroidSdkManager::OperationOutput>();
auto future = Utils::runAsync(&AndroidSdkManagerPrivate::getPendingLicense, m_d.get());
auto future = Utils::asyncRun(&AndroidSdkManagerPrivate::getPendingLicense, m_d.get());
m_d->addWatcher(future);
return future;
}
@@ -422,29 +422,29 @@ void AndroidSdkManagerPrivate::refreshSdkPackages(bool forceReload)
reloadSdkPackages();
}
void AndroidSdkManagerPrivate::updateInstalled(SdkCmdFutureInterface &fi)
void AndroidSdkManagerPrivate::updateInstalled(SdkCmdPromise &promise)
{
fi.setProgressRange(0, 100);
fi.setProgressValue(0);
promise.setProgressRange(0, 100);
promise.setProgressValue(0);
AndroidSdkManager::OperationOutput result;
result.type = AndroidSdkManager::UpdateAll;
result.stdOutput = Tr::tr("Updating installed packages.");
fi.reportResult(result);
promise.addResult(result);
QStringList args("--update");
args << m_config.sdkManagerToolArgs();
if (!fi.isCanceled())
sdkManagerCommand(m_config, args, m_sdkManager, fi, result, 100);
if (!promise.isCanceled())
sdkManagerCommand(m_config, args, m_sdkManager, promise, result, 100);
else
qCDebug(sdkManagerLog) << "Update: Operation cancelled before start";
if (result.stdError.isEmpty() && !result.success)
result.stdError = Tr::tr("Failed.");
result.stdOutput = Tr::tr("Done\n\n");
fi.reportResult(result);
fi.setProgressValue(100);
promise.addResult(result);
promise.setProgressValue(100);
}
void AndroidSdkManagerPrivate::update(SdkCmdFutureInterface &fi, const QStringList &install,
void AndroidSdkManagerPrivate::update(SdkCmdPromise &fi, const QStringList &install,
const QStringList &uninstall)
{
fi.setProgressRange(0, 100);
@@ -461,7 +461,7 @@ void AndroidSdkManagerPrivate::update(SdkCmdFutureInterface &fi, const QStringLi
result.type = AndroidSdkManager::UpdatePackage;
result.stdOutput = QString("%1 %2").arg(isInstall ? installTag : uninstallTag)
.arg(packagePath);
fi.reportResult(result);
fi.addResult(result);
if (fi.isCanceled())
qCDebug(sdkManagerLog) << args << "Update: Operation cancelled before start";
else
@@ -471,7 +471,7 @@ void AndroidSdkManagerPrivate::update(SdkCmdFutureInterface &fi, const QStringLi
if (result.stdError.isEmpty() && !result.success)
result.stdError = Tr::tr("AndroidSdkManager", "Failed");
result.stdOutput = Tr::tr("AndroidSdkManager", "Done\n\n");
fi.reportResult(result);
fi.addResult(result);
return fi.isCanceled();
};
@@ -495,7 +495,7 @@ void AndroidSdkManagerPrivate::update(SdkCmdFutureInterface &fi, const QStringLi
fi.setProgressValue(100);
}
void AndroidSdkManagerPrivate::checkPendingLicense(SdkCmdFutureInterface &fi)
void AndroidSdkManagerPrivate::checkPendingLicense(SdkCmdPromise &fi)
{
fi.setProgressRange(0, 100);
fi.setProgressValue(0);
@@ -509,11 +509,11 @@ void AndroidSdkManagerPrivate::checkPendingLicense(SdkCmdFutureInterface &fi)
qCDebug(sdkManagerLog) << "Update: Operation cancelled before start";
}
fi.reportResult(result);
fi.addResult(result);
fi.setProgressValue(100);
}
void AndroidSdkManagerPrivate::getPendingLicense(SdkCmdFutureInterface &fi)
void AndroidSdkManagerPrivate::getPendingLicense(SdkCmdPromise &fi)
{
fi.setProgressRange(0, 100);
fi.setProgressValue(0);
@@ -571,7 +571,7 @@ void AndroidSdkManagerPrivate::getPendingLicense(SdkCmdFutureInterface &fi)
result.success = licenseCommand.exitStatus() == QProcess::NormalExit;
if (!result.success)
result.stdError = Tr::tr("License command failed.\n\n");
fi.reportResult(result);
fi.addResult(result);
fi.setProgressValue(100);
}
@@ -595,14 +595,14 @@ void AndroidSdkManagerPrivate::clearUserInput()
bool AndroidSdkManagerPrivate::onLicenseStdOut(const QString &output, bool notify,
AndroidSdkManager::OperationOutput &result,
SdkCmdFutureInterface &fi)
SdkCmdPromise &fi)
{
m_licenseTextCache.append(output);
const QRegularExpressionMatch assertionMatch = assertionRegExp().match(m_licenseTextCache);
if (assertionMatch.hasMatch()) {
if (notify) {
result.stdOutput = m_licenseTextCache;
fi.reportResult(result);
fi.addResult(result);
}
// Clear the current contents. The found license text is dispatched. Continue collecting the
// next license text.
@@ -620,7 +620,7 @@ void AndroidSdkManagerPrivate::addWatcher(const QFuture<AndroidSdkManager::Opera
m_activeOperation->setFuture(QFuture<void>(future));
}
void AndroidSdkManagerPrivate::parseCommonArguments(QFutureInterface<QString> &fi)
void AndroidSdkManagerPrivate::parseCommonArguments(QPromise<QString> &promise)
{
QString argumentDetails;
QString output;
@@ -628,7 +628,7 @@ void AndroidSdkManagerPrivate::parseCommonArguments(QFutureInterface<QString> &f
bool foundTag = false;
const auto lines = output.split('\n');
for (const QString& line : lines) {
if (fi.isCanceled())
if (promise.isCanceled())
break;
if (foundTag)
argumentDetails.append(line + "\n");
@@ -636,8 +636,8 @@ void AndroidSdkManagerPrivate::parseCommonArguments(QFutureInterface<QString> &f
foundTag = true;
}
if (!fi.isCanceled())
fi.reportResult(argumentDetails);
if (!promise.isCanceled())
promise.addResult(argumentDetails);
}
void AndroidSdkManagerPrivate::clearPackages()