2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2012-07-25 17:41:01 +02:00
|
|
|
|
2011-07-07 10:43:59 +02:00
|
|
|
#include "abstractremotelinuxdeploystep.h"
|
|
|
|
|
|
2023-01-09 09:28:58 +01:00
|
|
|
#include "deploymenttimeinfo.h"
|
2022-07-15 12:20:23 +02:00
|
|
|
#include "remotelinuxtr.h"
|
2011-07-07 10:43:59 +02:00
|
|
|
|
2023-01-09 09:28:58 +01:00
|
|
|
#include <projectexplorer/deployablefile.h>
|
|
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
2023-08-11 09:18:56 +02:00
|
|
|
#include <projectexplorer/kitaspects.h>
|
2023-01-09 09:28:58 +01:00
|
|
|
|
2023-05-10 21:38:41 +02:00
|
|
|
#include <solutions/tasking/tasktree.h>
|
|
|
|
|
|
2023-01-09 09:28:58 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QDateTime>
|
2011-07-07 10:43:59 +02:00
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
2023-05-10 19:54:52 +02:00
|
|
|
using namespace Tasking;
|
2023-01-09 09:28:58 +01:00
|
|
|
using namespace Utils;
|
2011-07-07 10:43:59 +02:00
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class AbstractRemoteLinuxDeployStepPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
2023-07-07 11:40:12 +02:00
|
|
|
std::function<expected_str<void>()> internalInit;
|
2023-03-21 16:07:20 +01:00
|
|
|
|
|
|
|
|
DeploymentTimeInfo deployTimes;
|
2011-07-07 10:43:59 +02:00
|
|
|
};
|
|
|
|
|
|
2023-01-09 09:28:58 +01:00
|
|
|
} // Internal
|
|
|
|
|
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
AbstractRemoteLinuxDeployStep::AbstractRemoteLinuxDeployStep(BuildStepList *bsl, Id id)
|
2023-03-22 09:34:34 +01:00
|
|
|
: BuildStep(bsl, id), d(new AbstractRemoteLinuxDeployStepPrivate)
|
2023-07-12 23:15:26 +02:00
|
|
|
{
|
|
|
|
|
}
|
2023-01-09 09:28:58 +01:00
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
AbstractRemoteLinuxDeployStep::~AbstractRemoteLinuxDeployStep()
|
2023-01-09 09:28:58 +01:00
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
IDevice::ConstPtr AbstractRemoteLinuxDeployStep::deviceConfiguration() const
|
2023-01-09 09:28:58 +01:00
|
|
|
{
|
2023-03-21 16:07:20 +01:00
|
|
|
return DeviceKitAspect::device(kit());
|
2023-01-09 09:28:58 +01:00
|
|
|
}
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
void AbstractRemoteLinuxDeployStep::saveDeploymentTimeStamp(const DeployableFile &deployableFile,
|
2023-07-11 05:53:34 +02:00
|
|
|
const QDateTime &remoteTimestamp)
|
2023-01-09 09:28:58 +01:00
|
|
|
{
|
|
|
|
|
d->deployTimes.saveDeploymentTimeStamp(deployableFile, kit(), remoteTimestamp);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
bool AbstractRemoteLinuxDeployStep::hasLocalFileChanged(
|
2023-01-09 09:28:58 +01:00
|
|
|
const DeployableFile &deployableFile) const
|
|
|
|
|
{
|
|
|
|
|
return d->deployTimes.hasLocalFileChanged(deployableFile, kit());
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
bool AbstractRemoteLinuxDeployStep::hasRemoteFileChanged(
|
2023-01-09 09:28:58 +01:00
|
|
|
const DeployableFile &deployableFile, const QDateTime &remoteTimestamp) const
|
|
|
|
|
{
|
|
|
|
|
return d->deployTimes.hasRemoteFileChanged(deployableFile, kit(), remoteTimestamp);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-07 11:40:12 +02:00
|
|
|
expected_str<void> AbstractRemoteLinuxDeployStep::isDeploymentPossible() const
|
2023-01-09 09:28:58 +01:00
|
|
|
{
|
|
|
|
|
if (!deviceConfiguration())
|
2023-07-07 11:40:12 +02:00
|
|
|
return make_unexpected(Tr::tr("No device configuration set."));
|
|
|
|
|
return {};
|
2023-01-09 09:28:58 +01:00
|
|
|
}
|
|
|
|
|
|
2023-07-07 11:40:12 +02:00
|
|
|
void AbstractRemoteLinuxDeployStep::setInternalInitializer(
|
|
|
|
|
const std::function<expected_str<void>()> &init)
|
2019-06-07 16:43:06 +02:00
|
|
|
{
|
|
|
|
|
d->internalInit = init;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-25 13:19:26 +02:00
|
|
|
void AbstractRemoteLinuxDeployStep::fromMap(const Store &map)
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2023-07-21 18:23:50 +02:00
|
|
|
BuildStep::fromMap(map);
|
|
|
|
|
if (hasError())
|
|
|
|
|
return;
|
2023-03-22 10:05:26 +01:00
|
|
|
d->deployTimes.importDeployTimes(map);
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-25 13:19:26 +02:00
|
|
|
void AbstractRemoteLinuxDeployStep::toMap(Store &map) const
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2023-07-21 17:44:01 +02:00
|
|
|
BuildStep::toMap(map);
|
2023-03-22 10:05:26 +01:00
|
|
|
map.insert(d->deployTimes.exportDeployTimes());
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2019-01-10 15:31:44 +01:00
|
|
|
bool AbstractRemoteLinuxDeployStep::init()
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2019-06-07 16:43:06 +02:00
|
|
|
QTC_ASSERT(d->internalInit, return false);
|
2023-07-07 11:40:12 +02:00
|
|
|
const auto canDeploy = d->internalInit();
|
2019-04-24 14:38:01 +02:00
|
|
|
if (!canDeploy) {
|
2023-07-07 11:40:12 +02:00
|
|
|
emit addOutput(Tr::tr("Cannot deploy: %1").arg(canDeploy.error()),
|
2019-04-24 14:38:01 +02:00
|
|
|
OutputFormat::ErrorMessage);
|
|
|
|
|
}
|
2023-07-07 11:40:12 +02:00
|
|
|
return bool(canDeploy);
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-22 09:34:34 +01:00
|
|
|
void AbstractRemoteLinuxDeployStep::addProgressMessage(const QString &message)
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2017-01-12 10:59:12 +01:00
|
|
|
emit addOutput(message, OutputFormat::NormalMessage);
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-22 09:34:34 +01:00
|
|
|
void AbstractRemoteLinuxDeployStep::addErrorMessage(const QString &message)
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2017-01-12 10:59:12 +01:00
|
|
|
emit addOutput(message, OutputFormat::ErrorMessage);
|
2020-04-16 13:53:05 +02:00
|
|
|
emit addTask(DeploymentTask(Task::Error, message), 1); // TODO correct?
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-22 09:34:34 +01:00
|
|
|
void AbstractRemoteLinuxDeployStep::addWarningMessage(const QString &message)
|
2011-09-29 15:00:15 +02:00
|
|
|
{
|
2017-01-12 10:59:12 +01:00
|
|
|
emit addOutput(message, OutputFormat::ErrorMessage);
|
2020-04-16 13:53:05 +02:00
|
|
|
emit addTask(DeploymentTask(Task::Warning, message), 1); // TODO correct?
|
2011-09-29 15:00:15 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-07 10:43:59 +02:00
|
|
|
void AbstractRemoteLinuxDeployStep::handleStdOutData(const QString &data)
|
|
|
|
|
{
|
2017-01-12 10:59:12 +01:00
|
|
|
emit addOutput(data, OutputFormat::Stdout, DontAppendNewline);
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AbstractRemoteLinuxDeployStep::handleStdErrData(const QString &data)
|
|
|
|
|
{
|
2017-01-12 10:59:12 +01:00
|
|
|
emit addOutput(data, OutputFormat::Stderr, DontAppendNewline);
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
bool AbstractRemoteLinuxDeployStep::isDeploymentNecessary() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-10 09:25:59 +02:00
|
|
|
GroupItem AbstractRemoteLinuxDeployStep::runRecipe()
|
2023-07-10 09:09:02 +02:00
|
|
|
{
|
|
|
|
|
const auto onSetup = [this] {
|
|
|
|
|
const auto canDeploy = isDeploymentPossible();
|
|
|
|
|
if (!canDeploy) {
|
|
|
|
|
addErrorMessage(canDeploy.error());
|
|
|
|
|
return SetupResult::StopWithError;
|
|
|
|
|
}
|
|
|
|
|
if (!isDeploymentNecessary()) {
|
|
|
|
|
addProgressMessage(Tr::tr("No deployment action necessary. Skipping."));
|
|
|
|
|
return SetupResult::StopWithDone;
|
|
|
|
|
}
|
|
|
|
|
return SetupResult::Continue;
|
|
|
|
|
};
|
2023-07-12 18:10:21 +02:00
|
|
|
const auto onDone = [this] {
|
|
|
|
|
emit addOutput(Tr::tr("Deploy step finished."), OutputFormat::NormalMessage);
|
|
|
|
|
};
|
|
|
|
|
const auto onError = [this] {
|
|
|
|
|
emit addOutput(Tr::tr("Deploy step failed."), OutputFormat::ErrorMessage);
|
|
|
|
|
};
|
|
|
|
|
return Group {
|
|
|
|
|
onGroupSetup(onSetup),
|
|
|
|
|
deployRecipe(),
|
|
|
|
|
onGroupDone(onDone),
|
|
|
|
|
onGroupError(onError)
|
|
|
|
|
};
|
2023-03-21 16:07:20 +01:00
|
|
|
}
|
|
|
|
|
|
2011-07-07 10:43:59 +02:00
|
|
|
} // namespace RemoteLinux
|