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 <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-02-21 12:49:14 +01:00
parent d979bd8da9
commit fd7bf831ba
5 changed files with 33 additions and 6 deletions

View File

@@ -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()) {
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;
}
setProcessInterface(d->createProcessInterface());
} else {
processImpl = 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();

View File

@@ -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<ProcessInterface *(const FilePath &)> processImplHook;
// TODO: remove this hook
std::function<void(QtcProcess &)> startProcessHook;
std::function<Environment(const FilePath &)> systemEnvironmentForBinary;
};

View File

@@ -595,6 +595,7 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
DeviceProcessHooks processHooks;
// TODO: remove this hook
processHooks.startProcessHook = [](QtcProcess &process) {
FilePath filePath = process.commandLine().executable();
auto device = DeviceManager::deviceForPath(filePath);
@@ -602,6 +603,12 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
device->runProcess(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());

View File

@@ -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);

View File

@@ -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;