forked from qt-creator/qt-creator
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:
@@ -822,12 +822,21 @@ void QtcProcess::start()
|
|||||||
// TODO: Uncomment when we de-virtualize start()
|
// TODO: Uncomment when we de-virtualize start()
|
||||||
// QTC_ASSERT(state() == QProcess::NotRunning, return);
|
// QTC_ASSERT(state() == QProcess::NotRunning, return);
|
||||||
|
|
||||||
|
ProcessInterface *processImpl = nullptr;
|
||||||
if (d->m_setup.m_commandLine.executable().needsDevice()) {
|
if (d->m_setup.m_commandLine.executable().needsDevice()) {
|
||||||
QTC_ASSERT(s_deviceHooks.startProcessHook, return);
|
if (s_deviceHooks.processImplHook) { // TODO: replace "if" with an assert for the hook
|
||||||
s_deviceHooks.startProcessHook(*this);
|
processImpl = s_deviceHooks.processImplHook(commandLine().executable());
|
||||||
return;
|
}
|
||||||
|
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->clearForRun();
|
||||||
d->m_process->m_setup.m_commandLine = d->fullCommandLine();
|
d->m_process->m_setup.m_commandLine = d->fullCommandLine();
|
||||||
d->m_process->m_setup.m_environment = d->fullEnvironment();
|
d->m_process->m_setup.m_environment = d->fullEnvironment();
|
||||||
|
@@ -56,8 +56,6 @@ public:
|
|||||||
QtcProcess(QObject *parent = nullptr);
|
QtcProcess(QObject *parent = nullptr);
|
||||||
~QtcProcess();
|
~QtcProcess();
|
||||||
|
|
||||||
void setProcessInterface(ProcessInterface *interface);
|
|
||||||
|
|
||||||
// ProcessInterface related
|
// ProcessInterface related
|
||||||
|
|
||||||
void start() override;
|
void start() override;
|
||||||
@@ -215,6 +213,8 @@ public:
|
|||||||
QString toStandaloneCommandLine() const;
|
QString toStandaloneCommandLine() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setProcessInterface(ProcessInterface *interface);
|
||||||
|
|
||||||
friend QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug str, const QtcProcess &r);
|
friend QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug str, const QtcProcess &r);
|
||||||
|
|
||||||
friend class Internal::QtcProcessPrivate;
|
friend class Internal::QtcProcessPrivate;
|
||||||
@@ -229,6 +229,8 @@ private:
|
|||||||
class DeviceProcessHooks
|
class DeviceProcessHooks
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
std::function<ProcessInterface *(const FilePath &)> processImplHook;
|
||||||
|
// TODO: remove this hook
|
||||||
std::function<void(QtcProcess &)> startProcessHook;
|
std::function<void(QtcProcess &)> startProcessHook;
|
||||||
std::function<Environment(const FilePath &)> systemEnvironmentForBinary;
|
std::function<Environment(const FilePath &)> systemEnvironmentForBinary;
|
||||||
};
|
};
|
||||||
|
@@ -595,6 +595,7 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
|||||||
|
|
||||||
DeviceProcessHooks processHooks;
|
DeviceProcessHooks processHooks;
|
||||||
|
|
||||||
|
// TODO: remove this hook
|
||||||
processHooks.startProcessHook = [](QtcProcess &process) {
|
processHooks.startProcessHook = [](QtcProcess &process) {
|
||||||
FilePath filePath = process.commandLine().executable();
|
FilePath filePath = process.commandLine().executable();
|
||||||
auto device = DeviceManager::deviceForPath(filePath);
|
auto device = DeviceManager::deviceForPath(filePath);
|
||||||
@@ -602,6 +603,12 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
|
|||||||
device->runProcess(process);
|
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) {
|
processHooks.systemEnvironmentForBinary = [](const FilePath &filePath) {
|
||||||
auto device = DeviceManager::deviceForPath(filePath);
|
auto device = DeviceManager::deviceForPath(filePath);
|
||||||
QTC_ASSERT(device, return Environment());
|
QTC_ASSERT(device, return Environment());
|
||||||
|
@@ -422,6 +422,13 @@ bool IDevice::setPermissions(const FilePath &filePath, QFile::Permissions) const
|
|||||||
return false;
|
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
|
void IDevice::runProcess(QtcProcess &process) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(process);
|
Q_UNUSED(process);
|
||||||
|
@@ -54,6 +54,7 @@ class Environment;
|
|||||||
class Icon;
|
class Icon;
|
||||||
class PortList;
|
class PortList;
|
||||||
class Port;
|
class Port;
|
||||||
|
class ProcessInterface;
|
||||||
class QtcProcess;
|
class QtcProcess;
|
||||||
} // Utils
|
} // Utils
|
||||||
|
|
||||||
@@ -266,6 +267,7 @@ public:
|
|||||||
virtual QDateTime lastModified(const Utils::FilePath &filePath) const;
|
virtual QDateTime lastModified(const Utils::FilePath &filePath) const;
|
||||||
virtual QFile::Permissions permissions(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 bool setPermissions(const Utils::FilePath &filePath, QFile::Permissions) const;
|
||||||
|
virtual Utils::ProcessInterface *createProcessInterface() const;
|
||||||
virtual void runProcess(Utils::QtcProcess &process) const;
|
virtual void runProcess(Utils::QtcProcess &process) const;
|
||||||
virtual Utils::Environment systemEnvironment() const;
|
virtual Utils::Environment systemEnvironment() const;
|
||||||
virtual qint64 fileSize(const Utils::FilePath &filePath) const;
|
virtual qint64 fileSize(const Utils::FilePath &filePath) const;
|
||||||
|
Reference in New Issue
Block a user