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 <david.schulz@qt.io>
This commit is contained in:
Cristian Adam
2022-10-17 17:43:47 +02:00
parent 6dd15ef3f3
commit ae07c31976

View File

@@ -2085,16 +2085,23 @@ std::optional<QString> 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");