forked from qt-creator/qt-creator
Utils: Add path search function to environment
In contrast to Environment::searchInPath This function returns _all_ executables found in the path variable. Change-Id: Ic62b8f70d0690ff9a3261db3ead2c919a2486c89 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -273,6 +273,45 @@ FilePath Environment::searchInPath(const QString &executable,
|
||||
return FilePath();
|
||||
}
|
||||
|
||||
FilePathList Environment::findAllInPath(const QString &executable,
|
||||
const FilePathList &additionalDirs,
|
||||
const Environment::PathFilter &func) const
|
||||
{
|
||||
if (executable.isEmpty())
|
||||
return {};
|
||||
|
||||
const QString exec = QDir::cleanPath(expandVariables(executable));
|
||||
const QFileInfo fi(exec);
|
||||
|
||||
const QStringList execs = appendExeExtensions(exec);
|
||||
|
||||
if (fi.isAbsolute()) {
|
||||
for (const QString &path : execs) {
|
||||
QFileInfo pfi = QFileInfo(path);
|
||||
if (pfi.isFile() && pfi.isExecutable())
|
||||
return {FilePath::fromString(path)};
|
||||
}
|
||||
return {FilePath::fromString(exec)};
|
||||
}
|
||||
|
||||
QSet<FilePath> result;
|
||||
QSet<FilePath> alreadyChecked;
|
||||
for (const FilePath &dir : additionalDirs) {
|
||||
FilePath tmp = searchInDirectory(execs, dir, alreadyChecked);
|
||||
if (!tmp.isEmpty() && (!func || func(tmp)))
|
||||
result << tmp;
|
||||
}
|
||||
|
||||
if (!executable.contains('/')) {
|
||||
for (const FilePath &p : path()) {
|
||||
FilePath tmp = searchInDirectory(execs, p, alreadyChecked);
|
||||
if (!tmp.isEmpty() && (!func || func(tmp)))
|
||||
result << tmp;
|
||||
}
|
||||
}
|
||||
return result.values();
|
||||
}
|
||||
|
||||
FilePathList Environment::path() const
|
||||
{
|
||||
return pathListValue("PATH");
|
||||
|
@@ -66,6 +66,9 @@ public:
|
||||
FilePath searchInPath(const QString &executable,
|
||||
const FilePathList &additionalDirs = FilePathList(),
|
||||
const PathFilter &func = PathFilter()) const;
|
||||
FilePathList findAllInPath(const QString &executable,
|
||||
const FilePathList &additionalDirs = FilePathList(),
|
||||
const PathFilter &func = PathFilter()) const;
|
||||
|
||||
FilePathList path() const;
|
||||
FilePathList pathListValue(const QString &varName) const;
|
||||
|
Reference in New Issue
Block a user