From 143bd4d425c3254866b4759954c52b44b4bd49f7 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 5 Jan 2018 13:30:05 -0500 Subject: [PATCH] msvs_env.bat: Fix VS2017 path discovery and avoid CWD change (issue #2350, issue #2351) --- tools/msvs_env.bat | 58 ++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/tools/msvs_env.bat b/tools/msvs_env.bat index e4ed3c768..0acb95cda 100644 --- a/tools/msvs_env.bat +++ b/tools/msvs_env.bat @@ -7,53 +7,34 @@ :: was specified on the command-line. set RC= -setlocal + +:: Support !! syntax for delayed variable expansion. +setlocal enabledelayedexpansion :: Require that platform is passed as the first argument. -set ARGSOK=F -if "%1" == "win32" set ARGSOK=T -if "%1" == "win64" set ARGSOK=T -if "%ARGSOK%" == "F" ( +if "%1" == "win32" ( + set bits=32 +) else if "%1" == "win64" ( + set bits=64 +) else ( echo ERROR: Please specify a target platform: win32 or win64 set ERRORLEVEL=1 goto end ) -:: In case vcvars is already provided via the environment. +:: Check if vcvars is already provided via the environment. set vcvars="%CEF_VCVARS%" -if exist %vcvars% goto found_vcvars if %vcvars% == "none" goto found_vcvars - -if "%1" == "win64" goto check_win64 - -:: Hardcoded list of MSVS paths for VS2017 32-bit builds. -set vcvars="%PROGRAMFILES(X86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat" -if exist %vcvars% goto found_vcvars -set vcvars="%PROGRAMFILES%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat" if exist %vcvars% goto found_vcvars -:: Hardcoded list of MSVS paths for VS2015 32-bit builds. -set vcvars="%PROGRAMFILES(X86)%\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" -if exist %vcvars% goto found_vcvars -set vcvars="%PROGRAMFILES%\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" -if exist %vcvars% goto found_vcvars +:: Search for the default VS2017 installation path. +for %%x in ("%PROGRAMFILES(X86)%" "%PROGRAMFILES%") do ( + for %%y in (Professional Enterprise Community) do ( + set vcvars="%%~x\Microsoft Visual Studio\2017\%%y\VC\Auxiliary\Build\vcvars%bits%.bat" + if exist !vcvars! goto found_vcvars + ) +) -goto notfound_vcvars - -:check_win64 -:: Hardcoded list of MSVS paths for VS2017 64-bit builds. -set vcvars="%PROGRAMFILES(X86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat" -if exist %vcvars% goto found_vcvars -set vcvars="%PROGRAMFILES%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars64.bat" -if exist %vcvars% goto found_vcvars - -:: Hardcoded list of MSVS paths for VS2015 64-bit builds. -set vcvars="%PROGRAMFILES(X86)%\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat" -if exist %vcvars% goto found_vcvars -set vcvars="%PROGRAMFILES%\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat" -if exist %vcvars% goto found_vcvars - -:notfound_vcvars echo ERROR: Failed to find vcvars set ERRORLEVEL=1 goto end @@ -61,7 +42,12 @@ goto end :found_vcvars echo vcvars: echo %vcvars% -if not %vcvars% == "none" call %vcvars% + +if not %vcvars% == "none" ( + :: Set this variable to keep VS2017 < 15.5 from changing the current working directory. + set "VSCMD_START_DIR=%CD%" + call %vcvars% +) echo PATH: echo %PATH%