2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2018-12-14 15:41:59 +01:00
|
|
|
|
|
|
|
#include "rsyncdeploystep.h"
|
|
|
|
|
2022-08-11 13:50:36 +02:00
|
|
|
#include "abstractremotelinuxdeploystep.h"
|
2018-12-14 15:41:59 +01:00
|
|
|
#include "abstractremotelinuxdeployservice.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-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>
|
|
|
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
using namespace Utils;
|
|
|
|
|
2022-10-12 14:37:14 +03:00
|
|
|
namespace RemoteLinux {
|
2018-12-14 15:41:59 +01:00
|
|
|
|
|
|
|
class RsyncDeployService : public AbstractRemoteLinuxDeployService
|
|
|
|
{
|
|
|
|
public:
|
2022-08-11 13:50:36 +02:00
|
|
|
RsyncDeployService()
|
2022-05-12 17:32:41 +02:00
|
|
|
{
|
|
|
|
connect(&m_mkdir, &QtcProcess::done, this, [this] {
|
|
|
|
if (m_mkdir.result() != ProcessResult::FinishedWithSuccess) {
|
2022-05-25 20:08:12 +02:00
|
|
|
QString finalMessage = m_mkdir.errorString();
|
2022-06-17 14:17:14 +02:00
|
|
|
const QString stdErr = m_mkdir.cleanedStdErr();
|
2022-05-25 20:08:12 +02:00
|
|
|
if (!stdErr.isEmpty()) {
|
|
|
|
if (!finalMessage.isEmpty())
|
|
|
|
finalMessage += '\n';
|
|
|
|
finalMessage += stdErr;
|
|
|
|
}
|
2022-07-15 12:20:23 +02:00
|
|
|
emit errorMessage(Tr::tr("Deploy via rsync: failed to create remote directories:")
|
2022-05-25 20:08:12 +02:00
|
|
|
+ '\n' + finalMessage);
|
2022-05-12 17:32:41 +02:00
|
|
|
setFinished();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
deployFiles();
|
|
|
|
});
|
2022-05-25 20:08:12 +02:00
|
|
|
connect(&m_mkdir, &QtcProcess::readyReadStandardError, this, [this] {
|
|
|
|
emit stdErrData(QString::fromLocal8Bit(m_mkdir.readAllStandardError()));
|
|
|
|
});
|
2022-05-12 17:32:41 +02:00
|
|
|
connect(&m_fileTransfer, &FileTransfer::progress,
|
|
|
|
this, &AbstractRemoteLinuxDeployService::stdOutData);
|
|
|
|
connect(&m_fileTransfer, &FileTransfer::done, this, [this](const ProcessResultData &result) {
|
|
|
|
auto notifyError = [this](const QString &message) {
|
|
|
|
emit errorMessage(message);
|
|
|
|
setFinished();
|
|
|
|
};
|
|
|
|
if (result.m_error == QProcess::FailedToStart)
|
2022-07-15 12:20:23 +02:00
|
|
|
notifyError(Tr::tr("rsync failed to start: %1").arg(result.m_errorString));
|
2022-05-12 17:32:41 +02:00
|
|
|
else if (result.m_exitStatus == QProcess::CrashExit)
|
2022-07-15 12:20:23 +02:00
|
|
|
notifyError(Tr::tr("rsync crashed."));
|
2022-05-12 17:32:41 +02:00
|
|
|
else if (result.m_exitCode != 0)
|
2022-07-15 12:20:23 +02:00
|
|
|
notifyError(Tr::tr("rsync failed with exit code %1.").arg(result.m_exitCode));
|
2022-05-12 17:32:41 +02:00
|
|
|
else
|
|
|
|
setFinished();
|
|
|
|
});
|
|
|
|
}
|
2018-12-14 15:41:59 +01:00
|
|
|
|
2022-05-12 17:32:41 +02:00
|
|
|
void setDeployableFiles(const QList<DeployableFile> &files);
|
2018-12-14 15:41:59 +01:00
|
|
|
void setIgnoreMissingFiles(bool ignore) { m_ignoreMissingFiles = ignore; }
|
2019-04-23 15:57:54 +02:00
|
|
|
void setFlags(const QString &flags) { m_flags = flags; }
|
2018-12-14 15:41:59 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool isDeploymentNecessary() const override;
|
|
|
|
|
|
|
|
void doDeploy() override;
|
|
|
|
void stopDeployment() override { setFinished(); };
|
|
|
|
|
|
|
|
void createRemoteDirectories();
|
|
|
|
void deployFiles();
|
|
|
|
void setFinished();
|
|
|
|
|
2022-05-12 17:32:41 +02:00
|
|
|
mutable FilesToTransfer m_files;
|
2018-12-14 15:41:59 +01:00
|
|
|
bool m_ignoreMissingFiles = false;
|
2019-04-23 15:57:54 +02:00
|
|
|
QString m_flags;
|
2022-05-12 17:32:41 +02:00
|
|
|
QtcProcess m_mkdir;
|
|
|
|
FileTransfer m_fileTransfer;
|
2018-12-14 15:41:59 +01:00
|
|
|
};
|
|
|
|
|
2022-05-12 17:32:41 +02:00
|
|
|
void RsyncDeployService::setDeployableFiles(const QList<DeployableFile> &files)
|
|
|
|
{
|
|
|
|
for (const DeployableFile &f : files)
|
|
|
|
m_files.append({f.localFilePath(), deviceConfiguration()->filePath(f.remoteFilePath())});
|
|
|
|
}
|
|
|
|
|
2018-12-14 15:41:59 +01:00
|
|
|
bool RsyncDeployService::isDeploymentNecessary() const
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void RsyncDeployService::doDeploy()
|
|
|
|
{
|
|
|
|
createRemoteDirectories();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RsyncDeployService::createRemoteDirectories()
|
|
|
|
{
|
|
|
|
QStringList remoteDirs;
|
2022-10-07 14:46:06 +02:00
|
|
|
for (const FileToTransfer &file : std::as_const(m_files))
|
2022-05-12 17:32:41 +02:00
|
|
|
remoteDirs << file.m_target.parentDir().path();
|
2018-12-14 15:41:59 +01:00
|
|
|
remoteDirs.sort();
|
|
|
|
remoteDirs.removeDuplicates();
|
2022-06-17 13:11:56 +02:00
|
|
|
|
|
|
|
m_mkdir.setCommand({deviceConfiguration()->filePath("mkdir"), QStringList("-p") + remoteDirs});
|
2022-05-12 17:32:41 +02:00
|
|
|
m_mkdir.start();
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RsyncDeployService::deployFiles()
|
|
|
|
{
|
2022-05-12 17:32:41 +02:00
|
|
|
m_fileTransfer.setTransferMethod(FileTransferMethod::Rsync);
|
|
|
|
m_fileTransfer.setRsyncFlags(m_flags);
|
|
|
|
m_fileTransfer.setFilesToTransfer(m_files);
|
|
|
|
m_fileTransfer.start();
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RsyncDeployService::setFinished()
|
|
|
|
{
|
2022-05-12 17:32:41 +02:00
|
|
|
m_mkdir.close();
|
|
|
|
m_fileTransfer.stop();
|
2018-12-14 15:41:59 +01:00
|
|
|
handleDeploymentDone();
|
|
|
|
}
|
|
|
|
|
2022-08-11 13:50:36 +02:00
|
|
|
// RsyncDeployStep
|
2018-12-14 15:41:59 +01:00
|
|
|
|
2022-10-12 14:37:14 +03:00
|
|
|
RsyncDeployStep::RsyncDeployStep(BuildStepList *bsl, Id id)
|
2022-08-11 13:50:36 +02:00
|
|
|
: AbstractRemoteLinuxDeployStep(bsl, id)
|
2022-10-12 14:37:14 +03:00
|
|
|
{
|
|
|
|
auto service = createDeployService<RsyncDeployService>();
|
|
|
|
|
|
|
|
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([service, flags, ignoreMissingFiles] {
|
|
|
|
service->setIgnoreMissingFiles(ignoreMissingFiles->value());
|
|
|
|
service->setFlags(flags->value());
|
|
|
|
return service->isDeploymentPossible();
|
|
|
|
});
|
|
|
|
|
|
|
|
setRunPreparer([this, service] {
|
|
|
|
service->setDeployableFiles(target()->deploymentData().allFiles());
|
|
|
|
});
|
|
|
|
}
|
2018-12-14 15:41:59 +01:00
|
|
|
|
2022-10-12 14:37:14 +03:00
|
|
|
RsyncDeployStep::~RsyncDeployStep() = default;
|
2019-04-12 14:49:59 +02:00
|
|
|
|
2022-10-12 14:37:14 +03:00
|
|
|
Utils::Id RsyncDeployStep::stepId()
|
|
|
|
{
|
|
|
|
return Constants::RsyncDeployStepId;
|
|
|
|
}
|
2018-12-14 15:41:59 +01:00
|
|
|
|
2022-10-12 14:37:14 +03:00
|
|
|
QString RsyncDeployStep::displayName()
|
2018-12-14 15:41:59 +01:00
|
|
|
{
|
2022-10-12 14:37:14 +03:00
|
|
|
return Tr::tr("Deploy files via rsync");
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
2022-10-12 14:37:14 +03:00
|
|
|
} // RemoteLinux
|