From a2790ac95bcec4899e450198a30ed7946124d514 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 29 Jun 2021 16:57:16 +0200 Subject: [PATCH] Utils: Implement FilePath::withExecutableSuffix() Change-Id: Ibf6919991b229eb91953b3c5b5cbb75a1be7ff5d Reviewed-by: Christian Stenger --- src/libs/utils/fileutils.cpp | 14 ++++++++++++++ src/libs/utils/fileutils.h | 2 ++ .../devicesupport/devicemanager.cpp | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index 1f5a7b7cbc1..1f32637cbf2 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -29,6 +29,7 @@ #include "algorithm.h" #include "commandline.h" #include "environment.h" +#include "hostosinfo.h" #include "qtcassert.h" #include @@ -1015,6 +1016,19 @@ FilePath FilePath::symLinkTarget() const return FilePath::fromString(info.symLinkTarget()); } +FilePath FilePath::withExecutableSuffix() const +{ + OsType osType; + if (needsDevice()) { + QTC_ASSERT(s_deviceHooks.osType, return {}); + osType = s_deviceHooks.osType(*this); + } else { + osType = HostOsInfo::hostOs(); + } + FilePath res = *this; + res.setPath(OsSpecificAspects::withExecutableSuffix(osType, m_data)); + return res; +} /// Find the parent directory of a given directory. diff --git a/src/libs/utils/fileutils.h b/src/libs/utils/fileutils.h index 6a67aaedd4a..96c27dc9d00 100644 --- a/src/libs/utils/fileutils.h +++ b/src/libs/utils/fileutils.h @@ -90,6 +90,7 @@ public: std::function writeFileContents; std::function lastModified; std::function permissions; + std::function osType; }; class QTCREATOR_UTILS_EXPORT FilePath @@ -190,6 +191,7 @@ public: FilePath canonicalPath() const; FilePath symLinkTarget() const; + FilePath withExecutableSuffix() const; FilePath operator/(const QString &str) const; diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp index 9390b0e740a..532240b1331 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp @@ -496,6 +496,12 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_uniquepermissions(filePath); }; + deviceHooks.osType = [](const FilePath &filePath) { + auto device = DeviceManager::deviceForPath(filePath); + QTC_ASSERT(device, return OsTypeOther); + return device->osType(); + }; + FilePath::setDeviceFileHooks(deviceHooks); DeviceProcessHooks processHooks;