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
|
2016-01-15 14:57:40 +01:00
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
#include "tarpackagedeploystep.h"
|
2011-07-07 10:43:59 +02:00
|
|
|
|
2022-06-02 18:01:30 +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"
|
2011-07-07 10:43:59 +02:00
|
|
|
|
2022-05-23 09:33:44 +02:00
|
|
|
#include <projectexplorer/deployconfiguration.h>
|
2022-05-20 17:53:20 +02:00
|
|
|
#include <projectexplorer/devicesupport/filetransfer.h>
|
2022-05-23 09:33:44 +02:00
|
|
|
#include <projectexplorer/devicesupport/idevice.h>
|
2022-06-02 18:01:30 +02:00
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
2022-05-23 09:33:44 +02:00
|
|
|
|
|
|
|
|
#include <utils/processinterface.h>
|
2022-05-27 13:39:30 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2022-05-23 09:33:44 +02:00
|
|
|
|
2011-07-07 10:43:59 +02:00
|
|
|
using namespace ProjectExplorer;
|
2022-05-23 09:33:44 +02:00
|
|
|
using namespace Utils;
|
2022-11-22 20:25:27 +01:00
|
|
|
using namespace Utils::Tasking;
|
2011-07-07 10:43:59 +02:00
|
|
|
|
2022-07-01 17:29:29 +02:00
|
|
|
namespace RemoteLinux::Internal {
|
2011-12-09 13:22:57 +01:00
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
// TarPackageDeployStep
|
|
|
|
|
|
|
|
|
|
class TarPackageDeployStep : public AbstractRemoteLinuxDeployStep
|
2022-05-27 13:39:30 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2023-03-21 16:07:20 +01:00
|
|
|
TarPackageDeployStep(BuildStepList *bsl, Id id)
|
|
|
|
|
: AbstractRemoteLinuxDeployStep(bsl, id)
|
|
|
|
|
{
|
|
|
|
|
setWidgetExpandedByDefault(false);
|
|
|
|
|
|
|
|
|
|
setInternalInitializer([this] {
|
|
|
|
|
const BuildStep *tarCreationStep = nullptr;
|
|
|
|
|
|
|
|
|
|
for (BuildStep *step : deployConfiguration()->stepList()->steps()) {
|
|
|
|
|
if (step == this)
|
|
|
|
|
break;
|
|
|
|
|
if (step->id() == Constants::TarPackageCreationStepId) {
|
|
|
|
|
tarCreationStep = step;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!tarCreationStep)
|
|
|
|
|
return CheckResult::failure(Tr::tr("No tarball creation step found."));
|
|
|
|
|
|
|
|
|
|
const FilePath tarFile =
|
|
|
|
|
FilePath::fromVariant(tarCreationStep->data(Constants::TarPackageFilePathId));
|
|
|
|
|
setPackageFilePath(tarFile);
|
|
|
|
|
return isDeploymentPossible();
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-07-01 17:29:29 +02:00
|
|
|
void setPackageFilePath(const FilePath &filePath);
|
|
|
|
|
|
|
|
|
|
private:
|
2022-11-22 20:25:27 +01:00
|
|
|
QString remoteFilePath() const;
|
2022-11-24 21:45:00 +01:00
|
|
|
bool isDeploymentNecessary() const final;
|
|
|
|
|
Group deployRecipe() final;
|
2022-11-22 20:25:27 +01:00
|
|
|
TaskItem uploadTask();
|
|
|
|
|
TaskItem installTask();
|
2022-07-01 17:29:29 +02:00
|
|
|
|
|
|
|
|
FilePath m_packageFilePath;
|
2022-05-27 13:39:30 +02:00
|
|
|
};
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
void TarPackageDeployStep::setPackageFilePath(const FilePath &filePath)
|
2022-05-23 09:33:44 +02:00
|
|
|
{
|
|
|
|
|
m_packageFilePath = filePath;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
QString TarPackageDeployStep::remoteFilePath() const
|
2022-05-23 09:33:44 +02:00
|
|
|
{
|
2022-11-22 20:25:27 +01:00
|
|
|
return QLatin1String("/tmp/") + m_packageFilePath.fileName();
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
bool TarPackageDeployStep::isDeploymentNecessary() const
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2022-05-23 09:33:44 +02:00
|
|
|
return hasLocalFileChanged(DeployableFile(m_packageFilePath, {}));
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
TaskItem TarPackageDeployStep::uploadTask()
|
2022-05-23 09:33:44 +02:00
|
|
|
{
|
2022-11-24 20:55:54 +01:00
|
|
|
const auto setupHandler = [this](FileTransfer &transfer) {
|
2022-11-22 20:25:27 +01:00
|
|
|
const FilesToTransfer files {{m_packageFilePath,
|
|
|
|
|
deviceConfiguration()->filePath(remoteFilePath())}};
|
|
|
|
|
transfer.setFilesToTransfer(files);
|
2023-03-21 16:07:20 +01:00
|
|
|
connect(&transfer, &FileTransfer::progress, this, &TarPackageDeployStep::progressMessage);
|
2022-11-22 20:25:27 +01:00
|
|
|
emit progressMessage(Tr::tr("Uploading package to device..."));
|
|
|
|
|
};
|
2022-11-24 20:55:54 +01:00
|
|
|
const auto doneHandler = [this](const FileTransfer &) {
|
2022-11-22 20:25:27 +01:00
|
|
|
emit progressMessage(Tr::tr("Successfully uploaded package file."));
|
|
|
|
|
};
|
2022-11-24 20:55:54 +01:00
|
|
|
const auto errorHandler = [this](const FileTransfer &transfer) {
|
2022-11-22 20:25:27 +01:00
|
|
|
const ProcessResultData result = transfer.resultData();
|
|
|
|
|
emit errorMessage(result.m_errorString);
|
|
|
|
|
};
|
|
|
|
|
return Transfer(setupHandler, doneHandler, errorHandler);
|
2022-05-23 09:33:44 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
TaskItem TarPackageDeployStep::installTask()
|
2022-05-23 09:33:44 +02:00
|
|
|
{
|
2022-11-24 20:55:54 +01:00
|
|
|
const auto setupHandler = [this](QtcProcess &process) {
|
2022-11-22 20:25:27 +01:00
|
|
|
const QString cmdLine = QLatin1String("cd / && tar xvf ") + remoteFilePath()
|
|
|
|
|
+ " && (rm " + remoteFilePath() + " || :)";
|
|
|
|
|
process.setCommand({deviceConfiguration()->filePath("/bin/sh"), {"-c", cmdLine}});
|
|
|
|
|
QtcProcess *proc = &process;
|
|
|
|
|
connect(proc, &QtcProcess::readyReadStandardOutput, this, [this, proc] {
|
2023-01-05 17:55:04 +01:00
|
|
|
emit stdOutData(proc->readAllStandardOutput());
|
2022-11-22 20:25:27 +01:00
|
|
|
});
|
|
|
|
|
connect(proc, &QtcProcess::readyReadStandardError, this, [this, proc] {
|
2023-01-05 17:55:04 +01:00
|
|
|
emit stdErrData(proc->readAllStandardError());
|
2022-11-22 20:25:27 +01:00
|
|
|
});
|
|
|
|
|
emit progressMessage(Tr::tr("Installing package to device..."));
|
|
|
|
|
};
|
2022-11-24 20:55:54 +01:00
|
|
|
const auto doneHandler = [this](const QtcProcess &) {
|
2022-11-22 20:25:27 +01:00
|
|
|
saveDeploymentTimeStamp(DeployableFile(m_packageFilePath, {}), {});
|
|
|
|
|
emit progressMessage(Tr::tr("Successfully installed package file."));
|
|
|
|
|
};
|
2022-11-24 20:55:54 +01:00
|
|
|
const auto errorHandler = [this](const QtcProcess &process) {
|
2022-11-22 20:25:27 +01:00
|
|
|
emit errorMessage(Tr::tr("Installing package failed.") + process.errorString());
|
|
|
|
|
};
|
|
|
|
|
return Process(setupHandler, doneHandler, errorHandler);
|
2022-05-23 09:33:44 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-21 16:07:20 +01:00
|
|
|
Group TarPackageDeployStep::deployRecipe()
|
2022-05-23 09:33:44 +02:00
|
|
|
{
|
2022-11-24 21:45:00 +01:00
|
|
|
return Group { uploadTask(), installTask() };
|
2022-05-23 09:33:44 +02:00
|
|
|
}
|
2011-07-07 10:43:59 +02:00
|
|
|
|
|
|
|
|
|
2022-06-02 18:01:30 +02:00
|
|
|
// TarPackageDeployStepFactory
|
2011-07-07 10:43:59 +02:00
|
|
|
|
2022-06-02 18:01:30 +02:00
|
|
|
TarPackageDeployStepFactory::TarPackageDeployStepFactory()
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2022-06-02 18:01:30 +02:00
|
|
|
registerStep<TarPackageDeployStep>(Constants::TarPackageDeployStepId);
|
2022-07-15 12:20:23 +02:00
|
|
|
setDisplayName(Tr::tr("Deploy tarball via SFTP upload"));
|
2022-06-02 18:01:30 +02:00
|
|
|
setSupportedConfiguration(RemoteLinux::Constants::DeployToGenericLinux);
|
|
|
|
|
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY);
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-01 17:29:29 +02:00
|
|
|
} // RemoteLinux::Internal
|