From 5e749c6d09b3d356b5030de1015a4a5b93c8de61 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 15 Mar 2019 10:43:35 +0100 Subject: [PATCH] QtVersionManager: Find all Qt installations in PATH Not just the first one. Change-Id: I60c4cd8721c0833e02d2311e6f47f3194fe1ace0 Reviewed-by: hjk --- src/libs/utils/buildablehelperlibrary.cpp | 70 +++++++++++++++------- src/libs/utils/buildablehelperlibrary.h | 1 + src/plugins/qtsupport/qtversionmanager.cpp | 6 +- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/libs/utils/buildablehelperlibrary.cpp b/src/libs/utils/buildablehelperlibrary.cpp index 3c53e09b2a4..ab108fab8c9 100644 --- a/src/libs/utils/buildablehelperlibrary.cpp +++ b/src/libs/utils/buildablehelperlibrary.cpp @@ -27,11 +27,13 @@ #include "hostosinfo.h" #include "synchronousprocess.h" -#include #include #include +#include #include +#include + 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 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()) diff --git a/src/libs/utils/buildablehelperlibrary.h b/src/libs/utils/buildablehelperlibrary.h index c818749f2b6..f2ec3668635 100644 --- a/src/libs/utils/buildablehelperlibrary.h +++ b/src/libs/utils/buildablehelperlibrary.h @@ -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) diff --git a/src/plugins/qtsupport/qtversionmanager.cpp b/src/plugins/qtsupport/qtversionmanager.cpp index a0d62e129d8..734363d2e68 100644 --- a/src/plugins/qtsupport/qtversionmanager.cpp +++ b/src/plugins/qtsupport/qtversionmanager.cpp @@ -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());