forked from qt-creator/qt-creator
RemoteLinux: Rework TarPackage related build steps
Change-Id: I13c27e89186ab5451e1f11cf3cf28cfd9ed10a9d Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
#include "abstractremotelinuxdeploystep.h"
|
||||
#include "remotelinux_constants.h"
|
||||
#include "remotelinuxtr.h"
|
||||
#include "tarpackagecreationstep.h"
|
||||
|
||||
#include <projectexplorer/deployconfiguration.h>
|
||||
#include <projectexplorer/devicesupport/filetransfer.h>
|
||||
@@ -22,74 +21,10 @@
|
||||
using namespace ProjectExplorer;
|
||||
using namespace Utils;
|
||||
|
||||
namespace RemoteLinux {
|
||||
namespace Internal {
|
||||
|
||||
class TarPackageInstaller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TarPackageInstaller();
|
||||
|
||||
void installPackage(const 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()
|
||||
{
|
||||
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::done, this, [this] {
|
||||
const QString errorMessage = m_installer.result() == ProcessResult::FinishedWithSuccess
|
||||
? QString() : Tr::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();
|
||||
}
|
||||
namespace RemoteLinux::Internal {
|
||||
|
||||
class TarPackageDeployService : public AbstractRemoteLinuxDeployService
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TarPackageDeployService();
|
||||
void setPackageFilePath(const FilePath &filePath);
|
||||
@@ -108,10 +43,18 @@ private:
|
||||
|
||||
void setFinished();
|
||||
|
||||
void installPackage(const IDeviceConstPtr &deviceConfig,
|
||||
const QString &packageFilePath,
|
||||
bool removePackageFile);
|
||||
void cancelInstallation();
|
||||
|
||||
State m_state = Inactive;
|
||||
FileTransfer m_uploader;
|
||||
FilePath m_packageFilePath;
|
||||
TarPackageInstaller m_installer;
|
||||
|
||||
IDevice::ConstPtr m_device;
|
||||
QtcProcess m_installer;
|
||||
QtcProcess m_killer;
|
||||
};
|
||||
|
||||
TarPackageDeployService::TarPackageDeployService()
|
||||
@@ -120,6 +63,41 @@ TarPackageDeployService::TarPackageDeployService()
|
||||
&TarPackageDeployService::handleUploadFinished);
|
||||
connect(&m_uploader, &FileTransfer::progress, this,
|
||||
&TarPackageDeployService::progressMessage);
|
||||
|
||||
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::done, this, [this] {
|
||||
const QString errorMessage = m_installer.result() == ProcessResult::FinishedWithSuccess
|
||||
? QString() : Tr::tr("Installing package failed.") + m_installer.errorString();
|
||||
handleInstallationFinished(errorMessage);
|
||||
});
|
||||
}
|
||||
|
||||
void TarPackageDeployService::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 TarPackageDeployService::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();
|
||||
}
|
||||
|
||||
void TarPackageDeployService::setPackageFilePath(const FilePath &filePath)
|
||||
@@ -161,7 +139,7 @@ void TarPackageDeployService::stopDeployment()
|
||||
setFinished();
|
||||
break;
|
||||
case Installing:
|
||||
m_installer.cancelInstallation();
|
||||
cancelInstallation();
|
||||
setFinished();
|
||||
break;
|
||||
}
|
||||
@@ -181,13 +159,8 @@ void TarPackageDeployService::handleUploadFinished(const ProcessResultData &resu
|
||||
const QString remoteFilePath = uploadDir() + '/' + m_packageFilePath.fileName();
|
||||
m_state = Installing;
|
||||
emit progressMessage(Tr::tr("Installing package to device..."));
|
||||
connect(&m_installer, &TarPackageInstaller::stdoutData,
|
||||
this, &AbstractRemoteLinuxDeployService::stdOutData);
|
||||
connect(&m_installer, &TarPackageInstaller::stderrData,
|
||||
this, &AbstractRemoteLinuxDeployService::stdErrData);
|
||||
connect(&m_installer, &TarPackageInstaller::finished,
|
||||
this, &TarPackageDeployService::handleInstallationFinished);
|
||||
m_installer.installPackage(deviceConfiguration(), remoteFilePath, true);
|
||||
|
||||
installPackage(deviceConfiguration(), remoteFilePath, true);
|
||||
}
|
||||
|
||||
void TarPackageDeployService::handleInstallationFinished(const QString &errorMsg)
|
||||
@@ -224,18 +197,22 @@ public:
|
||||
setWidgetExpandedByDefault(false);
|
||||
|
||||
setInternalInitializer([this, service] {
|
||||
const TarPackageCreationStep *pStep = nullptr;
|
||||
const BuildStep *tarCreationStep = nullptr;
|
||||
|
||||
for (BuildStep *step : deployConfiguration()->stepList()->steps()) {
|
||||
if (step == this)
|
||||
break;
|
||||
if ((pStep = qobject_cast<TarPackageCreationStep *>(step)))
|
||||
if (step->id() == Constants::TarPackageCreationStepId) {
|
||||
tarCreationStep = step;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!pStep)
|
||||
if (!tarCreationStep)
|
||||
return CheckResult::failure(Tr::tr("No tarball creation step found."));
|
||||
|
||||
service->setPackageFilePath(pStep->packageFilePath());
|
||||
const FilePath tarFile =
|
||||
FilePath::fromVariant(tarCreationStep->data(Constants::TarPackageFilePathId));
|
||||
service->setPackageFilePath(tarFile);
|
||||
return service->isDeploymentPossible();
|
||||
});
|
||||
}
|
||||
@@ -252,7 +229,4 @@ TarPackageDeployStepFactory::TarPackageDeployStepFactory()
|
||||
setSupportedStepList(ProjectExplorer::Constants::BUILDSTEPS_DEPLOY);
|
||||
}
|
||||
|
||||
} // Internal
|
||||
} // RemoteLinux
|
||||
|
||||
#include "tarpackagedeploystep.moc"
|
||||
} // RemoteLinux::Internal
|
||||
|
||||
Reference in New Issue
Block a user