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