Skip to content

Commit 608a20b

Browse files
joyeecheunggibfahn
authored andcommitted
build: make test-doc and lint addon docs
- Implements the make test-doc target that build, verify and lint docs - Lint the C++ snippets in addon docs - When generating addons and running the JS linter, use the global node executable if it is not built. Therefore one does not have to build node in order to run make test-doc. PR-URL: #16377 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 72f2f89 commit 608a20b

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

Makefile

+42-14
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ test: all
219219
$(CI_ASYNC_HOOKS) \
220220
$(CI_JS_SUITES) \
221221
$(CI_NATIVE_SUITES) \
222-
doctool known_issues
222+
$(CI_DOC) \
223+
known_issues
223224
endif
224225

225226
# For a quick test, does not run linter or build doc
@@ -268,7 +269,6 @@ test/gc/build/Release/binding.node: test/gc/binding.cc test/gc/binding.gyp
268269
--directory="$(shell pwd)/test/gc" \
269270
--nodedir="$(shell pwd)"
270271

271-
# Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
272272
DOCBUILDSTAMP_PREREQS = tools/doc/addon-verify.js doc/api/addons.md
273273

274274
ifeq ($(OSTYPE),aix)
@@ -277,7 +277,7 @@ endif
277277

278278
test/addons/.docbuildstamp: $(DOCBUILDSTAMP_PREREQS)
279279
$(RM) -r test/addons/??_*/
280-
$(NODE) $<
280+
[ -x $(NODE) ] && $(NODE) $< || node $<
281281
touch $@
282282

283283
ADDONS_BINDING_GYPS := \
@@ -313,10 +313,10 @@ test/addons/.buildstamp: config.gypi \
313313
done
314314
touch $@
315315

316-
# .buildstamp and .docbuildstamp need $(NODE_EXE) but cannot depend on it
316+
# .buildstamp needs $(NODE_EXE) but cannot depend on it
317317
# directly because it calls make recursively. The parent make cannot know
318318
# if the subprocess touched anything so it pessimistically assumes that
319-
# .buildstamp and .docbuildstamp are out of date and need a rebuild.
319+
# .buildstamp is out of date and need a rebuild.
320320
# Just goes to show that recursive make really is harmful...
321321
# TODO(bnoordhuis) Force rebuild after gyp update.
322322
build-addons: $(NODE_EXE) test/addons/.buildstamp
@@ -352,10 +352,10 @@ test/addons-napi/.buildstamp: config.gypi \
352352
done
353353
touch $@
354354

355-
# .buildstamp and .docbuildstamp need $(NODE_EXE) but cannot depend on it
355+
# .buildstamp needs $(NODE_EXE) but cannot depend on it
356356
# directly because it calls make recursively. The parent make cannot know
357357
# if the subprocess touched anything so it pessimistically assumes that
358-
# .buildstamp and .docbuildstamp are out of date and need a rebuild.
358+
# .buildstamp is out of date and need a rebuild.
359359
# Just goes to show that recursive make really is harmful...
360360
# TODO(bnoordhuis) Force rebuild after gyp or node-gyp update.
361361
build-addons-napi: $(NODE_EXE) test/addons-napi/.buildstamp
@@ -387,6 +387,7 @@ test-all-valgrind: test-build
387387
CI_NATIVE_SUITES ?= addons addons-napi
388388
CI_ASYNC_HOOKS := async-hooks
389389
CI_JS_SUITES ?= default
390+
CI_DOC := doctool
390391

391392
# Build and test addons without building anything else
392393
test-ci-native: LOGLEVEL := info
@@ -412,7 +413,8 @@ test-ci: | clear-stalled build-addons build-addons-napi doc-only
412413
out/Release/cctest --gtest_output=tap:cctest.tap
413414
$(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
414415
--mode=release --flaky-tests=$(FLAKY_TESTS) \
415-
$(TEST_CI_ARGS) $(CI_ASYNC_HOOKS) $(CI_JS_SUITES) $(CI_NATIVE_SUITES) doctool known_issues
416+
$(TEST_CI_ARGS) $(CI_ASYNC_HOOKS) $(CI_JS_SUITES) $(CI_NATIVE_SUITES) \
417+
$(CI_DOC) known_issues
416418
# Clean up any leftover processes, error if found.
417419
ps awwx | grep Release/node | grep -v grep | cat
418420
@PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \
@@ -448,6 +450,10 @@ test-tick-processor: all
448450
test-hash-seed: all
449451
$(NODE) test/pummel/test-hash-seed.js
450452

453+
test-doc: doc-only
454+
$(MAKE) lint
455+
$(PYTHON) tools/test.py $(CI_DOC)
456+
451457
test-known-issues: all
452458
$(PYTHON) tools/test.py known_issues
453459

@@ -981,26 +987,38 @@ lint-md: lint-md-build
981987
./*.md doc src lib benchmark tools/doc/ tools/icu/
982988

983989
LINT_JS_TARGETS = benchmark doc lib test tools
990+
LINT_JS_CMD = tools/eslint/bin/eslint.js --cache \
991+
--rulesdir=tools/eslint-rules --ext=.js,.mjs,.md \
992+
$(LINT_JS_TARGETS)
984993

985994
lint-js:
986995
@echo "Running JS linter..."
987-
$(NODE) tools/eslint/bin/eslint.js --cache --rulesdir=tools/eslint-rules --ext=.js,.mjs,.md \
988-
$(LINT_JS_TARGETS)
996+
@if [ -x $(NODE) ]; then \
997+
$(NODE) $(LINT_JS_CMD); \
998+
else \
999+
node $(LINT_JS_CMD); \
1000+
fi
9891001

9901002
jslint: lint-js
9911003
@echo "Please use lint-js instead of jslint"
9921004

9931005
lint-js-ci:
9941006
@echo "Running JS linter..."
995-
$(NODE) tools/lint-js.js $(PARALLEL_ARGS) -f tap -o test-eslint.tap \
996-
$(LINT_JS_TARGETS)
1007+
@if [ -x $(NODE) ]; then \
1008+
$(NODE) tools/lint-js.js $(PARALLEL_ARGS) -f tap -o test-eslint.tap \
1009+
$(LINT_JS_TARGETS); \
1010+
else \
1011+
node tools/lint-js.js $(PARALLEL_ARGS) -f tap -o test-eslint.tap \
1012+
$(LINT_JS_TARGETS); \
1013+
fi
9971014

9981015
jslint-ci: lint-js-ci
9991016
@echo "Please use lint-js-ci instead of jslint-ci"
10001017

1018+
LINT_CPP_ADDON_DOC_FILES = $(wildcard test/addons/??_*/*.cc test/addons/??_*/*.h)
10011019
LINT_CPP_EXCLUDE ?=
10021020
LINT_CPP_EXCLUDE += src/node_root_certs.h
1003-
LINT_CPP_EXCLUDE += $(wildcard test/addons/??_*/*.cc test/addons/??_*/*.h)
1021+
LINT_CPP_EXCLUDE += $(LINT_CPP_ADDON_DOC_FILES)
10041022
LINT_CPP_EXCLUDE += $(wildcard test/addons-napi/??_*/*.cc test/addons-napi/??_*/*.h)
10051023
# These files were copied more or less verbatim from V8.
10061024
LINT_CPP_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h
@@ -1024,11 +1042,19 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
10241042
tools/icu/*.h \
10251043
))
10261044

1045+
# Code blocks don't have newline at the end,
1046+
# and the actual filename is generated so it won't match header guards
1047+
ADDON_DOC_LINT_FLAGS=-whitespace/ending_newline,-build/header_guard
1048+
10271049
lint-cpp:
10281050
@echo "Running C++ linter..."
10291051
@$(PYTHON) tools/cpplint.py $(LINT_CPP_FILES)
10301052
@$(PYTHON) tools/check-imports.py
10311053

1054+
lint-addon-docs: test/addons/.docbuildstamp
1055+
@echo "Running C++ linter on addon docs..."
1056+
@$(PYTHON) tools/cpplint.py --filter=$(ADDON_DOC_LINT_FLAGS) $(LINT_CPP_ADDON_DOC_FILES)
1057+
10321058
cpplint: lint-cpp
10331059
@echo "Please use lint-cpp instead of cpplint"
10341060

@@ -1038,9 +1064,10 @@ lint:
10381064
$(MAKE) lint-js || EXIT_STATUS=$$? ; \
10391065
$(MAKE) lint-cpp || EXIT_STATUS=$$? ; \
10401066
$(MAKE) lint-md || EXIT_STATUS=$$? ; \
1067+
$(MAKE) lint-addon-docs || EXIT_STATUS=$$? ; \
10411068
exit $$EXIT_STATUS
10421069
CONFLICT_RE=^>>>>>>> [0-9A-Fa-f]+|^<<<<<<< [A-Za-z]+
1043-
lint-ci: lint-js-ci lint-cpp lint-md
1070+
lint-ci: lint-js-ci lint-cpp lint-md lint-addon-docs
10441071
@if ! ( grep -IEqrs "$(CONFLICT_RE)" benchmark deps doc lib src test tools ) \
10451072
&& ! ( find . -maxdepth 1 -type f | xargs grep -IEqs "$(CONFLICT_RE)" ); then \
10461073
exit 0 ; \
@@ -1120,6 +1147,7 @@ endif
11201147
test-ci \
11211148
test-ci-js \
11221149
test-ci-native \
1150+
test-doc \
11231151
test-gc \
11241152
test-gc-clean \
11251153
test-hash-seed \

doc/api/addons.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ static void at_exit_cb1(void* arg) {
10951095
Isolate* isolate = static_cast<Isolate*>(arg);
10961096
HandleScope scope(isolate);
10971097
Local<Object> obj = Object::New(isolate);
1098-
assert(!obj.IsEmpty()); // assert VM is still alive
1098+
assert(!obj.IsEmpty()); // assert VM is still alive
10991099
assert(obj->IsObject());
11001100
at_exit_cb1_called++;
11011101
}

0 commit comments

Comments
 (0)