aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2016-11-08 15:04:46 +0100
committerJoerg Bornemann <joerg.bornemann@qt.io>2016-11-10 15:13:27 +0000
commitfb2cf69d8322ed1dc165ca67ffe68825fc699123 (patch)
tree8f514b22b8283696151a4fcbe69456c496d0a7f1 /src
parent684548e2634ca620ae24b73f7715b70ac90cbb76 (diff)
Speed up qbs-setup-toolchains for MSVC
Determine the compiler's version by preprocessing a file containing _MSC_FULL_VER instead of compiling and linking a program to determine all compiler defines. With this change qbs-setup-toolchains needs less than 1/2 of the time to detect MSVC installations. Change-Id: I254e6c6d3abe489b328e979228e8b21f8d92f39c Task-number: QBS-866 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/app/qbs-setup-toolchains/msvcprobe.cpp49
-rw-r--r--src/lib/corelib/tools/msvcinfo.cpp33
-rw-r--r--src/lib/corelib/tools/msvcinfo.h8
3 files changed, 65 insertions, 25 deletions
diff --git a/src/app/qbs-setup-toolchains/msvcprobe.cpp b/src/app/qbs-setup-toolchains/msvcprobe.cpp
index 08d92319a..716d0aaee 100644
--- a/src/app/qbs-setup-toolchains/msvcprobe.cpp
+++ b/src/app/qbs-setup-toolchains/msvcprobe.cpp
@@ -67,32 +67,16 @@ Q_DECLARE_TYPEINFO(MSVC, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
// Not necessary but helps setup-qt automatically associate base profiles
-static void setQtHelperProperties(Profile &p, const QString &architecture,
- const QString &compilerFilePath)
+static void setQtHelperProperties(Profile &p, const MSVC *msvc)
{
- MSVC msvc(compilerFilePath);
- VsEnvironmentDetector envdetector;
- if (!envdetector.start(&msvc)) {
- qbsWarning() << (QStringLiteral("Detecting the MSVC build environment failed: ")
- + envdetector.errorString());
- return;
- }
-
- QString targetArch = architecture.split(QLatin1Char('_')).last();
+ QString targetArch = msvc->architecture.split(QLatin1Char('_')).last();
if (targetArch.isEmpty())
targetArch = QStringLiteral("x86");
if (targetArch == QStringLiteral("arm"))
targetArch = QStringLiteral("armv7");
p.setValue(QStringLiteral("qbs.architecture"), canonicalArchitecture(targetArch));
- try {
- const QVariantMap defines = msvc.compilerDefines(compilerFilePath);
- p.setValue(QStringLiteral("cpp.compilerVersionMajor"),
- defines[QStringLiteral("_MSC_FULL_VER")].toString().mid(0, 2).toInt());
- } catch (const ErrorInfo &error) {
- p.removeProfile();
- qDebug("Warning: Failed to retrieve compiler defines: %s", qPrintable(error.toString()));
- }
+ p.setValue(QStringLiteral("cpp.compilerVersionMajor"), msvc->compilerVersion.majorVersion());
}
static void addMSVCPlatform(Settings *settings, QList<Profile> &profiles, QString name, MSVC *msvc)
@@ -103,7 +87,7 @@ static void addMSVCPlatform(Settings *settings, QList<Profile> &profiles, QStrin
p.setValue(QLatin1String("qbs.targetOS"), QStringList(QLatin1String("windows")));
p.setValue(QLatin1String("qbs.toolchain"), QStringList(QLatin1String("msvc")));
p.setValue(QLatin1String("cpp.toolchainInstallPath"), msvc->binPath);
- setQtHelperProperties(p, msvc->architecture, msvc->binPath + QLatin1String("/cl.exe"));
+ setQtHelperProperties(p, msvc);
profiles << p;
}
@@ -225,18 +209,39 @@ void msvcProbe(Settings *settings, QList<Profile> &profiles)
return;
}
+ qbsInfo() << Tr::tr("Detecting build environment...");
+ QVector<MSVC *> msvcPtrs;
+ msvcPtrs.resize(winSDKs.size() + msvcs.size());
+ std::transform(winSDKs.begin(), winSDKs.end(), msvcPtrs.begin(),
+ [] (WinSDK &sdk) -> MSVC * { return &sdk; });
+ std::transform(msvcs.begin(), msvcs.end(), msvcPtrs.begin() + winSDKs.size(),
+ [] (MSVC &msvc) -> MSVC * { return &msvc; });
+
+ VsEnvironmentDetector envDetector;
+ envDetector.start(msvcPtrs);
+
for (int i = 0; i < winSDKs.count(); ++i) {
WinSDK &sdk = winSDKs[i];
const QString name = QLatin1String("WinSDK") + sdk.version + QLatin1Char('-')
+ sdk.architecture;
- addMSVCPlatform(settings, profiles, name, &sdk);
+ try {
+ sdk.init();
+ addMSVCPlatform(settings, profiles, name, &sdk);
+ } catch (const ErrorInfo &error) {
+ qbsWarning() << Tr::tr("Failed to set up %1: %2").arg(name, error.toString());
+ }
}
for (int i = 0; i < msvcs.count(); ++i) {
MSVC &msvc = msvcs[i];
const QString name = QLatin1String("MSVC") + msvc.version + QLatin1Char('-')
+ msvc.architecture;
- addMSVCPlatform(settings, profiles, name, &msvc);
+ try {
+ msvc.init();
+ addMSVCPlatform(settings, profiles, name, &msvc);
+ } catch (const ErrorInfo &error) {
+ qbsWarning() << Tr::tr("Failed to set up %1: %2").arg(name, error.toString());
+ }
}
}
diff --git a/src/lib/corelib/tools/msvcinfo.cpp b/src/lib/corelib/tools/msvcinfo.cpp
index e2862a591..d464f001e 100644
--- a/src/lib/corelib/tools/msvcinfo.cpp
+++ b/src/lib/corelib/tools/msvcinfo.cpp
@@ -41,7 +41,6 @@
#include <tools/error.h>
#include <tools/profile.h>
-#include <tools/version.h>
#include <tools/vsenvironmentdetector.h>
#include <QByteArray>
@@ -209,6 +208,11 @@ static QVariantMap getMsvcDefines(const QString &hostCompilerFilePath,
return map;
}
+void MSVC::init()
+{
+ determineCompilerVersion();
+}
+
QString MSVC::binPathForArchitecture(const QString &arch) const
{
QString archSubDir;
@@ -228,3 +232,30 @@ QVariantMap MSVC::compilerDefines(const QString &compilerFilePath) const
return getMsvcDefines(clPathForArchitecture(QStringLiteral("x86")), compilerFilePath,
environment);
}
+
+void MSVC::determineCompilerVersion()
+{
+ QString cppFilePath;
+ {
+ QTemporaryFile cppFile(QDir::tempPath() + QLatin1String("/qbsXXXXXX.cpp"));
+ cppFile.setAutoRemove(false);
+ if (!cppFile.open()) {
+ throw ErrorInfo(mkStr("Could not create temporary file (%1)")
+ .arg(cppFile.errorString()));
+ }
+ cppFilePath = cppFile.fileName();
+ cppFile.write("_MSC_FULL_VER");
+ cppFile.close();
+ }
+ DummyFile fileDeleter(cppFilePath);
+
+ const QByteArray origPath = qgetenv("PATH");
+ qputenv("PATH", environment.value(QStringLiteral("PATH")).toLatin1() + ';' + origPath);
+ QByteArray versionStr = runProcess(
+ binPath + QStringLiteral("/cl.exe"),
+ QStringList() << QStringLiteral("/nologo") << QStringLiteral("/EP")
+ << QDir::toNativeSeparators(cppFilePath));
+ qputenv("PATH", origPath);
+ compilerVersion = Version(versionStr.mid(0, 2).toInt(), versionStr.mid(2, 2).toInt(),
+ versionStr.mid(4).toInt());
+}
diff --git a/src/lib/corelib/tools/msvcinfo.h b/src/lib/corelib/tools/msvcinfo.h
index 9e9c68cf3..be64bf9cb 100644
--- a/src/lib/corelib/tools/msvcinfo.h
+++ b/src/lib/corelib/tools/msvcinfo.h
@@ -42,6 +42,7 @@
#include <logging/translator.h>
#include <tools/error.h>
+#include <tools/version.h>
#include <QDir>
#include <QFileInfo>
@@ -52,8 +53,6 @@
namespace qbs {
namespace Internal {
-class Version;
-
/**
* Represents one MSVC installation for one specific target architecture.
* There are potentially multiple MSVCs in one Visual Studio installation.
@@ -62,6 +61,7 @@ class MSVC
{
public:
QString version;
+ Version compilerVersion;
QString vcInstallPath;
QString binPath;
QString pathPrefix;
@@ -83,9 +83,13 @@ public:
binPath = vcInstallPath;
}
+ QBS_EXPORT void init();
QBS_EXPORT QString binPathForArchitecture(const QString &arch) const;
QBS_EXPORT QString clPathForArchitecture(const QString &arch) const;
QBS_EXPORT QVariantMap compilerDefines(const QString &compilerFilePath) const;
+
+private:
+ void determineCompilerVersion();
};
class WinSDK : public MSVC