RemoteLinux/Boot2Qt: Merge DeployStep and DeployService hierarchies

They were 1:1 now.

The change here is as small as possible, there are quite a few places
to clean up left.

Change-Id: I4f78d1de857b93d8372e2592a7723b02fe2fc947
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-03-21 16:07:20 +01:00
parent 1bdc638e65
commit a4ed630c7d
11 changed files with 286 additions and 420 deletions

View File

@@ -24,137 +24,116 @@ using namespace Utils;
namespace RemoteLinux {
namespace Internal {
class AbstractRemoteLinuxDeployServicePrivate
{
public:
IDevice::ConstPtr deviceConfiguration;
QPointer<Target> target;
DeploymentTimeInfo deployTimes;
std::unique_ptr<TaskTree> m_taskTree;
};
class AbstractRemoteLinuxDeployStepPrivate
{
public:
bool hasError;
std::function<CheckResult()> internalInit;
std::function<void()> runPreparer;
AbstractRemoteLinuxDeployService *deployService = nullptr;
DeploymentTimeInfo deployTimes;
std::unique_ptr<TaskTree> m_taskTree;
};
} // Internal
using namespace Internal;
AbstractRemoteLinuxDeployService::AbstractRemoteLinuxDeployService(QObject *parent)
: QObject(parent), d(new AbstractRemoteLinuxDeployServicePrivate)
AbstractRemoteLinuxDeployStep::AbstractRemoteLinuxDeployStep(BuildStepList *bsl, Id id)
: BuildStep(bsl, id), d(new Internal::AbstractRemoteLinuxDeployStepPrivate)
{
connect(this, &AbstractRemoteLinuxDeployStep::errorMessage,
this, &AbstractRemoteLinuxDeployStep::handleErrorMessage);
connect(this, &AbstractRemoteLinuxDeployStep::progressMessage,
this, &AbstractRemoteLinuxDeployStep::handleProgressMessage);
connect(this, &AbstractRemoteLinuxDeployStep::warningMessage,
this, &AbstractRemoteLinuxDeployStep::handleWarningMessage);
connect(this, &AbstractRemoteLinuxDeployStep::stdOutData,
this, &AbstractRemoteLinuxDeployStep::handleStdOutData);
connect(this, &AbstractRemoteLinuxDeployStep::stdErrData,
this, &AbstractRemoteLinuxDeployStep::handleStdErrData);
}
AbstractRemoteLinuxDeployService::~AbstractRemoteLinuxDeployService()
AbstractRemoteLinuxDeployStep::~AbstractRemoteLinuxDeployStep()
{
delete d;
}
const Target *AbstractRemoteLinuxDeployService::target() const
IDevice::ConstPtr AbstractRemoteLinuxDeployStep::deviceConfiguration() const
{
return d->target;
return DeviceKitAspect::device(kit());
}
const Kit *AbstractRemoteLinuxDeployService::kit() const
{
return d->target ? d->target->kit() : nullptr;
}
IDevice::ConstPtr AbstractRemoteLinuxDeployService::deviceConfiguration() const
{
return d->deviceConfiguration;
}
void AbstractRemoteLinuxDeployService::saveDeploymentTimeStamp(const DeployableFile &deployableFile,
void AbstractRemoteLinuxDeployStep::saveDeploymentTimeStamp(const DeployableFile &deployableFile,
const QDateTime &remoteTimestamp)
{
d->deployTimes.saveDeploymentTimeStamp(deployableFile, kit(), remoteTimestamp);
}
bool AbstractRemoteLinuxDeployService::hasLocalFileChanged(
bool AbstractRemoteLinuxDeployStep::hasLocalFileChanged(
const DeployableFile &deployableFile) const
{
return d->deployTimes.hasLocalFileChanged(deployableFile, kit());
}
bool AbstractRemoteLinuxDeployService::hasRemoteFileChanged(
bool AbstractRemoteLinuxDeployStep::hasRemoteFileChanged(
const DeployableFile &deployableFile, const QDateTime &remoteTimestamp) const
{
return d->deployTimes.hasRemoteFileChanged(deployableFile, kit(), remoteTimestamp);
}
void AbstractRemoteLinuxDeployService::setTarget(Target *target)
{
d->target = target;
d->deviceConfiguration = DeviceKitAspect::device(kit());
}
void AbstractRemoteLinuxDeployService::start()
void AbstractRemoteLinuxDeployStep::start()
{
QTC_ASSERT(!d->m_taskTree, return);
const CheckResult check = isDeploymentPossible();
if (!check) {
emit errorMessage(check.errorMessage());
emit finished();
handleFinished();
return;
}
if (!isDeploymentNecessary()) {
emit progressMessage(Tr::tr("No deployment action necessary. Skipping."));
emit finished();
handleFinished();
return;
}
d->m_taskTree.reset(new TaskTree(deployRecipe()));
const auto endHandler = [this] {
d->m_taskTree.release()->deleteLater();
emit finished();
handleFinished();
};
connect(d->m_taskTree.get(), &TaskTree::done, this, endHandler);
connect(d->m_taskTree.get(), &TaskTree::errorOccurred, this, endHandler);
d->m_taskTree->start();
}
void AbstractRemoteLinuxDeployService::stop()
void AbstractRemoteLinuxDeployStep::stop()
{
if (!d->m_taskTree)
return;
d->m_taskTree.reset();
emit finished();
handleFinished();
}
CheckResult AbstractRemoteLinuxDeployService::isDeploymentPossible() const
CheckResult AbstractRemoteLinuxDeployStep::isDeploymentPossible() const
{
if (!deviceConfiguration())
return CheckResult::failure(Tr::tr("No device configuration set."));
return CheckResult::success();
}
QVariantMap AbstractRemoteLinuxDeployService::exportDeployTimes() const
QVariantMap AbstractRemoteLinuxDeployStep::exportDeployTimes() const
{
return d->deployTimes.exportDeployTimes();
}
void AbstractRemoteLinuxDeployService::importDeployTimes(const QVariantMap &map)
void AbstractRemoteLinuxDeployStep::importDeployTimes(const QVariantMap &map)
{
d->deployTimes.importDeployTimes(map);
}
AbstractRemoteLinuxDeployStep::AbstractRemoteLinuxDeployStep(BuildStepList *bsl, Utils::Id id)
: BuildStep(bsl, id), d(new Internal::AbstractRemoteLinuxDeployStepPrivate)
{
}
void AbstractRemoteLinuxDeployStep::setInternalInitializer(const std::function<CheckResult ()> &init)
{
d->internalInit = init;
@@ -165,36 +144,23 @@ void AbstractRemoteLinuxDeployStep::setRunPreparer(const std::function<void ()>
d->runPreparer = prep;
}
void AbstractRemoteLinuxDeployStep::setDeployService(AbstractRemoteLinuxDeployService *service)
{
d->deployService = service;
}
AbstractRemoteLinuxDeployStep::~AbstractRemoteLinuxDeployStep()
{
delete d->deployService;
delete d;
}
bool AbstractRemoteLinuxDeployStep::fromMap(const QVariantMap &map)
{
if (!BuildStep::fromMap(map))
return false;
d->deployService->importDeployTimes(map);
importDeployTimes(map);
return true;
}
QVariantMap AbstractRemoteLinuxDeployStep::toMap() const
{
QVariantMap map = BuildStep::toMap();
map.insert(d->deployService->exportDeployTimes());
map.insert(exportDeployTimes());
return map;
}
bool AbstractRemoteLinuxDeployStep::init()
{
d->deployService->setTarget(target());
QTC_ASSERT(d->internalInit, return false);
const CheckResult canDeploy = d->internalInit();
if (!canDeploy) {
@@ -209,21 +175,8 @@ void AbstractRemoteLinuxDeployStep::doRun()
if (d->runPreparer)
d->runPreparer();
connect(d->deployService, &AbstractRemoteLinuxDeployService::errorMessage,
this, &AbstractRemoteLinuxDeployStep::handleErrorMessage);
connect(d->deployService, &AbstractRemoteLinuxDeployService::progressMessage,
this, &AbstractRemoteLinuxDeployStep::handleProgressMessage);
connect(d->deployService, &AbstractRemoteLinuxDeployService::warningMessage,
this, &AbstractRemoteLinuxDeployStep::handleWarningMessage);
connect(d->deployService, &AbstractRemoteLinuxDeployService::stdOutData,
this, &AbstractRemoteLinuxDeployStep::handleStdOutData);
connect(d->deployService, &AbstractRemoteLinuxDeployService::stdErrData,
this, &AbstractRemoteLinuxDeployStep::handleStdErrData);
connect(d->deployService, &AbstractRemoteLinuxDeployService::finished,
this, &AbstractRemoteLinuxDeployStep::handleFinished);
d->hasError = false;
d->deployService->start();
start();
}
void AbstractRemoteLinuxDeployStep::doCancel()
@@ -234,7 +187,7 @@ void AbstractRemoteLinuxDeployStep::doCancel()
emit addOutput(Tr::tr("User requests deployment to stop; cleaning up."),
OutputFormat::NormalMessage);
d->hasError = true;
d->deployService->stop();
stop();
}
void AbstractRemoteLinuxDeployStep::handleProgressMessage(const QString &message)
@@ -261,7 +214,6 @@ void AbstractRemoteLinuxDeployStep::handleFinished()
emit addOutput(Tr::tr("Deploy step failed."), OutputFormat::ErrorMessage);
else
emit addOutput(Tr::tr("Deploy step finished."), OutputFormat::NormalMessage);
disconnect(d->deployService, nullptr, this, nullptr);
emit finished(!d->hasError);
}
@@ -275,4 +227,14 @@ void AbstractRemoteLinuxDeployStep::handleStdErrData(const QString &data)
emit addOutput(data, OutputFormat::Stderr, DontAppendNewline);
}
bool AbstractRemoteLinuxDeployStep::isDeploymentNecessary() const
{
return true;
}
Tasking::Group AbstractRemoteLinuxDeployStep::deployRecipe()
{
return {};
}
} // namespace RemoteLinux