Skip to content

Commit 80949f3

Browse files
liusiitaloacasas
liusi
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. PR-URL: #11856 Fixes: #11816 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 5244ee3 commit 80949f3

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

CONTRIBUTING.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ Running `make test`/`vcbuild test` will run the linter as well unless one or
178178
more tests fail.
179179

180180
If you want to run the linter without running tests, use
181-
`make lint`/`vcbuild jslint`. At this time, only JavaScript linting is
182-
available on Windows. `make lint` on POSIX will run both JavaScript linting and
181+
`make lint`/`vcbuild lint`. It will run both JavaScript linting and
183182
C++ linting.
184183

185184
If you are updating tests and just want to run a single test to check it, you

tools/cpplint.py

+2-1
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
return fullname[len(prefix) + 1:]
10801081

vcbuild.bat

+50-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ set msi=
2727
set upload=
2828
set licensertf=
2929
set jslint=
30+
set cpplint=
3031
set build_testgc_addon=
3132
set noetw=
3233
set noetw_msi_arg=
@@ -57,7 +58,7 @@ if /i "%1"=="nosnapshot" set nosnapshot=1&goto arg-ok
5758
if /i "%1"=="noetw" set noetw=1&goto arg-ok
5859
if /i "%1"=="noperfctr" set noperfctr=1&goto arg-ok
5960
if /i "%1"=="licensertf" set licensertf=1&goto arg-ok
60-
if /i "%1"=="test" set test_args=%test_args% addons doctool known_issues message parallel sequential -J&set jslint=1&set build_addons=1&goto arg-ok
61+
if /i "%1"=="test" set test_args=%test_args% addons doctool known_issues message parallel sequential -J&set cpplint=1&set jslint=1&set build_addons=1&goto arg-ok
6162
if /i "%1"=="test-ci" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap addons doctool inspector known_issues message sequential parallel&set cctest_args=%cctest_args% --gtest_output=tap:cctest.tap&set build_addons=1&goto arg-ok
6263
if /i "%1"=="test-addons" set test_args=%test_args% addons&set build_addons=1&goto arg-ok
6364
if /i "%1"=="test-simple" set test_args=%test_args% sequential parallel -J&goto arg-ok
@@ -67,11 +68,13 @@ if /i "%1"=="test-inspector" set test_args=%test_args% inspector&goto arg-ok
6768
if /i "%1"=="test-tick-processor" set test_args=%test_args% tick-processor&goto arg-ok
6869
if /i "%1"=="test-internet" set test_args=%test_args% internet&goto arg-ok
6970
if /i "%1"=="test-pummel" set test_args=%test_args% pummel&goto arg-ok
70-
if /i "%1"=="test-all" set test_args=%test_args% sequential parallel message gc inspector internet pummel&set build_testgc_addon=1&set jslint=1&goto arg-ok
71+
if /i "%1"=="test-all" set test_args=%test_args% sequential parallel message gc inspector internet pummel&set build_testgc_addon=1&set cpplint=1&set jslint=1&goto arg-ok
7172
if /i "%1"=="test-known-issues" set test_args=%test_args% known_issues&goto arg-ok
7273
if /i "%1"=="test-node-inspect" set test_node_inspect=1&goto arg-ok
7374
if /i "%1"=="jslint" set jslint=1&goto arg-ok
7475
if /i "%1"=="jslint-ci" set jslint_ci=1&goto arg-ok
76+
if /i "%1"=="lint" set cpplint=1&set jslint=1&goto arg-ok
77+
if /i "%1"=="lint-ci" set cpplint=1&set jslint_ci=1&goto arg-ok
7578
if /i "%1"=="package" set package=1&goto arg-ok
7679
if /i "%1"=="msi" set msi=1&set licensertf=1&set download_arg="--download=all"&set i18n_arg=small-icu&goto arg-ok
7780
if /i "%1"=="build-release" set build_release=1&goto arg-ok
@@ -322,14 +325,14 @@ for /d %%F in (test\addons\??_*) do (
322325
"%node_exe%" tools\doc\addon-verify.js
323326
if %errorlevel% neq 0 exit /b %errorlevel%
324327
:: building addons
325-
SetLocal EnableDelayedExpansion
328+
setlocal EnableDelayedExpansion
326329
for /d %%F in (test\addons\*) do (
327330
"%node_exe%" deps\npm\node_modules\node-gyp\bin\node-gyp rebuild ^
328331
--directory="%%F" ^
329332
--nodedir="%cd%"
330333
if !errorlevel! neq 0 exit /b !errorlevel!
331334
)
332-
EndLocal
335+
endlocal
333336
goto run-tests
334337

335338
:run-tests
@@ -339,15 +342,57 @@ set USE_EMBEDDED_NODE_INSPECT=1
339342
goto node-tests
340343

341344
:node-tests
342-
if "%test_args%"=="" goto jslint
345+
if "%test_args%"=="" goto cpplint
343346
if "%config%"=="Debug" set test_args=--mode=debug %test_args%
344347
if "%config%"=="Release" set test_args=--mode=release %test_args%
345348
echo running 'cctest %cctest_args%'
346349
"%config%\cctest" %cctest_args%
347350
echo running 'python tools\test.py %test_args%'
348351
python tools\test.py %test_args%
352+
goto cpplint
353+
354+
:cpplint
355+
if not defined cpplint goto jslint
356+
echo running cpplint
357+
set cppfilelist=
358+
setlocal enabledelayedexpansion
359+
for /f "tokens=*" %%G in ('dir /b /s /a src\*.c src\*.cc src\*.h ^
360+
test\addons\*.cc test\addons\*.h test\cctest\*.cc test\cctest\*.h ^
361+
test\gc\binding.cc tools\icu\*.cc tools\icu\*.h') do (
362+
set relpath=%%G
363+
set relpath=!relpath:*%~dp0=!
364+
call :add-to-list !relpath!
365+
)
366+
( endlocal
367+
set cppfilelist=%localcppfilelist%
368+
)
369+
python tools/cpplint.py %cppfilelist%
370+
python tools/check-imports.py
349371
goto jslint
350372

373+
:add-to-list
374+
echo %1 | findstr /c:"src\node_root_certs.h"
375+
if %errorlevel% equ 0 goto exit
376+
377+
echo %1 | findstr /c:"src\queue.h"
378+
if %errorlevel% equ 0 goto exit
379+
380+
echo %1 | findstr /c:"src\tree.h"
381+
if %errorlevel% equ 0 goto exit
382+
383+
@rem skip subfolders under /src
384+
echo %1 | findstr /r /c:"src\\.*\\.*"
385+
if %errorlevel% equ 0 goto exit
386+
387+
echo %1 | findstr /r /c:"test\\addons\\[0-9].*_.*\.h"
388+
if %errorlevel% equ 0 goto exit
389+
390+
echo %1 | findstr /r /c:"test\\addons\\[0-9].*_.*\.cc"
391+
if %errorlevel% equ 0 goto exit
392+
393+
set "localcppfilelist=%localcppfilelist% %1"
394+
goto exit
395+
351396
:jslint
352397
if defined jslint_ci goto jslint-ci
353398
if not defined jslint goto exit

0 commit comments

Comments
 (0)