Node_Escargot_Release_210713_97834f7
[platform/framework/web/lwnode.git] / Makefile
1 -include config.mk
2
3 BUILDTYPE ?= Release
4 PYTHON ?= python
5 DESTDIR ?=
6 SIGN ?=
7 PREFIX ?= /usr/local
8 FLAKY_TESTS ?= run
9 TEST_CI_ARGS ?=
10 STAGINGSERVER ?= node-www
11 LOGLEVEL ?= silent
12 OSTYPE := $(shell uname -s | tr '[A-Z]' '[a-z]')
13 COVTESTS ?= test-cov
14 COV_SKIP_TESTS ?= core_line_numbers.js,testFinalizer.js,test_function/test.js
15 GTEST_FILTER ?= "*"
16 GNUMAKEFLAGS += --no-print-directory
17 GCOV ?= gcov
18 PWD = $(CURDIR)
19 BUILD_WITH ?= make
20 FIND ?= find
21
22 ifdef JOBS
23         PARALLEL_ARGS = -j $(JOBS)
24 else
25         PARALLEL_ARGS = -J
26 endif
27
28 ifdef ENABLE_V8_TAP
29         TAP_V8 := --junitout $(PWD)/v8-tap.xml
30         TAP_V8_INTL := --junitout $(PWD)/v8-intl-tap.xml
31         TAP_V8_BENCHMARKS := --junitout $(PWD)/v8-benchmarks-tap.xml
32 endif
33
34 V8_TEST_OPTIONS = $(V8_EXTRA_TEST_OPTIONS)
35 ifdef DISABLE_V8_I18N
36         V8_BUILD_OPTIONS += i18nsupport=off
37 endif
38
39 ifeq ($(OSTYPE), darwin)
40         GCOV = xcrun llvm-cov gcov
41 endif
42
43 BUILDTYPE_LOWER := $(shell echo $(BUILDTYPE) | tr '[A-Z]' '[a-z]')
44
45 # Determine EXEEXT
46 EXEEXT := $(shell $(PYTHON) -c \
47                 "import sys; print('.exe' if sys.platform == 'win32' else '')")
48
49 NODE_EXE = node$(EXEEXT)
50 NODE ?= ./$(NODE_EXE)
51 NODE_G_EXE = node_g$(EXEEXT)
52 NPM ?= ./deps/npm/bin/npm-cli.js
53
54 # Flags for packaging.
55 BUILD_DOWNLOAD_FLAGS ?= --download=all
56 BUILD_INTL_FLAGS ?= --with-intl=full-icu
57 BUILD_RELEASE_FLAGS ?= $(BUILD_DOWNLOAD_FLAGS) $(BUILD_INTL_FLAGS)
58
59 # Default to quiet/pretty builds.
60 # To do verbose builds, run `make V=1` or set the V environment variable.
61 V ?= 0
62
63 # Use -e to double check in case it's a broken link
64 # Use $(PWD) so we can cd to anywhere before calling this
65 available-node = \
66         if [ -x $(PWD)/$(NODE) ] && [ -e $(PWD)/$(NODE) ]; then \
67                 $(PWD)/$(NODE) $(1); \
68         elif [ -x `which node` ] && [ -e `which node` ] && [ `which node` ]; then \
69                 `which node` $(1); \
70         else \
71                 echo "No available node, cannot run \"node $(1)\""; \
72                 exit 1; \
73         fi;
74
75 .PHONY: all
76 # BUILDTYPE=Debug builds both release and debug builds. If you want to compile
77 # just the debug build, run `make -C out BUILDTYPE=Debug` instead.
78 ifeq ($(BUILDTYPE),Release)
79 all: $(NODE_EXE) ## Default target, builds node in out/Release/node.
80 else
81 all: $(NODE_EXE) $(NODE_G_EXE)
82 endif
83
84 .PHONY: help
85 # To add a target to the help, add a double comment (##) on the target line.
86 help: ## Print help for targets with comments.
87         @printf "For more targets and info see the comments in the Makefile.\n\n"
88         @grep -E '^[a-zA-Z0-9._-]+:.*?## .*$$' Makefile | sort | \
89                 awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
90
91 # The .PHONY is needed to ensure that we recursively use the out/Makefile
92 # to check for changes.
93 .PHONY: $(NODE_EXE) $(NODE_G_EXE)
94
95 # The -r/-L check stops it recreating the link if it is already in place,
96 # otherwise $(NODE_EXE) being a .PHONY target means it is always re-run.
97 # Without the check there is a race condition between the link being deleted
98 # and recreated which can break the addons build when running test-ci
99 # See comments on the build-addons target for some more info
100 ifeq ($(BUILD_WITH), make)
101 $(NODE_EXE): build_type:=Release
102 $(NODE_G_EXE): build_type:=Debug
103 $(NODE_EXE) $(NODE_G_EXE): config.gypi out/Makefile
104         $(MAKE) -C out BUILDTYPE=${build_type} V=$(V)
105         if [ ! -r $@ -o ! -L $@ ]; then \
106           ln -fs out/${build_type}/$(NODE_EXE) $@; fi
107 else
108 ifeq ($(BUILD_WITH), ninja)
109 ifeq ($(V),1)
110         NINJA_ARGS := $(NINJA_ARGS) -v
111 endif
112 ifdef JOBS
113         NINJA_ARGS := $(NINJA_ARGS) -j$(JOBS)
114 else
115         NINJA_ARGS := $(NINJA_ARGS) $(filter -j%,$(MAKEFLAGS))
116 endif
117 $(NODE_EXE): config.gypi out/Release/build.ninja
118         ninja -C out/Release $(NINJA_ARGS)
119         if [ ! -r $@ -o ! -L $@ ]; then ln -fs out/Release/$(NODE_EXE) $@; fi
120
121 $(NODE_G_EXE): config.gypi out/Debug/build.ninja
122         ninja -C out/Debug $(NINJA_ARGS)
123         if [ ! -r $@ -o ! -L $@ ]; then ln -fs out/Debug/$(NODE_EXE) $@; fi
124 else
125 $(NODE_EXE) $(NODE_G_EXE):
126         echo This Makefile currently only supports building with 'make' or 'ninja'
127 endif
128 endif
129
130
131 ifeq ($(BUILDTYPE),Debug)
132 CONFIG_FLAGS += --debug
133 endif
134
135 .PHONY: with-code-cache
136 with-code-cache:
137         echo "'with-code-cache' target is a noop"
138
139 .PHONY: test-code-cache
140 test-code-cache: with-code-cache
141         echo "'test-code-cache' target is a noop"
142
143 out/Makefile: config.gypi common.gypi node.gyp \
144         deps/uv/uv.gyp deps/llhttp/llhttp.gyp deps/zlib/zlib.gyp \
145         tools/v8_gypfiles/toolchain.gypi tools/v8_gypfiles/features.gypi \
146         tools/v8_gypfiles/inspector.gypi tools/v8_gypfiles/v8.gyp
147         $(PYTHON) tools/gyp_node.py -f make
148
149 # node_version.h is listed because the N-API version is taken from there
150 # and included in config.gypi
151 config.gypi: configure configure.py src/node_version.h
152         @if [ -x config.status ]; then \
153                 ./config.status; \
154         else \
155                 echo Missing or stale $@, please run ./$<; \
156                 exit 1; \
157         fi
158
159 .PHONY: install
160 install: all ## Installs node into $PREFIX (default=/usr/local).
161         $(PYTHON) tools/install.py $@ '$(DESTDIR)' '$(PREFIX)'
162
163 .PHONY: uninstall
164 uninstall: ## Uninstalls node from $PREFIX (default=/usr/local).
165         $(PYTHON) tools/install.py $@ '$(DESTDIR)' '$(PREFIX)'
166
167 .PHONY: clean
168 clean: ## Remove build artifacts.
169         $(RM) -r out/Makefile $(NODE_EXE) $(NODE_G_EXE) out/$(BUILDTYPE)/$(NODE_EXE) \
170                 out/$(BUILDTYPE)/node.exp
171         @if [ -d out ]; then $(FIND) out/ -name '*.o' -o -name '*.a' -o -name '*.d' | xargs $(RM) -r; fi
172         $(RM) -r node_modules
173         @if [ -d deps/icu ]; then echo deleting deps/icu; $(RM) -r deps/icu; fi
174         $(RM) test.tap
175         $(MAKE) testclean
176         $(MAKE) test-addons-clean
177         $(MAKE) bench-addons-clean
178
179 .PHONY: testclean
180 testclean:
181 # Next one is legacy remove this at some point
182         $(RM) -r test/tmp*
183         $(RM) -r test/.tmp*
184
185 .PHONY: distclean
186 distclean:
187         $(RM) -r out
188         $(RM) config.gypi icu_config.gypi config_fips.gypi
189         $(RM) config.mk
190         $(RM) -r $(NODE_EXE) $(NODE_G_EXE)
191         $(RM) -r node_modules
192         $(RM) -r deps/icu
193         $(RM) -r deps/icu4c*.tgz deps/icu4c*.zip deps/icu-tmp
194         $(RM) $(BINARYTAR).* $(TARBALL).*
195
196 .PHONY: check
197 check: test
198
199 .PHONY: coverage-clean
200 # Remove files generated by running coverage, put the non-instrumented lib back
201 # in place
202 coverage-clean:
203         if [ -d lib_ ]; then $(RM) -r lib; mv lib_ lib; fi
204         $(RM) -r node_modules
205         $(RM) -r gcovr build
206         $(RM) -r out/$(BUILDTYPE)/.coverage
207         $(RM) out/$(BUILDTYPE)/obj.target/node/gen/*.gcda
208         $(RM) out/$(BUILDTYPE)/obj.target/node/src/*.gcda
209         $(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing/*.gcda
210         $(RM) out/$(BUILDTYPE)/obj.target/node/gen/*.gcno
211         $(RM) out/$(BUILDTYPE)/obj.target/node/src/*.gcno
212         $(RM) out/$(BUILDTYPE)/obj.target/node/src/tracing/*.gcno
213         $(RM) out/$(BUILDTYPE)/obj.target/cctest/src/*.gcno
214         $(RM) out/$(BUILDTYPE)/obj.target/cctest/test/cctest/*.gcno
215         $(RM) out/$(BUILDTYPE)/obj.target/embedtest/src/*.gcno
216         $(RM) out/$(BUILDTYPE)/obj.target/embedtest/test/embedding/*.gcno
217
218 .PHONY: coverage
219 # Build and test with code coverage reporting.  Leave the lib directory
220 # instrumented for any additional runs the user may want to make.
221 # For C++ coverage reporting, this needs to be run in conjunction with configure
222 #  --coverage.  html coverage reports will be created under coverage/
223 # Related CI job: node-test-commit-linux-coverage
224 coverage: coverage-test ## Run the tests and generate a coverage report.
225
226 .PHONY: coverage-build
227 coverage-build: all
228         -$(MAKE) coverage-build-js
229         if [ ! -d gcovr ]; then git clone -b 3.4 --depth=1 \
230                 --single-branch https://github.com/gcovr/gcovr.git; fi
231         if [ ! -d build ]; then git clone --depth=1 \
232                 --single-branch https://github.com/nodejs/build.git; fi
233         if [ ! -f gcovr/scripts/gcovr.orig ]; then \
234                 (cd gcovr && patch -N -p1 < \
235                 "$(CURDIR)/build/jenkins/scripts/coverage/gcovr-patches-3.4.diff"); fi
236         $(MAKE)
237
238 .PHONY: coverage-build-js
239 coverage-build-js:
240         mkdir -p node_modules
241         if [ ! -d node_modules/c8 ]; then \
242                 $(NODE) ./deps/npm install c8 --no-save --no-package-lock;\
243         fi
244
245 .PHONY: coverage-test
246 coverage-test: coverage-build
247         $(RM) out/$(BUILDTYPE)/obj.target/node/src/*.gcda
248         $(RM) out/$(BUILDTYPE)/obj.target/node/src/*/*.gcda
249         $(RM) out/$(BUILDTYPE)/obj.target/node_lib/src/*.gcda
250         $(RM) out/$(BUILDTYPE)/obj.target/node_lib/src/*/*.gcda
251         -NODE_V8_COVERAGE=out/$(BUILDTYPE)/.coverage \
252                                                                 TEST_CI_ARGS="$(TEST_CI_ARGS) --type=coverage" $(MAKE) $(COVTESTS)
253         $(MAKE) coverage-report-js
254         -(cd out && "../gcovr/scripts/gcovr" \
255                 --gcov-exclude='.*\b(deps|usr|out|cctest|embedding)\b' -v \
256                 -r Release/obj.target --html --html-detail -o ../coverage/cxxcoverage.html \
257                 --gcov-executable="$(GCOV)")
258         @echo -n "Javascript coverage %: "
259         @grep -B1 Lines coverage/index.html | head -n1 \
260                 | sed 's/<[^>]*>//g'| sed 's/ //g'
261         @echo -n "C++ coverage %: "
262         @grep -A3 Lines coverage/cxxcoverage.html | grep style  \
263                 | sed 's/<[^>]*>//g'| sed 's/ //g'
264
265 COV_REPORT_OPTIONS = --reporter=html \
266         --temp-directory=out/$(BUILDTYPE)/.coverage --omit-relative=false \
267         --resolve=./lib --exclude="benchmark/" --exclude="deps/" --exclude="test/" --exclude="tools/" \
268         --wrapper-length=0
269 ifdef COV_ENFORCE_THRESHOLD
270         COV_REPORT_OPTIONS += --check-coverage --lines=$(COV_ENFORCE_THRESHOLD)
271 endif
272
273 .PHONY: coverage-report-js
274 coverage-report-js:
275         $(NODE) ./node_modules/.bin/c8 report $(COV_REPORT_OPTIONS)
276
277 .PHONY: cctest
278 # Runs the C++ tests using the built `cctest` executable.
279 cctest: all
280         @out/$(BUILDTYPE)/$@ --gtest_filter=$(GTEST_FILTER)
281         @out/$(BUILDTYPE)/embedtest "require('./test/embedding/test-embedding.js')"
282
283 .PHONY: list-gtests
284 list-gtests:
285 ifeq (,$(wildcard out/$(BUILDTYPE)/cctest))
286         $(error Please run 'make cctest' first)
287 endif
288         @out/$(BUILDTYPE)/cctest --gtest_list_tests
289
290 .PHONY: v8
291 # Related CI job: node-test-commit-v8-linux
292 # Rebuilds deps/v8 as a git tree, pulls its third-party dependencies, and
293 # builds it.
294 v8:
295         tools/make-v8.sh $(V8_ARCH).$(BUILDTYPE_LOWER) $(V8_BUILD_OPTIONS)
296
297 .PHONY: jstest
298 jstest: build-addons build-js-native-api-tests build-node-api-tests ## Runs addon tests and JS tests
299         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) \
300                 --skip-tests=$(CI_SKIP_TESTS) \
301                 $(JS_SUITES) \
302                 $(NATIVE_SUITES)
303
304 .PHONY: tooltest
305 tooltest:
306         @$(PYTHON) -m unittest discover -s ./test/tools
307
308 .PHONY: coverage-run-js
309 coverage-run-js:
310         $(RM) -r out/$(BUILDTYPE)/.coverage
311         $(MAKE) coverage-build-js
312         -NODE_V8_COVERAGE=out/$(BUILDTYPE)/.coverage CI_SKIP_TESTS=$(COV_SKIP_TESTS) \
313                                         TEST_CI_ARGS="$(TEST_CI_ARGS) --type=coverage" $(MAKE) jstest
314         $(MAKE) coverage-report-js
315
316 .PHONY: test
317 # This does not run tests of third-party libraries inside deps.
318 test: all ## Runs default tests, linters, and builds docs.
319         $(MAKE) -s tooltest
320         $(MAKE) -s test-doc
321         $(MAKE) -s build-addons
322         $(MAKE) -s build-js-native-api-tests
323         $(MAKE) -s build-node-api-tests
324         $(MAKE) -s cctest
325         $(MAKE) -s jstest
326
327 .PHONY: test-only
328 test-only: all  ## For a quick test, does not run linter or build docs.
329         $(MAKE) build-addons
330         $(MAKE) build-js-native-api-tests
331         $(MAKE) build-node-api-tests
332         $(MAKE) cctest
333         $(MAKE) jstest
334         $(MAKE) tooltest
335
336 # Used by `make coverage-test`
337 test-cov: all
338         $(MAKE) build-addons
339         $(MAKE) build-js-native-api-tests
340         $(MAKE) build-node-api-tests
341         $(MAKE) cctest
342         CI_SKIP_TESTS=$(COV_SKIP_TESTS) $(MAKE) jstest
343
344 test-parallel: all
345         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) parallel
346
347 test-valgrind: all
348         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) --valgrind sequential parallel message
349
350 test-check-deopts: all
351         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) --check-deopts parallel sequential
352
353 DOCBUILDSTAMP_PREREQS = tools/doc/addon-verify.js doc/api/addons.md
354
355 ifeq ($(OSTYPE),aix)
356 DOCBUILDSTAMP_PREREQS := $(DOCBUILDSTAMP_PREREQS) out/$(BUILDTYPE)/node.exp
357 endif
358
359 node_use_openssl = $(call available-node,"-p" \
360                          "process.versions.openssl != undefined")
361 test/addons/.docbuildstamp: $(DOCBUILDSTAMP_PREREQS) tools/doc/node_modules
362         @if [ "$(shell $(node_use_openssl))" != "true" ]; then \
363                 echo "Skipping .docbuildstamp (no crypto)"; \
364         else \
365                 $(RM) -r test/addons/??_*/; \
366                 [ -x $(NODE) ] && $(NODE) $< || node $< ; \
367                 touch $@; \
368         fi
369
370 ADDONS_BINDING_GYPS := \
371         $(filter-out test/addons/??_*/binding.gyp, \
372                 $(wildcard test/addons/*/binding.gyp))
373
374 ADDONS_BINDING_SOURCES := \
375         $(filter-out test/addons/??_*/*.cc, $(wildcard test/addons/*/*.cc)) \
376         $(filter-out test/addons/??_*/*.h, $(wildcard test/addons/*/*.h))
377
378 ADDONS_PREREQS := config.gypi \
379         deps/npm/node_modules/node-gyp/package.json tools/build-addons.js \
380         deps/uv/include/*.h deps/v8/include/*.h \
381         src/node.h src/node_buffer.h src/node_object_wrap.h src/node_version.h
382
383 define run_build_addons
384 env npm_config_loglevel=$(LOGLEVEL) npm_config_nodedir="$$PWD" \
385         npm_config_python="$(PYTHON)" $(NODE) "$$PWD/tools/build-addons" \
386         "$$PWD/deps/npm/node_modules/node-gyp/bin/node-gyp.js" \
387         $1
388 touch $2
389 endef
390
391 # Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale.
392 # Depends on node-gyp package.json so that build-addons is (re)executed when
393 # node-gyp is updated as part of an npm update.
394 test/addons/.buildstamp: $(ADDONS_PREREQS) \
395         $(ADDONS_BINDING_GYPS) $(ADDONS_BINDING_SOURCES) \
396         test/addons/.docbuildstamp
397         @$(call run_build_addons,"$$PWD/test/addons",$@)
398
399 .PHONY: build-addons
400 # .buildstamp needs $(NODE_EXE) but cannot depend on it
401 # directly because it calls make recursively.  The parent make cannot know
402 # if the subprocess touched anything so it pessimistically assumes that
403 # .buildstamp is out of date and need a rebuild.
404 # Just goes to show that recursive make really is harmful...
405 # TODO(bnoordhuis) Force rebuild after gyp update.
406 build-addons: | $(NODE_EXE) test/addons/.buildstamp
407
408 JS_NATIVE_API_BINDING_GYPS := \
409         $(filter-out test/js-native-api/??_*/binding.gyp, \
410                 $(wildcard test/js-native-api/*/binding.gyp))
411
412 JS_NATIVE_API_BINDING_SOURCES := \
413         $(filter-out test/js-native-api/??_*/*.c, $(wildcard test/js-native-api/*/*.c)) \
414         $(filter-out test/js-native-api/??_*/*.cc, $(wildcard test/js-native-api/*/*.cc)) \
415         $(filter-out test/js-native-api/??_*/*.h, $(wildcard test/js-native-api/*/*.h))
416
417 # Implicitly depends on $(NODE_EXE), see the build-js-native-api-tests rule for rationale.
418 test/js-native-api/.buildstamp: $(ADDONS_PREREQS) \
419         $(JS_NATIVE_API_BINDING_GYPS) $(JS_NATIVE_API_BINDING_SOURCES) \
420         src/node_api.h src/node_api_types.h src/js_native_api.h \
421         src/js_native_api_types.h src/js_native_api_v8.h src/js_native_api_v8_internals.h
422         @$(call run_build_addons,"$$PWD/test/js-native-api",$@)
423
424 .PHONY: build-js-native-api-tests
425 # .buildstamp needs $(NODE_EXE) but cannot depend on it
426 # directly because it calls make recursively.  The parent make cannot know
427 # if the subprocess touched anything so it pessimistically assumes that
428 # .buildstamp is out of date and need a rebuild.
429 # Just goes to show that recursive make really is harmful...
430 # TODO(bnoordhuis) Force rebuild after gyp or node-gyp update.
431 build-js-native-api-tests: | $(NODE_EXE) test/js-native-api/.buildstamp
432
433 NODE_API_BINDING_GYPS := \
434         $(filter-out test/node-api/??_*/binding.gyp, \
435                 $(wildcard test/node-api/*/binding.gyp))
436
437 NODE_API_BINDING_SOURCES := \
438         $(filter-out test/node-api/??_*/*.c, $(wildcard test/node-api/*/*.c)) \
439         $(filter-out test/node-api/??_*/*.cc, $(wildcard test/node-api/*/*.cc)) \
440         $(filter-out test/node-api/??_*/*.h, $(wildcard test/node-api/*/*.h))
441
442 # Implicitly depends on $(NODE_EXE), see the build-node-api-tests rule for rationale.
443 test/node-api/.buildstamp: $(ADDONS_PREREQS) \
444         $(NODE_API_BINDING_GYPS) $(NODE_API_BINDING_SOURCES) \
445         src/node_api.h src/node_api_types.h src/js_native_api.h \
446         src/js_native_api_types.h src/js_native_api_v8.h src/js_native_api_v8_internals.h
447         @$(call run_build_addons,"$$PWD/test/node-api",$@)
448
449 .PHONY: build-node-api-tests
450 # .buildstamp needs $(NODE_EXE) but cannot depend on it
451 # directly because it calls make recursively.  The parent make cannot know
452 # if the subprocess touched anything so it pessimistically assumes that
453 # .buildstamp is out of date and need a rebuild.
454 # Just goes to show that recursive make really is harmful...
455 # TODO(bnoordhuis) Force rebuild after gyp or node-gyp update.
456 build-node-api-tests: | $(NODE_EXE) test/node-api/.buildstamp
457
458 BENCHMARK_NAPI_BINDING_GYPS := $(wildcard benchmark/napi/*/binding.gyp)
459
460 BENCHMARK_NAPI_BINDING_SOURCES := \
461         $(wildcard benchmark/napi/*/*.c) \
462         $(wildcard benchmark/napi/*/*.cc) \
463         $(wildcard benchmark/napi/*/*.h)
464
465 benchmark/napi/.buildstamp: $(ADDONS_PREREQS) \
466         $(BENCHMARK_NAPI_BINDING_GYPS) $(BENCHMARK_NAPI_BINDING_SOURCES)
467         @$(call run_build_addons,"$$PWD/benchmark/napi",$@)
468
469 .PHONY: clear-stalled
470 clear-stalled:
471         @echo "Clean up any leftover processes but don't error if found."
472         ps awwx | grep Release/node | grep -v grep | cat
473         @PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \
474         if [ "$${PS_OUT}" ]; then \
475                 echo $${PS_OUT} | xargs kill -9; \
476         fi
477
478 test-build: | all build-addons build-js-native-api-tests build-node-api-tests
479
480 test-build-js-native-api: all build-js-native-api-tests
481
482 test-build-node-api: all build-node-api-tests
483
484 .PHONY: test-all
485 test-all: test-build ## Run default tests with both Debug and Release builds.
486         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=debug,release
487
488 test-all-valgrind: test-build
489         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=debug,release --valgrind
490
491 .PHONY: test-all-suites
492 test-all-suites: | clear-stalled test-build bench-addons-build doc-only ## Run all test suites.
493         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) test/*
494
495 JS_SUITES ?= default
496 NATIVE_SUITES ?= addons js-native-api node-api
497 # CI_* variables should be kept synchronized with the ones in vcbuild.bat
498 CI_NATIVE_SUITES ?= $(NATIVE_SUITES) benchmark
499 CI_JS_SUITES ?= $(JS_SUITES)
500 ifeq ($(node_use_openssl), false)
501         CI_DOC := doctool
502 else
503         CI_DOC =
504 endif
505
506 .PHONY: test-ci-native
507 # Build and test addons without building anything else
508 # Related CI job: node-test-commit-arm-fanned
509 test-ci-native: LOGLEVEL := info
510 test-ci-native: | benchmark/napi/.buildstamp test/addons/.buildstamp test/js-native-api/.buildstamp test/node-api/.buildstamp
511         $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
512                 --mode=$(BUILDTYPE_LOWER) --flaky-tests=$(FLAKY_TESTS) \
513                 $(TEST_CI_ARGS) $(CI_NATIVE_SUITES)
514
515 .PHONY: test-ci-js
516 # This target should not use a native compiler at all
517 # Related CI job: node-test-commit-arm-fanned
518 test-ci-js: | clear-stalled
519         $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
520                 --mode=$(BUILDTYPE_LOWER) --flaky-tests=$(FLAKY_TESTS) \
521                 $(TEST_CI_ARGS) $(CI_JS_SUITES)
522         @echo "Clean up any leftover processes, error if found."
523         ps awwx | grep Release/node | grep -v grep | cat
524         @PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \
525         if [ "$${PS_OUT}" ]; then \
526                 echo $${PS_OUT} | xargs kill -9; exit 1; \
527         fi
528
529 .PHONY: test-ci
530 # Related CI jobs: most CI tests, excluding node-test-commit-arm-fanned
531 test-ci: LOGLEVEL := info
532 test-ci: | clear-stalled bench-addons-build build-addons build-js-native-api-tests build-node-api-tests doc-only
533         out/Release/cctest --gtest_output=xml:out/junit/cctest.xml
534         $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
535                 --mode=$(BUILDTYPE_LOWER) --flaky-tests=$(FLAKY_TESTS) \
536                 $(TEST_CI_ARGS) $(CI_JS_SUITES) $(CI_NATIVE_SUITES) $(CI_DOC)
537         out/Release/embedtest 'require("./test/embedding/test-embedding.js")'
538         @echo "Clean up any leftover processes, error if found."
539         ps awwx | grep Release/node | grep -v grep | cat
540         @PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \
541         if [ "$${PS_OUT}" ]; then \
542                 echo $${PS_OUT} | xargs kill -9; exit 1; \
543         fi
544
545 .PHONY: build-ci
546 # Prepare the build for running the tests.
547 # Related CI jobs: most CI tests, excluding node-test-commit-arm-fanned
548 build-ci:
549         $(PYTHON) ./configure --verbose $(CONFIG_FLAGS)
550         $(MAKE)
551
552 .PHONY: run-ci
553 # Run by CI tests, exceptions:
554 # - node-test-commit-arm-fanned (Raspberry Pis), where the binaries are
555 #   cross-compiled, then transferred elsewhere to run different subsets
556 #   of tests. See `test-ci-native` and `test-ci-js`.
557 # - node-test-commit-linux-coverage: where the build and the tests need
558 #   to be instrumented, see `coverage`.
559 #
560 # Using -j1 as the sub target in `test-ci` already have internal parallelism.
561 # Refs: https://github.com/nodejs/node/pull/23733
562 run-ci: build-ci
563         $(MAKE) test-ci -j1
564
565 test-release: test-build
566         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER)
567
568 test-debug: test-build
569         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=debug
570
571 test-message: test-build
572         $(PYTHON) tools/test.py $(PARALLEL_ARGS) message
573
574 test-wpt: all
575         $(PYTHON) tools/test.py $(PARALLEL_ARGS) wpt
576
577 test-simple: | cctest # Depends on 'all'.
578         $(PYTHON) tools/test.py $(PARALLEL_ARGS) parallel sequential
579
580 test-pummel: all
581         $(PYTHON) tools/test.py $(PARALLEL_ARGS) pummel
582
583 test-internet: all
584         $(PYTHON) tools/test.py $(PARALLEL_ARGS) internet
585
586 test-node-inspect: $(NODE_EXE)
587         USE_EMBEDDED_NODE_INSPECT=1 $(NODE) tools/test-npm-package \
588                 --install deps/node-inspect test
589
590 test-benchmark: | bench-addons-build
591         $(PYTHON) tools/test.py $(PARALLEL_ARGS) benchmark
592
593 test-tick-processor: all
594         $(PYTHON) tools/test.py $(PARALLEL_ARGS) tick-processor
595
596 .PHONY: test-hash-seed
597 # Verifies the hash seed used by V8 for hashing is random.
598 test-hash-seed: all
599         $(NODE) test/pummel/test-hash-seed.js
600
601 .PHONY: test-doc
602 test-doc: doc-only lint ## Builds, lints, and verifies the docs.
603         @if [ "$(shell $(node_use_openssl))" != "true" ]; then \
604                 echo "Skipping test-doc (no crypto)"; \
605         else \
606                 $(PYTHON) tools/test.py $(PARALLEL_ARGS) doctool; \
607         fi
608         $(NODE) tools/doc/checkLinks.js .
609
610 test-known-issues: all
611         $(PYTHON) tools/test.py $(PARALLEL_ARGS) known_issues
612
613 # Related CI job: node-test-npm
614 test-npm: $(NODE_EXE) ## Run the npm test suite on deps/npm.
615         $(NODE) tools/test-npm-package --install --logfile=test-npm.tap deps/npm test-node
616
617 test-npm-publish: $(NODE_EXE)
618         npm_package_config_publishtest=true $(NODE) deps/npm/test/run.js
619
620 .PHONY: test-js-native-api
621 test-js-native-api: test-build-js-native-api
622         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) js-native-api
623
624 .PHONY: test-js-native-api-clean
625 test-js-native-api-clean:
626         $(RM) -r test/js-native-api/*/build
627         $(RM) test/js-native-api/.buildstamp
628
629 .PHONY: test-node-api
630 test-node-api: test-build-node-api
631         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) node-api
632
633 .PHONY: test-node-api-clean
634 test-node-api-clean:
635         $(RM) -r test/node-api/*/build
636         $(RM) test/node-api/.buildstamp
637
638 .PHONY: test-addons
639 test-addons: test-build test-js-native-api test-node-api
640         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) addons
641
642 .PHONY: test-addons-clean
643 test-addons-clean:
644         $(RM) -r test/addons/??_*/
645         $(RM) -r test/addons/*/build
646         $(RM) test/addons/.buildstamp test/addons/.docbuildstamp
647         $(MAKE) test-js-native-api-clean
648         $(MAKE) test-node-api-clean
649
650 test-async-hooks:
651         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) async-hooks
652
653 test-with-async-hooks:
654         $(MAKE) build-addons
655         $(MAKE) build-js-native-api-tests
656         $(MAKE) build-node-api-tests
657         $(MAKE) cctest
658         NODE_TEST_WITH_ASYNC_HOOKS=1 $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) \
659                 $(JS_SUITES) \
660                 $(NATIVE_SUITES)
661
662
663 .PHONY: test-v8
664 .PHONY: test-v8-all
665 .PHONY: test-v8-benchmarks
666 .PHONY: test-v8-intl
667 .PHONY: test-v8-updates
668 ifneq ("","$(wildcard deps/v8/tools/run-tests.py)")
669 # Related CI job: node-test-commit-v8-linux
670 test-v8: v8  ## Runs the V8 test suite on deps/v8.
671         deps/v8/tools/run-tests.py --gn --arch=$(V8_ARCH) \
672                                 --mode=$(BUILDTYPE_LOWER) $(V8_TEST_OPTIONS) \
673                                 mjsunit cctest debugger inspector message preparser \
674                                 $(TAP_V8)
675         @echo Testing hash seed
676         $(MAKE) test-hash-seed
677
678 test-v8-intl: v8
679         deps/v8/tools/run-tests.py --gn --arch=$(V8_ARCH) \
680                                 --mode=$(BUILDTYPE_LOWER) intl \
681                                 $(TAP_V8_INTL)
682
683 test-v8-benchmarks: v8
684         deps/v8/tools/run-tests.py --gn --arch=$(V8_ARCH) --mode=$(BUILDTYPE_LOWER) \
685                                 benchmarks \
686                                 $(TAP_V8_BENCHMARKS)
687
688 test-v8-updates:
689         $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) v8-updates
690
691 test-v8-all: test-v8 test-v8-intl test-v8-benchmarks test-v8-updates
692 # runs all v8 tests
693 else
694 test-v8 test-v8-intl test-v8-benchmarks test-v8-all:
695         @echo "Testing v8 is not available through the source tarball."
696         @echo "Use the git repo instead:" \
697                 "$ git clone https://github.com/nodejs/node.git"
698 endif
699
700 apidoc_dirs = out/doc out/doc/api out/doc/api/assets
701 apidoc_sources = $(wildcard doc/api/*.md)
702 apidocs_html = $(addprefix out/,$(apidoc_sources:.md=.html))
703 apidocs_json = $(addprefix out/,$(apidoc_sources:.md=.json))
704
705 apiassets = $(subst api_assets,api/assets,$(addprefix out/,$(wildcard doc/api_assets/*)))
706
707 tools/doc/node_modules: tools/doc/package.json
708         @if [ "$(shell $(node_use_openssl))" != "true" ]; then \
709                 echo "Skipping tools/doc/node_modules (no crypto)"; \
710         else \
711                 cd tools/doc && $(call available-node,$(run-npm-ci)) \
712         fi
713
714 .PHONY: doc-only
715 doc-only: tools/doc/node_modules \
716         $(apidoc_dirs) $(apiassets)  ## Builds the docs with the local or the global Node.js binary.
717         @if [ "$(shell $(node_use_openssl))" != "true" ]; then \
718                 echo "Skipping doc-only (no crypto)"; \
719         else \
720                 $(MAKE) out/doc/api/all.html out/doc/api/all.json; \
721         fi
722
723 .PHONY: doc
724 doc: $(NODE_EXE) doc-only
725
726 out/doc:
727         mkdir -p $@
728
729 # If it's a source tarball, doc/api already contains the generated docs.
730 # Just copy everything under doc/api over.
731 out/doc/api: doc/api
732         mkdir -p $@
733         cp -r doc/api out/doc
734
735 # If it's a source tarball, assets are already in doc/api/assets
736 out/doc/api/assets:
737         mkdir -p $@
738         if [ -d doc/api/assets ]; then cp -r doc/api/assets out/doc/api; fi;
739
740 # If it's not a source tarball, we need to copy assets from doc/api_assets
741 out/doc/api/assets/%: doc/api_assets/% | out/doc/api/assets
742         @cp $< $@ ; $(RM) out/doc/api/assets/README.md
743
744
745 run-npm-ci = $(PWD)/$(NPM) ci
746
747 LINK_DATA = out/doc/apilinks.json
748 VERSIONS_DATA = out/previous-doc-versions.json
749 gen-api = tools/doc/generate.js --node-version=$(FULLVERSION) \
750                 --apilinks=$(LINK_DATA) $< --output-directory=out/doc/api \
751                 --versions-file=$(VERSIONS_DATA)
752 gen-apilink = tools/doc/apilinks.js $(LINK_DATA) $(wildcard lib/*.js)
753
754 $(LINK_DATA): $(wildcard lib/*.js) tools/doc/apilinks.js | out/doc
755         $(call available-node, $(gen-apilink))
756
757 # Regenerate previous versions data if the current version changes
758 $(VERSIONS_DATA): CHANGELOG.md src/node_version.h tools/doc/versions.js
759         $(call available-node, tools/doc/versions.js $@)
760
761 out/doc/api/%.json out/doc/api/%.html: doc/api/%.md tools/doc/generate.js \
762         tools/doc/markdown.js tools/doc/html.js tools/doc/json.js \
763         tools/doc/apilinks.js $(VERSIONS_DATA) | $(LINK_DATA) out/doc/api
764         $(call available-node, $(gen-api))
765
766 out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.js \
767         tools/doc/apilinks.js | out/doc/api
768         $(call available-node, tools/doc/allhtml.js)
769
770 out/doc/api/all.json: $(apidocs_json) tools/doc/alljson.js | out/doc/api
771         $(call available-node, tools/doc/alljson.js)
772
773 .PHONY: docopen
774 docopen: out/doc/api/all.html
775         @$(PYTHON) -mwebbrowser file://$(abspath $<)
776
777 .PHONY: docserve
778 docserve: $(apidocs_html) $(apiassets)
779         @$(PYTHON) -m http.server 8000 --bind 127.0.0.1 --directory out/doc/api
780
781 .PHONY: docclean
782 docclean:
783         $(RM) -r out/doc
784         $(RM) "$(VERSIONS_DATA)"
785
786 RAWVER=$(shell $(PYTHON) tools/getnodeversion.py)
787 VERSION=v$(RAWVER)
788
789 # For nightly builds, you must set DISTTYPE to "nightly", "next-nightly" or
790 # "custom". For the nightly and next-nightly case, you need to set DATESTRING
791 # and COMMIT in order to properly name the build.
792 # For the rc case you need to set CUSTOMTAG to an appropriate CUSTOMTAG number
793
794 ifndef DISTTYPE
795 DISTTYPE=release
796 endif
797 ifeq ($(DISTTYPE),release)
798 FULLVERSION=$(VERSION)
799 else # ifeq ($(DISTTYPE),release)
800 ifeq ($(DISTTYPE),custom)
801 ifndef CUSTOMTAG
802 $(error CUSTOMTAG is not set for DISTTYPE=custom)
803 endif # ifndef CUSTOMTAG
804 TAG=$(CUSTOMTAG)
805 else # ifeq ($(DISTTYPE),custom)
806 ifndef DATESTRING
807 $(error DATESTRING is not set for nightly)
808 endif # ifndef DATESTRING
809 ifndef COMMIT
810 $(error COMMIT is not set for nightly)
811 endif # ifndef COMMIT
812 ifneq ($(DISTTYPE),nightly)
813 ifneq ($(DISTTYPE),next-nightly)
814 $(error DISTTYPE is not release, custom, nightly or next-nightly)
815 endif # ifneq ($(DISTTYPE),next-nightly)
816 endif # ifneq ($(DISTTYPE),nightly)
817 TAG=$(DISTTYPE)$(DATESTRING)$(COMMIT)
818 endif # ifeq ($(DISTTYPE),custom)
819 FULLVERSION=$(VERSION)-$(TAG)
820 endif # ifeq ($(DISTTYPE),release)
821
822 DISTTYPEDIR ?= $(DISTTYPE)
823 RELEASE=$(shell sed -ne 's/\#define NODE_VERSION_IS_RELEASE \([01]\)/\1/p' src/node_version.h)
824 PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]')
825 NPMVERSION=v$(shell cat deps/npm/package.json | grep '"version"' | sed 's/^[^:]*: "\([^"]*\)",.*/\1/')
826
827 UNAME_M=$(shell uname -m)
828 ifeq ($(findstring x86_64,$(UNAME_M)),x86_64)
829 DESTCPU ?= x64
830 else
831 ifeq ($(findstring amd64,$(UNAME_M)),amd64)
832 DESTCPU ?= x64
833 else
834 ifeq ($(findstring ppc64,$(UNAME_M)),ppc64)
835 DESTCPU ?= ppc64
836 else
837 ifeq ($(findstring ppc,$(UNAME_M)),ppc)
838 DESTCPU ?= ppc
839 else
840 ifeq ($(findstring s390x,$(UNAME_M)),s390x)
841 DESTCPU ?= s390x
842 else
843 ifeq ($(findstring s390,$(UNAME_M)),s390)
844 DESTCPU ?= s390
845 else
846 ifeq ($(findstring arm,$(UNAME_M)),arm)
847 DESTCPU ?= arm
848 else
849 ifeq ($(findstring aarch64,$(UNAME_M)),aarch64)
850 DESTCPU ?= arm64
851 else
852 ifeq ($(findstring powerpc,$(shell uname -p)),powerpc)
853 DESTCPU ?= ppc64
854 else
855 DESTCPU ?= x86
856 endif
857 endif
858 endif
859 endif
860 endif
861 endif
862 endif
863 endif
864 endif
865 ifeq ($(DESTCPU),x64)
866 ARCH=x64
867 else
868 ifeq ($(DESTCPU),arm)
869 ARCH=arm
870 else
871 ifeq ($(DESTCPU),arm64)
872 ARCH=arm64
873 else
874 ifeq ($(DESTCPU),ppc64)
875 ARCH=ppc64
876 else
877 ifeq ($(DESTCPU),ppc)
878 ARCH=ppc
879 else
880 ifeq ($(DESTCPU),s390)
881 ARCH=s390
882 else
883 ifeq ($(DESTCPU),s390x)
884 ARCH=s390x
885 else
886 ARCH=x86
887 endif
888 endif
889 endif
890 endif
891 endif
892 endif
893 endif
894
895 # node and v8 use different arch names (e.g. node 'x86' vs v8 'ia32').
896 # pass the proper v8 arch name to $V8_ARCH based on user-specified $DESTCPU.
897 ifeq ($(DESTCPU),x86)
898 V8_ARCH=ia32
899 else
900 V8_ARCH ?= $(DESTCPU)
901
902 endif
903
904 # enforce "x86" over "ia32" as the generally accepted way of referring to 32-bit intel
905 ifeq ($(ARCH),ia32)
906 override ARCH=x86
907 endif
908 ifeq ($(DESTCPU),ia32)
909 override DESTCPU=x86
910 endif
911
912 TARNAME=node-$(FULLVERSION)
913 TARBALL=$(TARNAME).tar
914 # Custom user-specified variation, use it directly
915 ifdef VARIATION
916 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)-$(VARIATION)
917 else
918 BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)
919 endif
920 BINARYTAR=$(BINARYNAME).tar
921 # OSX doesn't have xz installed by default, http://macpkg.sourceforge.net/
922 HAS_XZ ?= $(shell which xz > /dev/null 2>&1; [ $$? -eq 0 ] && echo 1 || echo 0)
923 # Supply SKIP_XZ=1 to explicitly skip .tar.xz creation
924 SKIP_XZ ?= 0
925 XZ = $(shell [ $(HAS_XZ) -eq 1 -a $(SKIP_XZ) -eq 0 ] && echo 1 || echo 0)
926 XZ_COMPRESSION ?= 9e
927 PKG=$(TARNAME).pkg
928 MACOSOUTDIR=out/macos
929
930 ifeq ($(SKIP_XZ), 1)
931 check-xz:
932         @echo "SKIP_XZ=1 supplied, skipping .tar.xz creation"
933 else
934 ifeq ($(HAS_XZ), 1)
935 check-xz:
936 else
937 check-xz:
938         @echo "No xz command, cannot continue"
939         @exit 1
940 endif
941 endif
942
943 .PHONY: release-only
944 release-only: check-xz
945         @if [ "$(DISTTYPE)" = "release" ] && `grep -q REPLACEME doc/api/*.md`; then \
946                 echo 'Please update REPLACEME tags in the following doc/api/*.md files (See doc/guides/releases.md):\n' ; \
947                 REPLACEMES="$(shell grep -l REPLACEME doc/api/*.md)" ; \
948                 echo "$$REPLACEMES\n" | tr " " "\n" ; \
949                 exit 1 ; \
950         fi
951         @if [ "$(DISTTYPE)" = "release" ] && \
952                 `grep -q DEP...X doc/api/deprecations.md`; then \
953                 echo 'Please update DEP...X in doc/api/deprecations.md (See doc/guides/releases.md)' ; \
954                 exit 1 ; \
955         fi
956         @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \
957                 exit 0 ; \
958         else \
959                 echo "" >&2 ; \
960                 echo "The git repository is not clean." >&2 ; \
961                 echo "Please commit changes before building release tarball." >&2 ; \
962                 echo "" >&2 ; \
963                 git status --porcelain | egrep -v '^\?\?' >&2 ; \
964                 echo "" >&2 ; \
965                 exit 1 ; \
966         fi
967         @if [ "$(DISTTYPE)" != "release" -o "$(RELEASE)" = "1" ]; then \
968                 exit 0; \
969         else \
970                 echo "" >&2 ; \
971                 echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \
972                 echo "Did you remember to update src/node_version.h?" >&2 ; \
973                 echo "" >&2 ; \
974                 exit 1 ; \
975         fi
976
977 $(PKG): release-only
978         $(RM) -r $(MACOSOUTDIR)
979         mkdir -p $(MACOSOUTDIR)/installer/productbuild
980         cat tools/macos-installer/productbuild/distribution.xml.tmpl  \
981                 | sed -E "s/\\{nodeversion\\}/$(FULLVERSION)/g" \
982                 | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g" \
983         >$(MACOSOUTDIR)/installer/productbuild/distribution.xml ; \
984
985         @for dirname in tools/macos-installer/productbuild/Resources/*/; do \
986                 lang=$$(basename $$dirname) ; \
987                 mkdir -p $(MACOSOUTDIR)/installer/productbuild/Resources/$$lang ; \
988                 printf "Found localization directory $$dirname\n" ; \
989                 cat $$dirname/welcome.html.tmpl  \
990                         | sed -E "s/\\{nodeversion\\}/$(FULLVERSION)/g" \
991                         | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g"  \
992                 >$(MACOSOUTDIR)/installer/productbuild/Resources/$$lang/welcome.html ; \
993                 cat $$dirname/conclusion.html.tmpl  \
994                         | sed -E "s/\\{nodeversion\\}/$(FULLVERSION)/g" \
995                         | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g"  \
996                 >$(MACOSOUTDIR)/installer/productbuild/Resources/$$lang/conclusion.html ; \
997         done
998         $(PYTHON) ./configure \
999                 --dest-cpu=x64 \
1000                 --tag=$(TAG) \
1001                 --release-urlbase=$(RELEASE_URLBASE) \
1002                 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
1003         $(MAKE) install V=$(V) DESTDIR=$(MACOSOUTDIR)/dist/node
1004         SIGN="$(CODESIGN_CERT)" PKGDIR="$(MACOSOUTDIR)/dist/node/usr/local" bash \
1005                 tools/osx-codesign.sh
1006         mkdir -p $(MACOSOUTDIR)/dist/npm/usr/local/lib/node_modules
1007         mkdir -p $(MACOSOUTDIR)/pkgs
1008         mv $(MACOSOUTDIR)/dist/node/usr/local/lib/node_modules/npm \
1009                 $(MACOSOUTDIR)/dist/npm/usr/local/lib/node_modules
1010         unlink $(MACOSOUTDIR)/dist/node/usr/local/bin/npm
1011         unlink $(MACOSOUTDIR)/dist/node/usr/local/bin/npx
1012         $(NODE) tools/license2rtf.js < LICENSE > \
1013                 $(MACOSOUTDIR)/installer/productbuild/Resources/license.rtf
1014         cp doc/osx_installer_logo.png $(MACOSOUTDIR)/installer/productbuild/Resources
1015         pkgbuild --version $(FULLVERSION) \
1016                 --identifier org.nodejs.node.pkg \
1017                 --root $(MACOSOUTDIR)/dist/node $(MACOSOUTDIR)/pkgs/node-$(FULLVERSION).pkg
1018         pkgbuild --version $(NPMVERSION) \
1019                 --identifier org.nodejs.npm.pkg \
1020                 --root $(MACOSOUTDIR)/dist/npm \
1021                 --scripts ./tools/macos-installer/pkgbuild/npm/scripts \
1022                         $(MACOSOUTDIR)/pkgs/npm-$(NPMVERSION).pkg
1023         productbuild --distribution $(MACOSOUTDIR)/installer/productbuild/distribution.xml \
1024                 --resources $(MACOSOUTDIR)/installer/productbuild/Resources \
1025                 --package-path $(MACOSOUTDIR)/pkgs ./$(PKG)
1026         SIGN="$(PRODUCTSIGN_CERT)" PKG="$(PKG)" bash tools/osx-productsign.sh
1027         bash tools/osx-notarize.sh $(FULLVERSION)
1028
1029 .PHONY: pkg
1030 # Builds the macOS installer for releases.
1031 pkg: $(PKG)
1032
1033 # Note: this is strictly for release builds on release machines only.
1034 pkg-upload: pkg
1035         ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
1036         chmod 664 $(TARNAME).pkg
1037         scp -p $(TARNAME).pkg $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).pkg
1038         ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).pkg.done"
1039
1040 $(TARBALL): release-only doc-only
1041         git checkout-index -a -f --prefix=$(TARNAME)/
1042         mkdir -p $(TARNAME)/doc/api
1043         cp doc/node.1 $(TARNAME)/doc/node.1
1044         cp -r out/doc/api/* $(TARNAME)/doc/api/
1045         $(RM) -r $(TARNAME)/.editorconfig
1046         $(RM) -r $(TARNAME)/.git*
1047         $(RM) -r $(TARNAME)/.mailmap
1048         $(RM) -r $(TARNAME)/deps/openssl/openssl/demos
1049         $(RM) -r $(TARNAME)/deps/openssl/openssl/doc
1050         $(RM) -r $(TARNAME)/deps/openssl/openssl/test
1051         $(RM) -r $(TARNAME)/deps/uv/docs
1052         $(RM) -r $(TARNAME)/deps/uv/samples
1053         $(RM) -r $(TARNAME)/deps/uv/test
1054         $(RM) -r $(TARNAME)/deps/v8/samples
1055         $(RM) -r $(TARNAME)/deps/v8/tools/profviz
1056         $(RM) -r $(TARNAME)/deps/v8/tools/run-tests.py
1057         $(RM) -r $(TARNAME)/doc/images # too big
1058         $(RM) -r $(TARNAME)/test*.tap
1059         $(RM) -r $(TARNAME)/tools/cpplint.py
1060         $(RM) -r $(TARNAME)/tools/eslint-rules
1061         $(RM) -r $(TARNAME)/tools/license-builder.sh
1062         $(RM) -r $(TARNAME)/tools/node_modules
1063         $(RM) -r $(TARNAME)/tools/osx-*
1064         $(RM) -r $(TARNAME)/tools/osx-pkg.pmdoc
1065         find $(TARNAME)/deps/v8/test/* -type d ! -regex '.*/test/torque$$' | xargs $(RM) -r
1066         find $(TARNAME)/deps/v8/test -type f ! -regex '.*/test/torque/.*' | xargs $(RM)
1067         find $(TARNAME)/deps/zlib/contrib/* -type d ! -regex '.*/contrib/optimizations$$' | xargs $(RM) -r
1068         find $(TARNAME)/ -name ".eslint*" -maxdepth 2 | xargs $(RM)
1069         find $(TARNAME)/ -type l | xargs $(RM) # annoying on windows
1070         tar -cf $(TARNAME).tar $(TARNAME)
1071         $(RM) -r $(TARNAME)
1072         gzip -c -f -9 $(TARNAME).tar > $(TARNAME).tar.gz
1073 ifeq ($(XZ), 1)
1074         xz -c -f -$(XZ_COMPRESSION) $(TARNAME).tar > $(TARNAME).tar.xz
1075 endif
1076         $(RM) $(TARNAME).tar
1077
1078 .PHONY: tar
1079 tar: $(TARBALL) ## Create a source tarball.
1080
1081 # Note: this is strictly for release builds on release machines only.
1082 tar-upload: tar
1083         ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
1084         chmod 664 $(TARNAME).tar.gz
1085         scp -p $(TARNAME).tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).tar.gz
1086         ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).tar.gz.done"
1087 ifeq ($(XZ), 1)
1088         chmod 664 $(TARNAME).tar.xz
1089         scp -p $(TARNAME).tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).tar.xz
1090         ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).tar.xz.done"
1091 endif
1092
1093 # Note: this is strictly for release builds on release machines only.
1094 doc-upload: doc
1095         ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs/"
1096         chmod -R ug=rw-x+X,o=r+X out/doc/
1097         scp -pr out/doc/* $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs/
1098         ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs.done"
1099
1100 .PHONY: $(TARBALL)-headers
1101 $(TARBALL)-headers: release-only
1102         $(PYTHON) ./configure \
1103                 --prefix=/ \
1104                 --dest-cpu=$(DESTCPU) \
1105                 --tag=$(TAG) \
1106                 --release-urlbase=$(RELEASE_URLBASE) \
1107                 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
1108         HEADERS_ONLY=1 $(PYTHON) tools/install.py install '$(TARNAME)' '/'
1109         find $(TARNAME)/ -type l | xargs $(RM)
1110         tar -cf $(TARNAME)-headers.tar $(TARNAME)
1111         $(RM) -r $(TARNAME)
1112         gzip -c -f -9 $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.gz
1113 ifeq ($(XZ), 1)
1114         xz -c -f -$(XZ_COMPRESSION) $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.xz
1115 endif
1116         $(RM) $(TARNAME)-headers.tar
1117
1118 tar-headers: $(TARBALL)-headers ## Build the node header tarball.
1119
1120 tar-headers-upload: tar-headers
1121         ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
1122         chmod 664 $(TARNAME)-headers.tar.gz
1123         scp -p $(TARNAME)-headers.tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz
1124         ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz.done"
1125 ifeq ($(XZ), 1)
1126         chmod 664 $(TARNAME)-headers.tar.xz
1127         scp -p $(TARNAME)-headers.tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz
1128         ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz.done"
1129 endif
1130
1131 $(BINARYTAR): release-only
1132         $(RM) -r $(BINARYNAME)
1133         $(RM) -r out/deps out/Release
1134         $(PYTHON) ./configure \
1135                 --prefix=/ \
1136                 --dest-cpu=$(DESTCPU) \
1137                 --tag=$(TAG) \
1138                 --release-urlbase=$(RELEASE_URLBASE) \
1139                 $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS)
1140         $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1
1141         cp README.md $(BINARYNAME)
1142         cp LICENSE $(BINARYNAME)
1143         cp CHANGELOG.md $(BINARYNAME)
1144 ifeq ($(OSTYPE),darwin)
1145         SIGN="$(CODESIGN_CERT)" PKGDIR="$(BINARYNAME)" bash tools/osx-codesign.sh
1146 endif
1147         tar -cf $(BINARYNAME).tar $(BINARYNAME)
1148         $(RM) -r $(BINARYNAME)
1149         gzip -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.gz
1150 ifeq ($(XZ), 1)
1151         xz -c -f -$(XZ_COMPRESSION) $(BINARYNAME).tar > $(BINARYNAME).tar.xz
1152 endif
1153         $(RM) $(BINARYNAME).tar
1154
1155 .PHONY: binary
1156 # This requires NODE_VERSION_IS_RELEASE defined as 1 in src/node_version.h.
1157 binary: $(BINARYTAR) ## Build release binary tarballs.
1158
1159 # Note: this is strictly for release builds on release machines only.
1160 binary-upload: binary
1161         ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)"
1162         chmod 664 $(TARNAME)-$(OSTYPE)-$(ARCH).tar.gz
1163         scp -p $(TARNAME)-$(OSTYPE)-$(ARCH).tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-$(OSTYPE)-$(ARCH).tar.gz
1164         ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-$(OSTYPE)-$(ARCH).tar.gz.done"
1165 ifeq ($(XZ), 1)
1166         chmod 664 $(TARNAME)-$(OSTYPE)-$(ARCH).tar.xz
1167         scp -p $(TARNAME)-$(OSTYPE)-$(ARCH).tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-$(OSTYPE)-$(ARCH).tar.xz
1168         ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-$(OSTYPE)-$(ARCH).tar.xz.done"
1169 endif
1170
1171 .PHONY: bench-all
1172 bench-all: bench-addons-build
1173         @echo "Please use benchmark/run.js or benchmark/compare.js to run the benchmarks."
1174
1175 .PHONY: bench
1176 bench: bench-addons-build
1177         @echo "Please use benchmark/run.js or benchmark/compare.js to run the benchmarks."
1178
1179 # Build required addons for benchmark before running it.
1180 .PHONY: bench-addons-build
1181 bench-addons-build: | $(NODE_EXE) benchmark/napi/.buildstamp
1182
1183 .PHONY: bench-addons-clean
1184 bench-addons-clean:
1185         $(RM) -r benchmark/napi/*/build
1186         $(RM) benchmark/napi/.buildstamp
1187
1188 .PHONY: lint-md-rollup
1189 lint-md-rollup:
1190         $(RM) tools/.*mdlintstamp
1191         cd tools/node-lint-md-cli-rollup && npm install
1192         cd tools/node-lint-md-cli-rollup && npm run build-node
1193
1194 .PHONY: lint-md-clean
1195 lint-md-clean:
1196         $(RM) -r tools/node-lint-md-cli-rollup/node_modules
1197         $(RM) tools/.*mdlintstamp
1198
1199 .PHONY: lint-md-build
1200 lint-md-build:
1201         $(warning "Deprecated no-op target 'lint-md-build'")
1202
1203 ifeq ("$(wildcard tools/.mdlintstamp)","")
1204 LINT_MD_NEWER =
1205 else
1206 LINT_MD_NEWER = -newer tools/.mdlintstamp
1207 endif
1208
1209 LINT_MD_TARGETS = doc src lib benchmark test tools/doc tools/icu $(wildcard *.md)
1210 LINT_MD_FILES = $(shell $(FIND) $(LINT_MD_TARGETS) -type f \
1211         ! -path '*node_modules*' ! -path 'test/fixtures/*' -name '*.md' \
1212         $(LINT_MD_NEWER))
1213 run-lint-md = tools/lint-md.js -q -f --no-stdout $(LINT_MD_FILES)
1214 # Lint all changed markdown files maintained by us
1215 tools/.mdlintstamp: $(LINT_MD_FILES)
1216         @echo "Running Markdown linter..."
1217         @$(call available-node,$(run-lint-md))
1218         @touch $@
1219
1220 .PHONY: lint-md
1221 # Lints the markdown documents maintained by us in the codebase.
1222 lint-md: | tools/.mdlintstamp
1223
1224
1225 LINT_JS_TARGETS = .eslintrc.js benchmark doc lib test tools
1226
1227 run-lint-js = tools/node_modules/eslint/bin/eslint.js --cache \
1228         --report-unused-disable-directives --ext=.js,.mjs,.md $(LINT_JS_TARGETS)
1229 run-lint-js-fix = $(run-lint-js) --fix
1230
1231 .PHONY: lint-js-fix
1232 lint-js-fix:
1233         @$(call available-node,$(run-lint-js-fix))
1234
1235 .PHONY: lint-js
1236 # Note that on the CI `lint-js-ci` is run instead.
1237 # Lints the JavaScript code with eslint.
1238 lint-js:
1239         @if [ "$(shell $(node_use_openssl))" != "true" ]; then \
1240                 echo "Skipping $@ (no crypto)"; \
1241         else \
1242                 echo "Running JS linter..."; \
1243                 $(call available-node,$(run-lint-js)) \
1244         fi
1245
1246 jslint: lint-js
1247         @echo "Please use lint-js instead of jslint"
1248
1249 run-lint-js-ci = tools/node_modules/eslint/bin/eslint.js \
1250   --report-unused-disable-directives --ext=.js,.mjs,.md -f tap \
1251         -o test-eslint.tap $(LINT_JS_TARGETS)
1252
1253 .PHONY: lint-js-ci
1254 # On the CI the output is emitted in the TAP format.
1255 lint-js-ci:
1256         @echo "Running JS linter..."
1257         @$(call available-node,$(run-lint-js-ci))
1258
1259 jslint-ci: lint-js-ci
1260         @echo "Please use lint-js-ci instead of jslint-ci"
1261
1262 LINT_CPP_ADDON_DOC_FILES_GLOB = test/addons/??_*/*.cc test/addons/??_*/*.h
1263 LINT_CPP_ADDON_DOC_FILES = $(wildcard $(LINT_CPP_ADDON_DOC_FILES_GLOB))
1264 LINT_CPP_EXCLUDE ?=
1265 LINT_CPP_EXCLUDE += src/node_root_certs.h
1266 LINT_CPP_EXCLUDE += $(LINT_CPP_ADDON_DOC_FILES)
1267 LINT_CPP_EXCLUDE += $(wildcard test/js-native-api/??_*/*.cc test/js-native-api/??_*/*.h test/node-api/??_*/*.cc test/node-api/??_*/*.h)
1268 # These files were copied more or less verbatim from V8.
1269 LINT_CPP_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h
1270
1271 LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
1272         benchmark/napi/*/*.cc \
1273         src/*.c \
1274         src/*.cc \
1275         src/*.h \
1276         src/*/*.c \
1277         src/*/*.cc \
1278         src/*/*.h \
1279         test/addons/*/*.cc \
1280         test/addons/*/*.h \
1281         test/cctest/*.cc \
1282         test/cctest/*.h \
1283         test/embedding/*.cc \
1284         test/embedding/*.h \
1285         test/js-native-api/*/*.cc \
1286         test/js-native-api/*/*.h \
1287         test/node-api/*/*.cc \
1288         test/node-api/*/*.h \
1289         tools/icu/*.cc \
1290         tools/icu/*.h \
1291         tools/code_cache/*.cc \
1292         tools/code_cache/*.h \
1293         tools/snapshot/*.cc \
1294         tools/snapshot/*.h \
1295         ))
1296
1297 # Code blocks don't have newline at the end,
1298 # and the actual filename is generated so it won't match header guards
1299 ADDON_DOC_LINT_FLAGS=-whitespace/ending_newline,-build/header_guard
1300
1301 format-cpp-build:
1302         cd tools/clang-format && $(call available-node,$(run-npm-ci))
1303
1304 format-cpp-clean:
1305         $(RM) -r tools/clang-format/node_modules
1306
1307 CLANG_FORMAT_START ?= HEAD
1308 .PHONY: format-cpp
1309 # To format staged changes:
1310 #  $ make format-cpp
1311 # To format HEAD~1...HEAD (latest commit):
1312 #  $ CLANG_FORMAT_START=`git rev-parse HEAD~1` make format-cpp
1313 # To format diff between master and current branch head (master...HEAD):
1314 #  $ CLANG_FORMAT_START=master make format-cpp
1315 format-cpp: ## Format C++ diff from $CLANG_FORMAT_START to current changes
1316 ifneq ("","$(wildcard tools/clang-format/node_modules/)")
1317         @echo "Formatting C++ diff from $(CLANG_FORMAT_START).."
1318         @$(PYTHON) tools/clang-format/node_modules/.bin/git-clang-format \
1319                 --binary=tools/clang-format/node_modules/.bin/clang-format \
1320                 --style=file \
1321                 $(CLANG_FORMAT_START) -- \
1322                 $(LINT_CPP_FILES)
1323 else
1324         @echo "clang-format is not installed."
1325         @echo "To install (requires internet access) run: $ make format-cpp-build"
1326 endif
1327
1328 ifeq ($(V),1)
1329 CPPLINT_QUIET =
1330 else
1331 CPPLINT_QUIET = --quiet
1332 endif
1333 .PHONY: lint-cpp
1334 # Lints the C++ code with cpplint.py and checkimports.py.
1335 lint-cpp: tools/.cpplintstamp
1336
1337 tools/.cpplintstamp: $(LINT_CPP_FILES)
1338         @echo "Running C++ linter..."
1339         @$(PYTHON) tools/cpplint.py $(CPPLINT_QUIET) $?
1340         @$(PYTHON) tools/checkimports.py $?
1341         @touch $@
1342
1343 .PHONY: lint-addon-docs
1344 lint-addon-docs: tools/.doclintstamp
1345
1346 tools/.doclintstamp: test/addons/.docbuildstamp
1347         @echo "Running C++ linter on addon docs..."
1348         @$(PYTHON) tools/cpplint.py $(CPPLINT_QUIET) --filter=$(ADDON_DOC_LINT_FLAGS) \
1349                 $(LINT_CPP_ADDON_DOC_FILES_GLOB)
1350         @touch $@
1351
1352 cpplint: lint-cpp
1353         @echo "Please use lint-cpp instead of cpplint"
1354
1355 .PHONY: lint-py-build
1356 # python -m pip install flake8
1357 # Try with '--system' is to overcome systems that blindly set '--user'
1358 lint-py-build:
1359         @echo "Pip installing flake8 linter on $(shell $(PYTHON) --version)..."
1360         $(PYTHON) -m pip install --upgrade -t tools/pip/site-packages flake8 || \
1361                 $(PYTHON) -m pip install --upgrade --system -t tools/pip/site-packages flake8
1362
1363 ifneq ("","$(wildcard tools/pip/site-packages)")
1364 .PHONY: lint-py
1365 # Lints the Python code with flake8.
1366 # Flag the build if there are Python syntax errors or undefined names
1367 lint-py:
1368         PYTHONPATH=tools/pip $(PYTHON) -m flake8 --count --show-source --statistics .
1369 else
1370 lint-py:
1371         @echo "Python linting with flake8 is not avalible"
1372         @echo "Run 'make lint-py-build'"
1373 endif
1374
1375 .PHONY: lint
1376 .PHONY: lint-ci
1377 ifneq ("","$(wildcard tools/node_modules/eslint/)")
1378 lint: ## Run JS, C++, MD and doc linters.
1379         @EXIT_STATUS=0 ; \
1380         $(MAKE) lint-js || EXIT_STATUS=$$? ; \
1381         $(MAKE) lint-cpp || EXIT_STATUS=$$? ; \
1382         $(MAKE) lint-addon-docs || EXIT_STATUS=$$? ; \
1383         $(MAKE) lint-md || EXIT_STATUS=$$? ; \
1384         exit $$EXIT_STATUS
1385 CONFLICT_RE=^>>>>>>> [0-9A-Fa-f]+|^<<<<<<< [A-Za-z]+
1386
1387 # Related CI job: node-test-linter
1388 lint-ci: lint-js-ci lint-cpp lint-py lint-md lint-addon-docs
1389         @if ! ( grep -IEqrs "$(CONFLICT_RE)" benchmark deps doc lib src test tools ) \
1390                 && ! ( $(FIND) . -maxdepth 1 -type f | xargs grep -IEqs "$(CONFLICT_RE)" ); then \
1391                 exit 0 ; \
1392         else \
1393                 echo "" >&2 ; \
1394                 echo "Conflict marker detected in one or more files. Please fix them first." >&2 ; \
1395                 exit 1 ; \
1396         fi
1397 else
1398 lint:
1399         @echo "Linting is not available through the source tarball."
1400         @echo "Use the git repo instead:" \
1401                 "$ git clone https://github.com/nodejs/node.git"
1402
1403 lint-ci: lint
1404 endif
1405
1406 .PHONY: lint-clean
1407 lint-clean:
1408         $(RM) tools/.*lintstamp
1409         $(RM) .eslintcache
1410
1411 HAS_DOCKER ?= $(shell which docker > /dev/null 2>&1; [ $$? -eq 0 ] && echo 1 || echo 0)
1412
1413 ifeq ($(HAS_DOCKER), 1)
1414 DOCKER_COMMAND ?= docker run -it -v $(PWD):/node
1415 IS_IN_WORKTREE = $(shell grep '^gitdir: ' $(PWD)/.git 2>/dev/null)
1416 GIT_WORKTREE_COMMON = $(shell git rev-parse --git-common-dir)
1417 DOCKER_COMMAND += $(if $(IS_IN_WORKTREE), -v $(GIT_WORKTREE_COMMON):$(GIT_WORKTREE_COMMON))
1418 gen-openssl: ## Generate platform dependent openssl files (requires docker)
1419         docker build -t node-openssl-builder deps/openssl/config/
1420         $(DOCKER_COMMAND) node-openssl-builder make -C deps/openssl/config
1421 else
1422 gen-openssl:
1423         @echo "No docker command, cannot continue"
1424         @exit 1
1425 endif