Skip to content

Commit 66cdcd9

Browse files
liusiMylesBorins
authored andcommitted
build: add cpp linting to windows build
This PR adds cpp linting to windows build script. After this change, running command `vcbuild lint` will run both cpp linting and javascript linting on a windows machine. Backport-PR-URL: #14879 PR-URL: #11856Fixes: #11816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent 38ae5c4 commit 66cdcd9

3 files changed

Lines changed: 54 additions & 7 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ Running `make test`/`vcbuild test` will run the linter as well unless one or
176176
more tests fail.
177177

178178
If you want to run the linter without running tests, use
179-
`make lint`/`vcbuild lint`.
179+
`make lint`/`vcbuild lint`. It will run both JavaScript linting and
180+
C++ linting.
180181

181182
If you are updating tests and just want to run a single test to check it, you
182183
can use this syntax to run it exactly as the test harness would:

‎tools/cpplint.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,8 @@ def RepositoryName(self):
10741074
"""
10751075
fullname=self.FullName()
10761076
# XXX(bnoordhuis) Expects that cpplint.py lives in the tools/ directory.
1077-
toplevel=os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
1077+
toplevel=os.path.abspath(
1078+
os.path.join(os.path.dirname(__file__), '..')).replace('\\', '/')
10781079
prefix=os.path.commonprefix([fullname, toplevel])
10791080
returnfullname[len(prefix) +1:]
10801081

‎vcbuild.bat‎

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set msi=
2727
setupload=
2828
setlicensertf=
2929
setjslint=
30+
setcpplint=
3031
setbuildnodeweak=
3132
setnoetw=
3233
setnoetw_msi_arg=
@@ -57,7 +58,7 @@ if /i "%1"=="nosnapshot" set nosnapshot=1&goto arg-ok
5758
if /i "%1"=="noetw"setnoetw=1&goto arg-ok
5859
if /i "%1"=="noperfctr"setnoperfctr=1&goto arg-ok
5960
if /i "%1"=="licensertf"setlicensertf=1&goto arg-ok
60-
if /i "%1"=="test"settest_args=%test_args% doctool known_issues message parallel sequential addons -J&set jslint=1&set build_addons=1&goto arg-ok
61+
if /i "%1"=="test"settest_args=%test_args% doctool known_issues message parallel sequential addons -J&set cpplint=1&set jslint=1&set build_addons=1&goto arg-ok
6162
if /i "%1"=="test-ci"settest_args=%test_args%%test_ci_args% -p tap --logfile test.tap doctool inspector known_issues message sequential parallel addons&set cctest_args=%cctest_args% --gtest_output=tap:cctest.tap&set build_addons=1&goto arg-ok
6263
if /i "%1"=="test-addons"settest_args=%test_args% addons&set build_addons=1&goto arg-ok
6364
if /i "%1"=="test-simple"settest_args=%test_args% sequential parallel -J&goto arg-ok
@@ -67,10 +68,12 @@ if /i "%1"=="test-inspector" set test_args=%test_args% inspector&goto arg-ok
6768
if /i "%1"=="test-tick-processor"settest_args=%test_args% tick-processor&goto arg-ok
6869
if /i "%1"=="test-internet"settest_args=%test_args% internet&goto arg-ok
6970
if /i "%1"=="test-pummel"settest_args=%test_args% pummel&goto arg-ok
70-
if /i "%1"=="test-all"settest_args=%test_args% sequential parallel message gc inspector internet pummel&set buildnodeweak=1&set jslint=1&goto arg-ok
71+
if /i "%1"=="test-all"settest_args=%test_args% sequential parallel message gc inspector internet pummel&set buildnodeweak=1&set cpplint=1&set jslint=1&goto arg-ok
7172
if /i "%1"=="test-known-issues"settest_args=%test_args% known_issues&goto arg-ok
7273
if /i "%1"=="jslint"setjslint=1&goto arg-ok
7374
if /i "%1"=="jslint-ci"setjslint_ci=1&goto arg-ok
75+
if /i "%1"=="lint"setcpplint=1&set jslint=1&goto arg-ok
76+
if /i "%1"=="lint-ci"setcpplint=1&set jslint_ci=1&goto arg-ok
7477
if /i "%1"=="package"setpackage=1&goto arg-ok
7578
if /i "%1"=="msi"setmsi=1&set licensertf=1&set download_arg="--download=all"&set i18n_arg=small-icu&goto arg-ok
7679
if /i "%1"=="build-release"setbuild_release=1&goto arg-ok
@@ -323,25 +326,67 @@ for /d %%F in (test\addons\??_*) do (
323326
"%node_exe%" tools\doc\addon-verify.js
324327
if%errorlevel%neq0exit /b %errorlevel%
325328
:: building addons
326-
SetLocalEnableDelayedExpansion
329+
setlocalEnableDelayedExpansion
327330
for /d %%Fin (test\addons\*) do (
328331
"%node_exe%" deps\npm\node_modules\node-gyp\bin\node-gyp rebuild ^
329332
--directory="%%F"^
330333
--nodedir="%cd%"
331334
if!errorlevel!neq0exit /b !errorlevel!
332335
)
333-
EndLocal
336+
endlocal
334337
goto run-tests
335338

336339
:run-tests
337-
if"%test_args%"==""gotojslint
340+
if"%test_args%"==""gotocpplint
338341
if"%config%"=="Debug"settest_args=--mode=debug %test_args%
339342
if"%config%"=="Release"settest_args=--mode=release %test_args%
340343
echo running 'cctest %cctest_args%'
341344
"%config%\cctest"%cctest_args%
342345
call :run-python tools\test.py %test_args%
346+
goto cpplint
347+
348+
:cpplint
349+
ifnotdefined cpplint goto jslint
350+
echo running cpplint
351+
setcppfilelist=
352+
setlocalenabledelayedexpansion
353+
for /f "tokens=*"%%Gin ('dir /b /s /a src\*.c src\*.cc src\*.h ^
354+
test\addons\*.cc test\addons\*.h test\cctest\*.cc test\cctest\*.h ^
355+
test\gc\binding.cc tools\icu\*.cc tools\icu\*.h') do (
356+
setrelpath=%%G
357+
setrelpath=!relpath:*%~dp0=!
358+
call :add-to-list!relpath!
359+
)
360+
( endlocal
361+
setcppfilelist=%localcppfilelist%
362+
)
363+
python tools/cpplint.py %cppfilelist%
364+
python tools/check-imports.py
343365
goto jslint
344366

367+
:add-to-list
368+
echo%1|findstr /c:"src\node_root_certs.h"
369+
if%errorlevel%equ0gotoexit
370+
371+
echo%1|findstr /c:"src\queue.h"
372+
if%errorlevel%equ0gotoexit
373+
374+
echo%1|findstr /c:"src\tree.h"
375+
if%errorlevel%equ0gotoexit
376+
377+
@rem skip subfolders under /src
378+
echo%1|findstr /r /c:"src\\.*\\.*"
379+
if%errorlevel%equ0gotoexit
380+
381+
echo%1|findstr /r /c:"test\\addons\\[0-9].*_.*\.h"
382+
if%errorlevel%equ0gotoexit
383+
384+
echo%1|findstr /r /c:"test\\addons\\[0-9].*_.*\.cc"
385+
if%errorlevel%equ0gotoexit
386+
387+
set"localcppfilelist=%localcppfilelist%%1"
388+
gotoexit
389+
345390
:jslint
346391
ifdefined jslint_ci goto jslint-ci
347392
ifnotdefined jslint gotoexit

0 commit comments

Comments
 (0)