forked from qt-creator/qt-creator
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:
@@ -27,11 +27,13 @@
|
|||||||
#include "hostosinfo.h"
|
#include "hostosinfo.h"
|
||||||
#include "synchronousprocess.h"
|
#include "synchronousprocess.h"
|
||||||
|
|
||||||
#include <QDir>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
bool BuildableHelperLibrary::isQtChooser(const QFileInfo &info)
|
bool BuildableHelperLibrary::isQtChooser(const QFileInfo &info)
|
||||||
@@ -71,34 +73,56 @@ static bool isQmake(const QString &path)
|
|||||||
return !BuildableHelperLibrary::qtVersionForQMake(fi.absoluteFilePath()).isEmpty();
|
return !BuildableHelperLibrary::qtVersionForQMake(fi.absoluteFilePath()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileName BuildableHelperLibrary::findSystemQt(const Environment &env)
|
static FileName findQmakeInDir(const FileName &path)
|
||||||
{
|
{
|
||||||
const QString qmake = QLatin1String("qmake");
|
if (path.isEmpty())
|
||||||
FileNameList paths = env.path();
|
return FileName();
|
||||||
foreach (const FileName &path, paths) {
|
|
||||||
if (path.isEmpty())
|
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;
|
continue;
|
||||||
|
if (isQmake(fi.absoluteFilePath()))
|
||||||
QDir dir(path.toString());
|
return FileName(fi);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return FileName();
|
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)
|
QString BuildableHelperLibrary::qtVersionForQMake(const QString &qmakePath)
|
||||||
{
|
{
|
||||||
if (qmakePath.isEmpty())
|
if (qmakePath.isEmpty())
|
||||||
|
@@ -38,6 +38,7 @@ public:
|
|||||||
// returns the full path to the first qmake, qmake-qt4, qmake4 that has
|
// 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
|
// at least version 2.0.0 and thus is a qt4 qmake
|
||||||
static FileName findSystemQt(const Environment &env);
|
static FileName findSystemQt(const Environment &env);
|
||||||
|
static FileNameList findQtsInEnvironment(const Environment &env, int maxCount = -1);
|
||||||
static bool isQtChooser(const QFileInfo &info);
|
static bool isQtChooser(const QFileInfo &info);
|
||||||
static QString qtChooserToQmakePath(const QString &path);
|
static QString qtChooserToQmakePath(const QString &path);
|
||||||
// return true if the qmake at qmakePath is a Qt (used by QtVersion)
|
// return true if the qmake at qmakePath is a Qt (used by QtVersion)
|
||||||
|
@@ -427,10 +427,8 @@ static FileNameList gatherQmakePathsFromQtChooser()
|
|||||||
|
|
||||||
static void findSystemQt()
|
static void findSystemQt()
|
||||||
{
|
{
|
||||||
FileNameList systemQMakes;
|
FileNameList systemQMakes
|
||||||
FileName systemQMakePath = BuildableHelperLibrary::findSystemQt(Environment::systemEnvironment());
|
= BuildableHelperLibrary::findQtsInEnvironment(Environment::systemEnvironment());
|
||||||
if (!systemQMakePath.isEmpty())
|
|
||||||
systemQMakes << systemQMakePath;
|
|
||||||
|
|
||||||
systemQMakes.append(gatherQmakePathsFromQtChooser());
|
systemQMakes.append(gatherQmakePathsFromQtChooser());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user