From 49243fb43f727b4baaff271e0d818793439e8d90 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 11 Aug 2022 15:34:56 +0300 Subject: [PATCH] [scripts] package.cmd: remove comment regarding MSVC_CL I think it's actually a good thing that these are set separately instead of being duplicated across all of the IF EXIST blocks. The reason why the old value of a variable is used inside an IF statement is because cmd does variable expansion right after reading a line, prior to any parsing being done. E.g. you can swap two variables like so: SET "X=%Y%" & SET "Y=%X%" During parsing, if a newline is reached while inside parentheses, another line is read. As a consequence, the entire IF/FOR block is read and expanded before being executed. The following script (with ECHO deliberately left ON) demonstrates this behavior: SET X=123 IF "" == "" (ECHO START SET X=456 ECHO %X%) To the solution to this is to enable delayed expansion: SETLOCAL ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS Then replace %s with !s and the variables will be expanded after parsing is done: SET "MSVC_CL=!MSVC32_DIR!\bin\HostX86\x86\cl.exe" SET "MSVC_CL64_CROSS=!MSVC64_DIR!\bin\HostX86\x64\cl.exe" SET "MSVC_CL64_NATIVE=!MSVC64_DIR!\bin\HostX64\x64\cl.exe" --- scripts/package.cmd | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/package.cmd b/scripts/package.cmd index 254f60d20..caa4e3dde 100644 --- a/scripts/package.cmd +++ b/scripts/package.cmd @@ -146,9 +146,6 @@ ECHO - 64-bit: MSVC %MSVC64_YEAR% (%MSVC64_VERSION%) ECHO. :: MSVC 2017+ uses a different directory layout. -:: NOTE: This must be set here, since you can't use a variable -:: set in a block within the same block. (It'll have the previous -:: value for some reason.) SET MSVC_CL= FOR %%I IN (2017 2019 2022) DO ( IF "%MSVC64_YEAR%" == "%%I" (