QtVersionManager: Find all Qt installations in PATH

Not just the first one.

Change-Id: I60c4cd8721c0833e02d2311e6f47f3194fe1ace0
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2019-03-15 10:43:35 +01:00
parent 8c0037af52
commit 5e749c6d09
3 changed files with 50 additions and 27 deletions

View File

@@ -27,11 +27,13 @@
#include "hostosinfo.h"
#include "synchronousprocess.h"
#include <QDir>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#include <QRegExp>
#include <set>
namespace Utils {
bool BuildableHelperLibrary::isQtChooser(const QFileInfo &info)
@@ -71,34 +73,56 @@ static bool isQmake(const QString &path)
return !BuildableHelperLibrary::qtVersionForQMake(fi.absoluteFilePath()).isEmpty();
}
FileName BuildableHelperLibrary::findSystemQt(const Environment &env)
static FileName findQmakeInDir(const FileName &path)
{
const QString qmake = QLatin1String("qmake");
FileNameList paths = env.path();
foreach (const FileName &path, paths) {
if (path.isEmpty())
if (path.isEmpty())
return FileName();
const QString qmake = "qmake";
QDir dir(path.toString());
if (dir.exists(qmake)) {
const QString qmakePath = dir.absoluteFilePath(qmake);
if (isQmake(qmakePath))
return FileName::fromString(qmakePath);
}
// Prefer qmake-qt5 to qmake-qt4 by sorting the filenames in reverse order.
const QFileInfoList candidates = dir.entryInfoList(
BuildableHelperLibrary::possibleQMakeCommands(),
QDir::Files, QDir::Name | QDir::Reversed);
for (const QFileInfo &fi : candidates) {
if (fi.fileName() == qmake)
continue;
QDir dir(path.toString());
if (dir.exists(qmake)) {
const QString qmakePath = dir.absoluteFilePath(qmake);
if (isQmake(qmakePath))
return FileName::fromString(qmakePath);
}
// Prefer qmake-qt5 to qmake-qt4 by sorting the filenames in reverse order.
foreach (const QFileInfo &fi, dir.entryInfoList(possibleQMakeCommands(), QDir::Files, QDir::Name | QDir::Reversed)) {
if (fi.fileName() == qmake)
continue;
if (isQmake(fi.absoluteFilePath()))
return FileName(fi);
}
if (isQmake(fi.absoluteFilePath()))
return FileName(fi);
}
return FileName();
}
FileName BuildableHelperLibrary::findSystemQt(const Environment &env)
{
const FileNameList list = findQtsInEnvironment(env, 1);
return list.size() == 1 ? list.first() : FileName();
}
FileNameList BuildableHelperLibrary::findQtsInEnvironment(const Environment &env, int maxCount)
{
FileNameList qmakeList;
std::set<QString> canonicalEnvPaths;
const FileNameList paths = env.path();
for (const FileName &path : paths) {
if (!canonicalEnvPaths.insert(path.toFileInfo().canonicalFilePath()).second)
continue;
const FileName qmake = findQmakeInDir(path);
if (qmake.isEmpty())
continue;
qmakeList << qmake;
if (maxCount != -1 && qmakeList.size() == maxCount)
break;
}
return qmakeList;
}
QString BuildableHelperLibrary::qtVersionForQMake(const QString &qmakePath)
{
if (qmakePath.isEmpty())

View File

@@ -38,6 +38,7 @@ public:
// returns the full path to the first qmake, qmake-qt4, qmake4 that has
// at least version 2.0.0 and thus is a qt4 qmake
static FileName findSystemQt(const Environment &env);
static FileNameList findQtsInEnvironment(const Environment &env, int maxCount = -1);
static bool isQtChooser(const QFileInfo &info);
static QString qtChooserToQmakePath(const QString &path);
// return true if the qmake at qmakePath is a Qt (used by QtVersion)

View File

@@ -427,10 +427,8 @@ static FileNameList gatherQmakePathsFromQtChooser()
static void findSystemQt()
{
FileNameList systemQMakes;
FileName systemQMakePath = BuildableHelperLibrary::findSystemQt(Environment::systemEnvironment());
if (!systemQMakePath.isEmpty())
systemQMakes << systemQMakePath;
FileNameList systemQMakes
= BuildableHelperLibrary::findQtsInEnvironment(Environment::systemEnvironment());
systemQMakes.append(gatherQmakePathsFromQtChooser());