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)
|
(BuildStepList *bsl, Utils::Id id)
|
||||||
: AbstractRemoteLinuxDeployStep(bsl, id)
|
: AbstractRemoteLinuxDeployStep(bsl, id)
|
||||||
{
|
{
|
||||||
auto service = createDeployService<RemoteLinuxCustomCommandDeployService>();
|
auto service = createDeployService<Internal::RemoteLinuxCustomCommandDeployService>();
|
||||||
|
|
||||||
auto commandLine = addAspect<StringAspect>();
|
auto commandLine = addAspect<StringAspect>();
|
||||||
commandLine->setSettingsKey("RemoteLinuxCustomCommandDeploymentStep.CommandLine");
|
commandLine->setSettingsKey("RemoteLinuxCustomCommandDeploymentStep.CommandLine");
|
||||||
|
@@ -26,53 +26,53 @@
|
|||||||
#include "remotelinuxcustomcommanddeployservice.h"
|
#include "remotelinuxcustomcommanddeployservice.h"
|
||||||
|
|
||||||
#include <projectexplorer/devicesupport/idevice.h>
|
#include <projectexplorer/devicesupport/idevice.h>
|
||||||
#include <ssh/sshremoteprocessrunner.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/qtcassert.h>
|
|
||||||
#include <utils/fileutils.h>
|
|
||||||
|
|
||||||
using namespace QSsh;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace RemoteLinux {
|
namespace RemoteLinux {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
namespace {
|
|
||||||
enum State { Inactive, Running };
|
|
||||||
}
|
|
||||||
|
|
||||||
class RemoteLinuxCustomCommandDeployservicePrivate
|
class RemoteLinuxCustomCommandDeployservicePrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QString commandLine;
|
QString m_commandLine;
|
||||||
State state = Inactive;
|
QtcProcess m_process;
|
||||||
SshRemoteProcessRunner *runner = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
|
|
||||||
using namespace Internal;
|
|
||||||
|
|
||||||
|
|
||||||
RemoteLinuxCustomCommandDeployService::RemoteLinuxCustomCommandDeployService(QObject *parent)
|
RemoteLinuxCustomCommandDeployService::RemoteLinuxCustomCommandDeployService(QObject *parent)
|
||||||
: AbstractRemoteLinuxDeployService(parent), d(new RemoteLinuxCustomCommandDeployservicePrivate)
|
: 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()
|
RemoteLinuxCustomCommandDeployService::~RemoteLinuxCustomCommandDeployService() = default;
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RemoteLinuxCustomCommandDeployService::setCommandLine(const QString &commandLine)
|
void RemoteLinuxCustomCommandDeployService::setCommandLine(const QString &commandLine)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(d->state == Inactive, return);
|
d->m_commandLine = commandLine;
|
||||||
|
|
||||||
d->commandLine = commandLine;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckResult RemoteLinuxCustomCommandDeployService::isDeploymentPossible() const
|
CheckResult RemoteLinuxCustomCommandDeployService::isDeploymentPossible() const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(d->state == Inactive, return CheckResult::failure());
|
if (d->m_commandLine.isEmpty())
|
||||||
|
|
||||||
if (d->commandLine.isEmpty())
|
|
||||||
return CheckResult::failure(tr("No command line given."));
|
return CheckResult::failure(tr("No command line given."));
|
||||||
|
|
||||||
return AbstractRemoteLinuxDeployService::isDeploymentPossible();
|
return AbstractRemoteLinuxDeployService::isDeploymentPossible();
|
||||||
@@ -80,57 +80,17 @@ CheckResult RemoteLinuxCustomCommandDeployService::isDeploymentPossible() const
|
|||||||
|
|
||||||
void RemoteLinuxCustomCommandDeployService::doDeploy()
|
void RemoteLinuxCustomCommandDeployService::doDeploy()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(d->state == Inactive, handleDeploymentDone());
|
emit progressMessage(tr("Starting remote command \"%1\"...").arg(d->m_commandLine));
|
||||||
|
d->m_process.setCommand({deviceConfiguration()->mapToGlobalPath("/bin/sh"),
|
||||||
if (!d->runner)
|
{"-c", d->m_commandLine}});
|
||||||
d->runner = new SshRemoteProcessRunner(this);
|
d->m_process.start();
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteLinuxCustomCommandDeployService::stopDeployment()
|
void RemoteLinuxCustomCommandDeployService::stopDeployment()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(d->state == Running, return);
|
d->m_process.close();
|
||||||
|
|
||||||
disconnect(d->runner, nullptr, this, nullptr);
|
|
||||||
d->runner->cancel();
|
|
||||||
d->state = Inactive;
|
|
||||||
handleDeploymentDone();
|
handleDeploymentDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteLinuxCustomCommandDeployService::handleStdout()
|
} // namespace Internal
|
||||||
{
|
|
||||||
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 RemoteLinux
|
} // namespace RemoteLinux
|
||||||
|
@@ -28,10 +28,11 @@
|
|||||||
#include "abstractremotelinuxdeployservice.h"
|
#include "abstractremotelinuxdeployservice.h"
|
||||||
|
|
||||||
namespace RemoteLinux {
|
namespace RemoteLinux {
|
||||||
namespace Internal { class RemoteLinuxCustomCommandDeployservicePrivate; }
|
namespace Internal {
|
||||||
|
|
||||||
class REMOTELINUX_EXPORT RemoteLinuxCustomCommandDeployService
|
class RemoteLinuxCustomCommandDeployservicePrivate;
|
||||||
: public AbstractRemoteLinuxDeployService
|
|
||||||
|
class RemoteLinuxCustomCommandDeployService : public AbstractRemoteLinuxDeployService
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@@ -48,11 +49,8 @@ protected:
|
|||||||
void stopDeployment() override;
|
void stopDeployment() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleStdout();
|
std::unique_ptr<Internal::RemoteLinuxCustomCommandDeployservicePrivate> d;
|
||||||
void handleStderr();
|
|
||||||
void handleProcessClosed();
|
|
||||||
|
|
||||||
Internal::RemoteLinuxCustomCommandDeployservicePrivate *d;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
} // namespace RemoteLinux
|
} // namespace RemoteLinux
|
||||||
|
Reference in New Issue
Block a user