Browse Source

build,windows: implement PEP514 python detection

PR-URL: https://github.com/nodejs/node/pull/13900
Fixes: https://github.com/nodejs/node/issues/13882
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
v6
Refael Ackermann 8 years ago
parent
commit
614dbbd728
  1. 51
      tools/msvs/find_python.cmd
  2. 32
      vcbuild.bat

51
tools/msvs/find_python.cmd

@ -0,0 +1,51 @@
@IF NOT DEFINED DEBUG_HELPER @ECHO OFF
SETLOCAL
:: If python.exe is in %Path%, just validate
FOR /F "delims=" %%a IN ('where python 2^> NUL') DO (
SET need_path=0
SET p=%%~dpa
IF NOT ERRORLEVEL 1 GOTO :validate
)
:: Query the 3 locations mentioned in PEP 514 for a python2 InstallPath
FOR %%K IN ( "HKCU\Software", "HKLM\SOFTWARE", "HKLM\Software\Wow6432Node") DO (
SET need_path=1
CALL :find-main-branch %%K
:: If validate returns 0 just jump to the end
IF NOT ERRORLEVEL 1 GOTO :validate
)
EXIT /B 1
:: Helper subroutine to handle quotes in %1
:find-main-branch
SET main_key="%~1\Python\PythonCore"
REG QUERY %main_key% /s | findstr "2." | findstr InstallPath > NUL 2> NUL
IF NOT ERRORLEVEL 1 CALL :find-key %main_key%
EXIT /B
:: Query registry sub-tree for InstallPath
:find-key
FOR /F "delims=" %%a IN ('REG QUERY %1 /s ^| findstr "2." ^| findstr InstallPath') DO IF NOT ERRORLEVEL 1 CALL :find-path %%a
EXIT /B
:: Parse the value of %1 as the path for python.exe
:find-path
FOR /F "tokens=3*" %%a IN ('REG QUERY %1 /ve') DO (
SET pt=%%a
IF NOT ERRORLEVEL 1 SET p=%pt%
EXIT /B 0
)
EXIT /B 1
:: Check if %p% holds a path to a real python2 executable
:validate
IF NOT EXIST "%p%python.exe" EXIT /B 1
:: Check if %p% is python2
%p%python.exe -V 2>&1 | findstr /R "^Python.2.*" > NUL
IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL%
:: We can wrap it up
ENDLOCAL & SET pt=%p%& SET need_path_ext=%need_path%
SET VCBUILD_PYTHON_LOCATION=%pt%python.exe
IF %need_path_ext%==1 SET Path=%Path%;%pt%
SET need_path_ext=
EXIT /B %ERRORLEVEL%

32
vcbuild.bat

@ -222,8 +222,7 @@ goto run
if defined noprojgen goto msbuild if defined noprojgen goto msbuild
@rem Generate the VS project. @rem Generate the VS project.
echo configure %configure_flags% --dest-cpu=%target_arch% --tag=%TAG% call :run-python configure %configure_flags% --dest-cpu=%target_arch% --tag=%TAG%
python configure %configure_flags% --dest-cpu=%target_arch% --tag=%TAG%
if errorlevel 1 goto create-msvs-files-failed if errorlevel 1 goto create-msvs-files-failed
if not exist node.sln goto create-msvs-files-failed if not exist node.sln goto create-msvs-files-failed
echo Project files generated. echo Project files generated.
@ -408,7 +407,7 @@ if defined test_node_inspect goto node-test-inspect
goto node-tests goto node-tests
:node-check-deopts :node-check-deopts
python tools\test.py --mode=release --check-deopts parallel sequential -J call :run-python tools\test.py --mode=release --check-deopts parallel sequential -J
if defined test_node_inspect goto node-test-inspect if defined test_node_inspect goto node-test-inspect
goto node-tests goto node-tests
@ -423,8 +422,7 @@ if "%config%"=="Debug" set test_args=--mode=debug %test_args%
if "%config%"=="Release" set test_args=--mode=release %test_args% if "%config%"=="Release" set test_args=--mode=release %test_args%
echo running 'cctest %cctest_args%' echo running 'cctest %cctest_args%'
"%config%\cctest" %cctest_args% "%config%\cctest" %cctest_args%
echo running 'python tools\test.py %test_args%' call :run-python tools\test.py %test_args%
python tools\test.py %test_args%
goto cpplint goto cpplint
:cpplint :cpplint
@ -442,8 +440,8 @@ test\gc\binding.cc tools\icu\*.cc tools\icu\*.h') do (
( endlocal ( endlocal
set cppfilelist=%localcppfilelist% set cppfilelist=%localcppfilelist%
) )
python tools/cpplint.py %cppfilelist% call :run-python tools/cpplint.py %cppfilelist%
python tools/check-imports.py call :run-python tools/check-imports.py
goto jslint goto jslint
:add-to-list :add-to-list
@ -502,6 +500,14 @@ echo vcbuild.bat build-release : builds the release distribution as used by n
echo vcbuild.bat enable-vtune : builds nodejs with Intel VTune profiling support to profile JavaScript echo vcbuild.bat enable-vtune : builds nodejs with Intel VTune profiling support to profile JavaScript
goto exit goto exit
:run-python
call tools\msvs\find_python.cmd
if errorlevel 1 echo Could not find python2 & goto :exit
set cmd1=%VCBUILD_PYTHON_LOCATION% %*
echo %cmd1%
%cmd1%
exit /b %ERRORLEVEL%
:exit :exit
goto :EOF goto :EOF
@ -513,8 +519,9 @@ rem ***************
set NODE_VERSION= set NODE_VERSION=
set TAG= set TAG=
set FULLVERSION= set FULLVERSION=
:: Call as subroutine for validation of python
for /F "usebackq tokens=*" %%i in (`python "%~dp0tools\getnodeversion.py"`) do set NODE_VERSION=%%i call :run-python tools\getnodeversion.py > nul
for /F "tokens=*" %%i in ('%VCBUILD_PYTHON_LOCATION% tools\getnodeversion.py') do set NODE_VERSION=%%i
if not defined NODE_VERSION ( if not defined NODE_VERSION (
echo Cannot determine current version of Node.js echo Cannot determine current version of Node.js
exit /b 1 exit /b 1
@ -523,7 +530,7 @@ if not defined NODE_VERSION (
if not defined DISTTYPE set DISTTYPE=release if not defined DISTTYPE set DISTTYPE=release
if "%DISTTYPE%"=="release" ( if "%DISTTYPE%"=="release" (
set FULLVERSION=%NODE_VERSION% set FULLVERSION=%NODE_VERSION%
goto exit exit /b 0
) )
if "%DISTTYPE%"=="custom" ( if "%DISTTYPE%"=="custom" (
if not defined CUSTOMTAG ( if not defined CUSTOMTAG (
@ -550,7 +557,4 @@ if not "%DISTTYPE%"=="custom" (
set TAG=%DISTTYPE%%DATESTRING%%COMMIT% set TAG=%DISTTYPE%%DATESTRING%%COMMIT%
) )
set FULLVERSION=%NODE_VERSION%-%TAG% set FULLVERSION=%NODE_VERSION%-%TAG%
exit /b 0
:exit
if not defined DISTTYPEDIR set DISTTYPEDIR=%DISTTYPE%
goto :EOF

Loading…
Cancel
Save