2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-07-07 10:43:59 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-07-07 10:43:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-07-07 10:43:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2011-07-07 10:43:59 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2011-07-07 10:43:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
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-05-27 15:41:57 +02:00
|
|
|
#include "abstractremotelinuxdeployservice.h"
|
2020-09-16 12:08:11 +02:00
|
|
|
#include "remotelinux_constants.h"
|
2011-07-15 16:57:25 +02:00
|
|
|
#include "tarpackagecreationstep.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>
|
|
|
|
|
|
|
|
|
|
#include <utils/processinterface.h>
|
2022-05-27 13:39:30 +02:00
|
|
|
#include <utils/qtcprocess.h>
|
2022-05-23 09:33:44 +02:00
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
|
|
2011-07-07 10:43:59 +02:00
|
|
|
using namespace ProjectExplorer;
|
2022-05-23 09:33:44 +02:00
|
|
|
using namespace Utils;
|
2011-07-07 10:43:59 +02:00
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
|
|
|
|
namespace Internal {
|
2011-12-09 13:22:57 +01:00
|
|
|
|
2022-05-27 13:39:30 +02:00
|
|
|
class TarPackageInstaller : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
TarPackageInstaller(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
|
|
void installPackage(const ProjectExplorer::IDeviceConstPtr &deviceConfig,
|
|
|
|
|
const QString &packageFilePath, bool removePackageFile);
|
|
|
|
|
void cancelInstallation();
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void stdoutData(const QString &output);
|
|
|
|
|
void stderrData(const QString &output);
|
|
|
|
|
void finished(const QString &errorMsg = QString());
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
IDevice::ConstPtr m_device;
|
|
|
|
|
QtcProcess m_installer;
|
|
|
|
|
QtcProcess m_killer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TarPackageInstaller::TarPackageInstaller(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
connect(&m_installer, &QtcProcess::readyReadStandardOutput, this, [this] {
|
|
|
|
|
emit stdoutData(QString::fromUtf8(m_installer.readAllStandardOutput()));
|
|
|
|
|
});
|
|
|
|
|
connect(&m_installer, &QtcProcess::readyReadStandardError, this, [this] {
|
|
|
|
|
emit stderrData(QString::fromUtf8(m_installer.readAllStandardError()));
|
|
|
|
|
});
|
|
|
|
|
connect(&m_installer, &QtcProcess::finished, this, [this] {
|
|
|
|
|
const QString errorMessage = m_installer.result() == ProcessResult::FinishedWithSuccess
|
|
|
|
|
? QString() : tr("Installing package failed.") + m_installer.errorString();
|
|
|
|
|
emit finished(errorMessage);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TarPackageInstaller::installPackage(const IDevice::ConstPtr &deviceConfig,
|
|
|
|
|
const QString &packageFilePath, bool removePackageFile)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_installer.state() == QProcess::NotRunning, return);
|
|
|
|
|
|
|
|
|
|
m_device = deviceConfig;
|
|
|
|
|
|
|
|
|
|
QString cmdLine = QLatin1String("cd / && tar xvf ") + packageFilePath;
|
|
|
|
|
if (removePackageFile)
|
|
|
|
|
cmdLine += QLatin1String(" && (rm ") + packageFilePath + QLatin1String(" || :)");
|
|
|
|
|
m_installer.setCommand({m_device->filePath("/bin/sh"), {"-c", cmdLine}});
|
|
|
|
|
m_installer.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TarPackageInstaller::cancelInstallation()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_installer.state() != QProcess::NotRunning, return);
|
|
|
|
|
|
|
|
|
|
m_killer.setCommand({m_device->filePath("/bin/sh"), {"-c", "pkill tar"}});
|
|
|
|
|
m_killer.start();
|
|
|
|
|
m_installer.close();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
class TarPackageDeployService : public AbstractRemoteLinuxDeployService
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2022-05-23 09:33:44 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
2011-07-07 10:43:59 +02:00
|
|
|
public:
|
2022-05-27 12:31:46 +02:00
|
|
|
TarPackageDeployService();
|
2022-05-23 09:33:44 +02:00
|
|
|
void setPackageFilePath(const FilePath &filePath);
|
2011-12-09 13:22:57 +01:00
|
|
|
|
2022-05-23 09:33:44 +02:00
|
|
|
private:
|
|
|
|
|
enum State { Inactive, Uploading, Installing };
|
2011-07-07 10:43:59 +02:00
|
|
|
|
2022-05-23 09:33:44 +02:00
|
|
|
void handleUploadFinished(const ProcessResultData &resultData);
|
|
|
|
|
void handleInstallationFinished(const QString &errorMsg);
|
|
|
|
|
|
|
|
|
|
QString uploadDir() const; // Defaults to remote user's home directory.
|
|
|
|
|
|
|
|
|
|
bool isDeploymentNecessary() const override;
|
|
|
|
|
void doDeploy() override;
|
|
|
|
|
void stopDeployment() override;
|
|
|
|
|
|
|
|
|
|
void setFinished();
|
|
|
|
|
|
|
|
|
|
State m_state = Inactive;
|
|
|
|
|
FileTransfer m_uploader;
|
|
|
|
|
FilePath m_packageFilePath;
|
2022-05-27 13:39:30 +02:00
|
|
|
TarPackageInstaller m_installer;
|
2022-05-23 09:33:44 +02:00
|
|
|
};
|
2011-07-07 10:43:59 +02:00
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
TarPackageDeployService::TarPackageDeployService()
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2022-05-23 09:33:44 +02:00
|
|
|
connect(&m_uploader, &FileTransfer::done, this,
|
2022-05-27 12:31:46 +02:00
|
|
|
&TarPackageDeployService::handleUploadFinished);
|
2022-05-23 09:33:44 +02:00
|
|
|
connect(&m_uploader, &FileTransfer::progress, this,
|
2022-05-27 12:31:46 +02:00
|
|
|
&TarPackageDeployService::progressMessage);
|
2022-05-23 09:33:44 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
void TarPackageDeployService::setPackageFilePath(const FilePath &filePath)
|
2022-05-23 09:33:44 +02:00
|
|
|
{
|
|
|
|
|
m_packageFilePath = filePath;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
QString TarPackageDeployService::uploadDir() const
|
2022-05-23 09:33:44 +02:00
|
|
|
{
|
|
|
|
|
return QLatin1String("/tmp");
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
bool TarPackageDeployService::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
|
|
|
}
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
void TarPackageDeployService::doDeploy()
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2022-05-23 09:33:44 +02:00
|
|
|
QTC_ASSERT(m_state == Inactive, return);
|
|
|
|
|
|
|
|
|
|
m_state = Uploading;
|
|
|
|
|
|
|
|
|
|
const QString remoteFilePath = uploadDir() + QLatin1Char('/') + m_packageFilePath.fileName();
|
|
|
|
|
const FilesToTransfer files {{m_packageFilePath,
|
|
|
|
|
deviceConfiguration()->filePath(remoteFilePath)}};
|
|
|
|
|
m_uploader.setFilesToTransfer(files);
|
|
|
|
|
m_uploader.start();
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
void TarPackageDeployService::stopDeployment()
|
2022-05-23 09:33:44 +02:00
|
|
|
{
|
|
|
|
|
switch (m_state) {
|
|
|
|
|
case Inactive:
|
|
|
|
|
qWarning("%s: Unexpected state 'Inactive'.", Q_FUNC_INFO);
|
|
|
|
|
break;
|
|
|
|
|
case Uploading:
|
|
|
|
|
m_uploader.stop();
|
|
|
|
|
setFinished();
|
|
|
|
|
break;
|
|
|
|
|
case Installing:
|
|
|
|
|
m_installer.cancelInstallation();
|
|
|
|
|
setFinished();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
void TarPackageDeployService::handleUploadFinished(const ProcessResultData &resultData)
|
2022-05-23 09:33:44 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_state == Uploading, return);
|
|
|
|
|
|
|
|
|
|
if (resultData.m_error != QProcess::UnknownError) {
|
|
|
|
|
emit errorMessage(resultData.m_errorString);
|
|
|
|
|
setFinished();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit progressMessage(tr("Successfully uploaded package file."));
|
|
|
|
|
const QString remoteFilePath = uploadDir() + '/' + m_packageFilePath.fileName();
|
|
|
|
|
m_state = Installing;
|
|
|
|
|
emit progressMessage(tr("Installing package to device..."));
|
2022-05-27 13:39:30 +02:00
|
|
|
connect(&m_installer, &TarPackageInstaller::stdoutData,
|
2022-05-23 09:33:44 +02:00
|
|
|
this, &AbstractRemoteLinuxDeployService::stdOutData);
|
2022-05-27 13:39:30 +02:00
|
|
|
connect(&m_installer, &TarPackageInstaller::stderrData,
|
2022-05-23 09:33:44 +02:00
|
|
|
this, &AbstractRemoteLinuxDeployService::stdErrData);
|
2022-05-27 13:39:30 +02:00
|
|
|
connect(&m_installer, &TarPackageInstaller::finished,
|
2022-05-27 12:31:46 +02:00
|
|
|
this, &TarPackageDeployService::handleInstallationFinished);
|
2022-05-23 09:33:44 +02:00
|
|
|
m_installer.installPackage(deviceConfiguration(), remoteFilePath, true);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
void TarPackageDeployService::handleInstallationFinished(const QString &errorMsg)
|
2022-05-23 09:33:44 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(m_state == Installing, return);
|
|
|
|
|
|
|
|
|
|
if (errorMsg.isEmpty()) {
|
|
|
|
|
saveDeploymentTimeStamp(DeployableFile(m_packageFilePath, {}), {});
|
|
|
|
|
emit progressMessage(tr("Package installed."));
|
|
|
|
|
} else {
|
|
|
|
|
emit errorMessage(errorMsg);
|
|
|
|
|
}
|
|
|
|
|
setFinished();
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
void TarPackageDeployService::setFinished()
|
2022-05-23 09:33:44 +02:00
|
|
|
{
|
|
|
|
|
m_state = Inactive;
|
|
|
|
|
m_uploader.stop();
|
|
|
|
|
disconnect(&m_installer, nullptr, this, nullptr);
|
|
|
|
|
handleDeploymentDone();
|
|
|
|
|
}
|
2011-07-07 10:43:59 +02:00
|
|
|
|
2022-05-23 09:33:44 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
TarPackageDeployStep::TarPackageDeployStep(BuildStepList *bsl, Id id)
|
2019-12-20 17:05:30 +01:00
|
|
|
: AbstractRemoteLinuxDeployStep(bsl, id)
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2022-05-27 12:31:46 +02:00
|
|
|
auto service = createDeployService<TarPackageDeployService>();
|
2019-06-13 17:03:56 +02:00
|
|
|
|
2018-10-19 17:40:33 +02:00
|
|
|
setWidgetExpandedByDefault(false);
|
2011-07-07 10:43:59 +02:00
|
|
|
|
2019-06-13 17:03:56 +02:00
|
|
|
setInternalInitializer([this, service] {
|
2019-06-07 16:43:06 +02:00
|
|
|
const TarPackageCreationStep *pStep = nullptr;
|
|
|
|
|
|
|
|
|
|
for (BuildStep *step : deployConfiguration()->stepList()->steps()) {
|
|
|
|
|
if (step == this)
|
|
|
|
|
break;
|
2022-05-27 10:42:33 +02:00
|
|
|
if ((pStep = qobject_cast<TarPackageCreationStep *>(step)))
|
2019-06-07 16:43:06 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (!pStep)
|
|
|
|
|
return CheckResult::failure(tr("No tarball creation step found."));
|
|
|
|
|
|
2019-06-13 17:03:56 +02:00
|
|
|
service->setPackageFilePath(pStep->packageFilePath());
|
|
|
|
|
return service->isDeploymentPossible();
|
2019-06-07 16:43:06 +02:00
|
|
|
});
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
Id TarPackageDeployStep::stepId()
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
2022-05-27 12:31:46 +02:00
|
|
|
return Constants::TarPackageDeployStepId;
|
2011-07-07 10:43:59 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
QString TarPackageDeployStep::displayName()
|
2011-07-07 10:43:59 +02:00
|
|
|
{
|
|
|
|
|
return tr("Deploy tarball via SFTP upload");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //namespace RemoteLinux
|
2022-05-23 09:33:44 +02:00
|
|
|
|
2022-05-27 12:31:46 +02:00
|
|
|
#include "tarpackagedeploystep.moc"
|