Skip to content

Commit b1e5e81

Browse files
pbo-linarotru
authored andcommitted
Detect Visual Studio automatically in Windows packaging script
Instead of hardcoding several VS paths, use vswhere.exe (available from VS 2017) to get latest version available. Reviewed By: hans, thieta Differential Revision: https://reviews.llvm.org/D135873
1 parent 50d9bb6 commit b1e5e81

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

llvm/utils/release/build_llvm_release.bat

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,18 @@ REM https://github.com/swig/swig/issues/769
8383
REM
8484

8585
:: Detect Visual Studio
86-
set vsdevcmd=
87-
set vs_2019_prefix=C:\Program Files (x86)\Microsoft Visual Studio\2019
88-
:: try potential activated visual studio, then 2019, with different editions
89-
call :find_visual_studio "%VSINSTALLDIR%"
90-
call :find_visual_studio "%vs_2019_prefix%\Enterprise"
91-
call :find_visual_studio "%vs_2019_prefix%\Professional"
92-
call :find_visual_studio "%vs_2019_prefix%\Community"
93-
call :find_visual_studio "%vs_2019_prefix%\BuildTools"
86+
set vsinstall=
87+
set vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
88+
89+
if "%VSINSTALLDIR%" NEQ "" (
90+
echo using enabled Visual Studio installation
91+
set "vsinstall=%VSINSTALLDIR%"
92+
) else (
93+
echo using vswhere to detect Visual Studio installation
94+
FOR /F "delims=" %%r IN ('^""%vswhere%" -nologo -latest -products "*" -all -property installationPath^"') DO set vsinstall=%%r
95+
)
96+
set "vsdevcmd=%vsinstall%\Common7\Tools\VsDevCmd.bat"
97+
9498
if not exist "%vsdevcmd%" (
9599
echo Can't find any installation of Visual Studio
96100
exit /b 1
@@ -359,14 +363,3 @@ exit /b 0
359363

360364
:parse_args_done
361365
exit /b 0
362-
::==============================================================================
363-
:find_visual_studio
364-
set "vs_install=%~1"
365-
if "%vs_install%" == "" exit /b 1
366-
367-
if "%vsdevcmd%" NEQ "" exit /b 0 :: already found
368-
369-
set "candidate=%vs_install%\Common7\Tools\VsDevCmd.bat"
370-
echo trying VS devcmd: %candidate%
371-
if exist "%candidate%" set "vsdevcmd=%candidate%"
372-
exit /b 0

0 commit comments

Comments
 (0)