forked from qt-creator/qt-creator
RemoteLinuxCustomCommandDeployService: Don't use SshRemoteProcessRunner
Use QtcProcess with a path on device instead. Make the RemoteLinuxCustomCommandDeployService class internal and don't export it. Change-Id: Iac02f3a8ab5a5f2e3647c95c6710dbe3f9b4994f Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -39,7 +39,7 @@ RemoteLinuxCustomCommandDeploymentStep::RemoteLinuxCustomCommandDeploymentStep
|
||||
(BuildStepList *bsl, Utils::Id id)
|
||||
: AbstractRemoteLinuxDeployStep(bsl, id)
|
||||
{
|
||||
auto service = createDeployService<RemoteLinuxCustomCommandDeployService>();
|
||||
auto service = createDeployService<Internal::RemoteLinuxCustomCommandDeployService>();
|
||||
|
||||
auto commandLine = addAspect<StringAspect>();
|
||||
commandLine->setSettingsKey("RemoteLinuxCustomCommandDeploymentStep.CommandLine");
|
||||
|
@@ -26,53 +26,53 @@
|
||||
#include "remotelinuxcustomcommanddeployservice.h"
|
||||
|
||||
#include <projectexplorer/devicesupport/idevice.h>
|
||||
#include <ssh/sshremoteprocessrunner.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
using namespace QSsh;
|
||||
using namespace Utils;
|
||||
|
||||
namespace RemoteLinux {
|
||||
namespace Internal {
|
||||
namespace {
|
||||
enum State { Inactive, Running };
|
||||
}
|
||||
|
||||
class RemoteLinuxCustomCommandDeployservicePrivate
|
||||
{
|
||||
public:
|
||||
QString commandLine;
|
||||
State state = Inactive;
|
||||
SshRemoteProcessRunner *runner = nullptr;
|
||||
QString m_commandLine;
|
||||
QtcProcess m_process;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
using namespace Internal;
|
||||
|
||||
|
||||
RemoteLinuxCustomCommandDeployService::RemoteLinuxCustomCommandDeployService(QObject *parent)
|
||||
: AbstractRemoteLinuxDeployService(parent), d(new RemoteLinuxCustomCommandDeployservicePrivate)
|
||||
{
|
||||
connect(&d->m_process, &QtcProcess::readyReadStandardOutput, this, [this] {
|
||||
emit stdOutData(QString::fromUtf8(d->m_process.readAllStandardOutput()));
|
||||
});
|
||||
connect(&d->m_process, &QtcProcess::readyReadStandardError, this, [this] {
|
||||
emit stdErrData(QString::fromUtf8(d->m_process.readAllStandardError()));
|
||||
});
|
||||
connect(&d->m_process, &QtcProcess::done, this, [this] {
|
||||
if (d->m_process.error() != QProcess::UnknownError
|
||||
|| d->m_process.exitStatus() != QProcess::NormalExit) {
|
||||
emit errorMessage(tr("Remote process failed: %1").arg(d->m_process.errorString()));
|
||||
} else if (d->m_process.exitCode() != 0) {
|
||||
emit errorMessage(tr("Remote process finished with exit code %1.")
|
||||
.arg(d->m_process.exitCode()));
|
||||
} else {
|
||||
emit progressMessage(tr("Remote command finished successfully."));
|
||||
}
|
||||
stopDeployment();
|
||||
});
|
||||
}
|
||||
|
||||
RemoteLinuxCustomCommandDeployService::~RemoteLinuxCustomCommandDeployService()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
RemoteLinuxCustomCommandDeployService::~RemoteLinuxCustomCommandDeployService() = default;
|
||||
|
||||
void RemoteLinuxCustomCommandDeployService::setCommandLine(const QString &commandLine)
|
||||
{
|
||||
QTC_ASSERT(d->state == Inactive, return);
|
||||
|
||||
d->commandLine = commandLine;
|
||||
d->m_commandLine = commandLine;
|
||||
}
|
||||
|
||||
CheckResult RemoteLinuxCustomCommandDeployService::isDeploymentPossible() const
|
||||
{
|
||||
QTC_ASSERT(d->state == Inactive, return CheckResult::failure());
|
||||
|
||||
if (d->commandLine.isEmpty())
|
||||
if (d->m_commandLine.isEmpty())
|
||||
return CheckResult::failure(tr("No command line given."));
|
||||
|
||||
return AbstractRemoteLinuxDeployService::isDeploymentPossible();
|
||||
@@ -80,57 +80,17 @@ CheckResult RemoteLinuxCustomCommandDeployService::isDeploymentPossible() const
|
||||
|
||||
void RemoteLinuxCustomCommandDeployService::doDeploy()
|
||||
{
|
||||
QTC_ASSERT(d->state == Inactive, handleDeploymentDone());
|
||||
|
||||
if (!d->runner)
|
||||
d->runner = new SshRemoteProcessRunner(this);
|
||||
connect(d->runner, &SshRemoteProcessRunner::readyReadStandardOutput,
|
||||
this, &RemoteLinuxCustomCommandDeployService::handleStdout);
|
||||
connect(d->runner, &SshRemoteProcessRunner::readyReadStandardError,
|
||||
this, &RemoteLinuxCustomCommandDeployService::handleStderr);
|
||||
connect(d->runner, &SshRemoteProcessRunner::finished,
|
||||
this, &RemoteLinuxCustomCommandDeployService::handleProcessClosed);
|
||||
|
||||
emit progressMessage(tr("Starting remote command \"%1\"...").arg(d->commandLine));
|
||||
d->state = Running;
|
||||
d->runner->run(d->commandLine, deviceConfiguration()->sshParameters());
|
||||
emit progressMessage(tr("Starting remote command \"%1\"...").arg(d->m_commandLine));
|
||||
d->m_process.setCommand({deviceConfiguration()->mapToGlobalPath("/bin/sh"),
|
||||
{"-c", d->m_commandLine}});
|
||||
d->m_process.start();
|
||||
}
|
||||
|
||||
void RemoteLinuxCustomCommandDeployService::stopDeployment()
|
||||
{
|
||||
QTC_ASSERT(d->state == Running, return);
|
||||
|
||||
disconnect(d->runner, nullptr, this, nullptr);
|
||||
d->runner->cancel();
|
||||
d->state = Inactive;
|
||||
d->m_process.close();
|
||||
handleDeploymentDone();
|
||||
}
|
||||
|
||||
void RemoteLinuxCustomCommandDeployService::handleStdout()
|
||||
{
|
||||
emit stdOutData(QString::fromUtf8(d->runner->readAllStandardOutput()));
|
||||
}
|
||||
|
||||
void RemoteLinuxCustomCommandDeployService::handleStderr()
|
||||
{
|
||||
emit stdErrData(QString::fromUtf8(d->runner->readAllStandardError()));
|
||||
}
|
||||
|
||||
void RemoteLinuxCustomCommandDeployService::handleProcessClosed()
|
||||
{
|
||||
const QString error = d->runner->errorString();
|
||||
QTC_ASSERT(d->state == Running, return);
|
||||
|
||||
if (!error.isEmpty()) {
|
||||
emit errorMessage(tr("Remote process failed: %1").arg(error));
|
||||
} else if (d->runner->exitCode() != 0) {
|
||||
emit errorMessage(tr("Remote process finished with exit code %1.")
|
||||
.arg(d->runner->exitCode()));
|
||||
} else {
|
||||
emit progressMessage(tr("Remote command finished successfully."));
|
||||
}
|
||||
|
||||
stopDeployment();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace RemoteLinux
|
||||
|
@@ -28,10 +28,11 @@
|
||||
#include "abstractremotelinuxdeployservice.h"
|
||||
|
||||
namespace RemoteLinux {
|
||||
namespace Internal { class RemoteLinuxCustomCommandDeployservicePrivate; }
|
||||
namespace Internal {
|
||||
|
||||
class REMOTELINUX_EXPORT RemoteLinuxCustomCommandDeployService
|
||||
: public AbstractRemoteLinuxDeployService
|
||||
class RemoteLinuxCustomCommandDeployservicePrivate;
|
||||
|
||||
class RemoteLinuxCustomCommandDeployService : public AbstractRemoteLinuxDeployService
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@@ -48,11 +49,8 @@ protected:
|
||||
void stopDeployment() override;
|
||||
|
||||
private:
|
||||
void handleStdout();
|
||||
void handleStderr();
|
||||
void handleProcessClosed();
|
||||
|
||||
Internal::RemoteLinuxCustomCommandDeployservicePrivate *d;
|
||||
std::unique_ptr<Internal::RemoteLinuxCustomCommandDeployservicePrivate> d;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace RemoteLinux
|
||||
|
Reference in New Issue
Block a user