From 298d07d8c883b1efa66f5bfaf4ac6e77c66ed0ef Mon Sep 17 00:00:00 2001 From: Tobias Hunger <tobias.hunger@theqtcompany.com> Date: Thu, 30 Oct 2014 15:54:25 +0100 Subject: [PATCH] QtVersion: Fix detection of system Qt We used to get a list of possible qmake file names, but now we just get a list of filename patterns. Task-number: QTCREATORBUG-13200 Change-Id: I9e635ec04b25139cfa8e7096173ac9e1910d0ef5 Reviewed-by: Daniel Teske <daniel.teske@digia.com> --- src/libs/utils/buildablehelperlibrary.cpp | 42 ++++++++++++++++------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/libs/utils/buildablehelperlibrary.cpp b/src/libs/utils/buildablehelperlibrary.cpp index abcae50ca8b..fd1b6363558 100644 --- a/src/libs/utils/buildablehelperlibrary.cpp +++ b/src/libs/utils/buildablehelperlibrary.cpp @@ -65,22 +65,40 @@ QString BuildableHelperLibrary::qtChooserToQmakePath(const QString &path) return result; } +static bool isQmake(const QString &path) +{ + if (path.isEmpty()) + return false; + QFileInfo fi(path); + if (BuildableHelperLibrary::isQtChooser(fi)) + fi.setFile(BuildableHelperLibrary::qtChooserToQmakePath(fi.symLinkTarget())); + + return !BuildableHelperLibrary::qtVersionForQMake(fi.absoluteFilePath()).isEmpty(); +} + FileName BuildableHelperLibrary::findSystemQt(const Environment &env) { + const QString qmake = QLatin1String("qmake"); QStringList paths = env.path(); foreach (const QString &path, paths) { - QString prefix = path; - if (!prefix.endsWith(QLatin1Char('/'))) - prefix.append(QLatin1Char('/')); - foreach (const QString &possibleCommand, possibleQMakeCommands()) { - QFileInfo qmake(prefix + possibleCommand); - if (qmake.exists()) { - if (isQtChooser(qmake)) - qmake.setFile(qtChooserToQmakePath(qmake.symLinkTarget())); - - if (!qtVersionForQMake(qmake.absoluteFilePath()).isNull()) - return FileName(qmake); - } + if (path.isEmpty()) + continue; + + QDir dir(path); + + 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(); -- GitLab