2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2018 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
|
2018-12-14 15:41:59 +01:00
|
|
|
|
|
|
|
#include "rsyncdeploystep.h"
|
|
|
|
|
2022-07-01 16:42:37 +02:00
|
|
|
#include "abstractremotelinuxdeploystep.h"
|
2020-09-16 12:08:11 +02:00
|
|
|
#include "remotelinux_constants.h"
|
2022-07-15 12:20:23 +02:00
|
|
|
#include "remotelinuxtr.h"
|
2018-12-14 15:41:59 +01:00
|
|
|
|
|
|
|
#include <projectexplorer/deploymentdata.h>
|
2022-05-20 17:53:20 +02:00
|
|
|
#include <projectexplorer/devicesupport/filetransfer.h>
|
2022-05-03 00:38:11 +02:00
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
2022-10-13 14:14:51 +02:00
|
|
|
#include <projectexplorer/kitinformation.h>
|
2022-08-11 13:50:36 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2018-12-14 15:41:59 +01:00
|
|
|
#include <projectexplorer/runconfigurationaspects.h>
|
|
|
|
#include <projectexplorer/target.h>
|
2022-07-15 12:20:23 +02:00
|
|
|
|
2018-12-14 15:41:59 +01:00
|
|
|
#include <utils/algorithm.h>
|
2022-05-12 17:32:41 +02:00
|
|
|
#include <utils/processinterface.h>
|
2018-12-14 15:41:59 +01:00
|
|
|
#include <utils/qtcprocess.h>
|
2023-03-29 08:09:49 +02:00
|
|
|
#include <utils/tasktree.h>
|
2018-12-14 15:41:59 +01:00
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
using namespace Utils;
|
2022-11-22 12:29:02 +01:00
|
|
|
using namespace Utils::Tasking;
|
2018-12-14 15:41:59 +01:00
|
|
|
|
2022-10-12 14:37:14 +03:00
|
|
|
namespace RemoteLinux {
|
2018-12-14 15:41:59 +01:00
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
// RsyncDeployStep
|
|
|
|
|
2023-03-29 08:09:49 +02:00
|
|
|
class RsyncDeployStep : public AbstractRemoteLinuxDeployStep
|
|
|
|
{
|
|
|
|
public:
|
2023-04-06 12:11:41 +02:00
|
|
|
RsyncDeployStep(BuildStepList *bsl, Id id);
|
2023-03-29 08:09:49 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool isDeploymentNecessary() const final;
|
2023-04-06 12:11:41 +02:00
|
|
|
Tasking::Group deployRecipe() final;
|
|
|
|
Tasking::TaskItem mkdirTask();
|
|
|
|
Tasking::TaskItem transferTask();
|
2023-03-29 08:09:49 +02:00
|
|
|
|
2023-04-06 12:11:41 +02:00
|
|
|
mutable FilesToTransfer m_files;
|
2023-03-29 08:09:49 +02:00
|
|
|
bool m_ignoreMissingFiles = false;
|
|
|
|
QString m_flags;
|
|
|
|
};
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
RsyncDeployStep::RsyncDeployStep(BuildStepList *bsl, Id id)
|
|
|
|
: AbstractRemoteLinuxDeployStep(bsl, id)
|
2018-12-14 15:41:59 +01:00
|
|
|
{
|
2023-03-21 16:07:20 +01:00
|
|
|
auto flags = addAspect<StringAspect>();
|
|
|
|
flags->setDisplayStyle(StringAspect::LineEditDisplay);
|
|
|
|
flags->setSettingsKey("RemoteLinux.RsyncDeployStep.Flags");
|
|
|
|
flags->setLabelText(Tr::tr("Flags:"));
|
|
|
|
flags->setValue(FileTransferSetupData::defaultRsyncFlags());
|
|
|
|
|
|
|
|
auto ignoreMissingFiles = addAspect<BoolAspect>();
|
|
|
|
ignoreMissingFiles->setSettingsKey("RemoteLinux.RsyncDeployStep.IgnoreMissingFiles");
|
|
|
|
ignoreMissingFiles->setLabel(Tr::tr("Ignore missing files:"),
|
|
|
|
BoolAspect::LabelPlacement::InExtraLabel);
|
|
|
|
ignoreMissingFiles->setValue(false);
|
|
|
|
|
|
|
|
setInternalInitializer([this, ignoreMissingFiles, flags] {
|
|
|
|
if (BuildDeviceKitAspect::device(kit()) == DeviceKitAspect::device(kit())) {
|
|
|
|
// rsync transfer on the same device currently not implemented
|
|
|
|
// and typically not wanted.
|
|
|
|
return CheckResult::failure(
|
|
|
|
Tr::tr("rsync is only supported for transfers between different devices."));
|
|
|
|
}
|
2023-03-22 10:25:25 +01:00
|
|
|
m_ignoreMissingFiles = ignoreMissingFiles->value();
|
|
|
|
m_flags = flags->value();
|
2023-03-21 16:07:20 +01:00
|
|
|
return isDeploymentPossible();
|
|
|
|
});
|
|
|
|
|
|
|
|
setRunPreparer([this] {
|
2023-03-22 10:25:25 +01:00
|
|
|
const QList<DeployableFile> files = target()->deploymentData().allFiles();
|
|
|
|
m_files.clear();
|
|
|
|
for (const DeployableFile &f : files)
|
|
|
|
m_files.append({f.localFilePath(), deviceConfiguration()->filePath(f.remoteFilePath())});
|
2023-03-21 16:07:20 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsyncDeployStep::isDeploymentNecessary() const
|
2018-12-14 15:41:59 +01:00
|
|
|
{
|
2022-07-01 16:42:37 +02:00
|
|
|
if (m_ignoreMissingFiles)
|
|
|
|
Utils::erase(m_files, [](const FileToTransfer &file) { return !file.m_source.exists(); });
|
2022-05-12 17:32:41 +02:00
|
|
|
return !m_files.empty();
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
TaskItem RsyncDeployStep::mkdirTask()
|
2018-12-14 15:41:59 +01:00
|
|
|
{
|
2022-11-24 20:55:54 +01:00
|
|
|
const auto setupHandler = [this](QtcProcess &process) {
|
2022-11-22 12:29:02 +01:00
|
|
|
QStringList remoteDirs;
|
|
|
|
for (const FileToTransfer &file : std::as_const(m_files))
|
|
|
|
remoteDirs << file.m_target.parentDir().path();
|
|
|
|
remoteDirs.sort();
|
|
|
|
remoteDirs.removeDuplicates();
|
|
|
|
process.setCommand({deviceConfiguration()->filePath("mkdir"),
|
|
|
|
QStringList("-p") + remoteDirs});
|
|
|
|
connect(&process, &QtcProcess::readyReadStandardError, this, [this, proc = &process] {
|
2023-03-22 09:34:34 +01:00
|
|
|
handleStdErrData(QString::fromLocal8Bit(proc->readAllRawStandardError()));
|
2022-11-22 12:29:02 +01:00
|
|
|
});
|
|
|
|
};
|
2022-11-24 20:55:54 +01:00
|
|
|
const auto errorHandler = [this](const QtcProcess &process) {
|
2022-11-22 12:29:02 +01:00
|
|
|
QString finalMessage = process.errorString();
|
|
|
|
const QString stdErr = process.cleanedStdErr();
|
|
|
|
if (!stdErr.isEmpty()) {
|
|
|
|
if (!finalMessage.isEmpty())
|
|
|
|
finalMessage += '\n';
|
|
|
|
finalMessage += stdErr;
|
|
|
|
}
|
2023-03-22 09:34:34 +01:00
|
|
|
addErrorMessage(Tr::tr("Deploy via rsync: failed to create remote directories:")
|
|
|
|
+ '\n' + finalMessage);
|
2022-11-22 12:29:02 +01:00
|
|
|
};
|
2023-05-03 14:06:15 +02:00
|
|
|
return ProcessTask(setupHandler, {}, errorHandler);
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
TaskItem RsyncDeployStep::transferTask()
|
2018-12-14 15:41:59 +01:00
|
|
|
{
|
2022-11-24 20:55:54 +01:00
|
|
|
const auto setupHandler = [this](FileTransfer &transfer) {
|
2022-11-22 12:29:02 +01:00
|
|
|
transfer.setTransferMethod(FileTransferMethod::Rsync);
|
|
|
|
transfer.setRsyncFlags(m_flags);
|
|
|
|
transfer.setFilesToTransfer(m_files);
|
|
|
|
connect(&transfer, &FileTransfer::progress,
|
2023-03-22 09:34:34 +01:00
|
|
|
this, &AbstractRemoteLinuxDeployStep::handleStdOutData);
|
2022-11-22 12:29:02 +01:00
|
|
|
};
|
2022-11-24 20:55:54 +01:00
|
|
|
const auto errorHandler = [this](const FileTransfer &transfer) {
|
2022-11-22 12:29:02 +01:00
|
|
|
const ProcessResultData result = transfer.resultData();
|
2023-01-24 18:11:19 +01:00
|
|
|
if (result.m_error == QProcess::FailedToStart) {
|
2023-03-22 09:34:34 +01:00
|
|
|
addErrorMessage(Tr::tr("rsync failed to start: %1").arg(result.m_errorString));
|
2023-01-24 18:11:19 +01:00
|
|
|
} else if (result.m_exitStatus == QProcess::CrashExit) {
|
2023-03-22 09:34:34 +01:00
|
|
|
addErrorMessage(Tr::tr("rsync crashed."));
|
2023-01-24 18:11:19 +01:00
|
|
|
} else if (result.m_exitCode != 0) {
|
2023-03-22 09:34:34 +01:00
|
|
|
addErrorMessage(Tr::tr("rsync failed with exit code %1.").arg(result.m_exitCode)
|
|
|
|
+ "\n" + result.m_errorString);
|
2023-01-24 18:11:19 +01:00
|
|
|
}
|
2022-11-22 12:29:02 +01:00
|
|
|
};
|
|
|
|
return Transfer(setupHandler, {}, errorHandler);
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
Group RsyncDeployStep::deployRecipe()
|
2018-12-14 15:41:59 +01:00
|
|
|
{
|
2022-11-24 21:45:00 +01:00
|
|
|
return Group { mkdirTask(), transferTask() };
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
2023-03-24 17:45:44 +01:00
|
|
|
// Factory
|
|
|
|
|
|
|
|
RsyncDeployStepFactory::RsyncDeployStepFactory()
|
|
|
|
{
|
|
|
|
registerStep<RsyncDeployStep>(Constants::RsyncDeployStepId);
|
|
|
|
setDisplayName(Tr::tr("Deploy files via rsync"));
|
|
|
|
}
|
|
|
|
|
2022-10-12 14:37:14 +03:00
|
|
|
} // RemoteLinux
|