diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2018-12-13 08:35:11 +0100 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2018-12-14 08:38:30 +0000 |
commit | a376eb0a8191354d77616b10c7d577d58ad36193 (patch) | |
tree | a48366563a627d3a9d0f77d7bbba48158b43b4fa | |
parent | f7a905e602de8dd03422c57c3a587d5360c37d8a (diff) |
MsvcToolChain: Add installationFromPathAndVersion helper function
In preparation for an upcoming patch the creation of
VisualStudioInstallations from installationPath and version is moved to a
helper function.
Change-Id: I0c5973028be22b229d45f20045cf47b5da44f682
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Miguel Costa <miguel.costa@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r-- | src/plugins/projectexplorer/msvctoolchain.cpp | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/src/plugins/projectexplorer/msvctoolchain.cpp b/src/plugins/projectexplorer/msvctoolchain.cpp index 2f66ef1580..7f58378e7f 100644 --- a/src/plugins/projectexplorer/msvctoolchain.cpp +++ b/src/plugins/projectexplorer/msvctoolchain.cpp @@ -179,6 +179,36 @@ static QString windowsProgramFilesDir() return QDir::fromNativeSeparators(QFile::decodeName(qgetenv(programFilesC))); } +static Utils::optional<VisualStudioInstallation> installationFromPathAndVersion( + const QString &installationPath, + const QVersionNumber &version) +{ + QString vcVarsPath = QDir::fromNativeSeparators(installationPath); + if (!vcVarsPath.endsWith('/')) + vcVarsPath += '/'; + if (version.majorVersion() > 14) + vcVarsPath += QStringLiteral("VC/Auxiliary/Build"); + else + vcVarsPath += QStringLiteral("VC"); + + const QString vcVarsAllPath = vcVarsPath + QStringLiteral("/vcvarsall.bat"); + if (!QFileInfo(vcVarsAllPath).isFile()) { + qWarning().noquote() << "Unable to find MSVC setup script " + << QDir::toNativeSeparators(vcVarsPath) << " in version " + << version; + return Utils::nullopt; + } + + const QString versionString = version.toString(); + VisualStudioInstallation installation; + installation.path = installationPath; + installation.version = version; + installation.vsName = versionString; + installation.vcVarsPath = vcVarsPath; + installation.vcVarsAll = vcVarsAllPath; + return std::move(installation); +} + // Detect build tools introduced with MSVC2017 static Utils::optional<VisualStudioInstallation> detectCppBuildTools2017() { @@ -210,34 +240,15 @@ static QVector<VisualStudioInstallation> detectVisualStudio() #endif QSettings vsRegistry(keyRoot + QStringLiteral("VS7"), QSettings::NativeFormat); QScopedPointer<QSettings> vcRegistry; - const QString vcvarsall = QStringLiteral("/vcvarsall.bat"); foreach (const QString &vsName, vsRegistry.allKeys()) { const QVersionNumber version = QVersionNumber::fromString(vsName); if (!version.isNull()) { - VisualStudioInstallation installation; - installation.vsName = vsName; - installation.version = version; - if (version.majorVersion() > 14) { - // Starting with 15 (MSVC2017): There are no more VC entries, - // build path from VS installation - installation.path = fixRegistryPath(vsRegistry.value(vsName).toString()); - installation.vcVarsPath = installation.path + QStringLiteral("/VC/Auxiliary/Build"); - installation.vcVarsAll = installation.vcVarsPath + vcvarsall; - } else { - // Up to 14 (MSVC2015): Look up via matching VC entry - if (vcRegistry.isNull()) - vcRegistry.reset(new QSettings(keyRoot + QStringLiteral("VC7"), QSettings::NativeFormat)); - installation.path = fixRegistryPath(vcRegistry->value(vsName).toString()); - installation.vcVarsPath = installation.path; - installation.vcVarsAll = installation.vcVarsPath + vcvarsall; - } - if (QFileInfo(installation.vcVarsAll).isFile()) { - result.append(installation); - } else { - qWarning().noquote() << "Unable to find MSVC setup script " - << QDir::toNativeSeparators(installation.vcVarsPath) << " in version " - << version; - } + const QString installationPath = fixRegistryPath(vsRegistry.value(vsName).toString()); + + Utils::optional<VisualStudioInstallation> installation + = installationFromPathAndVersion(installationPath, version); + if (installation) + result.append(*installation); } } |