msvs_env.bat: Fix VS2017 path discovery and avoid CWD change (issue #2350, issue #2351)

This commit is contained in:
Marshall Greenblatt 2018-01-05 13:30:05 -05:00
parent 86eb141c53
commit 143bd4d425
1 changed files with 22 additions and 36 deletions

View File

@ -7,53 +7,34 @@
:: was specified on the command-line. :: was specified on the command-line.
set RC= set RC=
setlocal
:: Support !! syntax for delayed variable expansion.
setlocal enabledelayedexpansion
:: Require that platform is passed as the first argument. :: Require that platform is passed as the first argument.
set ARGSOK=F if "%1" == "win32" (
if "%1" == "win32" set ARGSOK=T set bits=32
if "%1" == "win64" set ARGSOK=T ) else if "%1" == "win64" (
if "%ARGSOK%" == "F" ( set bits=64
) else (
echo ERROR: Please specify a target platform: win32 or win64 echo ERROR: Please specify a target platform: win32 or win64
set ERRORLEVEL=1 set ERRORLEVEL=1
goto end goto end
) )
:: In case vcvars is already provided via the environment. :: Check if vcvars is already provided via the environment.
set vcvars="%CEF_VCVARS%" set vcvars="%CEF_VCVARS%"
if exist %vcvars% goto found_vcvars
if %vcvars% == "none" 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 if exist %vcvars% goto found_vcvars
:: Hardcoded list of MSVS paths for VS2015 32-bit builds. :: Search for the default VS2017 installation path.
set vcvars="%PROGRAMFILES(X86)%\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" for %%x in ("%PROGRAMFILES(X86)%" "%PROGRAMFILES%") do (
if exist %vcvars% goto found_vcvars for %%y in (Professional Enterprise Community) do (
set vcvars="%PROGRAMFILES%\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat" set vcvars="%%~x\Microsoft Visual Studio\2017\%%y\VC\Auxiliary\Build\vcvars%bits%.bat"
if exist %vcvars% goto found_vcvars 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 echo ERROR: Failed to find vcvars
set ERRORLEVEL=1 set ERRORLEVEL=1
goto end goto end
@ -61,7 +42,12 @@ goto end
:found_vcvars :found_vcvars
echo vcvars: echo 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:
echo %PATH% echo %PATH%