forked from qt-creator/qt-creator
Utils: Add an Environment::searchInDirectories
And use it in the local branch for FilePath::searchInDirectory which so far erroneously also looked into the system environment's path. Change-Id: I60316831b74a55dee84fbf4b54c0eecc49dd8dde Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -136,7 +136,9 @@ void Environment::setupEnglishOutput()
|
|||||||
set("LANGUAGE", "en_US:en");
|
set("LANGUAGE", "en_US:en");
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath Environment::searchInDirectory(const QStringList &execs, const FilePath &directory,
|
static FilePath searchInDirectory(const Environment &env,
|
||||||
|
const QStringList &execs,
|
||||||
|
const FilePath &directory,
|
||||||
QSet<FilePath> &alreadyChecked)
|
QSet<FilePath> &alreadyChecked)
|
||||||
{
|
{
|
||||||
const int checkedCount = alreadyChecked.count();
|
const int checkedCount = alreadyChecked.count();
|
||||||
@@ -199,17 +201,19 @@ QString Environment::expandedValueForKey(const QString &key) const
|
|||||||
return expandVariables(value(key));
|
return expandVariables(value(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath Environment::searchInPath(const QString &executable,
|
static FilePath searchInDirectoriesHelper(const Environment &env,
|
||||||
const FilePaths &additionalDirs,
|
const QString &executable,
|
||||||
const PathFilter &func) const
|
const FilePaths &dirs,
|
||||||
|
const Environment::PathFilter &func,
|
||||||
|
bool usePath)
|
||||||
{
|
{
|
||||||
if (executable.isEmpty())
|
if (executable.isEmpty())
|
||||||
return FilePath();
|
return FilePath();
|
||||||
|
|
||||||
const QString exec = QDir::cleanPath(expandVariables(executable));
|
const QString exec = QDir::cleanPath(env.expandVariables(executable));
|
||||||
const QFileInfo fi(exec);
|
const QFileInfo fi(exec);
|
||||||
|
|
||||||
const QStringList execs = appendExeExtensions(exec);
|
const QStringList execs = env.appendExeExtensions(exec);
|
||||||
|
|
||||||
if (fi.isAbsolute()) {
|
if (fi.isAbsolute()) {
|
||||||
for (const QString &path : execs) {
|
for (const QString &path : execs) {
|
||||||
@@ -221,23 +225,38 @@ FilePath Environment::searchInPath(const QString &executable,
|
|||||||
}
|
}
|
||||||
|
|
||||||
QSet<FilePath> alreadyChecked;
|
QSet<FilePath> alreadyChecked;
|
||||||
for (const FilePath &dir : additionalDirs) {
|
for (const FilePath &dir : dirs) {
|
||||||
FilePath tmp = searchInDirectory(execs, dir, alreadyChecked);
|
FilePath tmp = searchInDirectory(env, execs, dir, alreadyChecked);
|
||||||
if (!tmp.isEmpty() && (!func || func(tmp)))
|
if (!tmp.isEmpty() && (!func || func(tmp)))
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (usePath) {
|
||||||
if (executable.contains('/'))
|
if (executable.contains('/'))
|
||||||
return FilePath();
|
return FilePath();
|
||||||
|
|
||||||
for (const FilePath &p : path()) {
|
for (const FilePath &p : env.path()) {
|
||||||
FilePath tmp = searchInDirectory(execs, p, alreadyChecked);
|
FilePath tmp = searchInDirectory(env, execs, p, alreadyChecked);
|
||||||
if (!tmp.isEmpty() && (!func || func(tmp)))
|
if (!tmp.isEmpty() && (!func || func(tmp)))
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return FilePath();
|
return FilePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FilePath Environment::searchInDirectories(const QString &executable,
|
||||||
|
const FilePaths &dirs) const
|
||||||
|
{
|
||||||
|
return searchInDirectoriesHelper(*this, executable, dirs, {}, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
FilePath Environment::searchInPath(const QString &executable,
|
||||||
|
const FilePaths &additionalDirs,
|
||||||
|
const PathFilter &func) const
|
||||||
|
{
|
||||||
|
return searchInDirectoriesHelper(*this, executable, additionalDirs, func, true);
|
||||||
|
}
|
||||||
|
|
||||||
FilePaths Environment::findAllInPath(const QString &executable,
|
FilePaths Environment::findAllInPath(const QString &executable,
|
||||||
const FilePaths &additionalDirs,
|
const FilePaths &additionalDirs,
|
||||||
const Environment::PathFilter &func) const
|
const Environment::PathFilter &func) const
|
||||||
@@ -262,14 +281,14 @@ FilePaths Environment::findAllInPath(const QString &executable,
|
|||||||
QSet<FilePath> result;
|
QSet<FilePath> result;
|
||||||
QSet<FilePath> alreadyChecked;
|
QSet<FilePath> alreadyChecked;
|
||||||
for (const FilePath &dir : additionalDirs) {
|
for (const FilePath &dir : additionalDirs) {
|
||||||
FilePath tmp = searchInDirectory(execs, dir, alreadyChecked);
|
FilePath tmp = searchInDirectory(*this, execs, dir, alreadyChecked);
|
||||||
if (!tmp.isEmpty() && (!func || func(tmp)))
|
if (!tmp.isEmpty() && (!func || func(tmp)))
|
||||||
result << tmp;
|
result << tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!executable.contains('/')) {
|
if (!executable.contains('/')) {
|
||||||
for (const FilePath &p : path()) {
|
for (const FilePath &p : path()) {
|
||||||
FilePath tmp = searchInDirectory(execs, p, alreadyChecked);
|
FilePath tmp = searchInDirectory(*this, execs, p, alreadyChecked);
|
||||||
if (!tmp.isEmpty() && (!func || func(tmp)))
|
if (!tmp.isEmpty() && (!func || func(tmp)))
|
||||||
result << tmp;
|
result << tmp;
|
||||||
}
|
}
|
||||||
|
@@ -63,6 +63,8 @@ public:
|
|||||||
FilePath searchInPath(const QString &executable,
|
FilePath searchInPath(const QString &executable,
|
||||||
const FilePaths &additionalDirs = FilePaths(),
|
const FilePaths &additionalDirs = FilePaths(),
|
||||||
const PathFilter &func = PathFilter()) const;
|
const PathFilter &func = PathFilter()) const;
|
||||||
|
FilePath searchInDirectories(const QString &executable,
|
||||||
|
const FilePaths &dirs) const;
|
||||||
FilePaths findAllInPath(const QString &executable,
|
FilePaths findAllInPath(const QString &executable,
|
||||||
const FilePaths &additionalDirs = FilePaths(),
|
const FilePaths &additionalDirs = FilePaths(),
|
||||||
const PathFilter &func = PathFilter()) const;
|
const PathFilter &func = PathFilter()) const;
|
||||||
@@ -80,10 +82,6 @@ public:
|
|||||||
|
|
||||||
static void modifySystemEnvironment(const EnvironmentItems &list); // use with care!!!
|
static void modifySystemEnvironment(const EnvironmentItems &list); // use with care!!!
|
||||||
static void setSystemEnvironment(const Environment &environment); // don't use at all!!!
|
static void setSystemEnvironment(const Environment &environment); // don't use at all!!!
|
||||||
|
|
||||||
private:
|
|
||||||
static FilePath searchInDirectory(const QStringList &execs, const FilePath &directory,
|
|
||||||
QSet<FilePath> &alreadyChecked);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT EnvironmentChange final
|
class QTCREATOR_UTILS_EXPORT EnvironmentChange final
|
||||||
|
@@ -1208,7 +1208,7 @@ FilePath FilePath::searchInDirectories(const FilePaths &dirs) const
|
|||||||
QTC_ASSERT(s_deviceHooks.searchInPath, return {});
|
QTC_ASSERT(s_deviceHooks.searchInPath, return {});
|
||||||
return s_deviceHooks.searchInPath(*this, dirs);
|
return s_deviceHooks.searchInPath(*this, dirs);
|
||||||
}
|
}
|
||||||
return Environment::systemEnvironment().searchInPath(path(), dirs);
|
return Environment::systemEnvironment().searchInDirectories(path(), dirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath FilePath::searchInPath(const QList<FilePath> &additionalDirs) const
|
FilePath FilePath::searchInPath(const QList<FilePath> &additionalDirs) const
|
||||||
|
Reference in New Issue
Block a user