Utils: Add a FilePath::environment

A hook into the system environment of the FilePath's device.

Change-Id: I274032f9e716f3cd8b2e4af2eca010b9805a4568
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-07-06 15:58:33 +02:00
parent 4eec360563
commit eb70e20453
3 changed files with 22 additions and 1 deletions

View File

@@ -1387,6 +1387,16 @@ FilePath FilePath::onDeviceSearchInPath() const
return Environment::systemEnvironment().searchInPath(path());
}
Environment FilePath::deviceEnvironment() const
{
if (needsDevice()) {
QTC_ASSERT(s_deviceHooks.environment, return {});
return s_deviceHooks.environment(*this);
}
return Environment::systemEnvironment();
}
FilePath FilePath::pathAppended(const QString &path) const
{
FilePath fn = *this;

View File

@@ -40,7 +40,10 @@
#include <functional>
#include <memory>
namespace Utils { class FilePath; }
namespace Utils {
class Environment;
class FilePath;
} // Utils
QT_BEGIN_NAMESPACE
class QDataStream;
@@ -91,6 +94,7 @@ public:
std::function<QDateTime(const FilePath &)> lastModified;
std::function<QFile::Permissions(const FilePath &)> permissions;
std::function<OsType(const FilePath &)> osType;
std::function<Environment(const FilePath &)> environment;
};
class QTCREATOR_UTILS_EXPORT FilePath
@@ -213,6 +217,7 @@ public:
static void setDeviceFileHooks(const DeviceFileHooks &hooks);
FilePath onDeviceSearchInPath() const;
Environment deviceEnvironment() const;
private:
friend class ::tst_fileutils;

View File

@@ -507,6 +507,12 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager
return device->osType();
};
deviceHooks.environment = [](const FilePath &filePath) {
auto device = DeviceManager::deviceForPath(filePath);
QTC_ASSERT(device, return Environment{});
return device->systemEnvironment();
};
FilePath::setDeviceFileHooks(deviceHooks);
DeviceProcessHooks processHooks;