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

@@ -94,32 +94,9 @@ bool TarPackageCreationStep::init()
return true;
}
void TarPackageCreationStep::run(QFutureInterface<bool> &fi)
void TarPackageCreationStep::doRun()
{
setPackagingStarted();
const QList<DeployableFile> &files = target()->deploymentData().allFiles();
if (m_incrementalDeploymentAspect->value()) {
m_files.clear();
for (const DeployableFile &file : files)
addNeededDeploymentFiles(file, target()->kit());
} else {
m_files = files;
}
const bool success = doPackage(fi);
setPackagingFinished(success);
if (success)
emit addOutput(tr("Packaging finished successfully."), OutputFormat::NormalMessage);
else
emit addOutput(tr("Packaging failed."), OutputFormat::ErrorMessage);
connect(BuildManager::instance(), &BuildManager::buildQueueFinished,
this, &TarPackageCreationStep::deployFinished);
reportRunResult(fi, success);
runInThread([this] { return runImpl(); });
}
void TarPackageCreationStep::addNeededDeploymentFiles(
@@ -151,7 +128,7 @@ void TarPackageCreationStep::addNeededDeploymentFiles(
}
}
bool TarPackageCreationStep::doPackage(QFutureInterface<bool> &fi)
bool TarPackageCreationStep::doPackage()
{
emit addOutput(tr("Creating tarball..."), OutputFormat::NormalMessage);
if (!m_packagingNeeded) {
@@ -176,7 +153,7 @@ bool TarPackageCreationStep::doPackage(QFutureInterface<bool> &fi)
}
QFileInfo fileInfo = d.localFilePath().toFileInfo();
if (!appendFile(tarFile, fileInfo, d.remoteDirectory() + QLatin1Char('/')
+ fileInfo.fileName(), fi)) {
+ fileInfo.fileName())) {
return false;
}
}
@@ -192,7 +169,7 @@ bool TarPackageCreationStep::doPackage(QFutureInterface<bool> &fi)
}
bool TarPackageCreationStep::appendFile(QFile &tarFile, const QFileInfo &fileInfo,
const QString &remoteFilePath, const QFutureInterface<bool> &fi)
const QString &remoteFilePath)
{
if (!writeHeader(tarFile, fileInfo, remoteFilePath))
return false;
@@ -202,7 +179,7 @@ bool TarPackageCreationStep::appendFile(QFile &tarFile, const QFileInfo &fileInf
dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot)) {
const QString thisLocalFilePath = dir.path() + QLatin1Char('/') + fileName;
const QString thisRemoteFilePath = remoteFilePath + QLatin1Char('/') + fileName;
if (!appendFile(tarFile, QFileInfo(thisLocalFilePath), thisRemoteFilePath, fi))
if (!appendFile(tarFile, QFileInfo(thisLocalFilePath), thisRemoteFilePath))
return false;
}
return true;
@@ -231,7 +208,7 @@ bool TarPackageCreationStep::appendFile(QFile &tarFile, const QFileInfo &fileInf
while (!file.atEnd() && file.error() == QFile::NoError && tarFile.error() == QFile::NoError) {
const QByteArray data = file.read(chunkSize);
tarFile.write(data);
if (fi.isCanceled())
if (isCanceled())
return false;
}
if (file.error() != QFile::NoError) {
@@ -339,6 +316,34 @@ QString TarPackageCreationStep::packageFileName() const
return project()->displayName() + QLatin1String(".tar");
}
bool TarPackageCreationStep::runImpl()
{
setPackagingStarted();
const QList<DeployableFile> &files = target()->deploymentData().allFiles();
if (m_incrementalDeploymentAspect->value()) {
m_files.clear();
for (const DeployableFile &file : files)
addNeededDeploymentFiles(file, target()->kit());
} else {
m_files = files;
}
const bool success = doPackage();
setPackagingFinished(success);
if (success)
emit addOutput(tr("Packaging finished successfully."), OutputFormat::NormalMessage);
else
emit addOutput(tr("Packaging failed."), OutputFormat::ErrorMessage);
connect(BuildManager::instance(), &BuildManager::buildQueueFinished,
this, &TarPackageCreationStep::deployFinished);
return success;
}
BuildStepConfigWidget *TarPackageCreationStep::createConfigWidget()
{
auto widget = BuildStep::createConfigWidget();