Utils: Reduce scope of Environment::appendExeExtensions()

The general idea is to use FilePath as entry point for this
kind of functionality.

Change-Id: Id6ade8809229d119eb6af44baa7d4e473676f6f9
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-11-21 11:33:55 +01:00
parent a333efe901
commit 3e941652e1
2 changed files with 8 additions and 9 deletions

View File

@@ -151,15 +151,15 @@ static FilePath searchInDirectory(const QStringList &execs,
return FilePath(); return FilePath();
} }
QStringList Environment::appendExeExtensions(const QString &executable) const static QStringList appendExeExtensions(const Environment &env, const QString &executable)
{ {
QStringList execs(executable); QStringList execs(executable);
const QFileInfo fi(executable); if (env.osType() == OsTypeWindows) {
if (osType() == OsTypeWindows) { const QFileInfo fi(executable);
// Check all the executable extensions on windows: // Check all the executable extensions on windows:
// PATHEXT is only used if the executable has no extension // PATHEXT is only used if the executable has no extension
if (fi.suffix().isEmpty()) { if (fi.suffix().isEmpty()) {
const QStringList extensions = expandedValueForKey("PATHEXT").split(';'); const QStringList extensions = env.expandedValueForKey("PATHEXT").split(';');
for (const QString &ext : extensions) for (const QString &ext : extensions)
execs << executable + ext.toLower(); execs << executable + ext.toLower();
@@ -170,8 +170,8 @@ QStringList Environment::appendExeExtensions(const QString &executable) const
bool Environment::isSameExecutable(const QString &exe1, const QString &exe2) const bool Environment::isSameExecutable(const QString &exe1, const QString &exe2) const
{ {
const QStringList exe1List = appendExeExtensions(exe1); const QStringList exe1List = appendExeExtensions(*this, exe1);
const QStringList exe2List = appendExeExtensions(exe2); const QStringList exe2List = appendExeExtensions(*this, exe2);
for (const QString &i1 : exe1List) { for (const QString &i1 : exe1List) {
for (const QString &i2 : exe2List) { for (const QString &i2 : exe2List) {
const FilePath f1 = FilePath::fromString(i1); const FilePath f1 = FilePath::fromString(i1);
@@ -200,7 +200,7 @@ static FilePath searchInDirectoriesHelper(const Environment &env,
const QString exec = QDir::cleanPath(env.expandVariables(executable)); const QString exec = QDir::cleanPath(env.expandVariables(executable));
const QFileInfo fi(exec); const QFileInfo fi(exec);
const QStringList execs = env.appendExeExtensions(exec); const QStringList execs = appendExeExtensions(env, exec);
if (fi.isAbsolute()) { if (fi.isAbsolute()) {
for (const QString &path : execs) { for (const QString &path : execs) {
@@ -254,7 +254,7 @@ FilePaths Environment::findAllInPath(const QString &executable,
const QString exec = QDir::cleanPath(expandVariables(executable)); const QString exec = QDir::cleanPath(expandVariables(executable));
const QFileInfo fi(exec); const QFileInfo fi(exec);
const QStringList execs = appendExeExtensions(exec); const QStringList execs = appendExeExtensions(*this, exec);
if (fi.isAbsolute()) { if (fi.isAbsolute()) {
for (const QString &path : execs) { for (const QString &path : execs) {

View File

@@ -64,7 +64,6 @@ public:
FilePaths path() const; FilePaths path() const;
FilePaths pathListValue(const QString &varName) const; FilePaths pathListValue(const QString &varName) const;
QStringList appendExeExtensions(const QString &executable) const;
bool isSameExecutable(const QString &exe1, const QString &exe2) const; bool isSameExecutable(const QString &exe1, const QString &exe2) const;