From d38fd9fa901cd7f30821367b831676837eb82fe3 Mon Sep 17 00:00:00 2001 From: Ivan Komissarov Date: Sun, 18 Apr 2021 22:24:23 +0300 Subject: Fix detecting MSVC via Probe when multiple versions are present Previously, Qbs iterated over different versions in the ascending order. During the setup-toolchains this means that the newest one will be written in the settings as only the last one is actually written. When running ClBinaryProbe, the first one (i.e. the oldest was picked up) which did not work well with vcvarsall (without -vcvars_ver parameter, it uses the newest one). So, pick up the newest compiler both when running setup-toolchains and when detecting via Probe. Task-number: QBS-1498 Change-Id: Ib1b433ca7e17747dee986ba383a3c01ee91851fb Reviewed-by: Christian Kandeler --- src/app/qbs-setup-toolchains/msvcprobe.cpp | 6 ++++++ src/lib/corelib/tools/msvcinfo.cpp | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app/qbs-setup-toolchains/msvcprobe.cpp b/src/app/qbs-setup-toolchains/msvcprobe.cpp index bb54add9f..19da1e25a 100644 --- a/src/app/qbs-setup-toolchains/msvcprobe.cpp +++ b/src/app/qbs-setup-toolchains/msvcprobe.cpp @@ -58,6 +58,7 @@ #include #include +#include #include using namespace qbs; @@ -182,9 +183,14 @@ void msvcProbe(Settings *settings, std::vector &profiles) } } + std::unordered_set seenNames; for (MSVC &msvc : msvcs) { const QString name = QLatin1String("MSVC") + msvc.version + QLatin1Char('-') + msvc.architecture; + // TODO: Qbs currently does not support multiple versions of installed MSVCs + // so we stop at the first (the newest) one + if (!seenNames.insert(name).second) + continue; try { msvc.init(); addMSVCPlatform(settings, profiles, name, &msvc); diff --git a/src/lib/corelib/tools/msvcinfo.cpp b/src/lib/corelib/tools/msvcinfo.cpp index 42cfefe7b..83c53ba5c 100644 --- a/src/lib/corelib/tools/msvcinfo.cpp +++ b/src/lib/corelib/tools/msvcinfo.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -471,12 +472,20 @@ static std::vector installedCompilersHelper(Logger &logger) QDir vcInstallDir = vsInstallDir; vcInstallDir.cd(QStringLiteral("Tools/MSVC")); const auto vcVersionStrs = vcInstallDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); + std::vector vcVersions; + vcVersions.reserve(vcVersionStrs.size()); for (const QString &vcVersionStr : vcVersionStrs) { const Version vcVersion = Version::fromString(vcVersionStr); if (!vcVersion.isValid()) continue; + vcVersions.push_back(vcVersion); + } + // sort the versions so the new one comes first + std::sort(vcVersions.begin(), vcVersions.end(), std::greater()); + + for (const Version &vcVersion : vcVersions) { QDir specificVcInstallDir = vcInstallDir; - if (!specificVcInstallDir.cd(vcVersionStr) + if (!specificVcInstallDir.cd(vcVersion.toString()) || !specificVcInstallDir.cd(QStringLiteral("bin"))) { continue; } -- cgit v1.2.3