Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions bin/phpsdk_setshell.bat
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,22 @@ if 15 gtr %PHP_SDK_VS_NUM% (
)
for /f "tokens=2*" %%a in ('reg query !TMPKEY! /v ProductDir') do set PHP_SDK_VC_DIR=%%b
) else (
rem the first one found seems the correct one
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version %PHP_SDK_VS_NUM% -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do (
rem build the version range, e.g. "[15,16)"
set /a PHP_SDK_VS_RANGE=PHP_SDK_VS_NUM + 1
set PHP_SDK_VS_RANGE="[%PHP_SDK_VS_NUM%,!PHP_SDK_VS_RANGE%!)"

for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea with the range. With this, the breaks are not needed in this loop, as it delivers just one result. Perhaps it would make sense to get rid of these breaks? The reason I rewrote it is that on my side the order was reversed - first 2017, then 2019. Now with your approach it seems to be consistent.

Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah. I wonder what would happen if one has a preview and an RC installed side-by-side, though. In that case likely two installations will be found, i.e. two lines.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, preview is checked further down the line, attaching -prerelease to the command. Until vswhere changes behaviors, it should be ok.

Thanks.

set PHP_SDK_VC_DIR=%%b\VC
goto break0
)
:break0
if not exist "!PHP_SDK_VC_DIR!" (
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version %PHP_SDK_VS_NUM% -products Microsoft.VisualStudio.Product.BuildTools -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do (
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -products Microsoft.VisualStudio.Product.BuildTools -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do (
set PHP_SDK_VC_DIR=%%b\VC
goto break1
)
:break1
if not exist "!PHP_SDK_VC_DIR!" (
rem check for a preview release
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version %PHP_SDK_VS_NUM% -prerelease -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do (
for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -prerelease -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do (
set PHP_SDK_VC_DIR=%%b\VC
goto break3
)
:break3
if not exist "!PHP_SDK_VC_DIR!" (
echo Could not determine '%PHP_SDK_VS%' directory
goto out_error;
Expand All @@ -109,6 +106,7 @@ if 15 gtr %PHP_SDK_VS_NUM% (
set VSCMD_ARG_no_logo=nologo
)
set TMPKEY=
set PHP_SDK_VS_RANGE=

if 15 gtr %PHP_SDK_VS_NUM% (
rem get sdk dir
Expand Down