aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2022-11-28 11:43:18 +0100
committerhjk <hjk@qt.io>2022-11-28 11:30:38 +0000
commita1464035962dfcf871773c28216f79ad228b26a0 (patch)
tree5429bff66b07667007255652fdfb7121dd9ddb9c
parent9e0ed9eeac9adf3948d7640074f2cce504149cad (diff)
Utils: Make FilePath::refersToExe(...) return the found item
... and use in on the CMake side. Change-Id: Ib215ebc4f87beb67b6a302d0c42e7b955a2fa5b7 Reviewed-by: Cristian Adam <cristian.adam@qt.io>
-rw-r--r--src/libs/utils/devicefileaccess.cpp34
-rw-r--r--src/libs/utils/devicefileaccess.h4
-rw-r--r--src/libs/utils/filepath.cpp2
-rw-r--r--src/libs/utils/filepath.h2
-rw-r--r--src/plugins/cmakeprojectmanager/cmaketoolsettingsaccessor.cpp4
5 files changed, 26 insertions, 20 deletions
diff --git a/src/libs/utils/devicefileaccess.cpp b/src/libs/utils/devicefileaccess.cpp
index 43ed665524..924a9ad56e 100644
--- a/src/libs/utils/devicefileaccess.cpp
+++ b/src/libs/utils/devicefileaccess.cpp
@@ -250,12 +250,14 @@ QByteArray DeviceFileAccess::fileId(const FilePath &filePath) const
return {};
}
-bool DeviceFileAccess::refersToExecutableFile(
+std::optional<FilePath> DeviceFileAccess::refersToExecutableFile(
const FilePath &filePath,
FilePath::MatchScope matchScope) const
{
Q_UNUSED(matchScope)
- return isExecutableFile(filePath);
+ if (isExecutableFile(filePath))
+ return filePath;
+ return {};
}
void DeviceFileAccess::asyncFileContents(
@@ -301,38 +303,42 @@ bool DesktopDeviceFileAccess::isExecutableFile(const FilePath &filePath) const
return fi.isExecutable() && !fi.isDir();
}
-static bool isWindowsExecutableHelper(const FilePath &filePath, const QStringView suffix)
+static std::optional<FilePath> isWindowsExecutableHelper
+ (const FilePath &filePath, const QStringView suffix)
{
const QFileInfo fi(filePath.path().append(suffix));
- return fi.isExecutable() && !fi.isDir();
+ if (!fi.isExecutable() || fi.isDir())
+ return {};
+
+ return filePath.withNewPath(FileUtils::normalizedPathName(fi.filePath()));
}
-bool DesktopDeviceFileAccess::refersToExecutableFile(
+std::optional<FilePath> DesktopDeviceFileAccess::refersToExecutableFile(
const FilePath &filePath,
FilePath::MatchScope matchScope) const
{
if (isExecutableFile(filePath))
- return true;
+ return filePath;
if (HostOsInfo::isWindowsHost()) {
if (matchScope == FilePath::WithExeSuffix || matchScope == FilePath::WithExeOrBatSuffix) {
- if (isWindowsExecutableHelper(filePath, u".exe"))
- return true;
+ if (auto res = isWindowsExecutableHelper(filePath, u".exe"))
+ return res;
}
if (matchScope == FilePath::WithBatSuffix || matchScope == FilePath::WithExeOrBatSuffix) {
- if (isWindowsExecutableHelper(filePath, u".bat"))
- return true;
+ if (auto res = isWindowsExecutableHelper(filePath, u".bat"))
+ return res;
}
if (matchScope == FilePath::WithAnySuffix) {
// That's usually .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH,
- static const QStringList exts = qtcEnvironmentVariable("PATHEXT").split(';');
+ static const QStringList exts = qtcEnvironmentVariable("PATHEXT").toLower().split(';');
for (const QString &ext : exts) {
- if (isWindowsExecutableHelper(filePath, ext))
- return true;
+ if (auto res = isWindowsExecutableHelper(filePath, ext))
+ return res;
}
}
}
- return false;
+ return {};
}
bool DesktopDeviceFileAccess::isReadableFile(const FilePath &filePath) const
diff --git a/src/libs/utils/devicefileaccess.h b/src/libs/utils/devicefileaccess.h
index 8e5633aa34..91390c4d53 100644
--- a/src/libs/utils/devicefileaccess.h
+++ b/src/libs/utils/devicefileaccess.h
@@ -47,7 +47,7 @@ protected:
virtual qint64 bytesAvailable(const FilePath &filePath) const;
virtual QByteArray fileId(const FilePath &filePath) const;
- virtual bool refersToExecutableFile(
+ virtual std::optional<FilePath> refersToExecutableFile(
const FilePath &filePath,
FilePath::MatchScope matchScope) const;
@@ -118,7 +118,7 @@ protected:
qint64 bytesAvailable(const FilePath &filePath) const override;
QByteArray fileId(const FilePath &filePath) const override;
- bool refersToExecutableFile(
+ std::optional<FilePath> refersToExecutableFile(
const FilePath &filePath,
FilePath::MatchScope matchScope) const override;
diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp
index b6cef68bde..6df30ffd82 100644
--- a/src/libs/utils/filepath.cpp
+++ b/src/libs/utils/filepath.cpp
@@ -419,7 +419,7 @@ bool FilePath::isExecutableFile() const
///
/// This is equivalent to \c isExecutableFile() in general.
/// On Windows, it will check appending various suffixes, too.
-bool FilePath::refersToExecutableFile(MatchScope matchScope) const
+std::optional<FilePath> FilePath::refersToExecutableFile(MatchScope matchScope) const
{
return fileAccess()->refersToExecutableFile(*this, matchScope);
}
diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h
index 2e0f45b29d..c91403b5f7 100644
--- a/src/libs/utils/filepath.h
+++ b/src/libs/utils/filepath.h
@@ -184,7 +184,7 @@ public:
enum MatchScope { ExactMatchOnly, WithExeSuffix, WithBatSuffix,
WithExeOrBatSuffix, WithAnySuffix };
- bool refersToExecutableFile(MatchScope considerScript) const;
+ std::optional<FilePath> refersToExecutableFile(MatchScope considerScript) const;
// makes sure that capitalization of directories is canonical
// on Windows and macOS. This is rarely needed.
diff --git a/src/plugins/cmakeprojectmanager/cmaketoolsettingsaccessor.cpp b/src/plugins/cmakeprojectmanager/cmaketoolsettingsaccessor.cpp
index a92454e169..ea3e78dcec 100644
--- a/src/plugins/cmakeprojectmanager/cmaketoolsettingsaccessor.cpp
+++ b/src/plugins/cmakeprojectmanager/cmaketoolsettingsaccessor.cpp
@@ -70,8 +70,8 @@ static std::vector<std::unique_ptr<CMakeTool>> autoDetectCMakeTools()
if (base.isEmpty())
continue;
const FilePath suspect = base / "cmake";
- if (suspect.refersToExecutableFile(FilePath::WithAnySuffix))
- suspects << suspect;
+ if (std::optional<FilePath> foundExe = suspect.refersToExecutableFile(FilePath::WithAnySuffix))
+ suspects << *foundExe;
}
std::vector<std::unique_ptr<CMakeTool>> found;