Skip to content
This repository was archived by the owner on Aug 31, 2018. It is now read-only.

Commit 9851daa

Browse files
joyeecheungQard
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: nodejs/node#16377 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent e4a898a commit 9851daa

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
@@ -222,7 +222,8 @@ test: all
222222
$(CI_ASYNC_HOOKS) \
223223
$(CI_JS_SUITES) \
224224
$(CI_NATIVE_SUITES) \
225-
doctool known_issues
225+
$(CI_DOC) \
226+
known_issues
226227
endif
227228

228229
# For a quick test, does not run linter or build doc
@@ -271,7 +272,6 @@ test/gc/build/Release/binding.node: test/gc/binding.cc test/gc/binding.gyp
271272
--directory="$(shell pwd)/test/gc" \
272273
--nodedir="$(shell pwd)"
273274

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

277277
ifeq ($(OSTYPE),aix)
@@ -280,7 +280,7 @@ endif
280280

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

286286
ADDONS_BINDING_GYPS := \
@@ -316,10 +316,10 @@ test/addons/.buildstamp: config.gypi \
316316
done
317317
touch $@
318318

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

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

394395
# Build and test addons without building anything else
395396
test-ci-native: LOGLEVEL := silent
@@ -415,7 +416,8 @@ test-ci: | clear-stalled build-addons build-addons-napi doc-only
415416
out/Release/cctest --gtest_output=tap:cctest.tap
416417
$(PYTHON) tools/test.py $(PARALLEL_ARGS) -p oneline \
417418
--mode=release --flaky-tests=$(FLAKY_TESTS) \
418-
$(TEST_CI_ARGS) $(CI_ASYNC_HOOKS) $(CI_JS_SUITES) $(CI_NATIVE_SUITES) doctool known_issues
419+
$(TEST_CI_ARGS) $(CI_ASYNC_HOOKS) $(CI_JS_SUITES) $(CI_NATIVE_SUITES) \
420+
$(CI_DOC) known_issues
419421
# Clean up any leftover processes, error if found.
420422
ps awwx | grep Release/node | grep -v grep | cat
421423
@PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \
@@ -451,6 +453,10 @@ test-tick-processor: all
451453
test-hash-seed: all
452454
$(NODE) test/pummel/test-hash-seed.js
453455

456+
test-doc: doc-only
457+
$(MAKE) lint
458+
$(PYTHON) tools/test.py $(CI_DOC)
459+
454460
test-known-issues: all
455461
$(PYTHON) tools/test.py known_issues
456462

@@ -984,26 +990,38 @@ lint-md: lint-md-build
984990
./*.md doc src lib benchmark tools/doc/ tools/icu/
985991

986992
LINT_JS_TARGETS = benchmark doc lib test tools
993+
LINT_JS_CMD = tools/eslint/bin/eslint.js --cache \
994+
--rulesdir=tools/eslint-rules --ext=.js,.mjs,.md \
995+
$(LINT_JS_TARGETS)
987996

988997
lint-js:
989998
@echo "Running JS linter..."
990-
$(NODE) tools/eslint/bin/eslint.js --cache --rulesdir=tools/eslint-rules --ext=.js,.mjs,.md \
991-
$(LINT_JS_TARGETS)
999+
@if [ -x $(NODE) ]; then \
1000+
$(NODE) $(LINT_JS_CMD); \
1001+
else \
1002+
node $(LINT_JS_CMD); \
1003+
fi
9921004

9931005
jslint: lint-js
9941006
@echo "Please use lint-js instead of jslint"
9951007

9961008
lint-js-ci:
9971009
@echo "Running JS linter..."
998-
$(NODE) tools/lint-js.js $(PARALLEL_ARGS) -f tap -o test-eslint.tap \
999-
$(LINT_JS_TARGETS)
1010+
@if [ -x $(NODE) ]; then \
1011+
$(NODE) tools/lint-js.js $(PARALLEL_ARGS) -f tap -o test-eslint.tap \
1012+
$(LINT_JS_TARGETS); \
1013+
else \
1014+
node tools/lint-js.js $(PARALLEL_ARGS) -f tap -o test-eslint.tap \
1015+
$(LINT_JS_TARGETS); \
1016+
fi
10001017

10011018
jslint-ci: lint-js-ci
10021019
@echo "Please use lint-js-ci instead of jslint-ci"
10031020

1021+
LINT_CPP_ADDON_DOC_FILES = $(wildcard test/addons/??_*/*.cc test/addons/??_*/*.h)
10041022
LINT_CPP_EXCLUDE ?=
10051023
LINT_CPP_EXCLUDE += src/node_root_certs.h
1006-
LINT_CPP_EXCLUDE += $(wildcard test/addons/??_*/*.cc test/addons/??_*/*.h)
1024+
LINT_CPP_EXCLUDE += $(LINT_CPP_ADDON_DOC_FILES)
10071025
LINT_CPP_EXCLUDE += $(wildcard test/addons-napi/??_*/*.cc test/addons-napi/??_*/*.h)
10081026
# These files were copied more or less verbatim from V8.
10091027
LINT_CPP_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h
@@ -1027,11 +1045,19 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
10271045
tools/icu/*.h \
10281046
))
10291047

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

1057+
lint-addon-docs: test/addons/.docbuildstamp
1058+
@echo "Running C++ linter on addon docs..."
1059+
@$(PYTHON) tools/cpplint.py --filter=$(ADDON_DOC_LINT_FLAGS) $(LINT_CPP_ADDON_DOC_FILES)
1060+
10351061
cpplint: lint-cpp
10361062
@echo "Please use lint-cpp instead of cpplint"
10371063

@@ -1041,9 +1067,10 @@ lint:
10411067
$(MAKE) lint-js || EXIT_STATUS=$$? ; \
10421068
$(MAKE) lint-cpp || EXIT_STATUS=$$? ; \
10431069
$(MAKE) lint-md || EXIT_STATUS=$$? ; \
1070+
$(MAKE) lint-addon-docs || EXIT_STATUS=$$? ; \
10441071
exit $$EXIT_STATUS
10451072
CONFLICT_RE=^>>>>>>> [0-9A-Fa-f]+|^<<<<<<< [A-Za-z]+
1046-
lint-ci: lint-js-ci lint-cpp lint-md
1073+
lint-ci: lint-js-ci lint-cpp lint-md lint-addon-docs
10471074
@if ! ( grep -IEqrs "$(CONFLICT_RE)" benchmark deps doc lib src test tools ) \
10481075
&& ! ( find . -maxdepth 1 -type f | xargs grep -IEqs "$(CONFLICT_RE)" ); then \
10491076
exit 0 ; \
@@ -1123,6 +1150,7 @@ endif
11231150
test-ci \
11241151
test-ci-js \
11251152
test-ci-native \
1153+
test-doc \
11261154
test-gc \
11271155
test-gc-clean \
11281156
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)