forked from qt-creator/qt-creator
ProjectExplorer: Base DeviceProcess on QtcProcess
... instead of having a member. Change-Id: I75e8d7600eb17c7528fe9525d2e1aa871b282ad9 Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -126,8 +126,8 @@ public:
|
|||||||
void setAbortOnMetaChars(bool abort);
|
void setAbortOnMetaChars(bool abort);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void terminate();
|
virtual void terminate();
|
||||||
void interrupt();
|
virtual void interrupt();
|
||||||
|
|
||||||
static bool startDetached(const CommandLine &cmd, const FilePath &workingDirectory = {},
|
static bool startDetached(const CommandLine &cmd, const FilePath &workingDirectory = {},
|
||||||
qint64 *pid = nullptr);
|
qint64 *pid = nullptr);
|
||||||
@@ -175,7 +175,7 @@ public:
|
|||||||
|
|
||||||
QByteArray rawStdOut() const;
|
QByteArray rawStdOut() const;
|
||||||
|
|
||||||
int exitCode() const;
|
virtual int exitCode() const;
|
||||||
|
|
||||||
QString exitMessage();
|
QString exitMessage();
|
||||||
|
|
||||||
@@ -195,10 +195,10 @@ public:
|
|||||||
void setProcessChannelMode(QProcess::ProcessChannelMode mode);
|
void setProcessChannelMode(QProcess::ProcessChannelMode mode);
|
||||||
|
|
||||||
QProcess::ProcessError error() const;
|
QProcess::ProcessError error() const;
|
||||||
QProcess::ProcessState state() const;
|
virtual QProcess::ProcessState state() const;
|
||||||
bool isRunning() const; // Short for state() == QProcess::Running.
|
bool isRunning() const; // Short for state() == QProcess::Running.
|
||||||
|
|
||||||
QString errorString() const;
|
virtual QString errorString() const;
|
||||||
void setErrorString(const QString &str);
|
void setErrorString(const QString &str);
|
||||||
|
|
||||||
qint64 processId() const;
|
qint64 processId() const;
|
||||||
@@ -207,14 +207,14 @@ public:
|
|||||||
bool waitForReadyRead(int msecs = 30000);
|
bool waitForReadyRead(int msecs = 30000);
|
||||||
bool waitForFinished(int msecs = 30000);
|
bool waitForFinished(int msecs = 30000);
|
||||||
|
|
||||||
QByteArray readAllStandardOutput();
|
virtual QByteArray readAllStandardOutput();
|
||||||
QByteArray readAllStandardError();
|
virtual QByteArray readAllStandardError();
|
||||||
|
|
||||||
QProcess::ExitStatus exitStatus() const;
|
virtual QProcess::ExitStatus exitStatus() const;
|
||||||
|
|
||||||
void kill();
|
virtual void kill();
|
||||||
|
|
||||||
qint64 write(const QByteArray &input);
|
virtual qint64 write(const QByteArray &input);
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
void setStandardInputFile(const QString &inputFile);
|
void setStandardInputFile(const QString &inputFile);
|
||||||
|
@@ -105,20 +105,7 @@ public:
|
|||||||
~DockerDeviceProcess() {}
|
~DockerDeviceProcess() {}
|
||||||
|
|
||||||
void start(const Runnable &runnable) override;
|
void start(const Runnable &runnable) override;
|
||||||
|
|
||||||
void interrupt() override;
|
void interrupt() override;
|
||||||
void terminate() override { process()->terminate(); }
|
|
||||||
void kill() override;
|
|
||||||
|
|
||||||
QProcess::ProcessState state() const override;
|
|
||||||
QProcess::ExitStatus exitStatus() const override;
|
|
||||||
int exitCode() const override;
|
|
||||||
QString errorString() const override;
|
|
||||||
|
|
||||||
QByteArray readAllStandardOutput() override;
|
|
||||||
QByteArray readAllStandardError() override;
|
|
||||||
|
|
||||||
qint64 write(const QByteArray &data) override { return process()->write(data); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DockerDeviceProcess::DockerDeviceProcess(const QSharedPointer<const IDevice> &device,
|
DockerDeviceProcess::DockerDeviceProcess(const QSharedPointer<const IDevice> &device,
|
||||||
@@ -129,7 +116,7 @@ DockerDeviceProcess::DockerDeviceProcess(const QSharedPointer<const IDevice> &de
|
|||||||
|
|
||||||
void DockerDeviceProcess::start(const Runnable &runnable)
|
void DockerDeviceProcess::start(const Runnable &runnable)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(process()->state() == QProcess::NotRunning, return);
|
QTC_ASSERT(state() == QProcess::NotRunning, return);
|
||||||
DockerDevice::ConstPtr dockerDevice = qSharedPointerCast<const DockerDevice>(device());
|
DockerDevice::ConstPtr dockerDevice = qSharedPointerCast<const DockerDevice>(device());
|
||||||
QTC_ASSERT(dockerDevice, return);
|
QTC_ASSERT(dockerDevice, return);
|
||||||
|
|
||||||
@@ -142,68 +129,23 @@ void DockerDeviceProcess::start(const Runnable &runnable)
|
|||||||
MessageManager::writeDisrupting(QString::fromLocal8Bit(readAllStandardError()));
|
MessageManager::writeDisrupting(QString::fromLocal8Bit(readAllStandardError()));
|
||||||
});
|
});
|
||||||
|
|
||||||
disconnect(process());
|
|
||||||
|
|
||||||
CommandLine command = runnable.command;
|
CommandLine command = runnable.command;
|
||||||
command.setExecutable(
|
command.setExecutable(
|
||||||
command.executable().withNewPath(dockerDevice->mapToDevicePath(command.executable())));
|
command.executable().withNewPath(dockerDevice->mapToDevicePath(command.executable())));
|
||||||
process()->setCommand(command);
|
setCommand(command);
|
||||||
process()->setEnvironment(runnable.environment);
|
setEnvironment(runnable.environment);
|
||||||
process()->setWorkingDirectory(runnable.workingDirectory);
|
setWorkingDirectory(runnable.workingDirectory);
|
||||||
connect(process(), &QtcProcess::errorOccurred, this, &DeviceProcess::errorOccurred);
|
|
||||||
connect(process(), &QtcProcess::finished, this, &DeviceProcess::finished);
|
|
||||||
connect(process(), &QtcProcess::readyReadStandardOutput,
|
|
||||||
this, &DeviceProcess::readyReadStandardOutput);
|
|
||||||
connect(process(), &QtcProcess::readyReadStandardError,
|
|
||||||
this, &DeviceProcess::readyReadStandardError);
|
|
||||||
connect(process(), &QtcProcess::started, this, &DeviceProcess::started);
|
|
||||||
|
|
||||||
LOG("Running process:" << command.toUserOutput()
|
LOG("Running process:" << command.toUserOutput()
|
||||||
<< "in" << runnable.workingDirectory.toUserOutput());
|
<< "in" << runnable.workingDirectory.toUserOutput());
|
||||||
dockerDevice->runProcess(*process());
|
dockerDevice->runProcess(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DockerDeviceProcess::interrupt()
|
void DockerDeviceProcess::interrupt()
|
||||||
{
|
{
|
||||||
device()->signalOperation()->interruptProcess(process()->processId());
|
device()->signalOperation()->interruptProcess(processId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DockerDeviceProcess::kill()
|
|
||||||
{
|
|
||||||
process()->kill();
|
|
||||||
}
|
|
||||||
|
|
||||||
QProcess::ProcessState DockerDeviceProcess::state() const
|
|
||||||
{
|
|
||||||
return process()->state();
|
|
||||||
}
|
|
||||||
|
|
||||||
QProcess::ExitStatus DockerDeviceProcess::exitStatus() const
|
|
||||||
{
|
|
||||||
return process()->exitStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
int DockerDeviceProcess::exitCode() const
|
|
||||||
{
|
|
||||||
return process()->exitCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DockerDeviceProcess::errorString() const
|
|
||||||
{
|
|
||||||
return process()->errorString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray DockerDeviceProcess::readAllStandardOutput()
|
|
||||||
{
|
|
||||||
return process()->readAllStandardOutput();
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray DockerDeviceProcess::readAllStandardError()
|
|
||||||
{
|
|
||||||
return process()->readAllStandardError();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class DockerPortsGatheringMethod : public PortsGatheringMethod
|
class DockerPortsGatheringMethod : public PortsGatheringMethod
|
||||||
{
|
{
|
||||||
Runnable runnable(QAbstractSocket::NetworkLayerProtocol protocol) const override
|
Runnable runnable(QAbstractSocket::NetworkLayerProtocol protocol) const override
|
||||||
|
@@ -41,73 +41,21 @@ DesktopDeviceProcess::DesktopDeviceProcess(const QSharedPointer<const IDevice> &
|
|||||||
QObject *parent)
|
QObject *parent)
|
||||||
: DeviceProcess(device, ProcessMode::Writer, parent)
|
: DeviceProcess(device, ProcessMode::Writer, parent)
|
||||||
{
|
{
|
||||||
connect(process(), &QtcProcess::errorOccurred, this, &DeviceProcess::errorOccurred);
|
|
||||||
connect(process(), &QtcProcess::finished, this, &DeviceProcess::finished);
|
|
||||||
connect(process(), &QtcProcess::readyReadStandardOutput,
|
|
||||||
this, &DeviceProcess::readyReadStandardOutput);
|
|
||||||
connect(process(), &QtcProcess::readyReadStandardError,
|
|
||||||
this, &DeviceProcess::readyReadStandardError);
|
|
||||||
connect(process(), &QtcProcess::started, this, &DeviceProcess::started);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopDeviceProcess::start(const Runnable &runnable)
|
void DesktopDeviceProcess::start(const Runnable &runnable)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(process()->state() == QProcess::NotRunning, return);
|
QTC_ASSERT(state() == QProcess::NotRunning, return);
|
||||||
if (runnable.environment.size())
|
if (runnable.environment.size())
|
||||||
process()->setEnvironment(runnable.environment);
|
setEnvironment(runnable.environment);
|
||||||
process()->setWorkingDirectory(runnable.workingDirectory);
|
setWorkingDirectory(runnable.workingDirectory);
|
||||||
process()->setCommand(runnable.command);
|
setCommand(runnable.command);
|
||||||
process()->start();
|
QtcProcess::start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopDeviceProcess::interrupt()
|
void DesktopDeviceProcess::interrupt()
|
||||||
{
|
{
|
||||||
device()->signalOperation()->interruptProcess(process()->processId());
|
device()->signalOperation()->interruptProcess(processId());
|
||||||
}
|
|
||||||
|
|
||||||
void DesktopDeviceProcess::terminate()
|
|
||||||
{
|
|
||||||
process()->terminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DesktopDeviceProcess::kill()
|
|
||||||
{
|
|
||||||
process()->kill();
|
|
||||||
}
|
|
||||||
|
|
||||||
QProcess::ProcessState DesktopDeviceProcess::state() const
|
|
||||||
{
|
|
||||||
return process()->state();
|
|
||||||
}
|
|
||||||
|
|
||||||
QProcess::ExitStatus DesktopDeviceProcess::exitStatus() const
|
|
||||||
{
|
|
||||||
return process()->exitStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
int DesktopDeviceProcess::exitCode() const
|
|
||||||
{
|
|
||||||
return process()->exitCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString DesktopDeviceProcess::errorString() const
|
|
||||||
{
|
|
||||||
return process()->errorString();
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray DesktopDeviceProcess::readAllStandardOutput()
|
|
||||||
{
|
|
||||||
return process()->readAllStandardOutput();
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray DesktopDeviceProcess::readAllStandardError()
|
|
||||||
{
|
|
||||||
return process()->readAllStandardError();
|
|
||||||
}
|
|
||||||
|
|
||||||
qint64 DesktopDeviceProcess::write(const QByteArray &data)
|
|
||||||
{
|
|
||||||
return process()->write(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -41,18 +41,6 @@ public:
|
|||||||
|
|
||||||
void start(const Runnable &runnable) override;
|
void start(const Runnable &runnable) override;
|
||||||
void interrupt() override;
|
void interrupt() override;
|
||||||
void terminate() override;
|
|
||||||
void kill() override;
|
|
||||||
|
|
||||||
QProcess::ProcessState state() const override;
|
|
||||||
QProcess::ExitStatus exitStatus() const override;
|
|
||||||
int exitCode() const override;
|
|
||||||
QString errorString() const override;
|
|
||||||
|
|
||||||
QByteArray readAllStandardOutput() override;
|
|
||||||
QByteArray readAllStandardError() override;
|
|
||||||
|
|
||||||
qint64 write(const QByteArray &data) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
@@ -37,7 +37,7 @@ namespace ProjectExplorer {
|
|||||||
DeviceProcess::DeviceProcess(const IDevice::ConstPtr &device,
|
DeviceProcess::DeviceProcess(const IDevice::ConstPtr &device,
|
||||||
const QtcProcess::Setup &setup,
|
const QtcProcess::Setup &setup,
|
||||||
QObject *parent)
|
QObject *parent)
|
||||||
: QObject(parent), m_process(setup), m_device(device)
|
: QtcProcess(setup, parent), m_device(device)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
@@ -38,47 +37,24 @@ namespace ProjectExplorer {
|
|||||||
class IDevice;
|
class IDevice;
|
||||||
class Runnable;
|
class Runnable;
|
||||||
|
|
||||||
class PROJECTEXPLORER_EXPORT DeviceProcess : public QObject
|
class PROJECTEXPLORER_EXPORT DeviceProcess : public Utils::QtcProcess
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
using Utils::QtcProcess::start;
|
||||||
virtual void start(const Runnable &runnable) = 0;
|
virtual void start(const Runnable &runnable) = 0;
|
||||||
virtual void interrupt() = 0;
|
|
||||||
virtual void terminate() = 0;
|
|
||||||
virtual void kill() = 0;
|
|
||||||
|
|
||||||
virtual QProcess::ProcessState state() const = 0;
|
|
||||||
virtual QProcess::ExitStatus exitStatus() const = 0;
|
|
||||||
virtual int exitCode() const = 0;
|
|
||||||
virtual QString errorString() const = 0;
|
|
||||||
|
|
||||||
virtual QByteArray readAllStandardOutput() = 0;
|
|
||||||
virtual QByteArray readAllStandardError() = 0;
|
|
||||||
|
|
||||||
virtual qint64 write(const QByteArray &data) = 0;
|
|
||||||
|
|
||||||
void setRunInTerminal(bool term) { m_runInTerminal = term; }
|
void setRunInTerminal(bool term) { m_runInTerminal = term; }
|
||||||
bool runInTerminal() const { return m_runInTerminal; }
|
bool runInTerminal() const { return m_runInTerminal; }
|
||||||
|
|
||||||
signals:
|
|
||||||
void started();
|
|
||||||
void finished();
|
|
||||||
void errorOccurred(QProcess::ProcessError error);
|
|
||||||
|
|
||||||
void readyReadStandardOutput();
|
|
||||||
void readyReadStandardError();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit DeviceProcess(const QSharedPointer<const IDevice> &device,
|
explicit DeviceProcess(const QSharedPointer<const IDevice> &device,
|
||||||
const Utils::QtcProcess::Setup &setup,
|
const Utils::QtcProcess::Setup &setup,
|
||||||
QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
|
|
||||||
QSharedPointer<const IDevice> device() const;
|
QSharedPointer<const IDevice> device() const;
|
||||||
Utils::QtcProcess *process() { return &m_process; }
|
|
||||||
const Utils::QtcProcess *process() const { return &m_process; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Utils::QtcProcess m_process;
|
|
||||||
const QSharedPointer<const IDevice> m_device;
|
const QSharedPointer<const IDevice> m_device;
|
||||||
bool m_runInTerminal = false;
|
bool m_runInTerminal = false;
|
||||||
};
|
};
|
||||||
|
@@ -192,15 +192,11 @@ void SshDeviceProcess::handleConnected()
|
|||||||
if (!display.isEmpty())
|
if (!display.isEmpty())
|
||||||
d->remoteProcess->requestX11Forwarding(display);
|
d->remoteProcess->requestX11Forwarding(display);
|
||||||
if (runInTerminal()) {
|
if (runInTerminal()) {
|
||||||
connect(process(), &QtcProcess::errorOccurred,
|
connect(this, &QtcProcess::finished,
|
||||||
this, &DeviceProcess::errorOccurred);
|
this, [this] { handleProcessFinished(errorString()); });
|
||||||
connect(process(), &QtcProcess::started,
|
setAbortOnMetaChars(false);
|
||||||
this, &SshDeviceProcess::handleProcessStarted);
|
setCommand(d->remoteProcess->fullLocalCommandLine(true));
|
||||||
connect(process(), &QtcProcess::finished,
|
QtcProcess::start();
|
||||||
this, [this] { handleProcessFinished(process()->errorString()); });
|
|
||||||
process()->setAbortOnMetaChars(false);
|
|
||||||
process()->setCommand(d->remoteProcess->fullLocalCommandLine(true));
|
|
||||||
process()->start();
|
|
||||||
} else {
|
} else {
|
||||||
connect(d->remoteProcess.get(), &QSsh::SshRemoteProcess::started,
|
connect(d->remoteProcess.get(), &QSsh::SshRemoteProcess::started,
|
||||||
this, &SshDeviceProcess::handleProcessStarted);
|
this, &SshDeviceProcess::handleProcessStarted);
|
||||||
@@ -251,7 +247,7 @@ void SshDeviceProcess::handleProcessStarted()
|
|||||||
void SshDeviceProcess::handleProcessFinished(const QString &error)
|
void SshDeviceProcess::handleProcessFinished(const QString &error)
|
||||||
{
|
{
|
||||||
d->errorMessage = error;
|
d->errorMessage = error;
|
||||||
d->exitCode = runInTerminal() ? process()->exitCode() : d->remoteProcess->exitCode();
|
d->exitCode = runInTerminal() ? QtcProcess::exitCode() : d->remoteProcess->exitCode();
|
||||||
if (d->killOperation && error.isEmpty())
|
if (d->killOperation && error.isEmpty())
|
||||||
d->errorMessage = tr("The process was ended forcefully.");
|
d->errorMessage = tr("The process was ended forcefully.");
|
||||||
d->setState(SshDeviceProcessPrivate::Inactive);
|
d->setState(SshDeviceProcessPrivate::Inactive);
|
||||||
@@ -356,10 +352,10 @@ void SshDeviceProcess::SshDeviceProcessPrivate::setState(SshDeviceProcess::SshDe
|
|||||||
killOperation->disconnect(q);
|
killOperation->disconnect(q);
|
||||||
killOperation.clear();
|
killOperation.clear();
|
||||||
if (q->runInTerminal())
|
if (q->runInTerminal())
|
||||||
QMetaObject::invokeMethod(q->process(), &QtcProcess::stopProcess, Qt::QueuedConnection);
|
QMetaObject::invokeMethod(q, &QtcProcess::stopProcess, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
killTimer.stop();
|
killTimer.stop();
|
||||||
q->process()->disconnect();
|
q->disconnect();
|
||||||
if (remoteProcess)
|
if (remoteProcess)
|
||||||
remoteProcess->disconnect(q);
|
remoteProcess->disconnect(q);
|
||||||
if (connection) {
|
if (connection) {
|
||||||
|
Reference in New Issue
Block a user