From 830e13f06c4b3855a31f7cf5d399b48bff2cb668 Mon Sep 17 00:00:00 2001 From: Thomas Desveaux Date: Sat, 4 May 2019 15:30:15 +0200 Subject: [PATCH] Bootstrap.bat: Change default behaviour to bootstrap with latest Visual Studio available --- Bootstrap.bat | 66 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/Bootstrap.bat b/Bootstrap.bat index 9424dfae..cc02bce5 100644 --- a/Bootstrap.bat +++ b/Bootstrap.bat @@ -2,9 +2,17 @@ SETLOCAL SETLOCAL ENABLEDELAYEDEXPANSION +REM =========================================================================== + +SET SelfPath="%0" +SET VsWherePath="C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe" + +REM =========================================================================== + SET vsversion=%1 IF "%vsversion%" == "" ( - SET vsversion=vs2015 + CALL :BootstrapLatest + EXIT /B %ERRORLEVEL% ) IF "%vsversion%" == "vs2010" ( @@ -74,14 +82,12 @@ SET "VsVersionMax=%~3" REM ref: https://github.com/Microsoft/vswhere/wiki/Start-Developer-Command-Prompt -SET VsWherePath="C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe" - IF NOT EXIST %VsWherePath% ( ECHO Could not find vswhere.exe EXIT /B 2 ) -SET VsWhereCmdLine="%VsWherePath% -nologo -latest -version [%VsVersionMin%,%VsVersionMax%) -property installationPath" +SET VsWhereCmdLine="!VsWherePath! -nologo -latest -version [%VsVersionMin%,%VsVersionMax%) -property installationPath" FOR /F "usebackq delims=" %%i in (`!VsWhereCmdLine!`) DO ( @@ -98,6 +104,58 @@ REM :VsWhereVisualBootstrap REM =========================================================================== +:BootstrapLatest + +IF EXIST %VsWherePath% ( + + REM First try for not legacy Visual Studios ( >vs2017 ) + + SET VsWhereCmdLine="!VsWherePath! -nologo -latest -property catalog.productLineVersion" + + FOR /F "usebackq delims=" %%i in (`!VsWhereCmdLine!`) DO ( + + CALL %SelfPath% vs%%i + + EXIT /B %ERRORLEVEL% + ) + +) + +SET LegacyVSVersions= + +REM Get latest Visual Studio legacy version + +REM For all env var starting with VS +FOR /F "usebackq delims==" %%i in (`SET VS`) DO ( + + REM Check if env var match pattern VS*COMNTOOLS (ie: VS140COMNTOOLS) + ECHO "%%i" | FINDSTR /R /C:VS.*COMNTOOLS >nul && ( + + SET "LegacyVSVersions=%%i" + ) +) + +REM Strip VS +SET LegacyVSVersions=%LegacyVSVersions:VS=% +REM Strip COMNTOOLS +SET LegacyVSVersions=%LegacyVSVersions:COMNTOOLS=% + +SET "VsVersionMap=140-vs2015;120-vs2013;110-vs2012;100-vs2010" +CALL SET PremakeVsVersion=%%VsVersionMap:*%LegacyVSVersions%-=%% +SET PremakeVsVersion=%PremakeVsVersion:;=&REM.% + +IF NOT "%PremakeVsVersion%" == "" ( + CALL %SelfPath% %PremakeVsVersion% + EXIT /B %ERRORLEVEL% +) + +ECHO Could not find a Visual Studio installation +EXIT /B 2 + +REM :BootstrapLatest + +REM =========================================================================== + REM SETLOCAL ENABLEDELAYEDEXPANSION ENDLOCAL REM SETLOCAL