diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2016-10-10 13:57:33 +0200 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@qt.io> | 2016-10-31 05:03:45 +0000 |
commit | 65858057f0f76908e4734fd06e0cfaeb2ee233cd (patch) | |
tree | 01256a7d1e54899e5300c443d242b4d45f8034f1 | |
parent | ab0ba668642d2d4c941f57e949118327530234af (diff) |
configure: Determine MSVC version by evaluating macro _MSC_FULL_VER
The previously used regular expression failed for messages
in local languages, particularly for the French message containing
a non-breaking space.
Task-number: QTBUG-56388
Change-Id: Ie757617f1b3a31820d0ed274c4b157d544ac1ea6
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
(cherry picked from commit 1bd53131d83cdf595f95f82f0c049d2d68957159)
-rw-r--r-- | tools/configure/environment.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/tools/configure/environment.cpp b/tools/configure/environment.cpp index 1a05c9ce62..8f18f3c489 100644 --- a/tools/configure/environment.cpp +++ b/tools/configure/environment.cpp @@ -36,6 +36,7 @@ #include <qfile.h> #include <qfileinfo.h> #include <qstandardpaths.h> +#include <qtemporaryfile.h> #include <process.h> #include <errno.h> @@ -150,24 +151,23 @@ QString Environment::gccVersion() QString Environment::msvcVersion() { int returnValue = 0; - // Extract version from standard error output of "cl /?" - const QString command = QFile::decodeName(qgetenv("ComSpec")) - + QLatin1String(" /c ") + QLatin1String(compilerInfo(CC_MSVC2015)->executable) - + QLatin1String(" /? 2>&1"); - QString version = execute(command, &returnValue); - if (returnValue != 0) { - cout << "Could not get cl version" << returnValue << qPrintable(version) << '\n';; - version.clear(); - } else { - QRegExp versionRegexp(QStringLiteral("^.*Compiler Version ([0-9.]+) for.*$")); - Q_ASSERT(versionRegexp.isValid()); - if (versionRegexp.exactMatch(version)) { - version = versionRegexp.cap(1); - } else { - cout << "Unable to determine cl version from the output of \"" - << qPrintable(command) << "\"\n"; - } + QString tempSourceName; + { // QTemporaryFile needs to go out of scope, otherwise cl.exe refuses to open it. + QTemporaryFile tempSource(QDir::tempPath() + QLatin1String("/XXXXXX.cpp")); + tempSource.setAutoRemove(false); + if (!tempSource.open()) + return QString(); + tempSource.write("_MSC_FULL_VER\n"); + tempSourceName = tempSource.fileName(); } + QString version = execute(QLatin1String("cl /nologo /EP \"") + + QDir::toNativeSeparators(tempSourceName) + QLatin1Char('"'), + &returnValue).trimmed(); + QFile::remove(tempSourceName); + if (returnValue || version.size() < 9 || !version.at(0).isDigit()) + return QString(); + version.insert(4, QLatin1Char('.')); + version.insert(2, QLatin1Char('.')); return version; } |