build,win: fix Python detection on localized OS

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: https://github.com/nodejs/node/issues/29417

PR-URL: https://github.com/nodejs/node/pull/29423
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
This commit is contained in:
João Reis 2019-09-03 16:44:50 +01:00 committed by Michaël Zasso
parent 9de417ad59
commit 42fd139279
No known key found for this signature in database
GPG Key ID: 770F7A9A5AE15600
2 changed files with 11 additions and 8 deletions

1
.gitattributes vendored
View File

@ -1,2 +1,3 @@
test/fixtures/* -text test/fixtures/* -text
vcbuild.bat text eol=crlf vcbuild.bat text eol=crlf
tools/msvs/find_python.cmd text eol=crlf

View File

@ -60,14 +60,16 @@ exit /b 1
:: Read the InstallPath of a given Environment Key to %p% :: Read the InstallPath of a given Environment Key to %p%
:: https://www.python.org/dev/peps/pep-0514/#installpath :: https://www.python.org/dev/peps/pep-0514/#installpath
:read-installpath :read-installpath
:: %%a will receive token 3 :: %%a will receive everything before ), might have spaces depending on language
:: %%b will receive *, corresponding to token 4 and all after :: %%b will receive *, corresponding to everything after )
for /f "skip=2 tokens=3*" %%a in ('reg query "%1\InstallPath" /ve /t REG_SZ 2^> nul') do ( :: %%c will receive REG_SZ
set "head=%%a" :: %%d will receive the path, including spaces
set "tail=%%b" for /f "skip=2 tokens=1* delims=)" %%a in ('reg query "%1\InstallPath" /ve /t REG_SZ 2^> nul') do (
set "p=!head!" for /f "tokens=1*" %%c in ("%%b") do (
if not "!tail!"=="" set "p=!head! !tail!" if not "%%c"=="REG_SZ" exit /b 1
exit /b 0 set "p=%%d"
exit /b 0
)
) )
exit /b 1 exit /b 1