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:
Christian Kandeler
2019-01-25 14:26:34 +01:00
parent 536618b012
commit 966f4ea6a9
52 changed files with 355 additions and 399 deletions

View File

@@ -169,9 +169,9 @@ QString IosBuildStep::buildCommand() const
return QString("xcodebuild"); // add path?
}
void IosBuildStep::run(QFutureInterface<bool> &fi)
void IosBuildStep::doRun()
{
AbstractProcessStep::run(fi);
AbstractProcessStep::doRun();
}
BuildStepConfigWidget *IosBuildStep::createConfigWidget()

View File

@@ -48,9 +48,6 @@ class IosBuildStep : public ProjectExplorer::AbstractProcessStep
public:
explicit IosBuildStep(ProjectExplorer::BuildStepList *parent);
bool init() override;
void run(QFutureInterface<bool> &fi) override;
ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
void setBaseArguments(const QStringList &args);
void setExtraArguments(const QStringList &extraArgs);
@@ -60,6 +57,8 @@ public:
QString buildCommand() const;
private:
bool init() override;
void doRun() override;
bool fromMap(const QVariantMap &map) override;
QVariantMap toMap() const override;

View File

@@ -58,7 +58,6 @@ IosDeployStep::IosDeployStep(BuildStepList *parent)
: BuildStep(parent, stepId())
{
setImmutable(true);
setRunInGuiThread(true);
updateDisplayNames();
connect(DeviceManager::instance(), &DeviceManager::updated,
this, &IosDeployStep::updateDisplayNames);
@@ -101,22 +100,19 @@ bool IosDeployStep::init()
return true;
}
void IosDeployStep::run(QFutureInterface<bool> &fi)
void IosDeployStep::doRun()
{
m_futureInterface = fi;
QTC_CHECK(m_transferStatus == NoTransfer);
if (device().isNull()) {
TaskHub::addTask(Task::Error, tr("Deployment failed. No iOS device found."),
ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT);
reportRunResult(m_futureInterface, !iossimulator().isNull());
emit finished(!iossimulator().isNull());
cleanup();
return;
}
m_toolHandler = new IosToolHandler(m_deviceType, this);
m_transferStatus = TransferInProgress;
m_futureInterface.setProgressRange(0, 200);
m_futureInterface.setProgressValueAndText(0, QLatin1String("Transferring application"));
m_futureInterface.reportStarted();
emit progress(0, tr("Transferring application"));
connect(m_toolHandler, &IosToolHandler::isTransferringApp,
this, &IosDeployStep::handleIsTransferringApp);
connect(m_toolHandler, &IosToolHandler::didTransferApp,
@@ -129,7 +125,7 @@ void IosDeployStep::run(QFutureInterface<bool> &fi)
m_toolHandler->requestTransferApp(appBundle(), m_deviceType.identifier);
}
void IosDeployStep::cancel()
void IosDeployStep::doCancel()
{
if (m_toolHandler)
m_toolHandler->stop();
@@ -150,8 +146,7 @@ void IosDeployStep::handleIsTransferringApp(IosToolHandler *handler, const QStri
{
Q_UNUSED(handler); Q_UNUSED(bundlePath); Q_UNUSED(deviceId);
QTC_CHECK(m_transferStatus == TransferInProgress);
m_futureInterface.setProgressRange(0, maxProgress);
m_futureInterface.setProgressValueAndText(progress, info);
emit this->progress(progress * 100 / maxProgress, info);
}
void IosDeployStep::handleDidTransferApp(IosToolHandler *handler, const QString &bundlePath,
@@ -168,7 +163,7 @@ void IosDeployStep::handleDidTransferApp(IosToolHandler *handler, const QString
tr("Deployment failed. The settings in the Devices window of Xcode might be incorrect."),
ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT);
}
reportRunResult(m_futureInterface, status == IosToolHandler::Success);
emit finished(status == IosToolHandler::Success);
}
void IosDeployStep::handleFinished(IosToolHandler *handler)
@@ -178,7 +173,7 @@ void IosDeployStep::handleFinished(IosToolHandler *handler)
m_transferStatus = TransferFailed;
TaskHub::addTask(Task::Error, tr("Deployment failed."),
ProjectExplorer::Constants::TASK_CATEGORY_DEPLOYMENT);
reportRunResult(m_futureInterface, false);
emit finished(false);
break;
case NoTransfer:
case TransferOk:

View File

@@ -32,7 +32,6 @@
#include <projectexplorer/buildstep.h>
#include <projectexplorer/devicesupport/idevice.h>
#include <QFutureInterface>
#include <QProcess>
namespace Ios {
@@ -54,14 +53,13 @@ public:
explicit IosDeployStep(ProjectExplorer::BuildStepList *bc);
static Core::Id stepId();
void cleanup();
private:
void doRun() override;
void doCancel() override;
bool fromMap(const QVariantMap &map) override;
QVariantMap toMap() const override;
void run(QFutureInterface<bool> &fi) override;
void cleanup();
void cancel() override;
private:
void handleIsTransferringApp(Ios::IosToolHandler *handler, const QString &bundlePath,
const QString &deviceId, int progress, int maxProgress,
const QString &info);
@@ -85,7 +83,6 @@ private:
TransferStatus m_transferStatus = NoTransfer;
IosToolHandler *m_toolHandler = nullptr;
QFutureInterface<bool> m_futureInterface;
ProjectExplorer::IDevice::ConstPtr m_device;
QString m_bundlePath;
IosDeviceType m_deviceType;

View File

@@ -187,9 +187,9 @@ bool IosDsymBuildStep::isDefault() const
return arguments() == defaultArguments() && command() == defaultCommand();
}
void IosDsymBuildStep::run(QFutureInterface<bool> &fi)
void IosDsymBuildStep::doRun()
{
AbstractProcessStep::run(fi);
AbstractProcessStep::doRun();
}
BuildStepConfigWidget *IosDsymBuildStep::createConfigWidget()

View File

@@ -42,9 +42,6 @@ class IosDsymBuildStep : public ProjectExplorer::AbstractProcessStep
public:
IosDsymBuildStep(ProjectExplorer::BuildStepList *parent);
bool init() override;
void run(QFutureInterface<bool> &fi) override;
ProjectExplorer::BuildStepConfigWidget *createConfigWidget() override;
void setArguments(const QStringList &args);
QStringList arguments() const;
@@ -54,10 +51,12 @@ public:
void setCommand(const QString &command);
bool isDefault() const;
QVariantMap toMap() const override;
private:
bool init() override;
void doRun() override;
QVariantMap toMap() const override;
bool fromMap(const QVariantMap &map) override;
QStringList defaultCleanCmdList() const;
QStringList defaultCmdList() const;