From ae07c31976045a859c5216ebc4866a17d2ae1f91 Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Mon, 17 Oct 2022 17:43:47 +0200 Subject: [PATCH] PE: Clean environment before compiler environment detection By calling vcvarsall.bat with "/clean_env" before the actual vcvarsall.bat call we make sure that the correct environment settings are picked up by Qt Creator. For example calling Visual Studio Community/vcvarsall from an environment where Visual Studio BuildTools/vcvarscall was already called, will not return a Visual Studio Community environment, but a Visual Studio BuildTools environment. The above scenario can happen when developing Qt Creator itself with a different Visual Studio setup. Fixes: QTCREATORBUG-28315 Change-Id: Ib99cbba2a5c6299953728e92cf0283c10f7837f3 Reviewed-by: David Schulz --- src/plugins/projectexplorer/msvctoolchain.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/plugins/projectexplorer/msvctoolchain.cpp b/src/plugins/projectexplorer/msvctoolchain.cpp index 125eb269722..a77b24bc059 100644 --- a/src/plugins/projectexplorer/msvctoolchain.cpp +++ b/src/plugins/projectexplorer/msvctoolchain.cpp @@ -2085,16 +2085,23 @@ std::optional MsvcToolChain::generateEnvironmentSettings(const Utils::E // Create a batch file to create and save the env settings Utils::TempFileSaver saver(Utils::TemporaryDirectory::masterDirectoryPath() + "/XXXXXX.bat"); - QByteArray call = "call "; - call += ProcessArgs::quoteArg(batchFile).toLocal8Bit(); - if (!batchArgs.isEmpty()) { - call += ' '; - call += batchArgs.toLocal8Bit(); - } + auto makeCall = [](const QString &batchFile, const QString &batchArgs) -> QByteArray { + QByteArray call = "call "; + call += ProcessArgs::quoteArg(batchFile).toLocal8Bit(); + if (!batchArgs.isEmpty()) { + call += ' '; + call += batchArgs.toLocal8Bit(); + } + return call; + }; + QByteArray callCleanEnv = makeCall(batchFile, "/clean_env"); + QByteArray call = makeCall(batchFile, batchArgs); + if (Utils::HostOsInfo::isWindowsHost()) saver.write("chcp 65001\r\n"); saver.write("set VSCMD_SKIP_SENDTELEMETRY=1\r\n"); saver.write("set CLINK_NOAUTORUN=1\r\n"); + saver.write(callCleanEnv + "\r\n"); saver.write(call + "\r\n"); saver.write("@echo " + marker.toLocal8Bit() + "\r\n"); saver.write("set\r\n");