diff --git a/src/libs/utils/qtcprocess.cpp b/src/libs/utils/qtcprocess.cpp index 2ecb538ea9b..713232a4343 100644 --- a/src/libs/utils/qtcprocess.cpp +++ b/src/libs/utils/qtcprocess.cpp @@ -73,7 +73,7 @@ enum { defaultMaxHangTimerCount = 10 }; static Q_LOGGING_CATEGORY(processLog, "qtc.utils.synchronousprocess", QtWarningMsg); -static std::function 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 &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"); diff --git a/src/libs/utils/qtcprocess.h b/src/libs/utils/qtcprocess.h index d2c1da1d617..365306867d3 100644 --- a/src/libs/utils/qtcprocess.h +++ b/src/libs/utils/qtcprocess.h @@ -41,9 +41,17 @@ namespace Utils { class CommandLine; class Environment; +class QtcProcess; namespace Internal { class QtcProcessPrivate; } +class DeviceProcessHooks +{ +public: + std::function startProcessHook; + std::function systemEnvironmentForBinary; +}; + class QTCREATOR_UTILS_EXPORT QtcProcess : public QProcess { Q_OBJECT @@ -92,7 +100,7 @@ public: void setStdOutCallback(const std::function &callback); void setStdErrCallback(const std::function &callback); - static void setRemoteStartProcessHook(const std::function &hook); + static void setRemoteProcessHooks(const DeviceProcessHooks &hooks); void setOpenMode(OpenMode mode); @@ -123,6 +131,8 @@ public: static QString locateBinary(const QString &binary); static QString locateBinary(const QString &path, const QString &binary); + static Environment systemEnvironmentForBinary(const FilePath &filePath); + private: #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void setupChildProcess() override; diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp index b3c55f9892c..8ad2ff67f76 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp @@ -363,59 +363,69 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_uniqueisExecutableFile(filePath); }; - hooks.isReadableFile = [](const FilePath &filePath) { + deviceHooks.isReadableFile = [](const FilePath &filePath) { auto device = DeviceManager::deviceForPath(filePath); QTC_ASSERT(device, return false); return device->isReadableFile(filePath); }; - hooks.isReadableDir = [](const FilePath &filePath) { + deviceHooks.isReadableDir = [](const FilePath &filePath) { auto device = DeviceManager::deviceForPath(filePath); QTC_ASSERT(device, return false); return device->isReadableDirectory(filePath); }; - hooks.isWritableDir = [](const FilePath &filePath) { + deviceHooks.isWritableDir = [](const FilePath &filePath) { auto device = DeviceManager::deviceForPath(filePath); QTC_ASSERT(device, return false); return device->isWritableDirectory(filePath); }; - hooks.createDir = [](const FilePath &filePath) { + deviceHooks.createDir = [](const FilePath &filePath) { auto device = DeviceManager::deviceForPath(filePath); QTC_ASSERT(device, return false); return device->createDirectory(filePath); }; - hooks.dirEntries = [](const FilePath &filePath, + deviceHooks.dirEntries = [](const FilePath &filePath, const QStringList &nameFilters, QDir::Filters filters) { auto device = DeviceManager::deviceForPath(filePath); QTC_ASSERT(device, return FilePaths()); return device->directoryEntries(filePath, nameFilters, filters); }; - hooks.fileContents = [](const FilePath &filePath, int maxSize) { + deviceHooks.fileContents = [](const FilePath &filePath, int maxSize) { auto device = DeviceManager::deviceForPath(filePath); QTC_ASSERT(device, return QByteArray()); return device->fileContents(filePath, maxSize); }; - FilePath::setDeviceFileHooks(hooks); + FilePath::setDeviceFileHooks(deviceHooks); - QtcProcess::setRemoteStartProcessHook([](QtcProcess &process) { + DeviceProcessHooks processHooks; + + processHooks.startProcessHook = [](QtcProcess &process) { FilePath filePath = process.commandLine().executable(); auto device = DeviceManager::deviceForPath(filePath); QTC_ASSERT(device, return); device->runProcess(process); - }); + }; + + processHooks.systemEnvironmentForBinary = [](const FilePath &filePath) { + auto device = DeviceManager::deviceForPath(filePath); + QTC_ASSERT(device, return Environment()); + return device->systemEnvironment(); + }; + + QtcProcess::setRemoteProcessHooks(processHooks); } DeviceManager::~DeviceManager()