forked from qt-creator/qt-creator
ProjectExplorer: Rework the build step run interface
Originally, the build manager used to run all build steps in a dedicated thread. Communication between the step and the manager happened via a QFutureInterface that was passed into the step's run() function. Later, new steps were added that operated asynchronously, so the build manager had to differentiate between the different kinds of steps for starting and stopping. These days, almost all build and deploy steps work asynchronously, which made the QFuture-based interface look increasingly odd. With this patch, all build steps are expected to work asynchronously, so the build manager no longer needs to differentiate. Steps are started and requested to stop via the run() and cancel() functions, respectively, and emit the finished() signal when they are done. Build step implementors no longer have to deal with a QFutureInterface. For steps whose implementation is inherently synchronous, the BuildStep base class offers a runInThread() function. Change-Id: If905c68b234c5a669f6e19f43142eaa57d594803 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -327,17 +327,18 @@ QString AndroidAvdManager::findAvd(const QString &avdName) const
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString AndroidAvdManager::waitForAvd(const QString &avdName, const QFutureInterface<bool> &fi) const
|
||||
QString AndroidAvdManager::waitForAvd(const QString &avdName,
|
||||
const std::function<bool()> &cancelChecker) const
|
||||
{
|
||||
// we cannot use adb -e wait-for-device, since that doesn't work if a emulator is already running
|
||||
// 60 rounds of 2s sleeping, two minutes for the avd to start
|
||||
QString serialNumber;
|
||||
for (int i = 0; i < 60; ++i) {
|
||||
if (fi.isCanceled())
|
||||
if (cancelChecker())
|
||||
return QString();
|
||||
serialNumber = findAvd(avdName);
|
||||
if (!serialNumber.isEmpty())
|
||||
return waitForBooted(serialNumber, fi) ? serialNumber : QString();
|
||||
return waitForBooted(serialNumber, cancelChecker) ? serialNumber : QString();
|
||||
QThread::sleep(2);
|
||||
}
|
||||
return QString();
|
||||
@@ -358,11 +359,12 @@ bool AndroidAvdManager::isAvdBooted(const QString &device) const
|
||||
return value == "stopped";
|
||||
}
|
||||
|
||||
bool AndroidAvdManager::waitForBooted(const QString &serialNumber, const QFutureInterface<bool> &fi) const
|
||||
bool AndroidAvdManager::waitForBooted(const QString &serialNumber,
|
||||
const std::function<bool()> &cancelChecker) const
|
||||
{
|
||||
// found a serial number, now wait until it's done booting...
|
||||
for (int i = 0; i < 60; ++i) {
|
||||
if (fi.isCanceled())
|
||||
if (cancelChecker())
|
||||
return false;
|
||||
if (isAvdBooted(serialNumber)) {
|
||||
return true;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "androidconfigurations.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace Android {
|
||||
@@ -51,11 +52,12 @@ public:
|
||||
bool startAvdAsync(const QString &avdName) const;
|
||||
QString findAvd(const QString &avdName) const;
|
||||
QString waitForAvd(const QString &avdName,
|
||||
const QFutureInterface<bool> &fi = QFutureInterface<bool>()) const;
|
||||
const std::function<bool()> &cancelChecker = {}) const;
|
||||
bool isAvdBooted(const QString &device) const;
|
||||
|
||||
private:
|
||||
bool waitForBooted(const QString &serialNumber, const QFutureInterface<bool> &fi) const;
|
||||
bool waitForBooted(const QString &serialNumber,
|
||||
const std::function<bool()> &cancelChecker) const;
|
||||
|
||||
private:
|
||||
const AndroidConfig &m_config;
|
||||
|
||||
@@ -340,14 +340,14 @@ bool AndroidBuildApkStep::verifyCertificatePassword()
|
||||
return success;
|
||||
}
|
||||
|
||||
void AndroidBuildApkStep::run(QFutureInterface<bool> &fi)
|
||||
void AndroidBuildApkStep::doRun()
|
||||
{
|
||||
if (m_skipBuilding) {
|
||||
emit addOutput(tr("No application .pro file found, not building an APK."), BuildStep::OutputFormat::ErrorMessage);
|
||||
reportRunResult(fi, true);
|
||||
emit finished(true);
|
||||
return;
|
||||
}
|
||||
AbstractProcessStep::run(fi);
|
||||
AbstractProcessStep::doRun();
|
||||
}
|
||||
|
||||
void AndroidBuildApkStep::processStarted()
|
||||
|
||||
@@ -86,7 +86,7 @@ private:
|
||||
bool verifyKeystorePassword();
|
||||
bool verifyCertificatePassword();
|
||||
|
||||
void run(QFutureInterface<bool> &fi) override;
|
||||
void doRun() override;
|
||||
|
||||
bool m_signPackage = false;
|
||||
bool m_verbose = false;
|
||||
|
||||
@@ -298,7 +298,7 @@ bool AndroidDeployQtStep::init()
|
||||
return true;
|
||||
}
|
||||
|
||||
AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy(QFutureInterface<bool> &fi)
|
||||
AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy()
|
||||
{
|
||||
QString args;
|
||||
if (m_useAndroiddeployqt) {
|
||||
@@ -386,7 +386,7 @@ AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy(QFutureInter
|
||||
if (m_process->state() == QProcess::NotRunning)
|
||||
break;
|
||||
|
||||
if (fi.isCanceled()) {
|
||||
if (isCanceled()) {
|
||||
m_process->kill();
|
||||
m_process->waitForFinished();
|
||||
}
|
||||
@@ -472,25 +472,23 @@ void AndroidDeployQtStep::slotSetSerialNumber(const QString &serialNumber)
|
||||
AndroidManager::setDeviceSerialNumber(target(), serialNumber);
|
||||
}
|
||||
|
||||
void AndroidDeployQtStep::run(QFutureInterface<bool> &fi)
|
||||
bool AndroidDeployQtStep::runImpl()
|
||||
{
|
||||
if (!m_avdName.isEmpty()) {
|
||||
QString serialNumber = AndroidAvdManager().waitForAvd(m_avdName, fi);
|
||||
QString serialNumber = AndroidAvdManager().waitForAvd(m_avdName, cancelChecker());
|
||||
qCDebug(deployStepLog) << "Deploying to AVD:" << m_avdName << serialNumber;
|
||||
if (serialNumber.isEmpty()) {
|
||||
reportRunResult(fi, false);
|
||||
return;
|
||||
}
|
||||
if (serialNumber.isEmpty())
|
||||
return false;
|
||||
m_serialNumber = serialNumber;
|
||||
emit setSerialNumber(serialNumber);
|
||||
}
|
||||
|
||||
DeployErrorCode returnValue = runDeploy(fi);
|
||||
DeployErrorCode returnValue = runDeploy();
|
||||
if (returnValue > DeployErrorCode::NoError && returnValue < DeployErrorCode::Failure) {
|
||||
emit askForUninstall(returnValue);
|
||||
if (m_askForUninstall) {
|
||||
m_uninstallPreviousPackageRun = true;
|
||||
returnValue = runDeploy(fi);
|
||||
returnValue = runDeploy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,7 +507,7 @@ void AndroidDeployQtStep::run(QFutureInterface<bool> &fi)
|
||||
}
|
||||
}
|
||||
|
||||
reportRunResult(fi, returnValue == NoError);
|
||||
return returnValue == NoError;
|
||||
}
|
||||
|
||||
void AndroidDeployQtStep::gatherFilesToPull()
|
||||
@@ -550,6 +548,11 @@ void AndroidDeployQtStep::gatherFilesToPull()
|
||||
qCDebug(deployStepLog) << itr.key() << "to" << itr.value();
|
||||
}
|
||||
|
||||
void AndroidDeployQtStep::doRun()
|
||||
{
|
||||
runInThread([this] { return runImpl(); });
|
||||
}
|
||||
|
||||
void AndroidDeployQtStep::runCommand(const QString &program, const QStringList &arguments)
|
||||
{
|
||||
Utils::SynchronousProcess buildProc;
|
||||
|
||||
@@ -84,12 +84,14 @@ private:
|
||||
void runCommand(const QString &program, const QStringList &arguments);
|
||||
|
||||
bool init() override;
|
||||
void run(QFutureInterface<bool> &fi) override;
|
||||
void doRun() override;
|
||||
void gatherFilesToPull();
|
||||
DeployErrorCode runDeploy(QFutureInterface<bool> &fi);
|
||||
DeployErrorCode runDeploy();
|
||||
void slotAskForUninstall(DeployErrorCode errorCode);
|
||||
void slotSetSerialNumber(const QString &serialNumber);
|
||||
|
||||
bool runImpl();
|
||||
|
||||
ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
|
||||
|
||||
void processReadyReadStdOutput(DeployErrorCode &errorCode);
|
||||
|
||||
@@ -95,7 +95,7 @@ bool AndroidPackageInstallationStep::init()
|
||||
return AbstractProcessStep::init();
|
||||
}
|
||||
|
||||
void AndroidPackageInstallationStep::run(QFutureInterface<bool> &fi)
|
||||
void AndroidPackageInstallationStep::doRun()
|
||||
{
|
||||
QString error;
|
||||
foreach (const QString &dir, m_androidDirsToClean) {
|
||||
@@ -104,12 +104,12 @@ void AndroidPackageInstallationStep::run(QFutureInterface<bool> &fi)
|
||||
emit addOutput(tr("Removing directory %1").arg(dir), OutputFormat::NormalMessage);
|
||||
if (!FileUtils::removeRecursively(androidDir, &error)) {
|
||||
emit addOutput(error, OutputFormat::Stderr);
|
||||
reportRunResult(fi, false);
|
||||
emit finished(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
AbstractProcessStep::run(fi);
|
||||
AbstractProcessStep::doRun();
|
||||
}
|
||||
|
||||
BuildStepConfigWidget *AndroidPackageInstallationStep::createConfigWidget()
|
||||
|
||||
@@ -40,13 +40,13 @@ class ANDROID_EXPORT AndroidPackageInstallationStep : public ProjectExplorer::Ab
|
||||
|
||||
public:
|
||||
explicit AndroidPackageInstallationStep(ProjectExplorer::BuildStepList *bsl);
|
||||
bool init() override;
|
||||
|
||||
ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
|
||||
|
||||
void run(QFutureInterface<bool> &fi) override;
|
||||
|
||||
private:
|
||||
bool init() override;
|
||||
void doRun() override;
|
||||
|
||||
QStringList m_androidDirsToClean;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user