Skip to content

Commit 6a10eb5

Browse files
committed
build: better error message on python fail
1 parent 157df5a commit 6a10eb5

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

tools/msvs/find_python.cmd

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
@IF NOT DEFINED DEBUG_HELPER @ECHO OFF
2+
IF NOT "%VCBUILD_PYTHON_LOCATION%"=="" EXIT /B
23
SETLOCAL
34
:: If python.exe is in %Path%, just validate
4-
FOR /F "delims=" %%a IN ('where python 2^> NUL') DO (
5+
FOR /F "delims=" %%a IN ('where python') DO (
56
SET need_path=0
67
SET p=%%~dpa
78
IF NOT ERRORLEVEL 1 GOTO :validate
@@ -19,7 +20,7 @@ EXIT /B 1
1920
:: Helper subroutine to handle quotes in %1
2021
:find-main-branch
2122
SET main_key="%~1\Python\PythonCore"
22-
REG QUERY %main_key% /s | findstr "2." | findstr InstallPath > NUL 2> NUL
23+
REG QUERY %main_key% /s | findstr "2." | findstr InstallPath
2324
IF NOT ERRORLEVEL 1 CALL :find-key %main_key%
2425
EXIT /B
2526

@@ -41,7 +42,7 @@ EXIT /B 1
4142
:validate
4243
IF NOT EXIST "%p%python.exe" EXIT /B 1
4344
:: Check if %p% is python2
44-
"%p%python.exe" -V 2>&1 | findstr /R "^Python.2.*" > NUL
45+
"%p%python.exe" -V 2>&1 | findstr /R "^Python.2.*"
4546
IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL%
4647
:: We can wrap it up
4748
ENDLOCAL & SET pt=%p%& SET need_path_ext=%need_path%

vcbuild.bat

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,19 @@ goto next-arg
127127

128128
:args-done
129129

130+
REM Shortcut for just linting (does not need python)
130131
if "%*"=="lint" (
131132
goto lint-cpp
132133
)
133134

135+
REM Make sure we can find python
136+
call :run-python --version > NUL
137+
if errorlevel 1 (
138+
echo Could not find python2. More information can be found at
139+
echo https://github.com/nodejs/node/blob/master/BUILDING.md#windows-1
140+
exit /b 1
141+
)
142+
134143
if defined build_release (
135144
set config=Release
136145
set package=1
@@ -172,8 +181,6 @@ if "%target%"=="Clean" echo deleting %~dp0deps\icu
172181
if "%target%"=="Clean" rmdir /S /Q %~dp0deps\icu
173182
:no-depsicu
174183

175-
call :getnodeversion || exit /b 1
176-
177184
if "%target%"=="Clean" rmdir /Q /S "%~dp0%config%\node-v%FULLVERSION%-win-%target_arch%" > nul 2> nul
178185

179186
if defined noprojgen if defined nobuild if not defined sign if not defined msi goto licensertf
@@ -354,6 +361,7 @@ if not defined msi goto run
354361

355362
:msibuild
356363
echo Building node-v%FULLVERSION%-%target_arch%.msi
364+
call :getnodeversion || exit /b 1
357365
msbuild "%~dp0tools\msvs\msi\nodemsi.sln" /m /t:Clean,Build /p:PlatformToolset=%PLATFORM_TOOLSET% /p:GypMsvsVersion=%GYP_MSVS_VERSION% /p:Configuration=%config% /p:Platform=%target_arch% /p:NodeVersion=%NODE_VERSION% /p:FullVersion=%FULLVERSION% /p:DistTypeDir=%DISTTYPEDIR% %noetw_msi_arg% %noperfctr_msi_arg% /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
358366
if errorlevel 1 goto exit
359367

@@ -556,8 +564,13 @@ echo vcbuild.bat lint : runs the C++ and JavaScript linter
556564
goto exit
557565

558566
:run-python
559-
call tools\msvs\find_python.cmd
560-
if errorlevel 1 echo Could not find python2 & goto :exit
567+
IF NOT DEFINED DEBUG_HELPER (
568+
call tools\msvs\find_python.cmd 1>NUL 2>&1
569+
) ELSE (
570+
call tools\msvs\find_python.cmd
571+
)
572+
if errorlevel 1 exit /b 1
573+
561574
set cmd1="%VCBUILD_PYTHON_LOCATION%" %*
562575
echo %cmd1%
563576
%cmd1%
@@ -575,8 +588,6 @@ rem ***************
575588
set NODE_VERSION=
576589
set TAG=
577590
set FULLVERSION=
578-
:: Call as subroutine for validation of python
579-
call :run-python tools\getnodeversion.py > nul
580591
for /F "tokens=*" %%i in ('"%VCBUILD_PYTHON_LOCATION%" tools\getnodeversion.py') do set NODE_VERSION=%%i
581592
if not defined NODE_VERSION (
582593
echo Cannot determine current version of Node.js

0 commit comments

Comments
 (0)