LinuxDevice: Implement shared ssh connection

Change-Id: I1897f0a468e477e0be61767d4bad0086d59fb075
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2022-02-14 18:37:56 +01:00
parent c81a7b5c70
commit 8d2c9aa8d4
7 changed files with 876 additions and 75 deletions

View File

@@ -36,6 +36,8 @@
#include <projectexplorer/devicesupport/sshdeviceprocess.h>
#include <projectexplorer/runcontrol.h>
#include <remotelinux/sshprocessinterface.h>
#include <ssh/sshconnection.h>
#include <utils/port.h>
#include <utils/qtcassert.h>
@@ -47,11 +49,63 @@
#include <QThread>
using namespace ProjectExplorer;
using namespace RemoteLinux;
using namespace Utils;
namespace Qnx {
namespace Internal {
class QnxProcessImpl final : public SshProcessInterface
{
public:
QnxProcessImpl(const LinuxDevice *linuxDevice);
~QnxProcessImpl() { killIfRunning(); }
private:
QString fullCommandLine(const CommandLine &commandLine) const final;
QString pidArgumentForKill() const final;
const QString m_pidFile;
};
static std::atomic_int s_pidFileCounter = 1;
QnxProcessImpl::QnxProcessImpl(const LinuxDevice *linuxDevice)
: SshProcessInterface(linuxDevice)
, m_pidFile(QString::fromLatin1("/var/run/qtc.%1.pid").arg(s_pidFileCounter.fetch_add(1)))
{
}
QString QnxProcessImpl::fullCommandLine(const CommandLine &commandLine) const
{
QStringList args = ProcessArgs::splitArgs(commandLine.arguments());
args.prepend(commandLine.executable().toString());
const QString cmd = ProcessArgs::createUnixArgs(args).toString();
QString fullCommandLine =
"test -f /etc/profile && . /etc/profile ; "
"test -f $HOME/profile && . $HOME/profile ; ";
if (!m_setup.m_workingDirectory.isEmpty())
fullCommandLine += QString::fromLatin1("cd %1 ; ").arg(
ProcessArgs::quoteArg(m_setup.m_workingDirectory.toString()));
const Environment env = m_setup.m_remoteEnvironment;
for (auto it = env.constBegin(); it != env.constEnd(); ++it) {
fullCommandLine += QString::fromLatin1("%1='%2' ")
.arg(env.key(it)).arg(env.expandedValueForKey(env.key(it)));
}
fullCommandLine += QString::fromLatin1("%1 & echo $! > %2").arg(cmd).arg(m_pidFile);
return fullCommandLine;
}
QString QnxProcessImpl::pidArgumentForKill() const
{
return QString::fromLatin1("`cat %1`").arg(m_pidFile);
}
const char QnxVersionKey[] = "QnxVersion";
class QnxPortsGatheringMethod : public PortsGatheringMethod
@@ -130,12 +184,12 @@ void QnxDevice::updateVersionNumber() const
void QnxDevice::fromMap(const QVariantMap &map)
{
m_versionNumber = map.value(QLatin1String(QnxVersionKey), 0).toInt();
RemoteLinux::LinuxDevice::fromMap(map);
LinuxDevice::fromMap(map);
}
QVariantMap QnxDevice::toMap() const
{
QVariantMap map(RemoteLinux::LinuxDevice::toMap());
QVariantMap map(LinuxDevice::toMap());
map.insert(QLatin1String(QnxVersionKey), m_versionNumber);
return map;
}
@@ -160,6 +214,11 @@ QtcProcess *QnxDevice::createProcess(QObject *parent) const
return new QnxDeviceProcess(sharedFromThis(), parent);
}
Utils::ProcessInterface *QnxDevice::createProcessInterface() const
{
return new QnxProcessImpl(this);
}
DeviceProcessSignalOperation::Ptr QnxDevice::signalOperation() const
{
return DeviceProcessSignalOperation::Ptr(