2018-12-14 15:41:59 +01:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
**
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "rsyncdeploystep.h"
|
|
|
|
|
|
|
|
#include "abstractremotelinuxdeployservice.h"
|
2020-09-16 12:08:11 +02:00
|
|
|
#include "remotelinux_constants.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>
|
2018-12-14 15:41:59 +01:00
|
|
|
#include <projectexplorer/runconfigurationaspects.h>
|
|
|
|
#include <projectexplorer/target.h>
|
|
|
|
#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;
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
class RsyncDeployService : public AbstractRemoteLinuxDeployService
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2022-02-18 12:31:19 +01:00
|
|
|
RsyncDeployService(QObject *parent = nullptr) : AbstractRemoteLinuxDeployService(parent)
|
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;
|
|
|
|
}
|
|
|
|
emit errorMessage(tr("Deploy via rsync: failed to create remote directories:")
|
|
|
|
+ '\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)
|
|
|
|
notifyError(tr("rsync failed to start: %1").arg(result.m_errorString));
|
|
|
|
else if (result.m_exitStatus == QProcess::CrashExit)
|
|
|
|
notifyError(tr("rsync crashed."));
|
|
|
|
else if (result.m_exitCode != 0)
|
|
|
|
notifyError(tr("rsync failed with exit code %1.").arg(result.m_exitCode));
|
|
|
|
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(); };
|
|
|
|
|
2022-05-12 17:32:41 +02:00
|
|
|
void filterFiles() const;
|
2018-12-14 15:41:59 +01:00
|
|
|
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-05-12 17:32:41 +02:00
|
|
|
filterFiles();
|
|
|
|
return !m_files.empty();
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RsyncDeployService::doDeploy()
|
|
|
|
{
|
|
|
|
createRemoteDirectories();
|
|
|
|
}
|
|
|
|
|
2022-05-12 17:32:41 +02:00
|
|
|
void RsyncDeployService::filterFiles() const
|
2018-12-14 15:41:59 +01:00
|
|
|
{
|
2022-05-12 17:32:41 +02:00
|
|
|
if (!m_ignoreMissingFiles)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Utils::erase(m_files, [](const FileToTransfer &file) { return !file.m_source.exists(); });
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RsyncDeployService::createRemoteDirectories()
|
|
|
|
{
|
|
|
|
QStringList remoteDirs;
|
2022-05-12 17:32:41 +02:00
|
|
|
for (const FileToTransfer &file : qAsConst(m_files))
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
RsyncDeployStep::RsyncDeployStep(BuildStepList *bsl, Utils::Id id)
|
2019-12-20 17:05:30 +01:00
|
|
|
: AbstractRemoteLinuxDeployStep(bsl, id)
|
2018-12-14 15:41:59 +01:00
|
|
|
{
|
2019-06-13 17:03:56 +02:00
|
|
|
auto service = createDeployService<Internal::RsyncDeployService>();
|
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
auto flags = addAspect<StringAspect>();
|
|
|
|
flags->setDisplayStyle(StringAspect::LineEditDisplay);
|
2019-06-07 16:43:06 +02:00
|
|
|
flags->setSettingsKey("RemoteLinux.RsyncDeployStep.Flags");
|
|
|
|
flags->setLabelText(tr("Flags:"));
|
2022-05-20 17:53:20 +02:00
|
|
|
flags->setValue(FileTransferSetupData::defaultRsyncFlags());
|
2019-06-07 16:43:06 +02:00
|
|
|
|
2020-08-13 09:16:00 +02:00
|
|
|
auto ignoreMissingFiles = addAspect<BoolAspect>();
|
2019-06-07 16:43:06 +02:00
|
|
|
ignoreMissingFiles->setSettingsKey("RemoteLinux.RsyncDeployStep.IgnoreMissingFiles");
|
2019-11-26 17:11:01 +01:00
|
|
|
ignoreMissingFiles->setLabel(tr("Ignore missing files:"),
|
2020-08-13 09:16:00 +02:00
|
|
|
BoolAspect::LabelPlacement::InExtraLabel);
|
2019-06-07 16:43:06 +02:00
|
|
|
ignoreMissingFiles->setValue(false);
|
2018-12-14 15:41:59 +01:00
|
|
|
|
2019-06-13 17:03:56 +02:00
|
|
|
setInternalInitializer([service, flags, ignoreMissingFiles] {
|
|
|
|
service->setIgnoreMissingFiles(ignoreMissingFiles->value());
|
|
|
|
service->setFlags(flags->value());
|
|
|
|
return service->isDeploymentPossible();
|
2019-06-07 16:43:06 +02:00
|
|
|
});
|
2018-12-14 15:41:59 +01:00
|
|
|
|
2019-06-13 17:03:56 +02:00
|
|
|
setRunPreparer([this, service] {
|
|
|
|
service->setDeployableFiles(target()->deploymentData().allFiles());
|
|
|
|
});
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
2019-06-13 17:03:56 +02:00
|
|
|
RsyncDeployStep::~RsyncDeployStep() = default;
|
2019-04-12 14:49:59 +02:00
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id RsyncDeployStep::stepId()
|
2018-12-14 15:41:59 +01:00
|
|
|
{
|
2020-09-16 12:08:11 +02:00
|
|
|
return Constants::RsyncDeployStepId;
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString RsyncDeployStep::displayName()
|
|
|
|
{
|
|
|
|
return tr("Deploy files via rsync");
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace RemoteLinux
|
|
|
|
|
|
|
|
#include <rsyncdeploystep.moc>
|