Add comments.
[mono-project.git] / msvc / mono-sgen-msvc.bat
blob5458a8fe7a1d415a135f50b251142a7267aae582
1 :: Set up VS MSVC environment when running MSVC build mono-sgen.exe with all supplied arguments.\r
2 :: Simplify the setup of VS and MSVC toolchain, when running Mono AOT compiler\r
3 :: since it need to locate correct compiler and OS libraries as well as clang.exe and link.exe\r
4 :: from VS setup for the corresponding architecture.\r
5 \r
6 @echo off\r
7 setlocal\r
8 \r
9 set EXECUTE_RESULT=1\r
11 :: Get path for current running script.\r
12 set RUN_MONO_SGEN_MSVC_SCRIPT_PATH=%~dp0\r
14 :: Optimization, check if we need to setup full build environment, only needed when running mono-sgen.exe as AOT compiler.\r
15 if "%MONO_AS_AOT_COMPILER%" == "1" (\r
16     goto SETUP_VS_ENV\r
17 )\r
19 set MONO_AS_AOT_COMPILER=0\r
20 :: Look for --aot or --aot=, --aot-path alone should not trigger setup of VS env.\r
21 echo.%* | findstr /r /c:".*--aot[^-a-zA-Z0-9].*" > nul && (\r
22     set MONO_AS_AOT_COMPILER=1\r
23 )\r
25 if %MONO_AS_AOT_COMPILER% == 1 (\r
26     goto SETUP_VS_ENV\r
27 )\r
29 :: mono-sgen.exe not invoked as a AOT compiler, no need to setup full build environment.\r
30 goto ON_EXECUTE\r
32 :: Try setting up VS MSVC build environment.\r
33 :SETUP_VS_ENV\r
35 :: Optimization, check if we have something that looks like a VS MSVC build environment\r
36 :: already available.\r
37 if /i not "%VCINSTALLDIR%" == "" (\r
38     if /i not "%INCLUDE%" == "" (\r
39         if /i not "%LIB%" == "" (\r
40             goto ON_EXECUTE\r
41         )\r
42     )\r
43 )\r
45 :: Setup Windows environment.\r
46 call %RUN_MONO_SGEN_MSVC_SCRIPT_PATH%setup-windows-env.bat\r
48 if "%MONO_VS_MSVCBUILD_ENV_FILE%" == "" (\r
49     set MONO_VS_MSVCBUILD_ENV_FILE=%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%mono-sgen.exe.env\r
50 )\r
52 :: Check import of VS MSVC build environment using a file instead of running all commands.\r
53 :: NOTE, this is an optimization since setting up a development command\r
54 :: prompt could take some time.\r
55 if /i "%MONO_IMPORT_VS_MSVCBUILD_ENV_FILE%" == "true" (\r
56     if exist "%MONO_VS_MSVCBUILD_ENV_FILE%" (\r
57         for /f "delims=" %%a in (%MONO_VS_MSVCBUILD_ENV_FILE%) do SET %%a\r
58     )\r
59 )\r
61 if not "%MONO_MSVC_PATH%" == "" (\r
62     set "PATH=%MONO_MSVC_PATH%;%PATH%"\r
63     goto ON_EXECUTE\r
64 )\r
66 :: Setup VS MSVC build environment.\r
67 set TEMP_PATH=%PATH%\r
68 call %RUN_MONO_SGEN_MSVC_SCRIPT_PATH%setup-vs-msvcbuild-env.bat\r
69 call set MONO_MSVC_PATH=%%PATH:%TEMP_PATH%=%%\r
71 :: Check if msvc env should be exported into file for later import.\r
72 for /f %%a in ('uuidgen.exe') do set NEW_UUID=%%a\r
73 if /i "%MONO_EXPORT_VS_MSVCBUILD_ENV_FILE%" == "true" (\r
74     SET VCINSTALLDIR >> "%TEMP%\%NEW_UUID%.env"\r
75     SET INCLUDE >> "%TEMP%\%NEW_UUID%.env"\r
76     SET LIB >> "%TEMP%\%NEW_UUID%.env"\r
77     SET MONO_MSVC_PATH >> "%TEMP%\%NEW_UUID%.env"\r
78     move /Y "%TEMP%\%NEW_UUID%.env" "%MONO_VS_MSVCBUILD_ENV_FILE%" >nul 2>&1\r
79 )\r
81 :ON_EXECUTE\r
83 :: Add mono.sgen.exe (needed for optional LLVM tooling) to PATH\r
84 set "PATH=%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%;%PATH%"\r
86 call "%RUN_MONO_SGEN_MSVC_SCRIPT_PATH%mono-sgen.exe" %* && (\r
87     set EXECUTE_RESULT=0\r
88 ) || (\r
89     set EXECUTE_RESULT=1\r
90     if not %ERRORLEVEL% == 0 (\r
91         set EXECUTE_RESULT=%ERRORLEVEL%\r
92     )\r
93 )\r
95 exit /b %EXECUTE_RESULT%\r
97 @echo on