From fd7bf831ba3566c444f3fd4cdaf70d36d05a2573 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 21 Feb 2022 12:49:14 +0100 Subject: [PATCH] Introduce processImplHook Call new hook from inside QtcProcess::start(). This hook calls new virtual method IDevice::createProcessInterface(). That's all what should be needed from device to setup properly device specific process. Make QtcProcess::createProcessInterface() private now. Change-Id: I2136698063bafc846ebc2d3db6cc11376902eff0 Reviewed-by: Qt CI Bot Reviewed-by: hjk --- src/libs/utils/qtcprocess.cpp | 17 +++++++++++++---- src/libs/utils/qtcprocess.h | 6 ++++-- .../devicesupport/devicemanager.cpp | 7 +++++++ .../projectexplorer/devicesupport/idevice.cpp | 7 +++++++ .../projectexplorer/devicesupport/idevice.h | 2 ++ 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/libs/utils/qtcprocess.cpp b/src/libs/utils/qtcprocess.cpp index fc7c8583acb..363f594cc3d 100644 --- a/src/libs/utils/qtcprocess.cpp +++ b/src/libs/utils/qtcprocess.cpp @@ -822,12 +822,21 @@ void QtcProcess::start() // TODO: Uncomment when we de-virtualize start() // QTC_ASSERT(state() == QProcess::NotRunning, return); + ProcessInterface *processImpl = nullptr; if (d->m_setup.m_commandLine.executable().needsDevice()) { - QTC_ASSERT(s_deviceHooks.startProcessHook, return); - s_deviceHooks.startProcessHook(*this); - return; + if (s_deviceHooks.processImplHook) { // TODO: replace "if" with an assert for the hook + processImpl = s_deviceHooks.processImplHook(commandLine().executable()); + } + if (!processImpl) { // TODO: remove this branch when docker is adapted accordingly + QTC_ASSERT(s_deviceHooks.startProcessHook, return); + s_deviceHooks.startProcessHook(*this); + return; + } + } else { + processImpl = d->createProcessInterface(); } - setProcessInterface(d->createProcessInterface()); + QTC_ASSERT(processImpl, return); + setProcessInterface(processImpl); d->clearForRun(); d->m_process->m_setup.m_commandLine = d->fullCommandLine(); d->m_process->m_setup.m_environment = d->fullEnvironment(); diff --git a/src/libs/utils/qtcprocess.h b/src/libs/utils/qtcprocess.h index 01eb37951a8..33509a6fc41 100644 --- a/src/libs/utils/qtcprocess.h +++ b/src/libs/utils/qtcprocess.h @@ -56,8 +56,6 @@ public: QtcProcess(QObject *parent = nullptr); ~QtcProcess(); - void setProcessInterface(ProcessInterface *interface); - // ProcessInterface related void start() override; @@ -215,6 +213,8 @@ public: QString toStandaloneCommandLine() const; private: + void setProcessInterface(ProcessInterface *interface); + friend QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug str, const QtcProcess &r); friend class Internal::QtcProcessPrivate; @@ -229,6 +229,8 @@ private: class DeviceProcessHooks { public: + std::function processImplHook; + // TODO: remove this hook std::function startProcessHook; std::function systemEnvironmentForBinary; }; diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp index 256b93b6157..368d1a8f755 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp @@ -595,6 +595,7 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_uniquerunProcess(process); }; + processHooks.processImplHook = [](const FilePath &filePath) -> ProcessInterface * { + auto device = DeviceManager::deviceForPath(filePath); + QTC_ASSERT(device, return nullptr); + return device->createProcessInterface(); + }; + processHooks.systemEnvironmentForBinary = [](const FilePath &filePath) { auto device = DeviceManager::deviceForPath(filePath); QTC_ASSERT(device, return Environment()); diff --git a/src/plugins/projectexplorer/devicesupport/idevice.cpp b/src/plugins/projectexplorer/devicesupport/idevice.cpp index 4977cafac41..5f7e384f2fc 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.cpp +++ b/src/plugins/projectexplorer/devicesupport/idevice.cpp @@ -422,6 +422,13 @@ bool IDevice::setPermissions(const FilePath &filePath, QFile::Permissions) const return false; } +ProcessInterface *IDevice::createProcessInterface() const +{ +// TODO: uncomment below assert when docker device implements this method +// QTC_ASSERT(false, return nullptr); + return nullptr; +} + void IDevice::runProcess(QtcProcess &process) const { Q_UNUSED(process); diff --git a/src/plugins/projectexplorer/devicesupport/idevice.h b/src/plugins/projectexplorer/devicesupport/idevice.h index 9090500f493..0eee1ab8e76 100644 --- a/src/plugins/projectexplorer/devicesupport/idevice.h +++ b/src/plugins/projectexplorer/devicesupport/idevice.h @@ -54,6 +54,7 @@ class Environment; class Icon; class PortList; class Port; +class ProcessInterface; class QtcProcess; } // Utils @@ -266,6 +267,7 @@ public: virtual QDateTime lastModified(const Utils::FilePath &filePath) const; virtual QFile::Permissions permissions(const Utils::FilePath &filePath) const; virtual bool setPermissions(const Utils::FilePath &filePath, QFile::Permissions) const; + virtual Utils::ProcessInterface *createProcessInterface() const; virtual void runProcess(Utils::QtcProcess &process) const; virtual Utils::Environment systemEnvironment() const; virtual qint64 fileSize(const Utils::FilePath &filePath) const;