Skip to content

Commit

Permalink
build,win: fix Python detection on localized OS
Browse files Browse the repository at this point in the history
This code previously assumed the default value was always printed to
the console by reg.exe as "(default)", but this is not true on
localized versions of Windows and can contain spaces.

Fixes: #29417

PR-URL: #29423
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
Reviewed-By: David Carlier <[email protected]>
  • Loading branch information
joaocgreis authored and targos committed Sep 20, 2019
1 parent 9de417a commit 42fd139
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
test/fixtures/* -text
vcbuild.bat text eol=crlf
tools/msvs/find_python.cmd text eol=crlf
18 changes: 10 additions & 8 deletions tools/msvs/find_python.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ exit /b 1
:: Read the InstallPath of a given Environment Key to %p%
:: https://www.python.org/dev/peps/pep-0514/#installpath
:read-installpath
:: %%a will receive token 3
:: %%b will receive *, corresponding to token 4 and all after
for /f "skip=2 tokens=3*" %%a in ('reg query "%1\InstallPath" /ve /t REG_SZ 2^> nul') do (
set "head=%%a"
set "tail=%%b"
set "p=!head!"
if not "!tail!"=="" set "p=!head! !tail!"
exit /b 0
:: %%a will receive everything before ), might have spaces depending on language
:: %%b will receive *, corresponding to everything after )
:: %%c will receive REG_SZ
:: %%d will receive the path, including spaces
for /f "skip=2 tokens=1* delims=)" %%a in ('reg query "%1\InstallPath" /ve /t REG_SZ 2^> nul') do (
for /f "tokens=1*" %%c in ("%%b") do (
if not "%%c"=="REG_SZ" exit /b 1
set "p=%%d"
exit /b 0
)
)
exit /b 1

Expand Down

0 comments on commit 42fd139

Please sign in to comment.