From 86e23c4e1f89257ab9a26ca1c37a4b2d1cfb1252 Mon Sep 17 00:00:00 2001 From: Pierrick Bouvier Date: Thu, 6 Oct 2022 10:18:26 +0200 Subject: [PATCH] Detect Visual Studio in Windows packaging script 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 | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/llvm/utils/release/build_llvm_release.bat b/llvm/utils/release/build_llvm_release.bat index 8fb1f02..7922066 100755 --- a/llvm/utils/release/build_llvm_release.bat +++ b/llvm/utils/release/build_llvm_release.bat @@ -1,4 +1,4 @@ -@echo on +@echo off setlocal enabledelayedexpansion if "%1"=="" goto usage @@ -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 -REM You need to modify the paths below: -set vsdevcmd=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\VsDevCmd.bat +set vsdevcmd= +set vs_2019_prefix=C:\Program Files (x86)\Microsoft Visual Studio\2019 +:: try potential activated visual studio, then 2019, with different 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" +if not exist "%vsdevcmd%" ( + echo Can't find any installation of Visual Studio + exit /b 1 +) +echo Using VS devcmd: %vsdevcmd% +:: start echoing what we do +@echo on set python32_dir=C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python310-32 set python64_dir=C:\Users\%USERNAME%\AppData\Local\Programs\Python\Python310 @@ -314,3 +327,13 @@ 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 -- 2.7.4