[llvm] b1e5e81 - Detect Visual Studio automatically in Windows packaging script

Tobias Hieta via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 20 07:29:42 PDT 2022


Author: Pierrick Bouvier
Date: 2022-10-20T16:29:36+02:00
New Revision: b1e5e81efda4c020a990dc749ef8bfb8bd4b763c

URL: https://github.com/llvm/llvm-project/commit/b1e5e81efda4c020a990dc749ef8bfb8bd4b763c
DIFF: https://github.com/llvm/llvm-project/commit/b1e5e81efda4c020a990dc749ef8bfb8bd4b763c.diff

LOG: 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

Added: 
    

Modified: 
    llvm/utils/release/build_llvm_release.bat

Removed: 
    


################################################################################
diff  --git a/llvm/utils/release/build_llvm_release.bat b/llvm/utils/release/build_llvm_release.bat
index 01502a0c53ece..9ffcf9c098b2b 100755
--- a/llvm/utils/release/build_llvm_release.bat
+++ b/llvm/utils/release/build_llvm_release.bat
@@ -83,14 +83,18 @@ REM   https://github.com/swig/swig/issues/769
 REM
 
 :: Detect Visual Studio
-set vsdevcmd=
-set vs_2019_prefix=C:\Program Files (x86)\Microsoft Visual Studio\2019
-:: try potential activated visual studio, then 2019, with 
diff erent editions
-call :find_visual_studio "%VSINSTALLDIR%"
-call :find_visual_studio "%vs_2019_prefix%\Enterprise"
-call :find_visual_studio "%vs_2019_prefix%\Professional"
-call :find_visual_studio "%vs_2019_prefix%\Community"
-call :find_visual_studio "%vs_2019_prefix%\BuildTools"
+set vsinstall=
+set vswhere=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
+
+if "%VSINSTALLDIR%" NEQ "" (
+  echo using enabled Visual Studio installation
+  set "vsinstall=%VSINSTALLDIR%"
+) else (
+  echo using vswhere to detect Visual Studio installation
+  FOR /F "delims=" %%r IN ('^""%vswhere%" -nologo -latest -products "*" -all -property installationPath^"') DO set vsinstall=%%r
+)
+set "vsdevcmd=%vsinstall%\Common7\Tools\VsDevCmd.bat"
+
 if not exist "%vsdevcmd%" (
   echo Can't find any installation of Visual Studio
   exit /b 1
@@ -359,14 +363,3 @@ exit /b 0
 
 :parse_args_done
 exit /b 0
-::==============================================================================
-:find_visual_studio
-set "vs_install=%~1"
-if "%vs_install%" == "" exit /b 1
-
-if "%vsdevcmd%" NEQ "" exit /b 0 :: already found
-
-set "candidate=%vs_install%\Common7\Tools\VsDevCmd.bat"
-echo trying VS devcmd: %candidate%
-if exist "%candidate%" set "vsdevcmd=%candidate%"
-exit /b 0


        


More information about the llvm-commits mailing list