Skip to content

Commit 949f7be

Browse files
refackaddaleax
authored andcommitted
build,windows: implement PEP514 python detection
PR-URL: #13900Fixes: #13882 Reviewed-By: Tobias Nießen <[email protected]>
1 parent 9ff5212 commit 949f7be

File tree

2 files changed

+69
-14
lines changed

2 files changed

+69
-14
lines changed

‎tools/msvs/find_python.cmd‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@IF NOT DEFINED DEBUG_HELPER @ECHOOFF
2+
SETLOCAL
3+
:: If python.exe is in %Path%, just validate
4+
FOR /F "delims="%%aIN ('where python 2^>NUL') DO (
5+
SETneed_path=0
6+
SETp=%%~dpa
7+
IFNOTERRORLEVEL1GOTO :validate
8+
)
9+
10+
:: Query the 3 locations mentioned in PEP 514 for a python2 InstallPath
11+
FOR%%KIN ( "HKCU\Software", "HKLM\SOFTWARE", "HKLM\Software\Wow6432Node") DO (
12+
SETneed_path=1
13+
CALL :find-main-branch%%K
14+
:: If validate returns 0 just jump to the end
15+
IFNOTERRORLEVEL1GOTO :validate
16+
)
17+
EXIT /B 1
18+
19+
:: Helper subroutine to handle quotes in %1
20+
:find-main-branch
21+
SETmain_key="%~1\Python\PythonCore"
22+
REGQUERY%main_key% /s |findstr"2."|findstr InstallPath >NUL2>NUL
23+
IFNOTERRORLEVEL1CALL :find-key%main_key%
24+
EXIT /B
25+
26+
:: Query registry sub-tree for InstallPath
27+
:find-key
28+
FOR /F "delims="%%aIN ('REG QUERY%1 /s ^| findstr"2."^| findstr InstallPath') DOIFNOTERRORLEVEL1CALL :find-path%%a
29+
EXIT /B
30+
31+
:: Parse the value of %1 as the path for python.exe
32+
:find-path
33+
FOR /F "tokens=3*"%%aIN ('REG QUERY%1 /ve') DO (
34+
SETpt=%%a
35+
IFNOTERRORLEVEL1SETp=%pt%
36+
EXIT /B 0
37+
)
38+
EXIT /B 1
39+
40+
:: Check if %p% holds a path to a real python2 executable
41+
:validate
42+
IFNOTEXIST"%p%python.exe"EXIT /B 1
43+
:: Check if %p% is python2
44+
%p%python.exe -V 2>&1 |findstr /R "^Python.2.*">NUL
45+
IFERRORLEVEL1EXIT /B %ERRORLEVEL%
46+
:: We can wrap it up
47+
ENDLOCAL&SETpt=%p%&SETneed_path_ext=%need_path%
48+
SETVCBUILD_PYTHON_LOCATION=%pt%python.exe
49+
IF%need_path_ext%==1SETPath=%Path%;%pt%
50+
SETneed_path_ext=
51+
EXIT /B %ERRORLEVEL%

‎vcbuild.bat‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ goto run
222222
ifdefined noprojgen goto msbuild
223223

224224
@rem Generate the VS project.
225-
echo configure %configure_flags% --dest-cpu=%target_arch% --tag=%TAG%
226-
python configure %configure_flags% --dest-cpu=%target_arch% --tag=%TAG%
225+
call :run-python configure %configure_flags% --dest-cpu=%target_arch% --tag=%TAG%
227226
iferrorlevel1goto create-msvs-files-failed
228227
ifnotexist node.sln goto create-msvs-files-failed
229228
echo Project files generated.
@@ -408,7 +407,7 @@ if defined test_node_inspect goto node-test-inspect
408407
goto node-tests
409408

410409
:node-check-deopts
411-
python tools\test.py --mode=release --check-deopts parallel sequential -J
410+
call :run-python tools\test.py --mode=release --check-deopts parallel sequential -J
412411
ifdefined test_node_inspect goto node-test-inspect
413412
goto node-tests
414413

@@ -423,8 +422,7 @@ if "%config%"=="Debug" set test_args=--mode=debug %test_args%
423422
if"%config%"=="Release"settest_args=--mode=release %test_args%
424423
echo running 'cctest %cctest_args%'
425424
"%config%\cctest"%cctest_args%
426-
echo running 'python tools\test.py %test_args%'
427-
python tools\test.py %test_args%
425+
call :run-python tools\test.py %test_args%
428426
goto cpplint
429427

430428
:cpplint
@@ -442,8 +440,8 @@ test\gc\binding.cc tools\icu\*.cc tools\icu\*.h') do (
442440
( endlocal
443441
setcppfilelist=%localcppfilelist%
444442
)
445-
python tools/cpplint.py %cppfilelist%
446-
python tools/check-imports.py
443+
call :run-python tools/cpplint.py %cppfilelist%
444+
call :run-python tools/check-imports.py
447445
goto jslint
448446

449447
:add-to-list
@@ -502,6 +500,14 @@ echo vcbuild.bat build-release : builds the release distribution as used by n
502500
echo vcbuild.bat enable-vtune : builds nodejs with Intel VTune profiling support to profile JavaScript
503501
gotoexit
504502

503+
:run-python
504+
call tools\msvs\find_python.cmd
505+
iferrorlevel1echo Could not find python2 &goto :exit
506+
setcmd1=%VCBUILD_PYTHON_LOCATION%%*
507+
echo%cmd1%
508+
%cmd1%
509+
exit /b %ERRORLEVEL%
510+
505511
:exit
506512
goto :EOF
507513

@@ -513,8 +519,9 @@ rem ***************
513519
setNODE_VERSION=
514520
setTAG=
515521
setFULLVERSION=
516-
517-
for /F "usebackq tokens=*"%%iin (`python "%~dp0tools\getnodeversion.py"`) dosetNODE_VERSION=%%i
522+
:: Call as subroutine for validation of python
523+
call :run-python tools\getnodeversion.py >nul
524+
for /F "tokens=*"%%iin ('%VCBUILD_PYTHON_LOCATION% tools\getnodeversion.py') dosetNODE_VERSION=%%i
518525
ifnotdefined NODE_VERSION (
519526
echo Cannot determine current version of Node.js
520527
exit /b 1
@@ -523,7 +530,7 @@ if not defined NODE_VERSION (
523530
ifnotdefined DISTTYPE setDISTTYPE=release
524531
if"%DISTTYPE%"=="release" (
525532
setFULLVERSION=%NODE_VERSION%
526-
gotoexit
533+
exit /b 0
527534
)
528535
if"%DISTTYPE%"=="custom" (
529536
ifnotdefined CUSTOMTAG (
@@ -550,7 +557,4 @@ if not "%DISTTYPE%"=="custom" (
550557
setTAG=%DISTTYPE%%DATESTRING%%COMMIT%
551558
)
552559
setFULLVERSION=%NODE_VERSION%-%TAG%
553-
554-
:exit
555-
ifnotdefined DISTTYPEDIR setDISTTYPEDIR=%DISTTYPE%
556-
goto :EOF
560+
exit /b 0

0 commit comments

Comments
(0)