forked from qt-creator/qt-creator
Utils: Use a structure to specify several QtcProcess device hooks
... and add a QtcProcess::systemEnvironmentForBinary(filePath) redirecting to IDevice::systemEnvironment() of the device implicitly given by filePath. A device implied by e.g. a qmake binary or a compiler binary is a common scenario. Change-Id: Ieb2c724ae66f1a1752132e4e4648a604390ca369 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -73,7 +73,7 @@ enum { defaultMaxHangTimerCount = 10 };
|
||||
|
||||
static Q_LOGGING_CATEGORY(processLog, "qtc.utils.synchronousprocess", QtWarningMsg);
|
||||
|
||||
static std::function<void(QtcProcess &)> s_remoteRunProcessHook;
|
||||
static DeviceProcessHooks s_deviceHooks;
|
||||
|
||||
// Data for one channel buffer (stderr/stdout)
|
||||
class ChannelBuffer
|
||||
@@ -225,8 +225,8 @@ void QtcProcess::start()
|
||||
QTC_CHECK(d->m_writeData.isEmpty()); // FIXME: Use it.
|
||||
|
||||
if (d->m_commandLine.executable().needsDevice()) {
|
||||
QTC_ASSERT(s_remoteRunProcessHook, return);
|
||||
s_remoteRunProcessHook(*this);
|
||||
QTC_ASSERT(s_deviceHooks.startProcessHook, return);
|
||||
s_deviceHooks.startProcessHook(*this);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -336,9 +336,9 @@ void QtcProcess::setDisableUnixTerminal()
|
||||
d->m_disableUnixTerminal = true;
|
||||
}
|
||||
|
||||
void QtcProcess::setRemoteStartProcessHook(const std::function<void(QtcProcess &)> &hook)
|
||||
void QtcProcess::setRemoteProcessHooks(const DeviceProcessHooks &hooks)
|
||||
{
|
||||
s_remoteRunProcessHook = hook;
|
||||
s_deviceHooks = hooks;
|
||||
}
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
@@ -561,6 +561,16 @@ QString QtcProcess::locateBinary(const QString &path, const QString &binary)
|
||||
return QString();
|
||||
}
|
||||
|
||||
Environment QtcProcess::systemEnvironmentForBinary(const FilePath &filePath)
|
||||
{
|
||||
if (filePath.needsDevice()) {
|
||||
QTC_ASSERT(s_deviceHooks.systemEnvironmentForBinary, return {});
|
||||
return s_deviceHooks.systemEnvironmentForBinary(filePath);
|
||||
}
|
||||
|
||||
return Environment::systemEnvironment();
|
||||
}
|
||||
|
||||
QString QtcProcess::locateBinary(const QString &binary)
|
||||
{
|
||||
const QByteArray path = qgetenv("PATH");
|
||||
|
||||
Reference in New Issue
Block a user