Detect Visual Studio in Windows packaging script
authorPierrick Bouvier <pierrick.bouvier@linaro.org>
Thu, 6 Oct 2022 08:18:26 +0000 (10:18 +0200)
committerHans Wennborg <hans@chromium.org>
Thu, 6 Oct 2022 08:18:58 +0000 (10:18 +0200)
Instead of hardcoding a specific VS install, try sequentially:

- %VSINSTALLDIR% (already set from a vs prompt)
- 2019/Enterprise
- 2019/Professional
- 2019/Community
- 2019/BuildTools

It stops when one is found and set vsdevcmd env var.

Differential revision: https://reviews.llvm.org/D135173

llvm/utils/release/build_llvm_release.bat

index 8fb1f02..7922066 100755 (executable)
@@ -1,4 +1,4 @@
-@echo on\r
+@echo off\r
 setlocal enabledelayedexpansion\r
 \r
 if "%1"=="" goto usage\r
@@ -52,9 +52,22 @@ REM   For LLDB, SWIG version <= 3.0.8 needs to be used to work around
 REM   https://github.com/swig/swig/issues/769\r
 \r
 \r
-REM You need to modify the paths below:\r
-set vsdevcmd=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\VsDevCmd.bat\r
+set vsdevcmd=\r
+set vs_2019_prefix=C:\Program Files (x86)\Microsoft Visual Studio\2019\r
+:: try potential activated visual studio, then 2019, with different editions\r
+call :find_visual_studio "%VSINSTALLDIR%"\r
+call :find_visual_studio "%vs_2019_prefix%\Enterprise"\r
+call :find_visual_studio "%vs_2019_prefix%\Professional"\r
+call :find_visual_studio "%vs_2019_prefix%\Community"\r
+call :find_visual_studio "%vs_2019_prefix%\BuildTools"\r
+if not exist "%vsdevcmd%" (\r
+  echo Can't find any installation of Visual Studio\r
+  exit /b 1\r
+)\r
+echo Using VS devcmd: %vsdevcmd%\r
 \r
+:: start echoing what we do\r
+@echo on\r
 set python32_dir=C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python310-32\r
 set python64_dir=C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python310\r
 \r
@@ -314,3 +327,13 @@ exit /b 0
 :parse_args_done\r
 exit /b 0\r
 ::==============================================================================\r
+:find_visual_studio\r
+set "vs_install=%~1"\r
+if "%vs_install%" == "" exit /b 1\r
+\r
+if "%vsdevcmd%" NEQ "" exit /b 0 :: already found\r
+\r
+set "candidate=%vs_install%\Common7\Tools\VsDevCmd.bat"\r
+echo trying VS devcmd: %candidate%\r
+if exist "%candidate%" set "vsdevcmd=%candidate%"\r
+exit /b 0\r