From b1d1e10d23862d1d38b34bfec0620cea0891e59c Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Sun, 26 Dec 2021 18:57:11 +0300 Subject: Fix detection of MSVC environment for cross-compilers The MSVC profile has no mention of the host architecture, since it contains only the target architecture. Therefore, in the probe for the MSVC cross-compilers such as HostX64\x86, HostX86\x64, only the target architecture is passed to determine their build environment, which is incorrect. We need to pass the combined cross-architecture as x86_x64, x64_x86 by analogy as it is done in the qbs-setup-toolchains. Fixes: QBS-1681 Change-Id: I549d8673cd6d4b0e46bf714355206b9efb2f5b1f Reviewed-by: Ivan Komissarov --- src/lib/corelib/jsextensions/utilitiesextension.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/corelib/jsextensions/utilitiesextension.cpp b/src/lib/corelib/jsextensions/utilitiesextension.cpp index 2dc87e980..53596bd1b 100644 --- a/src/lib/corelib/jsextensions/utilitiesextension.cpp +++ b/src/lib/corelib/jsextensions/utilitiesextension.cpp @@ -465,6 +465,22 @@ QScriptValue UtilitiesExtension::js_signingIdentities(QScriptContext *context, } #ifdef Q_OS_WIN +// Try to detect the cross-architecture from the compiler path; prepend the host architecture +// if it is differ than the target architecture (e.g. something like x64_x86 and so forth). +static QString detectArchitecture(const QString &compilerFilePath, const QString &targetArch) +{ + const auto startIndex = compilerFilePath.lastIndexOf(QLatin1String("Host")); + if (startIndex == -1) + return targetArch; + const auto endIndex = compilerFilePath.indexOf(QLatin1Char('/'), startIndex); + if (endIndex == -1) + return targetArch; + const auto hostArch = compilerFilePath.mid(startIndex + 4, endIndex - startIndex - 4).toLower(); + if (hostArch.isEmpty() || (hostArch == targetArch)) + return targetArch; + return hostArch + QLatin1Char('_') + targetArch; +} + static std::pair msvcCompilerInfoHelper( const QString &compilerFilePath, MSVC::CompilerLanguage language, @@ -472,7 +488,8 @@ static std::pair msvcCompilerInfoHelp const QString &arch, const QString &sdkVersion) { - MSVC msvc(compilerFilePath, arch, sdkVersion); + QString detailedArch = detectArchitecture(compilerFilePath, arch); + MSVC msvc(compilerFilePath, std::move(detailedArch), sdkVersion); VsEnvironmentDetector envdetector(vcvarsallPath); if (!envdetector.start(&msvc)) return { {}, QStringLiteral("Detecting the MSVC build environment failed: ") -- cgit v1.2.3