[cxx] Make the externC of icalls configuration-dependent instead of always. (#17573)
[mono-project.git] / msvc / setup-windows-env.bat
blob80b5b7d8dba3c321d3046d55e93fb3648a993a49
1 :: Script will setup environment variables directly in callers environment.
3 :: If we are running from none Windows shell we will need to restore a clean PATH
4 :: before setting up VS MSVC build environment. If not there is a risk we will pick up
5 :: for example cygwin binaries when running toolchain commands not explicitly setup by
6 :: VS MSVC build environment.
7 set HKCU_ENV_PATH=
8 set HKLM_ENV_PATH=
9 if "%SHELL%" == "/bin/bash" (
10     for /f "tokens=2,*" %%a in ('%WINDIR%\System32\reg.exe query "HKCU\Environment" /v "Path" ^| %WINDIR%\System32\find.exe /i "REG_"') do (
11         SET HKCU_ENV_PATH=%%b
12     )
13     for /f "tokens=2,*" %%a in ('%WINDIR%\System32\reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" ^| %WINDIR%\System32\find.exe /i "REG_"') do (
14         SET HKLM_ENV_PATH=%%b
15     )
18 :: Restore default path, if we are running from none Windows shell.
19 if "%SHELL%" == "/bin/bash" (
20     call :restore_default_path "%HKCU_ENV_PATH%" "%HKLM_ENV_PATH%"
23 :: There is still a scenario where the default path can include cygwin\bin folder. If that's the case
24 :: there is still a big risk that build tools will be incorrectly resolved towards cygwin bin folder.
25 :: Make sure to adjust path and drop all cygwin paths.
26 set NEW_PATH=
27 call where /Q "cygpath.exe" && (
28     echo Warning, PATH includes cygwin bin folders. This can cause build errors due to incorrectly
29     echo located build tools. Build script will drop all cygwin folders from used PATH.
30     for %%a in ("%PATH:;=";"%") do (
31         if not exist "%%~a\cygpath.exe" (
32             call :add_to_new_path "%%~a"
33         )
34     )
37 if not "%NEW_PATH%" == "" (
38     set "PATH=%NEW_PATH%"
41 exit /b 0
43 :restore_default_path
45 :: Restore default PATH.
46 if not "%~2" == "" (
47     if not "%~1" == "" (
48         set "PATH=%~2;%~1"
49     ) else (
50         set "PATH=%~2"
51     )
54 goto :EOF
56 :add_to_new_path
58 if "%NEW_PATH%" == "" (
59     set "NEW_PATH=%~1"
60 ) else (
61     SET "NEW_PATH=%NEW_PATH%;%~1"
64 goto :EOF