From c131b522318cb6a5a5be4659aad8e95ed34b4f77 Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Wed, 1 May 2024 14:40:02 -0400 Subject: [PATCH] build: rewrite makefile in python --- .editorconfig | 7 - .gitattributes | 1 - .github/PULL_REQUEST_TEMPLATE.md | 2 +- .github/label-pr-config.yml | 2 +- .github/workflows/build-tarball.yml | 6 +- .github/workflows/build-windows.yml | 2 +- .../workflows/coverage-linux-without-intl.yml | 4 +- .github/workflows/coverage-linux.yml | 4 +- .github/workflows/coverage-windows.yml | 4 +- .github/workflows/daily-wpt-fyi.yml | 2 +- .github/workflows/doc.yml | 4 +- .github/workflows/linters.yml | 24 +- .github/workflows/test-asan.yml | 4 +- .github/workflows/test-internet.yml | 4 +- .github/workflows/test-linux.yml | 4 +- .github/workflows/test-macos.yml | 8 +- .github/workflows/test-ubsan.yml | 4 +- .github/workflows/tools.yml | 4 +- .gitignore | 3 - .gitpod.yml | 2 +- BUILDING.md | 64 +- Makefile | 1596 ------------ build.py | 2275 +++++++++++++++++ common.gypi | 2 +- doc/README.md | 2 +- vcbuild.bat | 803 ------ 26 files changed, 2351 insertions(+), 2486 deletions(-) delete mode 100644 Makefile create mode 100644 build.py delete mode 100644 vcbuild.bat diff --git a/.editorconfig b/.editorconfig index 3a416e87aba4..1c798d4a2cae 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,13 +9,6 @@ insert_final_newline = true trim_trailing_whitespace = true quote_type = single -[vcbuild.bat] -end_of_line = crlf - -[Makefile] -indent_size = 8 -indent_style = tab - [{deps}/**] charset = unset end_of_line = unset diff --git a/.gitattributes b/.gitattributes index bbfe62e6a034..112f9319b496 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,4 @@ test/fixtures/* -text -vcbuild.bat text eol=crlf deps/npm/bin/npm text eol=lf deps/npm/bin/npx text eol=lf deps/corepack/shims/corepack text eol=lf diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 936c2a061257..2cf4b5f3c1d0 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -8,7 +8,7 @@ Before submitting a pull request, please read: For code changes: 1. Include tests for any bug fixes or new features. 2. Update documentation if relevant. -3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes. +3. Ensure that `python3 build.py -j4 test` passes. If you believe this PR should be highlighted in the Node.js CHANGELOG please add the `notable-change` label. diff --git a/.github/label-pr-config.yml b/.github/label-pr-config.yml index 701d494ab40b..8bf07ee08fc4 100644 --- a/.github/label-pr-config.yml +++ b/.github/label-pr-config.yml @@ -48,7 +48,7 @@ subSystemLabels: # Different variants of Makefile and build files /^(?:tools\/)?(?:Makefile|BSDmakefile|create_android_makefiles)$/: build, needs-ci /^tools\/(?:install\.py|getnodeversion\.py|js2c\.py|utils\.py|configure\.d\/.*)$/: build, python, needs-ci - /^vcbuild\.bat$/: build, windows, needs-ci + /^build\.py$/: build, needs-ci /^(?:android-)?configure|node\.gyp|common\.gypi$/: build, needs-ci # More specific tools /^tools\/gyp/: tools, build, gyp, needs-ci diff --git a/.github/workflows/build-tarball.yml b/.github/workflows/build-tarball.yml index ff0a9d725d30..a448a7091763 100644 --- a/.github/workflows/build-tarball.yml +++ b/.github/workflows/build-tarball.yml @@ -53,7 +53,7 @@ jobs: export DISTTYPE=nightly export DATESTRING=`date "+%Y-%m-%d"` export COMMIT=$(git rev-parse --short=10 "$GITHUB_SHA") - ./configure && make tar -j8 SKIP_XZ=1 + ./configure && python3 build.py tar -j8 mkdir tarballs mv *.tar.gz tarballs - name: Upload tarball artifact @@ -90,8 +90,8 @@ jobs: - name: Build run: | cd $TAR_DIR - make build-ci -j4 V=1 + python3 build.py build-ci -j4 - name: Test run: | cd $TAR_DIR - make run-ci -j4 V=1 TEST_CI_ARGS="-p dots --node-args='--test-reporter=spec' --measure-flakiness 9" + TEST_CI_ARGS="-p dots --node-args='--test-reporter=spec' --measure-flakiness 9" python3 build.py run-ci -j4 diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml index 0b35c4f31571..d3b9a66d6b3b 100644 --- a/.github/workflows/build-windows.yml +++ b/.github/workflows/build-windows.yml @@ -50,4 +50,4 @@ jobs: - name: Environment Information run: npx envinfo - name: Build - run: ./vcbuild.bat + run: ./build.py diff --git a/.github/workflows/coverage-linux-without-intl.yml b/.github/workflows/coverage-linux-without-intl.yml index a2351225d6ef..136e5a4c238f 100644 --- a/.github/workflows/coverage-linux-without-intl.yml +++ b/.github/workflows/coverage-linux-without-intl.yml @@ -53,11 +53,11 @@ jobs: - name: Install gcovr run: pip install gcovr==4.2 - name: Build - run: make build-ci -j4 V=1 CONFIG_FLAGS="--error-on-warn --coverage --without-intl" + run: CONFIG_FLAGS="--error-on-warn --coverage --without-intl" python3 build.py build-ci -j4 # TODO(bcoe): fix the couple tests that fail with the inspector enabled. # The cause is most likely coverage's use of the inspector. - name: Test - run: NODE_V8_COVERAGE=coverage/tmp make test-cov -j4 V=1 TEST_CI_ARGS="-p dots --node-args='--test-reporter=spec' --measure-flakiness 9" || exit 0 + run: TEST_CI_ARGS="-p dots --node-args='--test-reporter=spec' --measure-flakiness 9" NODE_V8_COVERAGE=coverage/tmp python3 build.py test-cov -j4 || exit 0 - name: Report JS run: npx c8 report --check-coverage env: diff --git a/.github/workflows/coverage-linux.yml b/.github/workflows/coverage-linux.yml index 10705fc16a74..649423fa1c37 100644 --- a/.github/workflows/coverage-linux.yml +++ b/.github/workflows/coverage-linux.yml @@ -53,11 +53,11 @@ jobs: - name: Install gcovr run: pip install gcovr==4.2 - name: Build - run: make build-ci -j4 V=1 CONFIG_FLAGS="--error-on-warn --coverage" + run: V=1 CONFIG_FLAGS="--error-on-warn --coverage" python3 build.py build-ci -j4 # TODO(bcoe): fix the couple tests that fail with the inspector enabled. # The cause is most likely coverage's use of the inspector. - name: Test - run: NODE_V8_COVERAGE=coverage/tmp make test-cov -j4 V=1 TEST_CI_ARGS="-p dots --node-args='--test-reporter=spec' --measure-flakiness 9" || exit 0 + run: V=1 TEST_CI_ARGS="-p dots --node-args='--test-reporter=spec' --measure-flakiness 9" NODE_V8_COVERAGE=coverage/tmp python3 build.py test-cov -j4 || exit 0 - name: Report JS run: npx c8 report --check-coverage env: diff --git a/.github/workflows/coverage-windows.yml b/.github/workflows/coverage-windows.yml index ead5743f51b3..2aa2210de697 100644 --- a/.github/workflows/coverage-windows.yml +++ b/.github/workflows/coverage-windows.yml @@ -53,11 +53,11 @@ jobs: - name: Environment Information run: npx envinfo - name: Build - run: ./vcbuild.bat + run: python3 build.py # TODO(bcoe): investigate tests that fail with coverage enabled # on Windows. - name: Test - run: ./vcbuild.bat test-ci-js; node -e 'process.exit(0)' + run: python3 build.py test-ci-js; node -e 'process.exit(0)' env: NODE_V8_COVERAGE: ./coverage/tmp - name: Report diff --git a/.github/workflows/daily-wpt-fyi.yml b/.github/workflows/daily-wpt-fyi.yml index 62eb8b29f43e..d896ff8e5178 100644 --- a/.github/workflows/daily-wpt-fyi.yml +++ b/.github/workflows/daily-wpt-fyi.yml @@ -84,7 +84,7 @@ jobs: # Node.js WPT Runner - name: Run WPT and generate report run: | - make test-wpt-report || true + python3 build.py test-wpt-report || true if [ -e out/wpt/wptreport.json ]; then echo "WPT_REPORT=$(pwd)/out/wpt/wptreport.json" >> $GITHUB_ENV fi diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 5de7373a8baf..c6ee15efd5d3 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -34,10 +34,10 @@ jobs: - name: Environment Information run: npx envinfo - name: Build - run: NODE=$(command -v node) make doc-only + run: NODE=$(command -v node) python3 build.py doc-only - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 with: name: docs path: out/doc - name: Test - run: NODE=$(command -v node) make test-doc-ci TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' --measure-flakiness 9" + run: NODE=$(command -v node) python3 build.py test-doc-ci TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' --measure-flakiness 9" diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index dd1f9ee1ae65..8a348a7e8d98 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -35,7 +35,7 @@ jobs: - name: Environment Information run: npx envinfo - name: Lint addon docs - run: NODE=$(command -v node) make lint-addon-docs + run: NODE=$(command -v node) python3 build.py lint-addon-docs lint-cpp: if: github.event.pull_request.draft == false runs-on: ubuntu-latest @@ -50,7 +50,7 @@ jobs: - name: Environment Information run: npx envinfo - name: Lint C/C++ files - run: make lint-cpp + run: python3 build.py lint-cpp format-cpp: if: ${{ github.event.pull_request && github.event.pull_request.draft == false && github.base_ref == github.event.repository.default_branch }} runs-on: ubuntu-latest @@ -71,20 +71,20 @@ jobs: run: npx envinfo - name: Format C/C++ files run: | - make format-cpp-build - # The `make format-cpp` error code is intentionally ignored here + python3 build.py format-cpp-build + # The `python3 build.py format-cpp` error code is intentionally ignored here # because it is irrelevant. We already check if the formatter produced # a diff in the next line. # Refs: https://github.com/nodejs/node/pull/42764 CLANG_FORMAT_START="$(git merge-base HEAD refs/remotes/origin/$GITHUB_BASE_REF)" \ - make format-cpp || true + python3 build.py format-cpp || true git --no-pager diff --exit-code && EXIT_CODE="$?" || EXIT_CODE="$?" if [ "$EXIT_CODE" != "0" ] then echo echo 'ERROR: Please run:' echo - echo " CLANG_FORMAT_START="$\(git merge-base HEAD ${GITHUB_BASE_REF}\)" make format-cpp" + echo " CLANG_FORMAT_START="$\(git merge-base HEAD ${GITHUB_BASE_REF}\)" python3 build.py format-cpp" echo echo 'to format the commits in your branch.' exit "$EXIT_CODE" @@ -103,7 +103,7 @@ jobs: - name: Environment Information run: npx envinfo - name: Lint JavaScript files - run: NODE=$(command -v node) make lint-js + run: NODE=$(command -v node) python3 build.py lint-js - name: Get release version numbers if: ${{ github.event.pull_request && github.event.pull_request.base.ref == github.event.pull_request.base.repo.default_branch }} id: get-released-versions @@ -111,7 +111,7 @@ jobs: - name: Lint markdown files run: | echo "::add-matcher::.github/workflows/remark-lint-problem-matcher.json" - NODE=$(command -v node) make lint-md + NODE=$(command -v node) python3 build.py lint-md env: NODE_RELEASED_VERSIONS: ${{ steps.get-released-versions.outputs.NODE_RELEASED_VERSIONS }} lint-py: @@ -129,8 +129,8 @@ jobs: run: npx envinfo - name: Lint Python run: | - make lint-py-build - make lint-py + python3 build.py lint-py-build + python3 build.py lint-py lint-yaml: if: github.event.pull_request.draft == false runs-on: ubuntu-latest @@ -146,8 +146,8 @@ jobs: run: npx envinfo - name: Lint YAML run: | - make lint-yaml-build || true - make lint-yaml + python3 build.py lint-yaml-build || true + python3 build.py lint-yaml lint-sh: if: github.event.pull_request.draft == false diff --git a/.github/workflows/test-asan.yml b/.github/workflows/test-asan.yml index 495f6679d950..dc22d8515c8c 100644 --- a/.github/workflows/test-asan.yml +++ b/.github/workflows/test-asan.yml @@ -56,6 +56,6 @@ jobs: - name: Environment Information run: npx envinfo - name: Build - run: make build-ci -j4 V=1 + run: python3 build.py build-ci -j4 V=1 - name: Test - run: make run-ci -j4 V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' -t 300 --measure-flakiness 9" + run: python3 build.py run-ci -j4 V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' -t 300 --measure-flakiness 9" diff --git a/.github/workflows/test-internet.yml b/.github/workflows/test-internet.yml index 2f50448d45ad..984e42cbfe14 100644 --- a/.github/workflows/test-internet.yml +++ b/.github/workflows/test-internet.yml @@ -50,6 +50,6 @@ jobs: - name: Environment Information run: npx envinfo - name: Build - run: make build-ci -j4 V=1 CONFIG_FLAGS="--error-on-warn" + run: python3 build.py build-ci -j4 V=1 CONFIG_FLAGS="--error-on-warn" - name: Test Internet - run: make test-internet -j4 V=1; + run: python3 build.py test-internet -j4 V=1; diff --git a/.github/workflows/test-linux.yml b/.github/workflows/test-linux.yml index cebcf5d1152a..1d151fa7ce66 100644 --- a/.github/workflows/test-linux.yml +++ b/.github/workflows/test-linux.yml @@ -44,6 +44,6 @@ jobs: - name: Environment Information run: npx envinfo - name: Build - run: make build-ci -j4 V=1 CONFIG_FLAGS="--error-on-warn" + run: python3 build.py build-ci -j4 V=1 CONFIG_FLAGS="--error-on-warn" - name: Test - run: make run-ci -j4 V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' --measure-flakiness 9" + run: python3 build.py run-ci -j4 V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' --measure-flakiness 9" diff --git a/.github/workflows/test-macos.yml b/.github/workflows/test-macos.yml index ddcda36bd71a..4703d84841e3 100644 --- a/.github/workflows/test-macos.yml +++ b/.github/workflows/test-macos.yml @@ -52,12 +52,12 @@ jobs: # The `npm ci` for this step fails a lot as part of the Test step. Run it # now so that we don't have to wait 2 hours for the Build step to pass # first before that failure happens. (And if there's something about - # `make run-ci -j3` that is causing the failure and the failure doesn't + # `python3 build.py run-ci -j3` that is causing the failure and the failure doesn't # happen anymore running this step here first, that's also useful # information.) - name: tools/doc/node_modules workaround - run: make tools/doc/node_modules + run: python3 build.py tools/doc/node_modules - name: Build - run: make build-ci -j$(getconf _NPROCESSORS_ONLN) V=1 CONFIG_FLAGS="--error-on-warn" + run: python3 build.py build-ci -j$(getconf _NPROCESSORS_ONLN) V=1 CONFIG_FLAGS="--error-on-warn" - name: Test - run: make run-ci -j$(getconf _NPROCESSORS_ONLN) V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' --measure-flakiness 9" + run: python3 build.py run-ci -j$(getconf _NPROCESSORS_ONLN) V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' --measure-flakiness 9" diff --git a/.github/workflows/test-ubsan.yml b/.github/workflows/test-ubsan.yml index ef88b76496dc..39e3bd4b7ddf 100644 --- a/.github/workflows/test-ubsan.yml +++ b/.github/workflows/test-ubsan.yml @@ -58,6 +58,6 @@ jobs: - name: Environment Information run: npx envinfo - name: Build - run: make build-ci -j2 V=1 + run: python3 build.py build-ci -j2 V=1 - name: Test - run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' -t 300 --measure-flakiness 9" + run: python3 build.py run-ci -j2 V=1 TEST_CI_ARGS="-p actions --node-args='--test-reporter=spec' --node-args='--test-reporter-destination=stdout' -t 300 --measure-flakiness 9" diff --git a/.github/workflows/tools.yml b/.github/workflows/tools.yml index 4cc595b44141..50621de4ab51 100644 --- a/.github/workflows/tools.yml +++ b/.github/workflows/tools.yml @@ -117,7 +117,7 @@ jobs: subsystem: deps label: dependencies run: | - make corepack-update + python3 build.py corepack-update echo "NEW_VERSION=$(node deps/corepack/dist/corepack.js --version)" >> $GITHUB_ENV - id: doc subsystem: tools @@ -210,7 +210,7 @@ jobs: npm install --ignore-scripts $NEW_VERSION npm install --ignore-scripts cd ../.. - make lint-md-rollup + python3 build.py lint-md-rollup fi - id: llhttp subsystem: deps diff --git a/.gitignore b/.gitignore index 34c26e3a81e0..6791e321e425 100644 --- a/.gitignore +++ b/.gitignore @@ -146,9 +146,6 @@ tools/*/*.i.tmp # Ignore dependencies fetched by tools/v8/fetch_deps.py /deps/.cipd -# === Rules for Windows vcbuild.bat === -/temp-vcbuild - # === Rules for CMake === cmake-build-debug/ CMakeCache.txt diff --git a/.gitpod.yml b/.gitpod.yml index 1a56acf40f17..07a13d2d0cb8 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -1,6 +1,6 @@ # Ref: https://github.com/gitpod-io/gitpod/issues/6283#issuecomment-1001043454 tasks: - - init: ./configure && timeout 50m make -j16 || true + - init: ./configure && timeout 50m python3 build.py all -j16 || true - init: pnpm i -g @node-core/utils # Ref: https://www.gitpod.io/docs/prebuilds#github-specific-configuration diff --git a/BUILDING.md b/BUILDING.md index 0b0362e8bf37..a3fba0f8f870 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -272,7 +272,7 @@ To build Node.js: ```bash ./configure -make -j4 +python3 build.py node ``` We can speed up the builds by using [Ninja](https://ninja-build.org/). For more @@ -302,7 +302,7 @@ sudo ./tools/macos-firewall.sh To install this version of Node.js into a system directory: ```bash -[sudo] make install +[sudo] python3 build.py install ``` #### Running tests @@ -310,7 +310,7 @@ To install this version of Node.js into a system directory: To verify the build: ```bash -make test-only +python3 build.py test-only ``` At this point, you are ready to make code changes and re-run the tests. @@ -318,16 +318,16 @@ At this point, you are ready to make code changes and re-run the tests. If you are running tests before submitting a pull request, use: ```bash -make -j4 test +python3 build.py test -j4 ``` -`make -j4 test` does a full check on the codebase, including running linters and +`python3 build.py test -j4` does a full check on the codebase, including running linters and documentation tests. To run the linter without running tests, use -`make lint`/`vcbuild lint`. It will lint JavaScript, C++, and Markdown files. +`python3 build.py lint`. It will lint JavaScript, C++, and Markdown files. -To fix auto fixable JavaScript linting errors, use `make lint-js-fix`. +To fix auto fixable JavaScript linting errors, use `pyhon3 build.py lint-js --fix`. If you are updating tests and want to run tests in a single test file (e.g. `test/parallel/test-stream2-transform.js`): @@ -368,7 +368,7 @@ You can usually run tests directly with node: > Info: `./node` points to your local Node.js build. -Remember to recompile with `make -j4` in between test runs if you change code in +Remember to recompile with `-j4` in between test runs if you change code in the `lib` or `src` directories. The tests attempt to detect support for IPv6 and exclude IPv6 tests if @@ -392,43 +392,43 @@ You can do so by running the test suite with coverage enabled: ```bash ./configure --coverage -make coverage +python3 build.py coverage ``` A detailed coverage report will be written to `coverage/index.html` for JavaScript coverage and to `coverage/cxxcoverage.html` for C++ coverage. If you only want to run the JavaScript tests then you do not need to run -the first command (`./configure --coverage`). Run `make coverage-run-js`, +the first command (`./configure --coverage`). Run `python3 build.py coverage-run-js`, to execute JavaScript tests independently of the C++ test suite: ```bash -make coverage-run-js +python3 build.py coverage-run-js ``` If you are updating tests and want to collect coverage for a single test file (e.g. `test/parallel/test-stream2-transform.js`): ```bash -make coverage-clean +python3 build.py coverage-clean NODE_V8_COVERAGE=coverage/tmp tools/test.py test/parallel/test-stream2-transform.js -make coverage-report-js +python3 build.py coverage-report-js ``` You can collect coverage for the entire suite of tests for a given subsystem by providing the name of a subsystem: ```bash -make coverage-clean +python3 build.py coverage-clean NODE_V8_COVERAGE=coverage/tmp tools/test.py --mode=release child-process -make coverage-report-js +python3 build.py coverage-report-js ``` -The `make coverage` command downloads some tools to the project root directory. +The `coverage` command downloads some tools to the project root directory. To clean up after generating the coverage reports: ```bash -make coverage-clean +python3 build.py coverage-clean ``` #### Building the documentation @@ -438,13 +438,13 @@ To build the documentation: This will build Node.js first (if necessary) and then use it to build the docs: ```bash -make doc +python3 build.py doc ``` If you have an existing Node.js build, you can build just the docs with: ```bash -NODE=/path/to/node make doc-only +NODE=/path/to/node python3 build.py doc-only ``` To read the man page: @@ -456,7 +456,7 @@ man doc/node.1 If you prefer to read the full documentation in a browser, run the following. ```bash -make docserve +python3 build.py docserve ``` This will spin up a static file server and provide a URL to where you may browse @@ -466,14 +466,14 @@ If you're comfortable viewing the documentation using the program your operating system has associated with the default web browser, run the following. ```bash -make docopen +python3 build.py docopen ``` This will open a file URL to a one-page version of all the browsable HTML documents using the default browser. ```bash -make docclean +python3 build.py docclean ``` This will clean previously built doc. @@ -492,18 +492,18 @@ can try to build a debug enabled binary: ```bash ./configure --debug -make -j4 +python3 build.py all -j4 ``` -`make` with `./configure --debug` generates two binaries, the regular release +`python3 build.py` with `./configure --debug` generates two binaries, the regular release one in `out/Release/node` and a debug binary in `out/Debug/node`, only the -release version is actually installed when you run `make install`. +release version is actually installed when you run `python3 build.py install`. To use the debug build with all the normal dependencies overwrite the release version in the install directory: ```bash -make install PREFIX=/opt/node-debug/ +python3 build.py install PREFIX=/opt/node-debug/ cp -a -f out/Debug/node /opt/node-debug/node ``` @@ -535,8 +535,8 @@ The `--debug` is not necessary and will slow down build and testing, but it can show clear stacktrace if ASan hits an issue. ```bash -./configure --debug --enable-asan && make -j4 -make test-only +./configure --debug --enable-asan && python3 build.py all -j4 +python3 build.py test-only ``` #### Speeding up frequent rebuilds when developing @@ -590,13 +590,13 @@ Refs: #### Troubleshooting Unix and macOS builds Stale builds can sometimes result in `file not found` errors while building. -This and some other problems can be resolved with `make distclean`. The +This and some other problems can be resolved with `python3 build.py distclean`. The `distclean` recipe aggressively removes build artifacts. You will need to -build again (`make -j4`). Since all build artifacts have been removed, this +build again (`python3 build.py all -j4`). Since all build artifacts have been removed, this rebuild may take a lot more time than previous builds. Additionally, `distclean` removes the file that stores the results of `./configure`. If you ran `./configure` with non-default options (such as `--debug`), you will need -to run it again before invoking `make -j4`. +to run it again before invoking `python3 build.py all -j4`. ### Windows @@ -723,7 +723,7 @@ a folder. Then run: ```bash ./android-configure -make -j4 +python3 build.py all -j4 ``` The Android SDK version should be at least 24 (Android 7.0) and the target diff --git a/Makefile b/Makefile deleted file mode 100644 index 475043ceae7e..000000000000 --- a/Makefile +++ /dev/null @@ -1,1596 +0,0 @@ --include config.mk - -BUILDTYPE ?= Release -PYTHON ?= python3 -DESTDIR ?= -SIGN ?= -PREFIX ?= /usr/local -FLAKY_TESTS ?= run -TEST_CI_ARGS ?= -STAGINGSERVER ?= node-www -LOGLEVEL ?= silent -OSTYPE := $(shell uname -s | tr '[:upper:]' '[:lower:]') -ifeq ($(findstring os/390,$OSTYPE),os/390) -OSTYPE ?= os390 -endif -ARCHTYPE := $(shell uname -m | tr '[:upper:]' '[:lower:]') -COVTESTS ?= test-cov -COV_SKIP_TESTS ?= core_line_numbers.js,testFinalizer.js,test_function/test.js -GTEST_FILTER ?= "*" -GNUMAKEFLAGS += --no-print-directory -GCOV ?= gcov -PWD = $(CURDIR) -BUILD_WITH ?= make -FIND ?= find - -ifdef JOBS - PARALLEL_ARGS = -j $(JOBS) -else - PARALLEL_ARGS = -endif - -ifdef ENABLE_V8_TAP - TAP_V8 := --junitout $(PWD)/v8-tap.xml - TAP_V8_INTL := --junitout $(PWD)/v8-intl-tap.xml - TAP_V8_BENCHMARKS := --junitout $(PWD)/v8-benchmarks-tap.xml -define convert_to_junit - @true -endef -endif - -ifdef ENABLE_CONVERT_V8_JSON_TO_XML - TAP_V8_JSON := $(PWD)/v8-tap.json - TAP_V8_INTL_JSON := $(PWD)/v8-intl-tap.json - TAP_V8_BENCHMARKS_JSON := $(PWD)/v8-benchmarks-tap.json - - # By default, the V8's JSON test output only includes the tests which have - # failed. We use --slow-tests-cutoff to ensure that all tests are present - # in the output, including those which pass. - TAP_V8 := --json-test-results $(TAP_V8_JSON) --slow-tests-cutoff 1000000 - TAP_V8_INTL := --json-test-results $(TAP_V8_INTL_JSON) --slow-tests-cutoff 1000000 - TAP_V8_BENCHMARKS := --json-test-results $(TAP_V8_BENCHMARKS_JSON) --slow-tests-cutoff 1000000 - -define convert_to_junit - export PATH="$(NO_BIN_OVERRIDE_PATH)" && \ - $(PYTHON) tools/v8-json-to-junit.py < $(1) > $(1:.json=.xml) -endef -endif - -V8_TEST_OPTIONS = $(V8_EXTRA_TEST_OPTIONS) -ifdef DISABLE_V8_I18N - V8_BUILD_OPTIONS += i18nsupport=off -endif -# V8 build and test toolchains are not currently compatible with Python 3. -# config.mk may have prepended a symlink for `python` to PATH which we need -# to undo before calling V8's tools. -OVERRIDE_BIN_DIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))out/tools/bin -NO_BIN_OVERRIDE_PATH=$(subst $() $(),:,$(filter-out $(OVERRIDE_BIN_DIR),$(subst :, ,$(PATH)))) - -ifeq ($(OSTYPE), darwin) - GCOV = xcrun llvm-cov gcov -endif - -BUILDTYPE_LOWER := $(shell echo $(BUILDTYPE) | tr '[:upper:]' '[:lower:]') - -# Determine EXEEXT -EXEEXT := $(shell $(PYTHON) -c \ - "import sys; print('.exe' if sys.platform == 'win32' else '')") - -NODE_EXE = node$(EXEEXT) -# Use $(PWD) so we can cd to anywhere before calling this -NODE ?= "$(PWD)/$(NODE_EXE)" -NODE_G_EXE = node_g$(EXEEXT) -NPM ?= ./deps/npm/bin/npm-cli.js - -# Flags for packaging. -BUILD_DOWNLOAD_FLAGS ?= --download=all -BUILD_INTL_FLAGS ?= --with-intl=full-icu -BUILD_RELEASE_FLAGS ?= $(BUILD_DOWNLOAD_FLAGS) $(BUILD_INTL_FLAGS) - -# Default to quiet/pretty builds. -# To do verbose builds, run `make V=1` or set the V environment variable. -V ?= 0 - -# Use -e to double check in case it's a broken link -available-node = \ - if [ -x "$(NODE)" ] && [ -e "$(NODE)" ]; then \ - "$(NODE)" $(1); \ - elif [ -x `command -v node` ] && [ -e `command -v node` ] && [ `command -v node` ]; then \ - `command -v node` $(1); \ - else \ - echo "No available node, cannot run \"node $(1)\""; \ - exit 1; \ - fi; - -.PHONY: all -# BUILDTYPE=Debug builds both release and debug builds. If you want to compile -# just the debug build, run `make -C out BUILDTYPE=Debug` instead. -ifeq ($(BUILDTYPE),Release) -all: $(NODE_EXE) ## Default target, builds node in out/Release/node. -else -all: $(NODE_EXE) $(NODE_G_EXE) -endif - -.PHONY: help -# To add a target to the help, add a double comment (##) on the target line. -help: ## Print help for targets with comments. - @printf "For more targets and info see the comments in the Makefile.\n\n" - @grep -E '^[[:alnum:]._-]+:.*?## .*$$' Makefile | sort | \ - awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' - -# The .PHONY is needed to ensure that we recursively use the out/Makefile -# to check for changes. -.PHONY: $(NODE_EXE) $(NODE_G_EXE) - -# The -r/-L check stops it recreating the link if it is already in place, -# otherwise $(NODE_EXE) being a .PHONY target means it is always re-run. -# Without the check there is a race condition between the link being deleted -# and recreated which can break the addons build when running test-ci -# See comments on the build-addons target for some more info -ifeq ($(BUILD_WITH), make) -$(NODE_EXE): build_type:=Release -$(NODE_G_EXE): build_type:=Debug -$(NODE_EXE) $(NODE_G_EXE): config.gypi out/Makefile - $(MAKE) -C out BUILDTYPE=${build_type} V=$(V) - if [ ! -r $@ ] || [ ! -L $@ ]; then \ - ln -fs out/${build_type}/$(NODE_EXE) $@; fi -else -ifeq ($(BUILD_WITH), ninja) -NINJA ?= ninja -ifeq ($(V),1) - NINJA_ARGS := $(NINJA_ARGS) -v -endif -ifdef JOBS - NINJA_ARGS := $(NINJA_ARGS) -j$(JOBS) -else - NINJA_ARGS := $(NINJA_ARGS) $(filter -j%,$(MAKEFLAGS)) -endif -$(NODE_EXE): config.gypi out/Release/build.ninja - $(NINJA) -C out/Release $(NINJA_ARGS) - if [ ! -r $@ ] || [ ! -L $@ ]; then ln -fs out/Release/$(NODE_EXE) $@; fi - -$(NODE_G_EXE): config.gypi out/Debug/build.ninja - $(NINJA) -C out/Debug $(NINJA_ARGS) - if [ ! -r $@ ] || [ ! -L $@ ]; then ln -fs out/Debug/$(NODE_EXE) $@; fi -else -$(NODE_EXE) $(NODE_G_EXE): - $(warning This Makefile currently only supports building with 'make' or 'ninja') -endif -endif - - -ifeq ($(BUILDTYPE),Debug) -CONFIG_FLAGS += --debug -endif - -.PHONY: with-code-cache -.PHONY: test-code-cache -with-code-cache test-code-cache: - $(warning '$@' target is a noop) - -out/Makefile: config.gypi common.gypi node.gyp \ - deps/uv/uv.gyp deps/llhttp/llhttp.gyp deps/zlib/zlib.gyp \ - deps/simdutf/simdutf.gyp deps/ada/ada.gyp \ - tools/v8_gypfiles/toolchain.gypi tools/v8_gypfiles/features.gypi \ - tools/v8_gypfiles/inspector.gypi tools/v8_gypfiles/v8.gyp - $(PYTHON) tools/gyp_node.py -f make - -# node_version.h is listed because the N-API version is taken from there -# and included in config.gypi -config.gypi: configure configure.py src/node_version.h - @if [ -x config.status ]; then \ - export PATH="$(NO_BIN_OVERRIDE_PATH)" && ./config.status; \ - else \ - echo Missing or stale $@, please run ./$<; \ - exit 1; \ - fi - -.PHONY: install -install: all ## Installs node into $PREFIX (default=/usr/local). - $(PYTHON) tools/install.py $@ --dest-dir '$(DESTDIR)' --prefix '$(PREFIX)' - -.PHONY: uninstall -uninstall: ## Uninstalls node from $PREFIX (default=/usr/local). - $(PYTHON) tools/install.py $@ --dest-dir '$(DESTDIR)' --prefix '$(PREFIX)' - -.PHONY: clean -.NOTPARALLEL: clean -clean: ## Remove build artifacts. - $(RM) -r out/Makefile $(NODE_EXE) $(NODE_G_EXE) out/$(BUILDTYPE)/$(NODE_EXE) \ - out/$(BUILDTYPE)/node.exp - @if [ -d out ]; then $(FIND) out/ -name '*.o' -o -name '*.a' -o -name '*.d' | xargs $(RM) -r; fi - $(RM) -r node_modules - @if [ -d deps/icu ]; then echo deleting deps/icu; $(RM) -r deps/icu; fi - $(RM) test.tap - $(MAKE) testclean - $(MAKE) test-addons-clean - $(MAKE) bench-addons-clean - -.PHONY: testclean -.NOTPARALLEL: testclean -testclean: -# Next one is legacy remove this at some point - $(RM) -r test/tmp* - $(RM) -r test/.tmp* - -.PHONY: distclean -.NOTPARALLEL: distclean -distclean: - $(RM) -r out - $(RM) config.gypi icu_config.gypi - $(RM) config.mk - $(RM) -r $(NODE_EXE) $(NODE_G_EXE) - $(RM) -r node_modules - $(RM) -r deps/icu - $(RM) -r deps/icu4c*.tgz deps/icu4c*.zip deps/icu-tmp - $(RM) $(BINARYTAR).* $(TARBALL).* - -.PHONY: check -check: test - -.PHONY: coverage-clean -.NOTPARALLEL: coverage-clean -# Remove files generated by running coverage, put the non-instrumented lib back -# in place -coverage-clean: - $(RM) -r node_modules - $(RM) -r gcovr - $(RM) -r coverage/tmp - $(FIND) out/$(BUILDTYPE)/obj.target \( -name "*.gcda" -o -name "*.gcno" \) \ - -type f -exec $(RM) {} \; - -.PHONY: coverage -# Build and test with code coverage reporting. HTML coverage reports will be -# created under coverage/. For C++ coverage reporting, this needs to be run -# in conjunction with configure --coverage. -# Related CI job: node-test-commit-linux-coverage-daily -coverage: coverage-test ## Run the tests and generate a coverage report. - -.PHONY: coverage-build -coverage-build: all - -$(MAKE) coverage-build-js - if [ ! -d gcovr ]; then $(PYTHON) -m pip install -t gcovr gcovr==4.2; fi - $(MAKE) - -.PHONY: coverage-build-js -coverage-build-js: - mkdir -p node_modules - if [ ! -d node_modules/c8 ]; then \ - $(NODE) ./deps/npm install c8 --no-save --no-package-lock;\ - fi - -.PHONY: coverage-test -coverage-test: coverage-build - $(FIND) out/$(BUILDTYPE)/obj.target -name "*.gcda" -type f -exec $(RM) {} \; - -NODE_V8_COVERAGE=coverage/tmp \ - TEST_CI_ARGS="$(TEST_CI_ARGS) --type=coverage" $(MAKE) $(COVTESTS) - $(MAKE) coverage-report-js - -(cd out && PYTHONPATH=../gcovr $(PYTHON) -m gcovr \ - --gcov-exclude='.*\b(deps|usr|out|cctest|embedding)\b' -v \ - -r ../src/ --object-directory Release/obj.target \ - --html --html-details -o ../coverage/cxxcoverage.html \ - --gcov-executable="$(GCOV)") - @printf "Javascript coverage %%: " - @grep -B1 Lines coverage/index.html | head -n1 \ - | sed 's/<[^>]*>//g'| sed 's/ //g' - @printf "C++ coverage %%: " - @grep -A3 Lines coverage/cxxcoverage.html | grep style \ - | sed 's/<[^>]*>//g'| sed 's/ //g' - -.PHONY: coverage-report-js -coverage-report-js: - -$(MAKE) coverage-build-js - $(NODE) ./node_modules/.bin/c8 report - -.PHONY: cctest -# Runs the C++ tests using the built `cctest` executable. -cctest: all - @out/$(BUILDTYPE)/$@ --gtest_filter=$(GTEST_FILTER) - $(NODE) ./test/embedding/test-embedding.js - -.PHONY: list-gtests -list-gtests: -ifeq (,$(wildcard out/$(BUILDTYPE)/cctest)) - $(error Please run 'make cctest' first) -endif - @out/$(BUILDTYPE)/cctest --gtest_list_tests - -.PHONY: v8 -# Related CI job: node-test-commit-v8-linux -# Rebuilds deps/v8 as a git tree, pulls its third-party dependencies, and -# builds it. -v8: - export PATH="$(NO_BIN_OVERRIDE_PATH)" && \ - tools/make-v8.sh $(V8_ARCH).$(BUILDTYPE_LOWER) $(V8_BUILD_OPTIONS) - -.PHONY: jstest -jstest: build-addons build-js-native-api-tests build-node-api-tests ## Runs addon tests and JS tests - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) \ - $(TEST_CI_ARGS) \ - --skip-tests=$(CI_SKIP_TESTS) \ - $(JS_SUITES) \ - $(NATIVE_SUITES) - -.PHONY: tooltest -tooltest: - @$(PYTHON) -m unittest discover -s ./test/tools - -.PHONY: coverage-run-js -coverage-run-js: - $(RM) -r coverage/tmp - -NODE_V8_COVERAGE=coverage/tmp CI_SKIP_TESTS=$(COV_SKIP_TESTS) \ - TEST_CI_ARGS="$(TEST_CI_ARGS) --type=coverage" $(MAKE) jstest - $(MAKE) coverage-report-js - -.PHONY: test -# This does not run tests of third-party libraries inside deps. -test: all ## Runs default tests, linters, and builds docs. - $(MAKE) -s tooltest - $(MAKE) -s test-doc - $(MAKE) -s build-addons - $(MAKE) -s build-js-native-api-tests - $(MAKE) -s build-node-api-tests - $(MAKE) -s cctest - $(MAKE) -s jstest - -.PHONY: test-only -test-only: all ## For a quick test, does not run linter or build docs. - $(MAKE) build-addons - $(MAKE) build-js-native-api-tests - $(MAKE) build-node-api-tests - $(MAKE) cctest - $(MAKE) jstest - $(MAKE) tooltest - -# Used by `make coverage-test` -.PHONY: test-cov -test-cov: all - $(MAKE) build-addons - $(MAKE) build-js-native-api-tests - $(MAKE) build-node-api-tests - $(MAKE) cctest - CI_SKIP_TESTS=$(COV_SKIP_TESTS) $(MAKE) jstest - -.PHONY: test-valgrind -test-valgrind: all - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) --valgrind sequential parallel message - -.PHONY: test-check-deopts -test-check-deopts: all - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) --check-deopts parallel sequential - -DOCBUILDSTAMP_PREREQS = tools/doc/addon-verify.mjs doc/api/addons.md - -ifeq ($(OSTYPE),aix) -DOCBUILDSTAMP_PREREQS := $(DOCBUILDSTAMP_PREREQS) out/$(BUILDTYPE)/node.exp -endif -ifeq ($(OSTYPE),os400) -DOCBUILDSTAMP_PREREQS := $(DOCBUILDSTAMP_PREREQS) out/$(BUILDTYPE)/node.exp -endif - -node_use_openssl = $(call available-node,"-p" \ - "process.versions.openssl != undefined") -test/addons/.docbuildstamp: $(DOCBUILDSTAMP_PREREQS) tools/doc/node_modules - @if [ "$(shell $(node_use_openssl))" != "true" ]; then \ - echo "Skipping .docbuildstamp (no crypto)"; \ - else \ - $(RM) -r test/addons/??_*/; \ - [ -x $(NODE) ] && $(NODE) $< || node $< ; \ - [ $$? -eq 0 ] && touch $@; \ - fi - -# All files that will be included in headers tarball should be listed as deps -# for generating headers. The list is manually synchronized with install.py. -ADDONS_HEADERS_PREREQS := tools/install.py \ - config.gypi common.gypi \ - $(wildcard deps/openssl/config/*.h) \ - $(wildcard deps/openssl/openssl/include/openssl/*.h) \ - $(wildcard deps/uv/include/*.h) \ - $(wildcard deps/uv/include/*/*.h) \ - $(wildcard deps/v8/include/*.h) \ - $(wildcard deps/v8/include/*/*.h) \ - deps/zlib/zconf.h deps/zlib/zlib.h \ - src/node.h src/node_api.h src/js_native_api.h src/js_native_api_types.h \ - src/node_api_types.h src/node_buffer.h src/node_object_wrap.h \ - src/node_version.h - -ADDONS_HEADERS_DIR = out/$(BUILDTYPE)/addons_headers - -# Generate node headers which will be used for building addons. -test/addons/.headersbuildstamp: $(ADDONS_HEADERS_PREREQS) - $(PYTHON) tools/install.py install --headers-only --dest-dir '$(ADDONS_HEADERS_DIR)' --prefix '/' - @touch $@ - -ADDONS_BINDING_GYPS := \ - $(filter-out test/addons/??_*/binding.gyp, \ - $(wildcard test/addons/*/binding.gyp)) - -ADDONS_BINDING_SOURCES := \ - $(filter-out test/addons/??_*/*.cc, $(wildcard test/addons/*/*.cc)) \ - $(filter-out test/addons/??_*/*.h, $(wildcard test/addons/*/*.h)) - -ADDONS_PREREQS := test/addons/.headersbuildstamp \ - deps/npm/node_modules/node-gyp/package.json tools/build_addons.py - -define run_build_addons -env $(PYTHON) "$$PWD/tools/build_addons.py" --loglevel=$(LOGLEVEL) --headers-dir "$(ADDONS_HEADERS_DIR)" $1 -touch $2 -endef - -# Implicitly depends on $(NODE_EXE), see the build-addons rule for rationale. -# Depends on node-gyp package.json so that build-addons is (re)executed when -# node-gyp is updated as part of an npm update. -test/addons/.buildstamp: $(ADDONS_PREREQS) \ - $(ADDONS_BINDING_GYPS) $(ADDONS_BINDING_SOURCES) \ - test/addons/.docbuildstamp - @$(call run_build_addons,"$$PWD/test/addons",$@) - -.PHONY: build-addons -# .buildstamp needs $(NODE_EXE) but cannot depend on it -# directly because it calls make recursively. The parent make cannot know -# if the subprocess touched anything so it pessimistically assumes that -# .buildstamp is out of date and need a rebuild. -# Just goes to show that recursive make really is harmful... -# TODO(bnoordhuis) Force rebuild after gyp update. -build-addons: | $(NODE_EXE) test/addons/.buildstamp - -JS_NATIVE_API_BINDING_GYPS := \ - $(filter-out test/js-native-api/??_*/binding.gyp, \ - $(wildcard test/js-native-api/*/binding.gyp)) - -JS_NATIVE_API_BINDING_SOURCES := \ - $(filter-out test/js-native-api/??_*/*.c, $(wildcard test/js-native-api/*/*.c)) \ - $(filter-out test/js-native-api/??_*/*.cc, $(wildcard test/js-native-api/*/*.cc)) \ - $(filter-out test/js-native-api/??_*/*.h, $(wildcard test/js-native-api/*/*.h)) - -# Implicitly depends on $(NODE_EXE), see the build-js-native-api-tests rule for rationale. -test/js-native-api/.buildstamp: $(ADDONS_PREREQS) \ - $(JS_NATIVE_API_BINDING_GYPS) $(JS_NATIVE_API_BINDING_SOURCES) \ - src/js_native_api_v8.h src/js_native_api_v8_internals.h - @$(call run_build_addons,"$$PWD/test/js-native-api",$@) - -.PHONY: build-js-native-api-tests -# .buildstamp needs $(NODE_EXE) but cannot depend on it -# directly because it calls make recursively. The parent make cannot know -# if the subprocess touched anything so it pessimistically assumes that -# .buildstamp is out of date and need a rebuild. -# Just goes to show that recursive make really is harmful... -# TODO(bnoordhuis) Force rebuild after gyp or node-gyp update. -build-js-native-api-tests: | $(NODE_EXE) test/js-native-api/.buildstamp - -NODE_API_BINDING_GYPS := \ - $(filter-out test/node-api/??_*/binding.gyp, \ - $(wildcard test/node-api/*/binding.gyp)) - -NODE_API_BINDING_SOURCES := \ - $(filter-out test/node-api/??_*/*.c, $(wildcard test/node-api/*/*.c)) \ - $(filter-out test/node-api/??_*/*.cc, $(wildcard test/node-api/*/*.cc)) \ - $(filter-out test/node-api/??_*/*.h, $(wildcard test/node-api/*/*.h)) - -# Implicitly depends on $(NODE_EXE), see the build-node-api-tests rule for rationale. -test/node-api/.buildstamp: $(ADDONS_PREREQS) \ - $(NODE_API_BINDING_GYPS) $(NODE_API_BINDING_SOURCES) \ - src/js_native_api_v8.h src/js_native_api_v8_internals.h - @$(call run_build_addons,"$$PWD/test/node-api",$@) - -.PHONY: build-node-api-tests -# .buildstamp needs $(NODE_EXE) but cannot depend on it -# directly because it calls make recursively. The parent make cannot know -# if the subprocess touched anything so it pessimistically assumes that -# .buildstamp is out of date and need a rebuild. -# Just goes to show that recursive make really is harmful... -# TODO(bnoordhuis) Force rebuild after gyp or node-gyp update. -build-node-api-tests: | $(NODE_EXE) test/node-api/.buildstamp - -BENCHMARK_NAPI_BINDING_GYPS := $(wildcard benchmark/napi/*/binding.gyp) - -BENCHMARK_NAPI_BINDING_SOURCES := \ - $(wildcard benchmark/napi/*/*.c) \ - $(wildcard benchmark/napi/*/*.cc) \ - $(wildcard benchmark/napi/*/*.h) - -benchmark/napi/.buildstamp: $(ADDONS_PREREQS) \ - $(BENCHMARK_NAPI_BINDING_GYPS) $(BENCHMARK_NAPI_BINDING_SOURCES) - @$(call run_build_addons,"$$PWD/benchmark/napi",$@) - -.PHONY: clear-stalled -clear-stalled: - $(info Clean up any leftover processes but don't error if found.) - ps awwx | grep Release/node | grep -v grep | cat - @PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \ - if [ "$${PS_OUT}" ]; then \ - echo $${PS_OUT} | xargs kill -9; \ - fi - -.PHONY: test-build -test-build: | all build-addons build-js-native-api-tests build-node-api-tests - -.PHONY: test-build-js-native-api -test-build-js-native-api: all build-js-native-api-tests - -.PHONY: test-build-node-api -test-build-node-api: all build-node-api-tests - -.PHONY: test-all -test-all: test-build ## Run default tests with both Debug and Release builds. - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=debug,release - -.PHONY: test-all-valgrind -test-all-valgrind: test-build - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=debug,release --valgrind - -.PHONY: test-all-suites -test-all-suites: | clear-stalled test-build bench-addons-build doc-only ## Run all test suites. - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) test/* - -JS_SUITES ?= default -NATIVE_SUITES ?= addons js-native-api node-api -# CI_* variables should be kept synchronized with the ones in vcbuild.bat -CI_NATIVE_SUITES ?= $(NATIVE_SUITES) benchmark -CI_JS_SUITES ?= $(JS_SUITES) pummel -ifeq ($(node_use_openssl), false) - CI_DOC := doctool -else - CI_DOC = -endif - -.PHONY: test-ci-native -# Build and test addons without building anything else -# Related CI job: node-test-commit-arm-fanned -test-ci-native: LOGLEVEL := info -test-ci-native: | benchmark/napi/.buildstamp test/addons/.buildstamp test/js-native-api/.buildstamp test/node-api/.buildstamp - $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ - --mode=$(BUILDTYPE_LOWER) --flaky-tests=$(FLAKY_TESTS) \ - $(TEST_CI_ARGS) $(CI_NATIVE_SUITES) - -.PHONY: test-ci-js -# This target should not use a native compiler at all -# Related CI job: node-test-commit-arm-fanned -test-ci-js: | clear-stalled - $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ - --mode=$(BUILDTYPE_LOWER) --flaky-tests=$(FLAKY_TESTS) \ - $(TEST_CI_ARGS) $(CI_JS_SUITES) - $(info Clean up any leftover processes, error if found.) - ps awwx | grep Release/node | grep -v grep | cat - @PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \ - if [ "$${PS_OUT}" ]; then \ - echo $${PS_OUT} | xargs kill -9; exit 1; \ - fi - -.PHONY: test-ci -# Related CI jobs: most CI tests, excluding node-test-commit-arm-fanned -test-ci: LOGLEVEL := info -test-ci: | clear-stalled bench-addons-build build-addons build-js-native-api-tests build-node-api-tests doc-only - out/Release/cctest --gtest_output=xml:out/junit/cctest.xml - $(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \ - --mode=$(BUILDTYPE_LOWER) --flaky-tests=$(FLAKY_TESTS) \ - $(TEST_CI_ARGS) $(CI_JS_SUITES) $(CI_NATIVE_SUITES) $(CI_DOC) - $(NODE) ./test/embedding/test-embedding.js - $(info Clean up any leftover processes, error if found.) - ps awwx | grep Release/node | grep -v grep | cat - @PS_OUT=`ps awwx | grep Release/node | grep -v grep | awk '{print $$1}'`; \ - if [ "$${PS_OUT}" ]; then \ - echo $${PS_OUT} | xargs kill -9; exit 1; \ - fi - -.PHONY: build-ci -# Prepare the build for running the tests. -# Related CI jobs: most CI tests, excluding node-test-commit-arm-fanned -build-ci: - $(PYTHON) ./configure --verbose $(CONFIG_FLAGS) - $(MAKE) - -.PHONY: run-ci -# Run by CI tests, exceptions: -# - node-test-commit-arm-fanned (Raspberry Pis), where the binaries are -# cross-compiled, then transferred elsewhere to run different subsets -# of tests. See `test-ci-native` and `test-ci-js`. -# - node-test-commit-linux-coverage: where the build and the tests need -# to be instrumented, see `coverage`. -# -# Using -j1 as the sub target in `test-ci` already have internal parallelism. -# Refs: https://github.com/nodejs/node/pull/23733 -run-ci: build-ci - $(MAKE) test-ci -j1 - -.PHONY: test-release -.PHONY: test-debug -test-debug: BUILDTYPE_LOWER=debug -test-release test-debug: test-build - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) - -.PHONY: test-wpt -test-wpt: all - $(PYTHON) tools/test.py $(PARALLEL_ARGS) wpt - -.PHONY: test-wpt-report -test-wpt-report: - $(RM) -r out/wpt - mkdir -p out/wpt - -WPT_REPORT=1 $(PYTHON) tools/test.py --shell $(NODE) $(PARALLEL_ARGS) wpt - $(NODE) "$$PWD/tools/merge-wpt-reports.mjs" - -.PHONY: test-internet -test-internet: all - $(PYTHON) tools/test.py $(PARALLEL_ARGS) internet - -.PHONY: test-tick-processor -test-tick-processor: all - $(PYTHON) tools/test.py $(PARALLEL_ARGS) tick-processor - -.PHONY: test-hash-seed -# Verifies the hash seed used by V8 for hashing is random. -test-hash-seed: all - $(NODE) test/pummel/test-hash-seed.js - -.PHONY: test-doc -test-doc: doc-only lint-md ## Builds, lints, and verifies the docs. - @if [ "$(shell $(node_use_openssl))" != "true" ]; then \ - echo "Skipping test-doc (no crypto)"; \ - else \ - $(PYTHON) tools/test.py $(PARALLEL_ARGS) doctool; \ - fi - -.PHONY: test-doc-ci -test-doc-ci: doc-only - $(PYTHON) tools/test.py --shell $(NODE) $(TEST_CI_ARGS) $(PARALLEL_ARGS) doctool - -.PHONY: test-known-issues -test-known-issues: all - $(PYTHON) tools/test.py $(PARALLEL_ARGS) known_issues - -# Related CI job: node-test-npm -.PHONY: test-npm -test-npm: $(NODE_EXE) ## Run the npm test suite on deps/npm. - $(NODE) tools/test-npm-package --install --logfile=test-npm.tap deps/npm test - -.PHONY: test-npm-publish -test-npm-publish: $(NODE_EXE) - npm_package_config_publishtest=true $(NODE) deps/npm/test/run.js - -.PHONY: test-js-native-api -test-js-native-api: test-build-js-native-api - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) js-native-api - -.PHONY: test-js-native-api-clean -.NOTPARALLEL: test-js-native-api-clean -test-js-native-api-clean: - $(RM) -r test/js-native-api/*/build - $(RM) test/js-native-api/.buildstamp - -.PHONY: test-node-api -test-node-api: test-build-node-api - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) node-api - -.PHONY: test-node-api-clean -.NOTPARALLEL: test-node-api-clean -test-node-api-clean: - $(RM) -r test/node-api/*/build - $(RM) test/node-api/.buildstamp - -.PHONY: test-addons -test-addons: test-build test-js-native-api test-node-api - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) addons - -.PHONY: test-addons-clean -.NOTPARALLEL: test-addons-clean -test-addons-clean: - $(RM) -r "$(ADDONS_HEADERS_DIR)" - $(RM) -r test/addons/??_*/ - $(RM) -r test/addons/*/build - $(RM) test/addons/.buildstamp test/addons/.docbuildstamp test/addons/.headersbuildstamp - $(MAKE) test-js-native-api-clean - $(MAKE) test-node-api-clean - -.PHONY: test-with-async-hooks -test-with-async-hooks: - $(MAKE) build-addons - $(MAKE) build-js-native-api-tests - $(MAKE) build-node-api-tests - $(MAKE) cctest - NODE_TEST_WITH_ASYNC_HOOKS=1 $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) \ - $(JS_SUITES) \ - $(NATIVE_SUITES) - - -.PHONY: test-v8 -.PHONY: test-v8-all -.PHONY: test-v8-benchmarks -.PHONY: test-v8-intl -.PHONY: test-v8-updates -ifneq ("","$(wildcard deps/v8/tools/run-tests.py)") -# Related CI job: node-test-commit-v8-linux -test-v8: v8 ## Runs the V8 test suite on deps/v8. - export PATH="$(NO_BIN_OVERRIDE_PATH)" && \ - $(PYTHON) deps/v8/tools/run-tests.py --gn --arch=$(V8_ARCH) $(V8_TEST_OPTIONS) \ - mjsunit cctest debugger inspector message preparser \ - $(TAP_V8) - $(call convert_to_junit,$(TAP_V8_JSON)) - $(info Testing hash seed) - $(MAKE) test-hash-seed - -test-v8-intl: v8 - export PATH="$(NO_BIN_OVERRIDE_PATH)" && \ - $(PYTHON) deps/v8/tools/run-tests.py --gn --arch=$(V8_ARCH) \ - intl \ - $(TAP_V8_INTL) - $(call convert_to_junit,$(TAP_V8_INTL_JSON)) - -test-v8-benchmarks: v8 - export PATH="$(NO_BIN_OVERRIDE_PATH)" && \ - $(PYTHON) deps/v8/tools/run-tests.py --gn --arch=$(V8_ARCH) \ - benchmarks \ - $(TAP_V8_BENCHMARKS) - $(call convert_to_junit,$(TAP_V8_BENCHMARKS_JSON)) - -test-v8-updates: - $(PYTHON) tools/test.py $(PARALLEL_ARGS) --mode=$(BUILDTYPE_LOWER) v8-updates - -test-v8-all: test-v8 test-v8-intl test-v8-benchmarks test-v8-updates -# runs all v8 tests -else -test-v8 test-v8-intl test-v8-benchmarks test-v8-all: - $(warning Testing V8 is not available through the source tarball.) - $(warning Use the git repo instead: $$ git clone https://github.com/nodejs/node.git) -endif - -apidoc_dirs = out/doc out/doc/api out/doc/api/assets -apidoc_sources = $(wildcard doc/api/*.md) -apidocs_html = $(addprefix out/,$(apidoc_sources:.md=.html)) -apidocs_json = $(addprefix out/,$(apidoc_sources:.md=.json)) - -apiassets = $(subst api_assets,api/assets,$(addprefix out/,$(wildcard doc/api_assets/*))) - -tools/doc/node_modules: tools/doc/package.json - @if [ "$(shell $(node_use_openssl))" != "true" ]; then \ - echo "Skipping tools/doc/node_modules (no crypto)"; \ - else \ - cd tools/doc && $(call available-node,$(run-npm-ci)) \ - fi - -.PHONY: doc-only -doc-only: tools/doc/node_modules \ - $(apidoc_dirs) $(apiassets) ## Builds the docs with the local or the global Node.js binary. - @if [ "$(shell $(node_use_openssl))" != "true" ]; then \ - echo "Skipping doc-only (no crypto)"; \ - else \ - $(MAKE) out/doc/api/all.html out/doc/api/all.json out/doc/api/stability; \ - fi - -.PHONY: doc -doc: $(NODE_EXE) doc-only - -out/doc: - mkdir -p $@ - -# If it's a source tarball, doc/api already contains the generated docs. -# Just copy everything under doc/api over. -out/doc/api: doc/api - mkdir -p $@ - cp -r doc/api out/doc - -# If it's a source tarball, assets are already in doc/api/assets -out/doc/api/assets: - mkdir -p $@ - if [ -d doc/api/assets ]; then cp -r doc/api/assets out/doc/api; fi; - -# If it's not a source tarball, we need to copy assets from doc/api_assets -out/doc/api/assets/%: doc/api_assets/% | out/doc/api/assets - @cp $< $@ ; $(RM) out/doc/api/assets/README.md - - -run-npm-ci = $(PWD)/$(NPM) ci - -LINK_DATA = out/doc/apilinks.json -VERSIONS_DATA = out/previous-doc-versions.json -gen-api = tools/doc/generate.mjs --node-version=$(FULLVERSION) \ - --apilinks=$(LINK_DATA) $< --output-directory=out/doc/api \ - --versions-file=$(VERSIONS_DATA) -gen-apilink = tools/doc/apilinks.mjs $(LINK_DATA) $(wildcard lib/*.js) - -$(LINK_DATA): $(wildcard lib/*.js) tools/doc/apilinks.mjs | out/doc - $(call available-node, $(gen-apilink)) - -# Regenerate previous versions data if the current version changes -$(VERSIONS_DATA): CHANGELOG.md src/node_version.h tools/doc/versions.mjs - $(call available-node, tools/doc/versions.mjs $@) - -node_use_icu = $(call available-node,"-p" "typeof Intl === 'object'") - -out/doc/api/%.json out/doc/api/%.html: doc/api/%.md tools/doc/generate.mjs \ - tools/doc/markdown.mjs tools/doc/html.mjs tools/doc/json.mjs \ - tools/doc/apilinks.mjs $(VERSIONS_DATA) | $(LINK_DATA) out/doc/api - @if [ "$(shell $(node_use_icu))" != "true" ]; then \ - echo "Skipping documentation generation (no ICU)"; \ - else \ - $(call available-node, $(gen-api)) \ - fi - -out/doc/api/all.html: $(apidocs_html) tools/doc/allhtml.mjs \ - tools/doc/apilinks.mjs | out/doc/api - @if [ "$(shell $(node_use_icu))" != "true" ]; then \ - echo "Skipping HTML single-page doc generation (no ICU)"; \ - else \ - $(call available-node, tools/doc/allhtml.mjs) \ - fi - -out/doc/api/all.json: $(apidocs_json) tools/doc/alljson.mjs | out/doc/api - @if [ "$(shell $(node_use_icu))" != "true" ]; then \ - echo "Skipping JSON single-file generation (no ICU)"; \ - else \ - $(call available-node, tools/doc/alljson.mjs) \ - fi - -.PHONY: out/doc/api/stability -out/doc/api/stability: out/doc/api/all.json tools/doc/stability.mjs | out/doc/api - @if [ "$(shell $(node_use_icu))" != "true" ]; then \ - echo "Skipping stability indicator generation (no ICU)"; \ - else \ - $(call available-node, tools/doc/stability.mjs) \ - fi - -.PHONY: docopen -docopen: out/doc/api/all.html - @$(PYTHON) -mwebbrowser file://$(abspath $<) - -.PHONY: docserve -docserve: $(apidocs_html) $(apiassets) - @$(PYTHON) -m http.server 8000 --bind 127.0.0.1 --directory out/doc/api - -.PHONY: docclean -.NOTPARALLEL: docclean -docclean: - $(RM) -r out/doc - $(RM) "$(VERSIONS_DATA)" - -RAWVER=$(shell $(PYTHON) tools/getnodeversion.py) -VERSION=v$(RAWVER) -CHANGELOG=doc/changelogs/CHANGELOG_V$(firstword $(subst ., ,$(RAWVER))).md - -# For nightly builds, you must set DISTTYPE to "nightly", "next-nightly" or -# "custom". For the nightly and next-nightly case, you need to set DATESTRING -# and COMMIT in order to properly name the build. -# For the rc case you need to set CUSTOMTAG to an appropriate CUSTOMTAG number - -ifndef DISTTYPE -DISTTYPE=release -endif -ifeq ($(DISTTYPE),release) -FULLVERSION=$(VERSION) -else # ifeq ($(DISTTYPE),release) -ifeq ($(DISTTYPE),custom) -ifndef CUSTOMTAG -$(error CUSTOMTAG is not set for DISTTYPE=custom) -endif # ifndef CUSTOMTAG -TAG=$(CUSTOMTAG) -else # ifeq ($(DISTTYPE),custom) -ifndef DATESTRING -$(error DATESTRING is not set for nightly) -endif # ifndef DATESTRING -ifndef COMMIT -$(error COMMIT is not set for nightly) -endif # ifndef COMMIT -ifneq ($(DISTTYPE),nightly) -ifneq ($(DISTTYPE),next-nightly) -$(error DISTTYPE is not release, custom, nightly or next-nightly) -endif # ifneq ($(DISTTYPE),next-nightly) -endif # ifneq ($(DISTTYPE),nightly) -TAG=$(DISTTYPE)$(DATESTRING)$(COMMIT) -endif # ifeq ($(DISTTYPE),custom) -FULLVERSION=$(VERSION)-$(TAG) -endif # ifeq ($(DISTTYPE),release) - -DISTTYPEDIR ?= $(DISTTYPE) -RELEASE=$(shell sed -ne 's/\#define NODE_VERSION_IS_RELEASE \([01]\)/\1/p' src/node_version.h) -PLATFORM=$(shell uname | tr '[:upper:]' '[:lower:]') -ifeq ($(findstring os/390,$PLATFORM),os/390) -PLATFORM ?= os390 -endif -NPMVERSION=v$(shell cat deps/npm/package.json | grep '^ "version"' | sed 's/^[^:]*: "\([^"]*\)",.*/\1/') - -UNAME_M=$(shell uname -m) -ifeq ($(findstring x86_64,$(UNAME_M)),x86_64) -DESTCPU ?= x64 -else -ifeq ($(findstring amd64,$(UNAME_M)),amd64) -DESTCPU ?= x64 -else -ifeq ($(findstring ppc64,$(UNAME_M)),ppc64) -DESTCPU ?= ppc64 -else -ifeq ($(findstring ppc,$(UNAME_M)),ppc) -DESTCPU ?= ppc -else -ifeq ($(findstring s390x,$(UNAME_M)),s390x) -DESTCPU ?= s390x -else -ifeq ($(findstring s390,$(UNAME_M)),s390) -DESTCPU ?= s390 -else -ifeq ($(findstring OS/390,$(shell uname -s)),OS/390) -DESTCPU ?= s390x -else -ifeq ($(findstring arm64,$(UNAME_M)),arm64) -DESTCPU ?= arm64 -else -ifeq ($(findstring arm,$(UNAME_M)),arm) -DESTCPU ?= arm -else -ifeq ($(findstring aarch64,$(UNAME_M)),aarch64) -DESTCPU ?= arm64 -else -ifeq ($(findstring powerpc,$(shell uname -p)),powerpc) -DESTCPU ?= ppc64 -else -ifeq ($(findstring riscv64,$(UNAME_M)),riscv64) -DESTCPU ?= riscv64 -else -DESTCPU ?= x86 -endif -endif -endif -endif -endif -endif -endif -endif -endif -endif -endif -endif -ifeq ($(DESTCPU),x64) -ARCH=x64 -else -ifeq ($(DESTCPU),arm) -ARCH=arm -else -ifeq ($(DESTCPU),arm64) -ARCH=arm64 -else -ifeq ($(DESTCPU),ppc64) -ARCH=ppc64 -else -ifeq ($(DESTCPU),ppc) -ARCH=ppc -else -ifeq ($(DESTCPU),s390) -ARCH=s390 -else -ifeq ($(DESTCPU),s390x) -ARCH=s390x -else -ifeq ($(DESTCPU),riscv64) -ARCH=riscv64 -else -ARCH=x86 -endif -endif -endif -endif -endif -endif -endif -endif - -# node and v8 use different arch names (e.g. node 'x86' vs v8 'ia32'). -# pass the proper v8 arch name to $V8_ARCH based on user-specified $DESTCPU. -ifeq ($(DESTCPU),x86) -V8_ARCH=ia32 -else -V8_ARCH ?= $(DESTCPU) - -endif - -# enforce "x86" over "ia32" as the generally accepted way of referring to 32-bit intel -ifeq ($(ARCH),ia32) -override ARCH=x86 -endif -ifeq ($(DESTCPU),ia32) -override DESTCPU=x86 -endif - -TARNAME=node-$(FULLVERSION) -TARBALL=$(TARNAME).tar -# Custom user-specified variation, use it directly -ifdef VARIATION -BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH)-$(VARIATION) -else -BINARYNAME=$(TARNAME)-$(PLATFORM)-$(ARCH) -endif -BINARYTAR=$(BINARYNAME).tar -# OSX doesn't have xz installed by default, http://macpkg.sourceforge.net/ -HAS_XZ ?= $(shell command -v xz > /dev/null 2>&1; [ $$? -eq 0 ] && echo 1 || echo 0) -# Supply SKIP_XZ=1 to explicitly skip .tar.xz creation -SKIP_XZ ?= 0 -XZ = $(shell [ $(HAS_XZ) -eq 1 ] && [ $(SKIP_XZ) -eq 0 ] && echo 1 || echo 0) -XZ_COMPRESSION ?= 9e -PKG=$(TARNAME).pkg -MACOSOUTDIR=out/macos - -.PHONY: check-xz -ifeq ($(SKIP_XZ), 1) -check-xz: - $(info SKIP_XZ=1 supplied, skipping .tar.xz creation) -else -ifeq ($(HAS_XZ), 1) -check-xz: -else -check-xz: - $(error No xz command, cannot continue) -endif -endif - -.PHONY: release-only -release-only: check-xz - @if [ "$(DISTTYPE)" = "release" ] && `grep -q REPLACEME doc/api/*.md`; then \ - echo 'Please update REPLACEME tags in the following doc/api/*.md files (See doc/contributing/releases.md):\n' ; \ - REPLACEMES="$(shell grep -l REPLACEME doc/api/*.md)" ; \ - echo "$$REPLACEMES\n" | tr " " "\n" ; \ - exit 1 ; \ - fi - @if [ "$(DISTTYPE)" = "release" ] && \ - `grep -q DEP...X doc/api/deprecations.md`; then \ - echo 'Please update DEP...X in doc/api/deprecations.md (See doc/contributing/releases.md)' ; \ - exit 1 ; \ - fi - @if [ "$(shell git status --porcelain | egrep -v '^\?\? ')" = "" ]; then \ - exit 0 ; \ - else \ - echo "" >&2 ; \ - echo "The git repository is not clean." >&2 ; \ - echo "Please commit changes before building release tarball." >&2 ; \ - echo "" >&2 ; \ - git status --porcelain | egrep -v '^\?\?' >&2 ; \ - echo "" >&2 ; \ - exit 1 ; \ - fi - @if [ "$(DISTTYPE)" != "release" ] || [ "$(RELEASE)" = "1" ]; then \ - exit 0; \ - else \ - echo "" >&2 ; \ - echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE)." >&2 ; \ - echo "Did you remember to update src/node_version.h?" >&2 ; \ - echo "" >&2 ; \ - exit 1 ; \ - fi - @if [ "$(RELEASE)" = "0" ] || [ -f "$(CHANGELOG)" ]; then \ - exit 0; \ - else \ - echo "" >&2 ; \ - echo "#NODE_VERSION_IS_RELEASE is set to $(RELEASE) but " >&2 ; \ - echo "$(CHANGELOG) does not exist." >&2 ; \ - echo "" >&2 ; \ - exit 1 ; \ - fi - -$(PKG): release-only -# pkg building is currently only supported on an ARM64 macOS host for -# ease of compiling fat-binaries for both macOS architectures. -ifneq ($(OSTYPE),darwin) - $(warning Invalid OSTYPE) - $(error OSTYPE should be `darwin` currently is $(OSTYPE)) -endif -ifneq ($(ARCHTYPE),arm64) - $(warning Invalid ARCHTYPE) - $(error ARCHTYPE should be `arm64` currently is $(ARCHTYPE)) -endif - $(RM) -r $(MACOSOUTDIR) - mkdir -p $(MACOSOUTDIR)/installer/productbuild - cat tools/macos-installer/productbuild/distribution.xml.tmpl \ - | sed -E "s/\\{nodeversion\\}/$(FULLVERSION)/g" \ - | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g" \ - >$(MACOSOUTDIR)/installer/productbuild/distribution.xml ; \ - - @for dirname in tools/macos-installer/productbuild/Resources/*/; do \ - lang=$$(basename $$dirname) ; \ - mkdir -p $(MACOSOUTDIR)/installer/productbuild/Resources/$$lang ; \ - printf "Found localization directory $$dirname\n" ; \ - cat $$dirname/welcome.html.tmpl \ - | sed -E "s/\\{nodeversion\\}/$(FULLVERSION)/g" \ - | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g" \ - >$(MACOSOUTDIR)/installer/productbuild/Resources/$$lang/welcome.html ; \ - cat $$dirname/conclusion.html.tmpl \ - | sed -E "s/\\{nodeversion\\}/$(FULLVERSION)/g" \ - | sed -E "s/\\{npmversion\\}/$(NPMVERSION)/g" \ - >$(MACOSOUTDIR)/installer/productbuild/Resources/$$lang/conclusion.html ; \ - done - CC_host="cc -arch x86_64" CXX_host="c++ -arch x86_64" \ - CC_target="cc -arch x86_64" CXX_target="c++ -arch x86_64" \ - CC="cc -arch x86_64" CXX="c++ -arch x86_64" $(PYTHON) ./configure \ - --dest-cpu=x86_64 \ - --tag=$(TAG) \ - --release-urlbase=$(RELEASE_URLBASE) \ - $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS) - arch -x86_64 $(MAKE) install V=$(V) DESTDIR=$(MACOSOUTDIR)/dist/x64/node - SIGN="$(CODESIGN_CERT)" PKGDIR="$(MACOSOUTDIR)/dist/x64/node/usr/local" sh \ - tools/osx-codesign.sh - $(PYTHON) ./configure \ - --dest-cpu=arm64 \ - --tag=$(TAG) \ - --release-urlbase=$(RELEASE_URLBASE) \ - $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS) - $(MAKE) install V=$(V) DESTDIR=$(MACOSOUTDIR)/dist/node - SIGN="$(CODESIGN_CERT)" PKGDIR="$(MACOSOUTDIR)/dist/node/usr/local" sh \ - tools/osx-codesign.sh - lipo $(MACOSOUTDIR)/dist/x64/node/usr/local/bin/node \ - $(MACOSOUTDIR)/dist/node/usr/local/bin/node \ - -output $(MACOSOUTDIR)/dist/node/usr/local/bin/node \ - -create - mkdir -p $(MACOSOUTDIR)/dist/npm/usr/local/lib/node_modules - mkdir -p $(MACOSOUTDIR)/pkgs - mv $(MACOSOUTDIR)/dist/node/usr/local/lib/node_modules/npm \ - $(MACOSOUTDIR)/dist/npm/usr/local/lib/node_modules - unlink $(MACOSOUTDIR)/dist/node/usr/local/bin/npm - unlink $(MACOSOUTDIR)/dist/node/usr/local/bin/npx - $(NODE) tools/license2rtf.mjs < LICENSE > \ - $(MACOSOUTDIR)/installer/productbuild/Resources/license.rtf - cp doc/osx_installer_logo.png $(MACOSOUTDIR)/installer/productbuild/Resources - pkgbuild --version $(FULLVERSION) \ - --identifier org.nodejs.node.pkg \ - --root $(MACOSOUTDIR)/dist/node $(MACOSOUTDIR)/pkgs/node-$(FULLVERSION).pkg - pkgbuild --version $(NPMVERSION) \ - --identifier org.nodejs.npm.pkg \ - --root $(MACOSOUTDIR)/dist/npm \ - --scripts ./tools/macos-installer/pkgbuild/npm/scripts \ - $(MACOSOUTDIR)/pkgs/npm-$(NPMVERSION).pkg - productbuild --distribution $(MACOSOUTDIR)/installer/productbuild/distribution.xml \ - --resources $(MACOSOUTDIR)/installer/productbuild/Resources \ - --package-path $(MACOSOUTDIR)/pkgs ./$(PKG) - SIGN="$(PRODUCTSIGN_CERT)" PKG="$(PKG)" sh tools/osx-productsign.sh - sh tools/osx-notarize.sh $(FULLVERSION) - -.PHONY: pkg -# Builds the macOS installer for releases. -pkg: $(PKG) - -.PHONY: corepack-update -corepack-update: - mkdir -p /tmp/node-corepack - curl -qLo /tmp/node-corepack/package.tgz "$$(npm view corepack dist.tarball)" - - rm -rf deps/corepack && mkdir deps/corepack - cd deps/corepack && tar xf /tmp/node-corepack/package.tgz --strip-components=1 - chmod +x deps/corepack/shims/* - - node deps/corepack/dist/corepack.js --version - -.PHONY: pkg-upload -# Note: this is strictly for release builds on release machines only. -pkg-upload: pkg - ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)" - chmod 664 $(TARNAME).pkg - scp -p $(TARNAME).pkg $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).pkg - ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).pkg.done" - -$(TARBALL): release-only doc-only - git checkout-index -a -f --prefix=$(TARNAME)/ - mkdir -p $(TARNAME)/doc/api - cp doc/node.1 $(TARNAME)/doc/node.1 - cp -r out/doc/api/* $(TARNAME)/doc/api/ - $(RM) -r $(TARNAME)/.editorconfig - $(RM) -r $(TARNAME)/.git* - $(RM) -r $(TARNAME)/.mailmap - $(RM) -r $(TARNAME)/deps/openssl/openssl/demos - $(RM) -r $(TARNAME)/deps/openssl/openssl/doc - $(RM) -r $(TARNAME)/deps/openssl/openssl/test - $(RM) -r $(TARNAME)/deps/uv/docs - $(RM) -r $(TARNAME)/deps/uv/samples - $(RM) -r $(TARNAME)/deps/uv/test - $(RM) -r $(TARNAME)/deps/v8/samples - $(RM) -r $(TARNAME)/deps/v8/tools/profviz - $(RM) -r $(TARNAME)/deps/v8/tools/run-tests.py - $(RM) -r $(TARNAME)/doc/images # too big - $(RM) -r $(TARNAME)/test*.tap - $(RM) -r $(TARNAME)/tools/cpplint.py - $(RM) -r $(TARNAME)/tools/eslint-rules - $(RM) -r $(TARNAME)/tools/license-builder.sh - $(RM) -r $(TARNAME)/tools/node_modules - $(RM) -r $(TARNAME)/tools/osx-* - $(RM) -r $(TARNAME)/tools/osx-pkg.pmdoc - find $(TARNAME)/deps/v8/test/* -type d ! -regex '.*/test/torque$$' | xargs $(RM) -r - find $(TARNAME)/deps/v8/test -type f ! -regex '.*/test/torque/.*' | xargs $(RM) - find $(TARNAME)/deps/zlib/contrib/* -type d ! -regex '.*/contrib/optimizations$$' | xargs $(RM) -r - find $(TARNAME)/ -name ".eslint*" -maxdepth 2 | xargs $(RM) - find $(TARNAME)/ -type l | xargs $(RM) - tar -cf $(TARNAME).tar $(TARNAME) - $(RM) -r $(TARNAME) - gzip -c -f -9 $(TARNAME).tar > $(TARNAME).tar.gz -ifeq ($(XZ), 1) - xz -c -f -$(XZ_COMPRESSION) $(TARNAME).tar > $(TARNAME).tar.xz -endif - $(RM) $(TARNAME).tar - -.PHONY: tar -tar: $(TARBALL) ## Create a source tarball. - -.PHONY: tar-upload -# Note: this is strictly for release builds on release machines only. -tar-upload: tar - ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)" - chmod 664 $(TARNAME).tar.gz - scp -p $(TARNAME).tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).tar.gz - ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).tar.gz.done" -ifeq ($(XZ), 1) - chmod 664 $(TARNAME).tar.xz - scp -p $(TARNAME).tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).tar.xz - ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME).tar.xz.done" -endif - -.PHONY: doc-upload -# Note: this is strictly for release builds on release machines only. -doc-upload: doc - ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs/" - chmod -R ug=rw-x+X,o=r+X out/doc/ - scp -pr out/doc/* $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs/ - ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/docs.done" - -.PHONY: $(TARBALL)-headers -$(TARBALL)-headers: release-only - $(PYTHON) ./configure \ - --prefix=/ \ - --dest-cpu=$(DESTCPU) \ - --tag=$(TAG) \ - --release-urlbase=$(RELEASE_URLBASE) \ - $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS) - $(PYTHON) tools/install.py install --headers-only --dest-dir '$(TARNAME)' --prefix '/' - find $(TARNAME)/ -type l | xargs $(RM) - tar -cf $(TARNAME)-headers.tar $(TARNAME) - $(RM) -r $(TARNAME) - gzip -c -f -9 $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.gz -ifeq ($(XZ), 1) - xz -c -f -$(XZ_COMPRESSION) $(TARNAME)-headers.tar > $(TARNAME)-headers.tar.xz -endif - $(RM) $(TARNAME)-headers.tar - -.PHONY: tar-headers -tar-headers: $(TARBALL)-headers ## Build the node header tarball. - -.PHONY: tar-headers-upload -tar-headers-upload: tar-headers - ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)" - chmod 664 $(TARNAME)-headers.tar.gz - scp -p $(TARNAME)-headers.tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz - ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.gz.done" -ifeq ($(XZ), 1) - chmod 664 $(TARNAME)-headers.tar.xz - scp -p $(TARNAME)-headers.tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz - ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-headers.tar.xz.done" -endif - -$(BINARYTAR): release-only - $(RM) -r $(BINARYNAME) - $(RM) -r out/deps out/Release - $(PYTHON) ./configure \ - --prefix=/ \ - --dest-cpu=$(DESTCPU) \ - --tag=$(TAG) \ - --release-urlbase=$(RELEASE_URLBASE) \ - $(CONFIG_FLAGS) $(BUILD_RELEASE_FLAGS) - $(MAKE) install DESTDIR=$(BINARYNAME) V=$(V) PORTABLE=1 - cp README.md $(BINARYNAME) - cp LICENSE $(BINARYNAME) -ifeq ("$(wildcard $(CHANGELOG))","") - cp CHANGELOG.md $(BINARYNAME) -else - cp $(CHANGELOG) $(BINARYNAME)/CHANGELOG.md -endif -ifeq ($(OSTYPE),darwin) - SIGN="$(CODESIGN_CERT)" PKGDIR="$(BINARYNAME)" sh tools/osx-codesign.sh -endif - tar -cf $(BINARYNAME).tar $(BINARYNAME) - $(RM) -r $(BINARYNAME) - gzip -c -f -9 $(BINARYNAME).tar > $(BINARYNAME).tar.gz -ifeq ($(XZ), 1) - xz -c -f -$(XZ_COMPRESSION) $(BINARYNAME).tar > $(BINARYNAME).tar.xz -endif - $(RM) $(BINARYNAME).tar - -.PHONY: binary -# This requires NODE_VERSION_IS_RELEASE defined as 1 in src/node_version.h. -binary: $(BINARYTAR) ## Build release binary tarballs. - -.PHONY: binary-upload -# Note: this is strictly for release builds on release machines only. -binary-upload: binary - ssh $(STAGINGSERVER) "mkdir -p nodejs/$(DISTTYPEDIR)/$(FULLVERSION)" - chmod 664 $(TARNAME)-$(OSTYPE)-$(ARCH).tar.gz - scp -p $(TARNAME)-$(OSTYPE)-$(ARCH).tar.gz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-$(OSTYPE)-$(ARCH).tar.gz - ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-$(OSTYPE)-$(ARCH).tar.gz.done" -ifeq ($(XZ), 1) - chmod 664 $(TARNAME)-$(OSTYPE)-$(ARCH).tar.xz - scp -p $(TARNAME)-$(OSTYPE)-$(ARCH).tar.xz $(STAGINGSERVER):nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-$(OSTYPE)-$(ARCH).tar.xz - ssh $(STAGINGSERVER) "touch nodejs/$(DISTTYPEDIR)/$(FULLVERSION)/$(TARNAME)-$(OSTYPE)-$(ARCH).tar.xz.done" -endif - -.PHONY: bench-all -.PHONY: bench -bench bench-all: bench-addons-build - $(warning Please use benchmark/run.js or benchmark/compare.js to run the benchmarks.) - -# Build required addons for benchmark before running it. -.PHONY: bench-addons-build -bench-addons-build: | $(NODE_EXE) benchmark/napi/.buildstamp - -.PHONY: bench-addons-clean -.NOTPARALLEL: bench-addons-clean -bench-addons-clean: - $(RM) -r benchmark/napi/*/build - $(RM) benchmark/napi/.buildstamp - -.PHONY: lint-md-rollup -lint-md-rollup: - $(RM) tools/.*mdlintstamp - cd tools/lint-md && npm ci && npm run build - -.PHONY: lint-md-clean -.NOTPARALLEL: lint-md-clean -lint-md-clean: - $(RM) -r tools/lint-md/node_modules - $(RM) tools/.*mdlintstamp - -.PHONY: lint-md-build -lint-md-build: - $(warning Deprecated no-op target 'lint-md-build') - -ifeq ("$(wildcard tools/.mdlintstamp)","") -LINT_MD_NEWER = -else -LINT_MD_NEWER = -newer tools/.mdlintstamp -endif - -LINT_MD_TARGETS = doc src lib benchmark test tools/doc tools/icu $(wildcard *.md) -LINT_MD_FILES = $(shell $(FIND) $(LINT_MD_TARGETS) -type f \ - ! -path '*node_modules*' ! -path 'test/fixtures/*' -name '*.md' \ - $(LINT_MD_NEWER)) -run-lint-md = tools/lint-md/lint-md.mjs $(LINT_MD_FILES) -# Lint all changed markdown files maintained by us -tools/.mdlintstamp: $(LINT_MD_FILES) - $(info Running Markdown linter...) - @$(call available-node,$(run-lint-md)) - @touch $@ - -.PHONY: lint-md -# Lints the markdown documents maintained by us in the codebase. -lint-md: lint-js-doc | tools/.mdlintstamp - -run-format-md = tools/lint-md/lint-md.mjs --format $(LINT_MD_FILES) -.PHONY: format-md -# Formats the markdown documents maintained by us in the codebase. -format-md: - @$(call available-node,$(run-format-md)) - - - -LINT_JS_TARGETS = .eslintrc.js benchmark doc lib test tools - -run-lint-js = tools/node_modules/eslint/bin/eslint.js --cache \ - --max-warnings=0 --report-unused-disable-directives $(LINT_JS_TARGETS) -run-lint-js-fix = $(run-lint-js) --fix - -.PHONY: lint-js-fix -lint-js-fix: - @$(call available-node,$(run-lint-js-fix)) - -.PHONY: lint-js -.PHONY: lint-js-doc -# Note that on the CI `lint-js-ci` is run instead. -# Lints the JavaScript code with eslint. -lint-js-doc: LINT_JS_TARGETS=doc -lint-js lint-js-doc: - @if [ "$(shell $(node_use_openssl))" != "true" ]; then \ - echo "Skipping $@ (no crypto)"; \ - else \ - echo "Running JS linter..."; \ - $(call available-node,$(run-lint-js)) \ - fi - -jslint: lint-js - $(warning Please use lint-js instead of jslint) - -run-lint-js-ci = tools/node_modules/eslint/bin/eslint.js \ - --max-warnings=0 --report-unused-disable-directives -f tap \ - -o test-eslint.tap $(LINT_JS_TARGETS) - -.PHONY: lint-js-ci -# On the CI the output is emitted in the TAP format. -lint-js-ci: - $(info Running JS linter...) - @$(call available-node,$(run-lint-js-ci)) - -jslint-ci: lint-js-ci - $(warning Please use lint-js-ci instead of jslint-ci) - -LINT_CPP_ADDON_DOC_FILES_GLOB = test/addons/??_*/*.cc test/addons/??_*/*.h -LINT_CPP_ADDON_DOC_FILES = $(wildcard $(LINT_CPP_ADDON_DOC_FILES_GLOB)) -LINT_CPP_EXCLUDE ?= -LINT_CPP_EXCLUDE += src/node_root_certs.h -LINT_CPP_EXCLUDE += $(LINT_CPP_ADDON_DOC_FILES) -# These files were copied more or less verbatim from V8. -LINT_CPP_EXCLUDE += src/tracing/trace_event.h src/tracing/trace_event_common.h - -LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \ - benchmark/napi/*/*.cc \ - src/*.c \ - src/*.cc \ - src/*.h \ - src/*/*.c \ - src/*/*.cc \ - src/*/*.h \ - test/addons/*/*.cc \ - test/addons/*/*.h \ - test/cctest/*.cc \ - test/cctest/*.h \ - test/embedding/*.cc \ - test/embedding/*.h \ - test/fixtures/*.c \ - test/js-native-api/*/*.cc \ - test/node-api/*/*.cc \ - tools/js2c.cc \ - tools/icu/*.cc \ - tools/icu/*.h \ - tools/code_cache/*.cc \ - tools/code_cache/*.h \ - tools/snapshot/*.cc \ - tools/snapshot/*.h \ - )) - -FORMAT_CPP_FILES ?= -FORMAT_CPP_FILES += $(LINT_CPP_FILES) -# C source codes. -FORMAT_CPP_FILES += $(wildcard \ - benchmark/napi/*/*.c \ - test/js-native-api/*.h \ - test/js-native-api/*/*.c \ - test/js-native-api/*/*.h \ - test/node-api/*/*.c \ - test/node-api/*/*.h \ - ) - -# Code blocks don't have newline at the end, -# and the actual filename is generated so it won't match header guards -ADDON_DOC_LINT_FLAGS=-whitespace/ending_newline,-build/header_guard - -.PHONY: format-cpp-build -format-cpp-build: - cd tools/clang-format && $(call available-node,$(run-npm-ci)) - -.PHONY: format-cpp-clean -.NOTPARALLEL: format-cpp-clean -format-cpp-clean: - $(RM) -r tools/clang-format/node_modules - -CLANG_FORMAT_START ?= HEAD -.PHONY: format-cpp -# To format staged changes: -# $ make format-cpp -# To format HEAD~1...HEAD (latest commit): -# $ CLANG_FORMAT_START=`git rev-parse HEAD~1` make format-cpp -# To format diff between main and current branch head (main...HEAD): -# $ CLANG_FORMAT_START=main make format-cpp -format-cpp: ## Format C++ diff from $CLANG_FORMAT_START to current changes -ifneq ("","$(wildcard tools/clang-format/node_modules/)") - $(info Formatting C++ diff from $(CLANG_FORMAT_START)..) - @$(PYTHON) tools/clang-format/node_modules/.bin/git-clang-format \ - --binary=tools/clang-format/node_modules/.bin/clang-format \ - --style=file \ - $(CLANG_FORMAT_START) -- \ - $(FORMAT_CPP_FILES) -else - $(info Required tooling for C++ code formatting is not installed.) - $(info To install (requires internet access) run: $$ make format-cpp-build) -endif - -ifeq ($(V),1) -CPPLINT_QUIET = -else -CPPLINT_QUIET = --quiet -endif -.PHONY: lint-cpp -# Lints the C++ code with cpplint.py and checkimports.py. -lint-cpp: tools/.cpplintstamp - -tools/.cpplintstamp: $(LINT_CPP_FILES) - $(info Running C++ linter...) - @$(PYTHON) tools/cpplint.py $(CPPLINT_QUIET) $? - @$(PYTHON) tools/checkimports.py $? - @touch $@ - -.PHONY: lint-addon-docs -lint-addon-docs: tools/.doclintstamp - -tools/.doclintstamp: test/addons/.docbuildstamp - $(info Running C++ linter on addon docs...) - @$(PYTHON) tools/cpplint.py $(CPPLINT_QUIET) --filter=$(ADDON_DOC_LINT_FLAGS) \ - $(LINT_CPP_ADDON_DOC_FILES_GLOB) - @touch $@ - -cpplint: lint-cpp - $(warning Please use lint-cpp instead of cpplint) - -.PHONY: lint-py-build -# python -m pip install ruff -# Try with '--system' if it fails without; the system may have set '--user' -lint-py-build: - $(info Pip installing ruff on $(shell $(PYTHON) --version)...) - $(PYTHON) -m pip install --upgrade --target tools/pip/site-packages ruff==0.3.4 || \ - $(PYTHON) -m pip install --upgrade --system --target tools/pip/site-packages ruff==0.3.4 - -.PHONY: lint-py -ifneq ("","$(wildcard tools/pip/site-packages/ruff)") -# Lint the Python code with ruff. -lint-py: - tools/pip/site-packages/bin/ruff --version - tools/pip/site-packages/bin/ruff check . -else -lint-py: - $(warning Python linting with ruff is not available) - $(warning Run 'make lint-py-build') -endif - -.PHONY: lint-yaml-build -# python -m pip install yamllint -# Try with '--system' if it fails without; the system may have set '--user' -lint-yaml-build: - $(info Pip installing yamllint on $(shell $(PYTHON) --version)...) - $(PYTHON) -m pip install --upgrade -t tools/pip/site-packages yamllint || \ - $(PYTHON) -m pip install --upgrade --system -t tools/pip/site-packages yamllint - -.PHONY: lint-yaml -# Lints the YAML files with yamllint. -lint-yaml: - @if [ -d "tools/pip/site-packages/yamllint" ]; then \ - PYTHONPATH=tools/pip $(PYTHON) -m yamllint .; \ - else \ - echo 'YAML linting with yamllint is not available'; \ - echo "Run 'make lint-yaml-build'"; \ - fi - -.PHONY: lint -.PHONY: lint-ci -ifneq ("","$(wildcard tools/node_modules/eslint/)") -lint: ## Run JS, C++, MD and doc linters. - @EXIT_STATUS=0 ; \ - $(MAKE) lint-js || EXIT_STATUS=$$? ; \ - $(MAKE) lint-cpp || EXIT_STATUS=$$? ; \ - $(MAKE) lint-addon-docs || EXIT_STATUS=$$? ; \ - $(MAKE) lint-md || EXIT_STATUS=$$? ; \ - $(MAKE) lint-yaml || EXIT_STATUS=$$? ; \ - exit $$EXIT_STATUS -CONFLICT_RE=^>>>>>>> [[:xdigit:]]+|^<<<<<<< [[:alpha:]]+ - -# Related CI job: node-test-linter -lint-ci: lint-js-ci lint-cpp lint-py lint-md lint-addon-docs lint-yaml-build lint-yaml - @if ! ( grep -IEqrs "$(CONFLICT_RE)" --exclude="error-message.js" --exclude="merge-conflict.json" benchmark deps doc lib src test tools ) \ - && ! ( $(FIND) . -maxdepth 1 -type f | xargs grep -IEqs "$(CONFLICT_RE)" ); then \ - exit 0 ; \ - else \ - echo "" >&2 ; \ - echo "Conflict marker detected in one or more files. Please fix them first." >&2 ; \ - exit 1 ; \ - fi -else -lint lint-ci: - $(info Linting is not available through the source tarball.) - $(info Use the git repo instead: $$ git clone https://github.com/nodejs/node.git) -endif - -.PHONY: lint-clean -lint-clean: - $(RM) tools/.*lintstamp - $(RM) .eslintcache - -HAS_DOCKER ?= $(shell command -v docker > /dev/null 2>&1; [ $$? -eq 0 ] && echo 1 || echo 0) - -.PHONY: gen-openssl -ifeq ($(HAS_DOCKER), 1) -DOCKER_COMMAND ?= docker run -it -v $(PWD):/node -IS_IN_WORKTREE = $(shell grep '^gitdir: ' $(PWD)/.git 2>/dev/null) -GIT_WORKTREE_COMMON = $(shell git rev-parse --git-common-dir) -DOCKER_COMMAND += $(if $(IS_IN_WORKTREE), -v $(GIT_WORKTREE_COMMON):$(GIT_WORKTREE_COMMON)) -gen-openssl: ## Generate platform dependent openssl files (requires docker) - docker build -t node-openssl-builder deps/openssl/config/ - $(DOCKER_COMMAND) node-openssl-builder make -C deps/openssl/config -else -gen-openssl: - $(error No docker command, cannot continue) -endif diff --git a/build.py b/build.py new file mode 100644 index 000000000000..801bca4c091b --- /dev/null +++ b/build.py @@ -0,0 +1,2275 @@ +#!/usr/bin/env python3 + +import sys +import shutil +import fnmatch +import os +import importlib +import subprocess +import glob +import re +import pathlib +import json +import tarfile +import tempfile +import gzip + +# try to get 'requests', if not found, set HAS_REQUESTS to False +try: + import requests + HAS_REQUESTS = True +except ImportError: + HAS_REQUESTS = False + +def import_module(name, attr): + try: + return getattr(importlib.import_module(name), attr) + except ImportError: + print(f"Error: {name} module not found") + sys.exit(1) + +def anti_glob(pattern, files): + return [file for file in files if not fnmatch.fnmatch(file, pattern)] + +def max_depth(files, depth): + return [file for file in files if file.count(os.path.sep) <= depth] + +class CLI: + @staticmethod + def args(): + # return all the args AFTER build.py + return sys.argv[sys.argv.index('build.py') + 1:] + + @staticmethod + def has(key): + for arg in CLI.args(): + if arg.startswith(key): + return True + @staticmethod + def get(key): + args = CLI.args() + for arg in args: + if arg.startswith(key): + print(arg) + if arg == key: + return args[args.index(arg) + 1] + if arg[len(key)] == '=': + return arg[len(key) + 1:] + return arg[len(key):] + return None + + @staticmethod + def unescape(value): + if value[0] in ['"', "'"]: + value = value[1:] + + if value[-1] in ['"', "'"]: + value = value[:-1] + + return value + + @staticmethod + def get_cli_env(): + env = {} + for arg in CLI.args(): + if not arg.startswith('-') and '=' in arg: + key, value = arg.split('=') + env[CLI.unescape(key)] = CLI.unescape(value) + return env + + @staticmethod + def get_target_arg(): + for arg in CLI.args(): + if not arg.startswith('-') and '=' not in arg: + return arg + return None + +class Logger: + def __init__(self, loglevel): + if type(loglevel) is str: + match loglevel.lower(): + case 'error': + self.loglevel = 1 + case 'warn': + self.loglevel = 2 + case 'info': + self.loglevel = 3 + case 'debug': + self.loglevel = 4 + case _: + self.loglevel = 3 + elif type(loglevel) is int: + self.loglevel = loglevel + else: + self.loglevel = 3 + + def error(self, message): + if self.loglevel >= 1: + Logger.print("ERROR", "31", message) + + def warn(self, message): + if self.loglevel >= 2: + Logger.print("WARN", "33", message) + + def info(self, message): + if self.loglevel >= 3: + Logger.print("INFO", "32", message) + + def debug(self, message): + if self.loglevel >= 4: + Logger.print("DEBUG", "34", message) + + @staticmethod + def print(level, color, message): + print(f"\033[1m\033[{color}m{level}\033[0m {message}") + +class Environment: + def __init__(self, env): + self.env = env + + def string(self, key, default): + value = self.env.get(key) + if value is None: + return default + return value + + def array(self, key, default): + value = self.env.get(key) + if value is None: + return default + return value.replace(",", " ").split(" ") + + def int(self, key, default): + value = self.env.get(key) + if value is None: + return default + return int(value) + +def convert_to_junit(path): + conv_func = import_module('./tools/v8-json-to-junit.py', 'v8-json-to-junit') + with open(path, 'r') as f: + out = conv_func.Main(f.read()) + out_file = open(f'{path.replace(".json", ".xml")}', 'w') + out_file.write(out) + out_file.close() + f.close() + +class BuildOptions: + def persist(self, key, func): + if key in self.persistent_values: + return self.persistent_values[key] + value = func() + self.persistent_values[key] = value + return value + + def initialize(self): + if not os.path.exists('config.mk'): + Logger.print('ERROR', '31', 'Error: config.mk not found, run configure first') + sys.exit(1) + + with open('config.mk', 'r') as f: + for line in f: + match = re.search(r'(\w+)\s*=\s*(.*)', line) + if match: + self.environment.env[match.group(1)] = match.group(2) + f.close() + + extra_env = CLI.get_cli_env() + self.environment.env.update(extra_env) + + def __init__(self, env=None, options={}, persistent_values={}, do_init=False): + self.environment = Environment(env if env is not None else os.environ) + self.persistent_values = persistent_values + if do_init: self.initialize() + uname = os.uname() + self.options = { + 'build_type': self.environment.string('BUILDTYPE', 'Release'), + 'build_with': self.environment.string('BUILD_WITH', 'make'), + 'log_level': self.environment.int('LOG_LEVEL', 3), + 'ninja': self.environment.string('NINJA', 'ninja'), + 'dest_dir': self.environment.string('DESTDIR', ''), + 'prefix': self.environment.string('PREFIX', '/usr/local'), + 'distribution_type': self.environment.string('DISTTYPE', 'release'), + 'coverage_tests': self.environment.string('COVTESTS', 'test-cov'), + 'test_ci_args': self.environment.array('TEST_CI_ARGS', []), + 'gcov_executable': self.environment.string('GCOV', 'gcov'), + 'gtest_filter': self.environment.string('GTEST_FILTER', '*'), + 'v8_build_options': self.environment.array('V8_BUILD_OPTIONS', []), + 'ci_skip_tests': self.environment.array('CI_SKIP_TESTS', []), + 'js_suites': self.environment.array('JS_SUITES', ['default']), + 'native_suites': self.environment.array('NATIVE_SUITES', ['addons', 'js-native-api', 'node-api']), + 'coverage_skip_tests': self.environment.array('COV_SKIP_TESTS', ['core_line_numbers.js', 'testFinalizer.js', 'test_function/test.js']), + 'flaky_tests': self.environment.string('FLAKY_TESTS', 'run'), + "config_flags": self.environment.array('CONFIG_FLAGS', []), + 'v8_test_options': self.environment.array('V8_EXTRA_TEST_OPTIONS', []), + 'release_urlbase': self.environment.string('RELEASE_URLBASE', None), + 'codesign_certificate': self.environment.string('CODESIGN_CERT', None), + 'clang_format_start': self.environment.string('CLANG_FORMAT_START', 'HEAD'), + } + + # Parallel + parallel = CLI.get('-j') + self.options['parallel_args'] = [f'-j {parallel}'] if parallel is not None else [] + + for key, value in options.items(): + self.options[key] = value + + # Persistent Values + raw_version = self.persist( + 'raw_version', + lambda: subprocess.check_output([sys.executable, 'tools/getnodeversion.py']).decode('utf-8').strip(), + ) + + def get_release_version(): + with open('src/node_version.h', 'r') as f: + for line in f: + match = re.search(r'#define NODE_VERSION_IS_RELEASE ([01])', line) + if match: + return match.group(1) == '1' + f.close() + return False + release = self.persist('release', get_release_version) + self.options['release'] = release + + def get_npm_version(): + with open('deps/npm/package.json', 'r') as f: + return json.load(f)['version'] + self.options['npm_version'] = self.persist('npm_version', get_npm_version) + + # Node Versioning + + version = f'v{raw_version}' + self.options['version'] = version + self.options['changelog'] = f'doc/changelogs/{raw_version.split(".")[0]}.md' + + match self.get('distribution_type'): + case 'release': + self.options['full_version'] = version + case 'custom': + custom_tag = self.environment.string('CUSTOMTAG', None) + + assert custom_tag is not None, 'Error: Custom tag required for custom dist' + + self.options['tag'] = custom_tag + self.options['full_version'] = f'{version}-{self.options["tag"]}' + case 'nightly' | 'next-nightly': + date_string = self.environment.string('DATESTRING', None) + commit = self.environment.string('COMMIT', None) + + assert date_string is not None, 'Error: Datestring required for nightly dist' + assert commit is not None, 'Error: Commit required for nightly dist' + + self.options['tag'] = f'{self.options["distribution_type"]}{date_string}{commit}' + self.options['full_version'] = f'{version}-{self.options["tag"]}' + case _: + Logger.print('ERROR', '31', 'Invalid distribution type') + sys.exit(1) + + self.options['platform'] = uname.sysname.lower() + match uname.machine.lower(): + case 'x86_64': + self.options['arch'] = 'x64' + case 'amd64': + self.options['arch'] = 'x64' + case 'ppc64': + self.options['arch'] = 'ppc64' + case 'ppc': + self.options['arch'] = 'ppc' + case 's390x': + self.options['arch'] = 's390x' + case 's390': + self.options['arch'] = 's390' + case 'os/390': + self.options['arch'] = 's390x' + case 'arm64': + self.options['arch'] = 'arm64' + case 'aarch64': + self.options['arch'] = 'arm64' + case 'powerpc': + self.options['arch'] = 'ppc64' + case 'riscv64': + self.options['arch'] = 'riscv64' + case _: + self.options['arch'] = 'x86' + + self.options['v8_arch'] = self.environment.string('V8_ARCH', 'ia32' if self.options['arch'] == 'x86' else self.options['arch']) + + # Node EXE + extension = '.exe' if sys.platform == 'win32' else '' + self.options['node_exe'] = self.environment.string('NODE_EXE', f'node{extension}') + self.options['node'] = self.environment.string('NODE', f'${os.path.join(os.getcwd(), self.options["node_exe"])}') + self.options['node_g_exe'] = f'node_g{extension}' + self.options['npm'] = self.environment.string('NPM', f'${os.path.join("deps", "npm", "bin", "npm-cli.js")}') + + # Node Tarball + self.options['tar_name'] = f'node-{self.options["full_version"]}' + self.options['tarball'] = f'{self.options["tar_name"]}.tar' + self.options['binary_name'] = f'{self.options["tar_name"]}-{self.options["platform"]}-{self.options["arch"]}' + self.options['binary_tar'] = f'{self.options["binary_name"]}.tar' + + # Prerequisites + self.options['addons_header_dir'] = f'out/{self.options["build_type"]}/addons_headers' + self.options['addons_headers_prequisites'] = ( + ['tools/install.py', 'config.gypi', 'common.gypi'] + + glob.glob('deps/openssl/config/*.h') + + glob.glob('deps/openssl/openssl/include/openssl/*.h') + + glob.glob('deps/uv/include/*.h') + + glob.glob('deps/uv/include/*/*.h') + + glob.glob('deps/v8/include/*.h') + + glob.glob('deps/v8/include/*/*.h') + + ['deps/zlib/zconf.h', + 'deps/zlib/zlib.h', + 'src/node.h', + 'src/node_api.h', + 'src/js_native_api.h', + 'src/js_native_api_types.h', + 'src/node_api_types.h', + 'src/node_buffer.h', + 'src/node_object_wrap.h', + 'src/node_version.h' + ] + ) + + self.options['addons_binding_gypfiles'] = anti_glob( + 'test/addons/??_*/binding.gyp', + glob.glob('test/addons/*/binding.gyp') + ) + + self.options['addons_binding_sources'] = ( + anti_glob('test/addons/??_*/*.cc', glob.glob('test/addons/*/*.cc')) + + anti_glob('test/addons/??_*/*.h', glob.glob('test/addons/*/*.h')) + ) + + self.options['addons_prerequisites'] = ['test/addons/.headersbuildstamp', 'deps/npm/node_modules/node-gyp/package.json', 'tools/build_addons.py'] + + self.options['docbuildstamp_prerequisites'] = ['tools/doc/addon-verify.mjs', 'doc/api/addons.md'] + if (self.options['platform'] == 'aix' or self.options['platform'] == 'os/400'): + self.options['docbuildstamp_prerequisites'].append(f'out/{self.options["build_type"]}/node.exp') + + self.options['js_native_api_binding_gypfiles'] = anti_glob( + 'test/js-native-api/??_*/binding.gyp', + glob.glob('test/js-native-api/*/binding.gyp') + ) + + self.options['js_native_api_binding_sources'] = ( + anti_glob('test/js-native-api/??_*/*.c', glob.glob('test/js-native-api/*/*.c')) + + anti_glob('test/js-native-api/??_*/*.cc', glob.glob('test/js-native-api/*/*.cc')) + + anti_glob('test/js-native-api/??_*/*.h', glob.glob('test/js-native-api/*/*.h')) + ) + + self.options['node_api_binding_gypfiles'] = anti_glob( + 'test/node-api/??_*/binding.gyp', + glob.glob('test/node-api/*/binding.gyp') + ) + + self.options['node_api_binding_sources'] = ( + anti_glob('test/node-api/??_*/*.c', glob.glob('test/node-api/*/*.c')) + + anti_glob('test/node-api/??_*/*.cc', glob.glob('test/node-api/*/*.cc')) + + anti_glob('test/node-api/??_*/*.h', glob.glob('test/node-api/*/*.h')) + ) + + self.options['benchmark_napi_binding_gypfiles'] = glob.glob('test/benchmark-napi/*/binding.gyp') + self.options['benchmark_napi_binding_sources'] = ( + glob.glob('test/benchmark-napi/*/*.c') + + glob.glob('test/benchmark-napi/*/*.cc') + + glob.glob('test/benchmark-napi/*/*.h') + ) + + # Extended Testing Suites + self.options['ci_native_suites'] = self.environment.array('CI_NATIVE_SUITES', self.options['native_suites'] + ['benchmark']) + self.options['ci_js_suites'] = self.environment.array('CI_JS_SUITES', self.options['js_suites'] + ['pummel']) + + # Intl Specific + if 'DISABLE_V8_I18N' in self.environment.env: + self.options['v8_build_options'].append('i18nsupport=off') + + # Debug Specific + if self.options['build_type'] == 'Debug': + self.options["config_flags"].append('--debug') + + # MacOS Specific + if self.options['platform'] == 'darwin': + self.options['gcov_executable'] = 'xcrun llvm-cov gcov' + self.options['macos_output_directory'] = os.path.join('out', 'macos') + self.options['pkg'] = f'{self.options["tar_name"]}.pkg' + + # V8 Tap Setup + tap_v8_path = os.path.join(os.getcwd(), 'v8-tap') + tap_v8_intl_path = os.path.join(os.getcwd(), 'v8-intl-tap') + tap_v8_benchmarks_path = os.path.join(os.getcwd(), 'v8-benchmarks-tap') + + if 'ENABLE_CONVERT_V8_JSON_TO_XML' in self.environment.env: + self.options['tap_v8'] = ['--json-test-results', f'{tap_v8_path}.json', '--slow-tests-cutoff', '1000000'] + self.options['tap_v8_intl'] = ['--json-test-results', f'{tap_v8_intl_path}.json', '--slow-tests-cutoff', '1000000'] + self.options['tap_v8_benchmarks'] = ['--json-test-results', f'{tap_v8_benchmarks_path}.json', '--slow-tests-cutoff', '1000000'] + self.options['convert_to_junit'] = convert_to_junit + elif 'ENABLE_V8_TAP' in self.environment.env: + self.options['tap_v8'] = ['--junitout', f'{tap_v8_path}.xml'] + self.options['tap_v8_intl'] = ['--junitout', f'{tap_v8_intl_path}.xml'] + self.options['tap_v8_benchmarks'] = ['--junitout', f'{tap_v8_benchmarks_path}.xml'] + self.options['convert_to_junit'] = lambda x: True # no-op + + # API Docs + self.options["api_documentation_directories"] = ['out/doc', 'out/doc/api', 'out/doc/api/assets'] + self.options['api_documentation_sources'] = glob.glob('doc/api/*.md') + self.options['api_documentation_html'] = [os.path.join('out', md.replace('.md', '.html')) for md in self.options['api_documentation_sources']] + self.options['api_documentation_json'] = [os.path.join('out', md.replace('.md', '.json')) for md in self.options['api_documentation_sources']] + self.options['api_documentation_assets'] = [f"out/{source.replace('api_assets/', 'api/assets')}" for source in glob.glob("doc/api_assets/*")] + self.options['link_data_file'] = 'out/doc/api/link_data.json' + self.options['versions_data_file'] = 'out/doc/api/versions.json' + + # Linting + lint_markdown_targets = ['doc', 'src', 'lib', 'benchmark', 'test', 'tools/doc', 'tools/icu'] + self.options["lint_markdown_files"] = [] + for target in lint_markdown_targets: + globbed = glob.glob(f"{target}/**/*.md", recursive=True) + globbed = [file for file in globbed if f"{os.path.sep}node_modules{os.path.sep}" not in file] + globbed = [file for file in globbed if f"text{os.path.sep}fixtures{os.path.sep}" not in file] + self.options["lint_markdown_files"] += globbed + + self.options["lint_javascript_files"] = ['.eslintrc.js', 'benchmark', 'doc', 'lib', 'test', 'tools'] + + ## CPP + self.options['lint_cpp_addon_doc_files'] = glob.glob('test/addons/??_*/*.cc') + glob.glob('test/addons/??_*/*.h') + self.options['lint_cpp_exclude'] = ( + self.environment.array('LINT_CPP_EXCLUDE', []) + + ['src/node_root_certs.h', 'src/tracing/trace_event.h', 'src/tracing/trace_event_common.h'] + + self.options['lint_cpp_addon_doc_files'] + ) + + unfiltered_cpp_files = ( + glob.glob("benchmark/napi/*/*.cc") + + glob.glob("src/*.c") + + glob.glob("src/*.cc") + + glob.glob("src/*.h") + + glob.glob("src/*/*.c") + + glob.glob("src/*/*.cc") + + glob.glob("src/*/*.h") + + glob.glob("test/addons/*/*.cc") + + glob.glob("test/addons/*/*.h") + + glob.glob("test/cctest/*.cc") + + glob.glob("test/cctest/*.h") + + glob.glob("test/embedding/*.cc") + + glob.glob("test/embedding/*.h") + + glob.glob("test/fixtures/*.c") + + glob.glob("test/js-native-api/*/*.cc") + + glob.glob("test/node-api/*/*.cc") + + glob.glob("tools/js2c.cc") + + glob.glob("tools/icu/*.cc") + + glob.glob("tools/icu/*.h") + + glob.glob("tools/code_cache/*.cc") + + glob.glob("tools/code_cache/*.h") + + glob.glob("tools/snapshot/*.cc") + + glob.glob("tools/snapshot/*.h") + ) + + self.options["lint_cpp_files"] = [file for file in unfiltered_cpp_files if file not in self.options["lint_cpp_exclude"]] + + self.options["format_cpp_files"] = ( + self.environment.array('FORMAT_CPP_FILES', []) + + self.options["lint_cpp_files"] + + glob.glob("benchmark/napi/*/*.cc") + + glob.glob("test/js-native-api/*.h") + + glob.glob("test/js-native-api/*.c") + + glob.glob("test/js-native-api/*/*.c") + + glob.glob("test/js-native-api/*/*.h") + + glob.glob("test/node-api/*/*.c") + + glob.glob("test/node-api/*/*.h") + ) + + self.options["addon_doc_lint_flags"] = [ + "-whitespace/ending_newline", + "-build/header_guard" + ] + + def get(self, key): + return self.options[key] + + def set(self, key, value): + self.options[key] = value + + def new(self, options={}, environ={}): + env = dict(os.environ) + env.update(CLI.get_cli_env()) + env.update(environ) + return BuildOptions( + env=env, + options=options, + persistent_values=self.persistent_values # Prevents re-calculation w/ shells and files + ) + +class Builder: + def make(self, target, allow_remake=False, must_succeed=True, options=None): + if options is None: + options = self.options + + if not allow_remake and target in self.made_targets: + self.logger.debug(f"No need to re-make {target}") + return 0 + + # Prefer exact matches + if target in self.targets: + if target not in self.made_targets: + self.made_targets.append(target) + exit_code = self.targets[target][0](target, options) + if must_succeed and exit_code != 0: + self.logger.error(f"Failed to build {target}") + sys.exit(exit_code) + return exit_code + else: + for key, value in self.targets.items(): + if fnmatch.fnmatch(key, target): + if target not in self.made_targets: + self.made_targets.append(target) + exit_code = value[0](target, options) + if must_succeed and exit_code != 0: + self.logger.error(f"Failed to build {target}") + sys.exit(exit_code) + return exit_code + exit_code = subprocess.call([ + "make", + target, + ]) + if must_succeed and exit_code != 0: + self.logger.error(f"Failed to build {target}") + sys.exit(exit_code) + return exit_code + + def dependencies(self, deps, options, must_make=True): + for dep in deps: + code = self.make(dep, options=options) + if must_make and code != 0: + self.logger.error(f"Failed to build {dep}") + sys.exit(1) + + def remove(self, list, only_files=False, only_dirs=False, allow_missing=True): + for item in list: + try: + if os.path.isdir(item) and not only_files: + shutil.rmtree(item) + elif os.path.isfile(item) and not only_dirs: + os.remove(item) + except FileNotFoundError: + if not allow_missing: + self.logger.error(f"Failed to remove {item}") + sys.exit(1) + + def exec(self, args, options): + return subprocess.call(args, env=options.environment.env) + + def exec_output(self, args): + return subprocess.check_output(args).decode('utf-8').strip() + + def run_build_addons(self, input, output, options): + self.exec([ + sys.executable, + os.path.join(os.getcwd(), "tools", "build_addons.py"), + "--loglevel", options.get('log_level'), + "--headers-dir", options.get('addons_header_dir'), + input, + ], options) + + os.open(output, "w").close() + + def try_node(self, *args): + try: + return self.exec_output([self.options.get('node'), *args]) + except FileNotFoundError: + try: + return self.exec_output(["node", *args]) + except FileNotFoundError: + self.logger.error("Error: Node.js not found") + sys.exit(1) + + def node_has_openssl(self): + if 'node_has_openssl' in self.dynamic_options: + return self.dynamic_options['node_has_openssl'] + + nho = self.try_node('-p', 'process.versions.openssl != undefined') + self.dynamic_options['node_has_openssl'] = nho + return nho + + def is_v8_testing_available(self): + if 'is_v8_testing_available' in self.dynamic_options: + ivta = self.dynamic_options['is_v8_testing_available'] + else: + ivta = os.path.exists(os.path.join(os.getcwd(), "deps", "v8", "tools", "run-tests.py")) + self.dynamic_options['is_v8_testing_available'] = ivta + + if not ivta: + self.logger.error("Error: V8 testing not available") + return ivta + + def node_has_icu(self): + if 'node_has_icu' in self.dynamic_options: + return self.dynamic_options['node_has_icu'] + + nhi = self.try_node('-p', 'typeof Intl === \'object\'') + self.dynamic_options['node_has_icu'] = nhi + return nhi + + def fill_template(self, template_file, outfile, node_version, npm_version): + with open(template_file, 'r') as f: + template = f.read() + template = template.replace('{{NODE_VERSION}}', node_version) + template = template.replace('{{NPM_VERSION}}', npm_version) + with open(outfile, 'w') as out: + out.write(template) + out.close() + f.close() + + def __init__(self): + self.options = BuildOptions(do_init=True) + log_level = max(self.options.get('log_level'), 4 if self.options.get('build_type') == 'Debug' else 0) + self.logger = Logger(log_level) + self.made_targets = [] + self.dynamic_options = {} + self.targets = { + "all": [self.target_all, "Build all targets \x1b[3m(default)\x1b[0m"], + "help": [self.target_help, "Display help"], + f"{self.options.get('node_exe')}": [self.target_node, "Build node (Release)"], + 'node': [self.target_node, "Build node (Release)"], + f"{self.options.get('node_g_exe')}": [self.target_node, "Build node_g (Debug)"], + 'node_g': [self.target_node, "Build node_g (Debug)"], + "out/Makefile": [self.target_out_makefile, "Generate Makefile"], + "config.gypi": [self.target_config_gypi, "Generate config.gypi"], + "install": [self.target_install, "Install node"], + "uninstall": [self.target_install, "Uninstall node"], + "clean": [self.target_clean, "Clean build artifacts"], + "testclean": [self.target_testclean, "Clean test artifacts"], + "distclean": [self.target_distclean, "Clean all build artifacts"], + "coverage-clean": [self.target_coverage_clean, "Clean coverage artifacts"], + "coverage-build": [self.target_coverage_build, "Build coverage artifacts"], + "coverage-build-js": [self.target_coverage_build_js, "Build coverage artifacts for JS"], + "coverage-test": [self.target_coverage_test, "Run coverage tests"], + "coverage-report-js": [self.target_coverage_report_js, "Report coverage for JS"], + "cctest": [self.target_cctest, "Run C++ tests"], + "list-gtests": [self.target_list_gtests, "List Google Tests"], + "v8": [self.target_v8, "Build V8"], + "jstest": [self.target_jstest, "Run JS tests"], + "tooltest": [self.target_tooltest, "Run tool tests"], + "coverage-run-js": [self.target_coverage_run_js, "Run JS coverage tests"], + "test": [self.target_test, "Run all tests"], + "test-only": [self.target_test_only, "Run all tests without building"], + "test-cov": [self.target_test_cov, "Run coverage tests"], + "test-valgrind": [self.target_test_valgrind, "Run valgrind tests"], + "test-check-deopts": [self.target_test_check_deopts, "Check for deopts"], + "test/addons/.headersbuildstamp": [self.target_test_addons_headersbuildstamp, "Build Addon Headers (Buildstamp)"], + "test/addons/.buildstamp": [self.target_test_addons_buildstamp, "Build Addons (Buildstamp)"], + "test/addons/.docbuildstamp": [self.target_test_addons_docbuildstamp, "Build Addon Docs (Buildstamp)"], + "build-addons": [self.target_build_addons, "Build Addons"], + "test/js-native-api/.buildstamp": [self.target_test_js_native_api_buildstamp, "Build JS Native API (Buildstamp)"], + "build-js-native-api-tests": [self.target_build_js_native_api_tests, "Build JS Native API Tests"], + "test/node-api/.buildstamp": [self.target_test_node_api_buildstamp, "Build Node API (Buildstamp)"], + "build-node-api-tests": [self.target_build_node_api_tests, "Build Node API Tests"], + "test/benchmark-napi/.buildstamp": [self.target_test_benchmark_napi_buildstamp, "Build Benchmark NAPI (Buildstamp)"], + "test-build": [self.target_test_build, "Build all tests"], + "test-build-js-native-api": [self.target_test_build_js_native_api, "Build JS Native API Tests"], + "test-build-node-api": [self.target_test_build_node_api, "Build Node API Tests"], + "test-all": [self.target_test_all, "Run all tests"], + "test-all-valgrind": [self.target_test_all_valgrind, "Run all tests with valgrind"], + "test-all-suites": [self.target_test_all_suites, "Run all tests in suites"], + "test-ci-native": [self.target_test_ci_native, "Run CI Native Tests"], + "test-ci-js": [self.target_test_ci_js, "Run CI JS Tests"], + "test-ci": [self.target_test_ci, "Run CI Tests"], + "build-ci": [self.target_build_ci, "Build CI Tests"], + "run-ci": [self.target_run_ci, "Run (and Build) CI Tests"], + "run-test-release": [self.target_run_test, "Run Release Tests"], + "run-test-debug": [self.target_run_test, "Run Debug Tests"], + "test-wpt": [self.target_test_wpt, "Run WPT Tests"], + "test-wpt-report": [self.target_test_wpt_report, "Report WPT Tests"], + "test-internet": [self.target_test_system, "Run Internet Tests"], + "test-tick-processor": [self.target_test_system, "Run Tick Processor Tests"], + "test-hash-seed": [self.target_test_hash_seed, "Run Hash Seed Tests"], + "test-doc": [self.target_test_doc, "Run Doc Tests"], + "test-doc-ci": [self.target_test_doc_ci, "Run Doc CI Tests"], + "test-known-issue": [self.target_test_system, "Run Known Issue Tests"], + "test-npm": [self.target_test_npm, "Run NPM Tests"], + "test-npm-publish": [self.target_test_npm_publish, "Run NPM Publish Tests"], + "test-js-native-api": [self.target_test_js_native_api, "Run JS Native API Tests"], + "test-js-native-api-clean": [self.target_test_js_native_api_clean, "Clean JS Native API Tests"], + "test-node-api": [self.target_test_node_api, "Run Node API Tests"], + "test-node-api-clean": [self.target_test_node_api_clean, "Clean Node API Tests"], + "test-addons": [self.target_test_addons, "Run Addon Tests"], + "test-addons-clean": [self.target_test_addons_clean, "Clean Addon Tests"], + "test-with-async-hooks": [self.target_test_with_async_hooks, "Run Async Hooks Tests"], + "test-v8": [self.target_test_v8, "Run V8 Tests"], + "test-v8-intl": [self.target_test_v8_system, "Run V8 Intl Tests"], + "test-v8-benchmarks": [self.target_test_v8_system, "Run V8 Benchmarks"], + "test-v8-updates": [self.target_test_v8_updates, "Run V8 Updates Tests"], + "test-v8-all": [self.target_test_v8_all, "Run V8 All Tests"], + "tools/doc/node_modules": [self.target_tools_doc_node_modules, "Install Doc Node Modules"], + "doc-only": [self.target_doc_only, "Build Docs (Only)"], + "doc": [self.target_doc, "Build Docs"], + "out/doc": [self.target_out_doc, "Generate Docs"], + "out/doc/api": [self.target_out_doc_api, "Generate API Docs"], + "out/doc/api/assets": [self.target_out_doc_api_assets, "Generate API Docs Assets"], + "out/doc/api/assets/*": [self.target_out_doc_api_assets_wildcard, "Generate API Docs Asset (Wildcard)"], + f"{self.options.get('link_data_file')}": [self.target_link_data_file, "Generate Link Data File"], + 'link-data': [self.target_link_data_file, "Generate Link Data"], + f"{self.options.get('versions_data_file')}": [self.target_versions_data_file, "Generate Versions Data File"], + 'versions-data': [self.target_versions_data_file, "Generate Versions Data"], + "out/doc/api/*.html": [self.target_out_doc_api_wildcard, "Generate API Docs HTML (Wildcard)"], + "out/doc/api/*.json": [self.target_out_doc_api_wildcard, "Generate API Docs JSON (Wildcard)"], + "out/doc/api/all.html": [self.target_out_doc_api_all_html, "Generate API Docs All HTML"], + "out/doc/api/all.json": [self.target_out_doc_api_all_json, "Generate API Docs All JSON"], + "out/doc/api/stability": [self.target_out_doc_api_stability, "Generate API Docs Stability"], + "docopen": [self.target_docopen, "Open Docs"], + "docserve": [self.target_docserve, "Serve Docs"], + "docclean": [self.target_docclean, "Clean Docs"], + "release-only": [self.target_release_only, "Build Release (Only)"], + f"{self.options.get('pkg')}": [self.target_pkg, "Build Package"], + 'pkg': [self.target_pkg, "Build Package"], + "corepack-update": [self.target_corepack_update, "Update Corepack"], + f"{self.options.get('tarball')}": [self.target_tarball, "Build Tarball"], + 'tar': [self.target_tarball, "Build Tarball"], + "tar-upload": [self.target_tar_upload, "Upload Tarball"], + "doc-upload": [self.target_doc_upload, "Upload Docs"], + f"{self.options.get('tarball')}-headers": [self.target_tarball_headers, "Build Tarball Headers"], + 'tar-headers': [self.target_tarball_headers, "Build Tarball Headers"], + "tar-headers-upload": [self.target_tar_headers_upload, "Upload Tarball Headers"], + f"{self.options.get('binary_tar')}": [self.target_binary_tar, "Build Binary Tarball"], + 'binary': [self.target_binary_tar, "Build Binary Tarball"], + "binary-upload": [self.target_binary_upload, "Upload Binary Tarball"], + 'bench-addons-build': [self.target_bench_addons_build, "Build Bench Addons"], + 'bench-addons-clean': [self.target_bench_addons_clean, "Clean Bench Addons"], + 'lint-md-rollup': [self.target_lint_md_rollup, "Lint Markdown Rollup"], + 'lint-md-clean': [self.target_lint_md_clean, "Clean Markdown Lint"], + 'tools/.mdlintstamp': [self.target_tools_mdlintstamp, "Lint Markdown (Buildstamp)"], + 'lint-md': [self.target_lint_md, "Lint Markdown"], + 'format-md': [self.target_format_md, "Format Markdown"], + 'lint-js': [self.target_lint_js, "Lint JavaScript"], + 'lint-js-ci': [self.target_lint_js_ci, "Lint JavaScript CI"], + 'format-cpp-build': [self.target_format_cpp_build, "Build C++ Format"], + 'format-cpp-clean': [self.target_format_cpp_clean, "Clean C++ Format"], + 'format-cpp': [self.target_format_cpp, "Format C++"], + 'tools/.cpplintstamp': [self.target_tools_cpplintstamp, "Lint C++ (Buildstamp)"], + 'lint-cpp': [self.target_tools_cpplintstamp, "Lint C++"], + 'tools/.doclintstamp': [self.target_tools_doclintstamp, "Lint Docs (Buildstamp)"], + 'lint-doc': [self.target_tools_doclintstamp, "Lint Docs"], + 'lint-py-build': [self.target_lint_py_build, "Build Python Lint"], + 'lint-py': [self.target_lint_py, "Lint Python"], + 'lint-yaml-build': [self.target_lint_yaml_build, "Build YAML Lint"], + 'lint-yaml': [self.target_lint_yaml, "Lint YAML"], + 'lint': [self.target_lint, "Lint All"], + 'lint-ci': [self.target_lint_ci, "Lint CI"], + 'lint-clean': [self.target_lint_clean, "Clean Lint"], + 'gen-openssl': [self.target_gen_openssl, "Generate OpenSSL"], + 'verify-buildfile': [self.target_verify_buildfile, "Verify Buildfile"], + } + + ## Make sure to run this BEFORE pushing any changes to this file + def target_verify_buildfile(self, target, options): + global_unfound = False + for name, value in self.__class__.__dict__.items(): + if name.startswith('target_'): + found = False + for _, value in self.targets.items(): + if value[0].__name__ == name: + found = True + break + if not found: + global_unfound = True + self.logger.error(f"\x1b[1m{name}\x1b[0m not found in targets") + if global_unfound: + sys.exit(1) + + def target_all(self, target, options): + if options.get('build_type') == 'Release': + self.dependencies([options.get('node_exe')], options=options) + else: + self.dependencies([options.get('node_g_exe')], options=options) + return 0 + + def target_help(self, target, options): + is_debug = options.get('build_type') == 'Debug' + self.logger.info("Available targets:") + items = sorted(self.targets.items()) + if is_debug: + for key, value in items: + func_name = value[0].__name__ + self.logger.info(f"\x1b[1m{key}\x1b[0m: {value[1]} \x1b[3m({func_name})\x1b[0m") + self.logger.debug("Environment:") + for key, value in options.environment.env.items(): + self.logger.debug(f"\x1b[1m{key}\x1b[0m: {value}") + else: + for key, value in items: + self.logger.info(f"\x1b[1m{key}\x1b[0m: {value[1]}") + return 0 + + def target_node(self, target, options): + if target == 'node': target = options.get('node_exe') + if target == 'node_g': target = options.get('node_g_exe') + + if (options.get('build_with') == 'make'): + self.dependencies(['config.gypi', 'out/Makefile'], options=options) + + exit_code = self.exec(['make', '-C', 'out', f'BUILDTYPE={options.get("build_type")}', f'V={options.get("log_level")}'], options) + if exit_code != 0: + self.logger.error("Failed to build node") + return exit_code + + os.remove(target) if os.path.exists(target) else None + os.symlink(os.path.join(os.getcwd(), 'out', 'Release', options.get('node_exe')), target) + elif (options.get('build_with') == 'ninja'): + build_type = 'Debug' if target == options.get('node_g_exe') else 'Release' + self.dependencies(['config.gypi', f'out/{build_type}/build.ninja'], options=options) + + ninja_args = options.environment.array('NINJA_ARGS', []) + j_arg = CLI.get('-j') + if j_arg: ninja_args.append(f'-j{j_arg}') + + exit_code = self.exec([options.get('ninja'), '-C', f'out/{build_type}', *ninja_args], options) + if exit_code != 0: + self.logger.error("Failed to build node") + return exit_code + + os.remove(target) if os.path.exists(target) else None + os.symlink(os.path.join(os.getcwd(), f'out/{build_type}/{options.get("node_exe")}'), target) + else: + self.logger.error("Unknown build tool, must be 'make' or 'ninja'") + return 2 + return 0 + + def target_out_makefile(self, target, options): + self.dependencies([ + 'config.gypi', + 'common.gypi', + 'node.gyp', + 'deps/uv/uv.gyp', + 'deps/llhttp/llhttp.gyp', + 'deps/zlib/zlib.gyp', + 'deps/simdutf/simdutf.gyp', + 'deps/ada/ada.gyp', + 'tools/v8_gypfiles/toolchain.gypi', + 'tools/v8_gypfiles/features.gypi', + 'tools/v8_gypfiles/inspector.gypi', + 'tools/v8_gypfiles/v8.gyp' + ], options=options) + + return self.exec([ + sys.executable, + "tools/gyp_node.py", + "-f", "make", + ], options) + + def target_config_gypi(self, target, options): + self.dependencies(['configure', 'configure.py', 'src/node_version.h'], options=options) + return self.exec([sys.executable, 'configure.py'], options) + + def target_install(self, target, options): + return self.exec([ + sys.executable, + target, # install or uninstall + '--dest-dir', options.get('dest_dir'), + '--prefix', options.get('prefix'), + ], options) + + def target_clean(self, target, options): + self.remove([ + os.path.join('out', 'Makefile'), + options.get('node_exe'), + options.get('node_g_exe'), + os.path.join('out', options.get('build_type'), options.get('node_exe')), + 'node_modules', + 'test.tap', + ] + glob.glob('out/*.o') + glob.glob('out/*.a') + glob.glob('out/*.d')) + self.remove([os.path.join('deps', 'icu')], allow_missing=True) + + self.make('testclean', allow_remake=True, must_succeed=False, options=options) + self.make('test-addons-clean', allow_remake=True, must_succeed=False, options=options) + self.make('bench-addons-clean', allow_remake=True, must_succeed=False, options=options) + + return 0 + + def target_testclean(self, target, options): + self.remove(glob.glob('test/tmp*') + glob.glob('test/.tmp*')) + return 0 + + def target_distclean(self, target, options): + self.remove([ + 'out', + 'config.gypi', + 'icu_config.gypi', + 'config.mk', + options.get('node_exe'), + options.get('node_g_exe'), + 'node_modules', + os.path.join('deps', 'icu'), + os.path.join('deps', 'icu-tmp'), + ] + glob.glob('deps/icu4c*.tgz') + + glob.glob('deps/icu4c*.zip') + + glob.glob(f'{options.get("binary_tar")}.*') + + glob.glob(f'{options.get("tarball")}.*') + ) + return 0 + + def target_coverage_clean(self, target, options): + out = os.path.join('out', options.get('build_type'), 'obj.target') + self.remove([ + 'node_modules', + 'gcovr', + os.path.join('coverage', 'tmp') + ] + glob.glob(f'{out}/*.gcda') + glob.glob(f'{out}/*.gcno')) + + return 0 + + def target_coverage_build(self, target, options): + self.dependencies(['all']) + self.make('coverage-build-js', allow_remake=True, must_succeed=False, options=options) + + if not os.path.exists('gcovr'): + self.logger.info('Installing gcovr') + return self.exec([sys.executable, '-m', 'pip', 'install', '-t', 'gcovr', 'gcovr==4.2'], options) + + # $(MAKE)? 253 + return 0 + + def target_coverage_build_js(self, target, options): + os.makedirs('node_modules', exist_ok=True) + if not os.path.exists('node_modules/c8'): + self.logger.info('Installing c8') + return self.exec([options.get('node'), os.path.join('deps', 'npm'), 'install', 'c8', '--no-save', '--no-package-lock'], options) + return 0 + + def target_coverage_test(self, target, options): + self.dependencies(['coverage-build']) + + out = os.path.join('out', options.get('build_type'), 'obj.target') + self.remove(glob.glob(f'{out}/*.gcda') + glob.glob(f'{out}/*.gcno')) + + self.make( + options.get('coverage_tests'), + allow_remake=True, + must_succeed=False, + options=options.new( + environ={'NODE_V8_COVERAGE': 'coverage/tmp'}, + options={'test_ci_args': options.get('test_ci_args') + ['--type=coverage']} + ) + ) + + self.make('coverage-build-js', allow_remake=True, must_succeed=False, options=options) + + os.chdir(os.path.join(os.getcwd(), "out")) + pythonpath_env = dict(self.environment.env) + pythonpath_env["PYTHONPATH"] = os.path.join(os.getcwd(), "..", "gcovr") + subprocess.call([ + sys.executable, + "-m", "gcovr", + "--gcov-exclude='.*\b(deps|usr|out|cctest|embedding)\b'", + "-v", + "-r", "../src/", + "--object-directory", "Release/obj.target", + "--html", + "--html-details", + "-o", "../coverage/cxxcoverage.html", + f"--gcov-executable={self.options['gcov_executable']}", + ], env=pythonpath_env) + os.chdir(os.path.join(os.getcwd(), "..")) + + self.logger.info(r"Javascript Coverage \%\%: ") + with open("coverage/index.html", "r") as f: + lines = f.readlines() + for line in lines: + if "Lines" in line: + found_line = lines[lines.index(line) - 1] + self.logger.info(re.sub('s/<[^>]*>//g', '', found_line).strip()) + break + f.close() + + self.logger.info(r"C++ Coverage \%\%: ") + with open("coverage/cxxcoverage.html", "r") as f: + lines = f.readlines() + for line in lines: + if "Lines" in line: + context_lines = lines[lines.index(line) - 3:lines.index(line)] + for context_line in context_lines: + if "style" in context_line: + found_line = context_line + break + self.logger.info(re.sub('s/<[^>]*>//g', '', found_line).strip()) + break + f.close() + + return 0 + + def target_coverage_report_js(self, target, options): + self.make('coverage-build-js', allow_remake=True, must_succeed=False, options=options) + return self.exec([ + options.get('node'), + os.path.join('deps', 'c8', 'bin', 'c8'), + 'report', + ], options) + + def target_cctest(self, target, options): + self.dependencies(['all'], options=options) + exit = self.exec([ + f"out/{options.get('build_type')}/node", + "--gtest_filter=" + options.get('gtest_filter'), + ], options) + + if exit != 0: return exit + + return self.exec([ + options.get('node'), + os.path.join('test', 'embedding', 'test-embedding.js'), + ], options) + + def target_list_gtests(self, target, options): + if not os.path.exists(os.path.join(os.getcwd(), "out", options.get('build_type'), "cctest")): + self.logger.error("cctest not found, run 'cctest'") + return 1 + + return self.exec([ + os.path.join(os.getcwd(), "out", options.get('build_type'), "cctest"), + "--gtest_list_tests" + ], options) + + def target_v8(self, target, options): + return self.exec([ + os.path.join('tools', 'make-v8.sh'), + f"{options.get('v8_arch')}.{options.get('build_type').lower()}", + ] + options.get('v8_build_options'), options) + + def target_jstest(self, target, options): + self.dependencies(['build-addons', 'build-js-native-api-tests', 'build-node-api-tests'], options=options) + return self.exec([ + sys.executable, + os.path.join(os.getcwd(), "tools", "test.py"), + ] + options.get('parallel_args') + [ + f"--skip-tests={','.join(options.get('ci_skip_tests'))}", + ] + options.get('test_ci_args') + options.get('js_suites') + options.get('native_suites'), options) + + def target_tooltest(self, target, options): + return self.exec([ + sys.executable, + '-m', 'unittest', + 'discover', + '-s', os.path.join('test', 'tools'), + ], options) + + def target_coverage_run_js(self, target, options): + self.remove(['coverage/tmp']) + + self.make( + target='jstest', + allow_remake=True, + must_succeed=False, + options=options.new( + environ={ + 'NODE_V8_COVERAGE': 'coverage/tmp', + }, + options={ + 'ci_skip_tests': options.get('coverage_skip_tests'), + 'test_ci_args': options.get('test_ci_args') + ['--type=coverage'] + } + ) + ) + + return self.make('coverage-report-js', allow_remake=True, must_succeed=False, options=options) + + def target_test(self, target, options): + self.dependencies(['all'], options=options) + + makes = ['tooltest', 'test-doc', 'build-addons', 'build-js-native-api-tests', 'build-node-api-tests', 'cctest', 'jstest'] + for make in makes: + self.make(make, allow_remake=True, must_succeed=False, options=options) + return 0 + + def target_test_only(self, target, options): + self.dependencies(['all'], options=options) + + makes = ['build-addons', 'build-js-native-api-tests', 'build-node-api-tests', 'cctest', 'jstest', 'tooltest'] + for make in makes: + self.make(make, allow_remake=True, must_succeed=False, options=options) + return 0 + + def target_test_cov(self, target, options): + self.dependencies(['all'], options=options) + + makes = ['build-addons', 'build-js-native-api-tests', 'build-node-api-tests', 'cctest'] + for make in makes: + self.make(make, allow_remake=True, must_succeed=False, options=options) + + return self.make( + target='jstest', + allow_remake=True, + must_succeed=False, + options=options.new( + options={ + 'ci_skip_tests': options.get('coverage_skip_tests'), + } + ) + ) + + def target_test_valgrind(self, target, options): + self.dependencies(['all'], options=options) + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + f'--mode={options.get("build_type").lower()}', + '--valgrind', 'sequential', 'parallel', 'message', + ], options) + + def target_test_check_deopts(self, target, options): + self.dependencies(['all'], options=options) + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + f'--mode={options.get("build_type").lower()}', + '--check-deopts', 'parallel', 'message', + ], options) + + def target_test_addons_headersbuildstamp(self, target, options): + self.dependencies(options.get('addons_headers_prerequisities'), options=options) + self.exec([ + sys.executable, + os.path.join('tools', 'install.py'), + 'install', + '--headers-only', + '--dest-dir', options.get('addons_header_dir'), + '--prefix', '/' + ]) + + os.open(target, "w").close() + return 0 + + def target_test_addons_buildstamp(self, target, options): + self.dependencies( + options.get('addons_prerequisities') + + options.get('addons_binding_gypfiles') + + options.get('addons_binding_sources') + , options=options) + + self.run_build_addons(os.path.join(os.getcwd(), 'test', 'addons'), target, options) + return 0 + + def target_test_addons_docbuildstamp(self, target, options): + self.dependencies(options.get('docbuildstamp_prerequisites') + ['tools/doc/node_modules'], options=options) + if not self.node_has_openssl(): + self.logger.warn('Skipping doc build, missing openssl') + return 0 + + self.remove(glob.glob('test/addons/??_*/')) + + try: + self.try_node(options.get('docbuildstamp_prerequisites')[0]) + except: + return 0 + + os.open(target, "w").close() + return 0 + + def target_build_addons(self, target, options): + self.dependencies([ + 'test/addons/.headersbuildstamp', + 'test/addons/.buildstamp', + ], must_make=False, options=options) + return 0 + + def target_test_js_native_api_buildstamp(self, target, options): + self.dependencies( + options.get('addons_prerequisites') + + options.get('js_native_api_binding_gypfiles') + + options.get('js_native_api_binding_sources') + + ['src/js_native_api_v8.h', 'src/js_native_api_v8_internals.h'] + , options=options) + + self.run_build_addons(os.path.join(os.getcwd(), 'test', 'js-native-api'), target, options) + return 0 + + def target_build_js_native_api_tests(self, target, options): + self.dependencies([ + self.options.get('node_exe'), + 'test/js-native-api/.buildstamp', + ], must_make=False, options=options) + + return 0 + + def target_test_node_api_buildstamp(self, target, options): + self.dependencies( + options.get('addons_prerequisites') + + options.get('node_api_binding_gypfiles') + + options.get('node_api_binding_sources') + + ['src/node_api.h', 'src/node_api_types.h'] + , options=options) + + self.run_build_addons(os.path.join(os.getcwd(), 'test', 'node-api'), target, options) + return 0 + + def target_build_node_api_tests(self, target, options): + self.dependencies([ + self.options.get('node_exe'), + 'test/node-api/.buildstamp', + ], must_make=False, options=options) + + return 0 + + def target_test_benchmark_napi_buildstamp(self, target, options): + self.dependencies( + options.get('addons_prerequisites') + + options.get('benchmark_napi_binding_gypfiles') + + options.get('benchmark_napi_binding_sources') + , options=options) + + self.run_build_addons(os.path.join(os.getcwd(), 'test', 'benchmark-napi'), target, options) + return 0 + + def target_test_build(self, target, options): + self.dependencies(['all', 'build-addons', 'build-js-native-api-tests', 'build-node-api-tests'], must_make=False, options=options) + return 0 + + def target_test_build_js_native_api(self, target, options): + self.dependencies(['all', 'build-js-native-api-tests'], options=options) + return 0 + + def target_test_build_node_api(self, target, options): + self.dependencies(['all', 'build-node-api-tests'], options=options) + return 0 + + def target_test_all(self, target, options): + self.dependencies(['test-build'], options=options) + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + '--mode=debug,release', + ], options) + + def target_test_all_valgrind(self, target, options): + self.dependencies(['test-build'], options=options) + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + '--mode=debug,release', + '--valgrind', + ], options) + + def target_test_all_suites(self, target, options): + self.dependencies(['test-build', 'bench-addons-build', 'doc-only'], must_make=False, options=options) + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + f'--mode={options.get("build_type").lower()}', + 'test/*', + ], options) + + def target_test_ci_native(self, target, options): + custom_options = { 'LOGLEVEL': 'info' } + self.dependencies([ + 'benchmark/napi/.buildstamp', + 'test/addons/.buildstamp', + 'test/js-native-api/.buildstamp', + 'test/node-api/.buildstamp', + ], must_make=False, options=options) + + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + '-p', 'tap', + '--logfile', 'test.tap', + f'--mode={options.get("build_type").lower()}', + f'--flaky-tests={options.get("flaky_tests")}', + ] + options.get('test_ci_args') + options.get('ci_native_suites'), options.new(environ=custom_options)) + + def target_test_ci_js(self, target, options): + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + '-p', 'tap', + '--logfile', 'test.tap', + f'--mode={options.get("build_type").lower()}', + f'--flaky-tests={options.get("flaky_tests")}', + ] + options.get('test_ci_args') + options.get('ci_js_suites'), options) + + def target_test_ci(self, target, options): + custom_options = { 'LOGLEVEL': 'info' } + self.dependencies([ + 'bench-addons-build', + 'build-addons', + 'build-js-native-api-tests', + 'build-node-api-tests', + 'doc-only', + ], must_make=False, options=options) + + ci_doc = ['doctool'] if self.node_has_openssl() else [] + + self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + '-p', 'tap', + '--logfile', 'test.tap', + f'--mode={options.get("build_type").lower()}', + f'--flaky-tests={options.get("flaky_tests")}', + ] + options.get('test_ci_args') + options.get('ci_native_suites') + options.get('ci_js_suites') + [ci_doc], options.new(environ=custom_options)) + + return self.exec([options.get('node', os.path.join('test', 'embedding', 'test-embedding.js'))], options) + + def target_build_ci(self, target, options): + return self.exec([ + sys.executable, + './configure', + '--verbose', + ] + options.get('config_flags'), options) + # $(MAKE)? 581 + + def target_run_ci(self, target, options): + self.dependencies(['build-ci'], options=options) + return self.make('test-ci', allow_remake=True, must_succeed=False, options=options) # -j1 + + def target_run_test(self, target, options): + match = re.match(r"run-test-(\w+)", target) + mode = match.group(1) + return self.exec(sys.executable, os.path.join('tools', 'test.py'), f'--mode={mode}') + + def target_test_wpt(self, target, options): + self.dependencies(['all'], options=options) + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + '--wpt', + ], options) + + def target_test_wpt_report(self, target, options): + self.remove('out/wpt') + os.makedirs('out/wpt') + self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + '--shell', options.get('node'), + ] + options.get('parallel_args') + [ + 'wpt' + ], options.new(environ={'WPT_REPORT': '1'})) + + return self.exec([ + options.get('node'), + os.path.join('tools', 'merge-wpt-reports.mjs'), + ]) + + def target_test_system(self, target, options): + self.dependencies(['all'], options=options) + # test- + match = re.match(r"test-([^\s]+)", target) + system = match.group(1) + parallel = options.get('parallel_args') + if match == 'known-issues': + parallel = [] + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + parallel + [ + system, + ], options) + + def target_test_hash_seed(self, target, options): + self.dependencies(['all'], options=options) + return self.exec([ + options.get('node'), + os.path.join(os.getcwd(), 'test', 'pummel', 'test-hash-seed.js'), + ], options) + + def target_test_doc(self, target, options): + self.dependencies(['doc-only', 'lint-md'], options=options) + if self.node_has_openssl(): + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + 'doctool', + ]) + else: + self.logger.warn('Skipping doc tests, missing openssl') + return 0 + + def target_test_doc_ci(self, target, options): + self.dependencies(['doc-only'], options=options) + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + options.get('test_ci_args') + ['doctool'], options) + + def target_test_npm(self, target, options): + self.dependencies([options.get('node_exe')], options=options) + return self.exec([ + options.get('node'), + os.path.join(os.getcwd(), "tools", "test-npm-package"), + '--install', '--logfile=test-npm.tap', + 'deps/npm', 'test' + ], options) + + def target_test_npm_publish(self, target, options): + self.dependencies([options.get('node_exe')], options=options) + return self.exec([ + options.get('node'), + os.path.join(os.getcwd(), "deps", "npm", "test", "run.js") + ], options.new(environ={'npm_package_config_publishtest': 'true'})) + + def target_test_js_native_api(self, target, options): + self.dependencies(['test-build-js-native-api-tests'], options=options) + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + f'--mode={options.get("build_type").lower()}', + 'js-native-api', + ], options) + + def target_test_js_native_api_clean(self, target, options): + self.remove(glob.glob('test/js-native-api/*/build') + ["test/js-native-api/.buildstamp"]) + return 0 + + def target_test_node_api(self, target, options): + self.dependencies(['test-build-node-api-tests'], options=options) + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + f'--mode={options.get("build_type").lower()}', + 'node-api', + ], options) + + def target_test_node_api_clean(self, target, options): + self.remove(glob.glob('test/node-api/*/build') + ["test/node-api/.buildstamp"]) + return 0 + + def target_test_addons(self, target, options): + self.dependencies(['test-build', 'test-js-native-api', 'test-node-api'], options=options) + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + f'--mode={options.get("build_type").lower()}', + 'addons', + ], options) + + def target_test_addons_clean(self, target, options): + self.remove( + [options.get('addons_header_dir'), 'test/addons/.buildstamp', 'test/addons/.headersbuildstamp', 'test/addons/.docbuildstamp'] + + glob.glob('test/addons/*/build') + + glob.glob('test/addons/??_*/') + ) + + self.make('test-js-native-api-clean', allow_remake=True, must_succeed=False, options=options) + return self.make('test-node-api-clean', allow_remake=True, must_succeed=False, options=options) + + def target_test_with_async_hooks(self, target, options): + self.dependencies(['build-addons', 'build-js-native-api-tests', 'build-node-api-tests', 'cctest'], options=options) + + return self.exec([ + sys.executable, + os.path.join('tools', 'test.py'), + ] + options.get('parallel_args') + [ + f'--mode={options.get("build_type").lower()}', + ] + options.get('js_suites') + options.get('native_suites'), options=options.new(environ={'NODE_TEST_WITH_ASYNC_HOOKS': '1'})) + + def target_test_v8(self, target, options): + self.dependencies(['v8'], options=options) + + if not self.is_v8_testing_available(): return 1 + + self.exec([ + sys.executable, + os.path.join(os.getcwd(), "deps", "v8", "tools", "run-tests.py"), + "--gn", + f"--arch={options.get('v8_arch')}", + ] + options.get('v8_test_options') + [ + "mjsunit", + "cctest", + "debugger", + "inspector", + "message", + "preparser", + ] + options.get('tap_v8'), options) + + return self.make('test-hash-seed', allow_remake=True, must_succeed=False, options=options) + + def target_test_v8_system(self, target, options): + self.dependencies(['v8'], options=options) + + if not self.is_v8_testing_available(): return 1 + + match = re.match(r"test-v8-(\w+)", target) + system = match.group(1) + + self.exec([ + sys.executable, + os.path.join(os.getcwd(), "deps", "v8", "tools", "run-tests.py"), + "--gn", + f"--arch={options.get('v8_arch')}", + system, + ] + options.get('tap_v8_' + system), options) + + convert_to_junit(options.get('tap_v8_' + system + '_json')) + return 0 + + def target_test_v8_updates(self, target, options): + return self.exec([ + sys.executable, + os.path.join(os.getcwd(), "deps", "test.py"), + ] + options.get('parallel_args') + [ + f"--mode={options.get('build_type').lower()}", + 'v8-updates', + ], options) + + def target_test_v8_all(self, target, options): + self.dependencies(['test-v8', 'test-v8-intl', 'test-v8-benchmarks', 'test-v8-updates'], options=options) + return 0 + + def target_tools_doc_node_modules(self, target, options): + if not self.node_has_openssl(): + self.logger.warn('Skipping installing doc node modules, missing openssl') + return 0 + os.chdir(os.path.join(os.getcwd(), 'tools', 'doc')) + self.try_node([ + os.path.join(os.getcwd(), self.options["NPM"]), + "ci", + "--no-package-lock" + ]) + os.chdir(os.path.join(os.getcwd(), "..", "..")) + return 0 + + def target_doc_only(self, target, options): + self.dependencies(['tools/doc/node_modules'] + options.get('api_documentation_directories') + options.get('api_documentation_assets'), options=options) + + if not self.node_has_openssl(): + self.logger.warn('Skipping doc build, missing openssl') + return 0 + + self.make('out/doc/api/all.html', allow_remake=True, must_succeed=False, options=options) + self.make('out/doc/api/all.json', allow_remake=True, must_succeed=False, options=options) + self.make('out/doc/api/stability', allow_remake=True, must_succeed=False, options=options) + return 0 + + def target_doc(self, target, options): + self.dependencies([options.get('node_exe'), 'doc-only'], options=options) + return 0 + + def target_out_doc(self, target, options): + os.makedirs(os.path.join('out', 'doc'), exist_ok=True) + return 0 + + def target_out_doc_api(self, target, options): + os.makedirs(os.path.join('out', 'doc', 'api'), exist_ok=True) + shutil.copytree( + os.path.join(os.getcwd(), 'doc', 'api'), + os.path.join(os.getcwd(), 'out', 'doc', 'api'), + dirs_exist_ok=True + ) + return 0 + + def target_out_doc_api_assets(self, target, options): + os.makedirs(os.path.join('out', 'doc', 'api', 'assets'), exist_ok=True) + + if os.path.exist(os.path.join('doc', 'api', 'assets')): + shutil.copytree( + os.path.join(os.getcwd(), 'doc', 'api', 'assets'), + os.path.join(os.getcwd(), 'out', 'doc', 'api', 'assets'), + dirs_exist_ok=True + ) + return 0 + + def target_out_doc_api_assets_wildcard(self, target, options): + filename = os.path.basename(target) + self.dependencies(['out/doc/api/assets', f'doc/api_assets/{filename}'], options=options) + + shutil.copy( + os.path.join(os.getcwd(), 'doc', 'api_assets', filename), + os.path.join(os.getcwd(), 'out', 'doc', 'api', 'assets', filename) + ) + + self.remove(['out/doc/api/assets/README.md']) + return 0 + + def target_link_data_file(self, target, options): + lib = glob.glob('lib/*.js') + self.dependencies(['out/doc'] + lib + ['tools/doc/apilinks.mjs'], options=options) + self.try_node(os.path.join('tools', 'doc', 'apilinks.mjs'), target, *lib) + return 0 + + def target_versions_data_file(self, target, options): + self.dependencies(['CHANGELOG.md', 'src/node_version.h', 'tools/doc/versions.mjs'], options=options) + self.try_node(os.path.join('tools', 'doc', 'versions.mjs'), target) + return 0 + + def target_out_doc_api_wildcard(self, target, options): + filename = os.path.basename(target) + self.dependencies([ + options.get('link_data_file'), + 'out/doc/api', + f'doc/api/{filename.replace(".html", ".md")}', + 'tools/doc/generate.mjs', + 'tools/doc/markdown.mjs', + 'tools/doc/html.mjs', + 'tools/doc/json.mjs', + 'tools/doc/apilinks.mjs', + options.get('versions_data_file'), + ], options=options) + + if not self.node_has_icu(): + self.logger.warn('Skipping doc build, missing icu') + return 0 + + self.try_node( + os.path.join('tools', 'doc', 'generate.mjs'), + f'--node-version={options.get("full_version")}', + f'--apilinks={options.get("link_data_file")}', + f'doc/api/{filename.replace(".html", ".md")}', + '--output-directory=out/doc/api', + f'--versions-file={options.get("versions_data_file")}', + ) + + return 0 + + def target_out_doc_api_all_html(self, target, options): + self.dependencies(['out/doc/api'] + options.get('api_documentation_html') + ['tools/doc/allhtml.mjs', 'tools/doc/apilinks.mjs'], options=options) + + if not self.node_has_icu(): + self.logger.warn('Skipping doc build, missing icu') + return 0 + + self.try_node(os.path.join('tools', 'doc', 'allhtml.mjs')) + return 0 + + def target_out_doc_api_all_json(self, target, options): + self.dependencies(['out/doc/api'] + options.get('api_documentation_json') + ['tools/doc/alljson.mjs'], options=options) + + if not self.node_has_icu(): + self.logger.warn('Skipping doc build, missing icu') + return 0 + + self.try_node(os.path.join('tools', 'doc', 'alljson.mjs')) + return 0 + + def target_out_doc_api_stability(self, target, options): + self.dependencies(['out/doc/api', 'out/doc/api/all.json', 'tools/doc/stability.mjs'], options=options) + + if not self.node_has_icu(): + self.logger.warn('Skipping doc build, missing icu') + return 0 + + self.try_node(os.path.join('tools', 'doc', 'stability.mjs')) + return 0 + + def target_docopen(self, target, options): + self.dependencies(['out/doc/api/all.html'], options=options) + return self.exec([sys.executable, '-m', 'webbrowser', pathlib.Path(os.getcwd(), 'out', 'doc', 'api', 'all.html').as_uri()]) + + def target_docserve(self, target, options): + self.dependencies(options.get('api_documentation_html') + options.get('api_documentation_assets'), options=options) + return self.exec([sys.executable, '-m', 'http.server', '8000', '--bind', '127.0.0.1', '--directory', 'out/doc/api']) + + def target_docclean(self, target, options): + self.remove(['out/doc', self.options['versions_data_file']]) + return 0 + + def target_release_only(self, target, options): + dist_type = options.get("distribution_type") + release = options.get("release") + + if dist_type == "release": + for file in glob.glob("doc/api/*.md"): + with open(file, "r") as f: + if "REPLACEME" in f.read(): + f.close() + self.logger.error(f"REPLACEME present in {file}") + return 1 + f.close() + with open("doc/api/deprecations.md", "r") as f: + if "DEP...X" in f.read(): + f.close() + self.logger.error("DEP...X present in doc/api/deprecations.md") + return 1 + f.close() + if not release: + self.logger.error("#NODE_VERSION_IS_RELEASE is not set to 1") + return 1 + + porcelian = self.exec(["git", "status", "--porcelain"]) + if any(line.startswith("??") for line in porcelian.splitlines()): + self.logger.error("The git repository is not clean") + return 1 + + if not release and not os.path.exists(options.get("changelog")): + Logger.error("Error: #NODE_VERSION_IS_RELEASE's CHANGELOG.md does not exist") + return 1 + + return 0 + + def make_pkg(self, cpu, options, out_dir, environ={}): + if cpu == 'x64': + prefix_dir = os.path.join(out_dir, 'dist', 'x64', 'node') + else: + prefix_dir = os.path.join(out_dir, 'dist', 'node') + + self.exec([ + sys.executable, + './configure', + f'--dest-cpu={cpu}', + f'--tag={options.get("tag")}', + f'--release-urlbase={options.get("release_urlbase")}', + ] + options.get('config_flags') + options.get('build_release_flags'), options=options.new( + environ=environ + )) + + self.make('install', allow_remake=True, must_succeed=False, options=options.new(environ={'DESTDIR': os.path.join(prefix_dir)})) + + return self.exec(['sh', 'tools/osx-codesign.sh'], options=options.new( + environ={ + 'SIGN': options.get('codesign_certificate'), + 'PKGDIR': os.path.join(prefix_dir, 'usr', 'local'), + } + )) + + def target_pkg(self, target, options): + self.dependencies(['release-only'],options=options) + + if options.get('platform') != 'darwin' or options.get('arch') != 'arm64': + self.logger.error("Only macOS arm64 is supported") + return 1 + + out_dir = options.get('macos_output_directory') + full_version = options.get('full_version') + npm_version = options.get('npm_version') + + self.remove([out_dir]) + os.makedirs(os.path.join(out_dir, 'installer', 'productbuild'), exist_ok=True) + + self.fill_template( + os.path.join('tools', 'macos-installer', 'productbuild', 'distribution.xml.tmpl'), + os.path.join(out_dir, 'installer', 'productbuild', 'distribution.xml'), + full_version, + npm_version + ) + + for directory in glob.glob("tools/macos-installer/productbuild/Resources/*/"): + lang = os.path.basename(directory) + os.makedirs(os.path.join(out_dir, 'installer', 'productbuild', 'Resources', lang), exist_ok=True) + + self._fill_template( + os.path.join('tools', 'macos-installer', 'productbuild', 'Resources', lang, 'welcome.html.tmpl'), + os.path.join(out_dir, 'installer', 'productbuild', 'Resources', lang, 'welcome.html'), + full_version, + npm_version + ) + + self._fill_template( + os.path.join('tools', 'macos-installer', 'productbuild', 'Resources', lang, 'conclusion.html.tmpl'), + os.path.join(out_dir, 'installer', 'productbuild', 'Resources', lang, 'conclusion.html'), + full_version, + npm_version + ) + + CC = "cc -arch x86_64" + CXX = "c++ -arch x86_64" + self.make_pkg('x64', options, out_dir, environ={ + 'CC': CC, + 'CXX': CXX, + 'CC_host': CC, + 'CXX_host': CXX, + 'CC_target': CC, + 'CXX_target': CXX, + }) + self.make_pkg('arm64', options, out_dir) + + self.exec([ + "lipo", + os.path.join(out_dir, 'dist', 'x64', 'node', 'usr', 'local', 'bin', 'node'), + os.path.join(out_dir, 'dist', 'node', 'usr', 'local', 'bin', 'node'), + "-output", + os.path.join(out_dir, 'dist', 'node', 'usr', 'local', 'bin', 'node'), + "-create" + ], options) + + os.makedirs(os.path.join(out_dir, 'dist', 'npm', 'usr', 'local', 'lib', 'node_modules'), exist_ok=True) + os.makedirs(os.path.join(out_dir, 'pkg'), exist_ok=True) + + shutil.copytree( + os.path.join(out_dir, 'dist', 'node', 'usr', 'local', 'lib', 'node_modules', 'npm'), + os.path.join(out_dir, 'dist', 'npm', 'usr', 'local', 'lib', 'node_modules', 'npm'), + dirs_exist_ok=True + ) + + os.unlink(os.path.join(out_dir, 'dist', 'npm', 'usr', 'local', 'lib', 'node_modules', 'npm', 'bin', 'npm')) + os.unlink(os.path.join(out_dir, 'dist', 'npm', 'usr', 'local', 'lib', 'node_modules', 'npm', 'bin', 'npx')) + + self.exec([options.get('node'), 'tools/license2rtf.js', '<', 'LICENSE.md', '>', os.path.join(out_dir, 'installer', 'productbuild', 'Resources', 'License.rtf')]) + + shutil.copy( + os.path.join('doc', 'osx_installer_logo.png'), + os.path.join(out_dir, 'installer', 'productbuild', 'Resources', 'osx_installer_logo.png') + ) + + self.exec([ + "pkgbuild", + "--version", full_version, + "--identifier", "org.nodejs.node.pkg", + '--root', os.path.join(out_dir, 'dist', 'node'), + os.path.join(out_dir, 'pkgs', f'node-{full_version}.pkg'), + ], options) + + self.exec([ + "pkgbuild", + "--version", npm_version, + "--identifier", "org.nodejs.npm.pkg", + '--root', os.path.join(out_dir, 'dist', 'npm'), + '--scripts', os.path.join('tools', 'macos-installer', 'pkgbuild', 'npm', 'scripts'), + os.path.join(out_dir, 'pkgs', f'npm-{npm_version}.pkg'), + ], options) + + self.exec([ + "productbuild", + '--distribution', os.path.join(out_dir, 'installer', 'productbuild', 'distribution.xml'), + '--resources', os.path.join(out_dir, 'installer', 'productbuild', 'Resources'), + '--package-path', os.path.join(out_dir, 'pkgs'), f'./{options.get("pkg")}' + ], options) + + self.exec(['sh', os.path.join('tools', 'osx-productsign.sh')], options=options.new(environ={ + 'SIGN': options.get('codesign_certificate'), + 'PKG': options.get('pkg'), + })) + + return self.exec([ + "sh", "tools/osx-notarize.sh", + full_version + ], options) + + def target_corepack_update(self, target, options): + if not HAS_REQUESTS: + self.logger.error("requests is required to update corepack") + return 1 + + temp_dir = tempfile.mkdtemp() + url = self.exec_output(['npm', 'view', 'corepack', 'dist.tarball']) + + response = requests.get(url) + with open(os.path.join(temp_dir, 'corepack.tgz'), 'wb') as f: + f.write(response.content) + f.close() + + with tarfile.open(os.path.join(temp_dir, 'corepack.tgz')) as tar: + tar.extractall(temp_dir) + + shutil.move(os.path.join(temp_dir, 'package'), os.path.join('deps', 'corepack')) + + self.remove(temp_dir) + + for file in glob.glob('deps/corepack/shims/*'): + os.chmod(file, 0o755) + + return 0 + + def target_tarball(self, target, options): + self.dependencies(['release-only', 'doc-only'], options=options) + + tarname = options.get('tar_name') + self.exec(['git', 'checkout-index', '-a', '-f', f'--prefix={tarname}/']) + shutil.copyfile(os.path.join('doc', 'node.1'), os.path.join(tarname, 'doc', 'api', 'node.1')) + shutil.copytree(os.path.join('out', 'doc', 'api'), os.path.join(tarname, 'doc', 'api'), dirs_exist_ok=True) + + self.remove([ + os.path.join(tarname, '.editorconfig'), + os.path.join(tarname, '.mailmap'), + os.path.join(tarname, 'deps', 'openssl', 'openssl', 'demos'), + os.path.join(tarname, 'deps', 'openssl', 'openssl', 'doc'), + os.path.join(tarname, 'deps', 'openssl', 'openssl', 'test'), + os.path.join(tarname, 'deps', 'uv', 'docs'), + os.path.join(tarname, 'deps', 'uv', 'samples'), + os.path.join(tarname, 'deps', 'uv', 'test'), + os.path.join(tarname, 'deps', 'v8', 'samples'), + os.path.join(tarname, 'deps', 'v8', 'tools/profviz'), + os.path.join(tarname, 'deps', 'v8', 'tools/run-test.py'), + os.path.join(tarname, 'doc', 'images'), + os.path.join(tarname, 'tools', 'cpplint.py'), + os.path.join(tarname, 'tools', 'eslint-rules'), + os.path.join(tarname, 'tools', 'license-builder.sh'), + os.path.join(tarname, 'tools', 'node_modules'), + os.path.join(tarname, 'tools', 'osx-pkg.pmdoc') + ] + ( + glob.glob(f'{tarname}/.git*') + + glob.glob(f'{tarname}/test*.tap') + + glob.glob(f'{tarname}/osx-*') + )) + + self.remove( + anti_glob( + '.*/test/torque$', + glob.glob(f"{tarname}/deps/v8/test/*", recursive=True) + ), + only_dirs=True + ) + + self.remove( + anti_glob( + '.*/test/torque/.*', + glob.glob(f"{tarname}/deps/v8/test/**", recursive=True) + ), + only_files=True + ) + + self.remove( + anti_glob( + '.*/contrib/optimizations$', + glob.glob(f"{tarname}/deps/zlib/contrib/**", recursive=True) + ), + only_dirs=True + ) + + self.remove( + max_depth( + 3, + glob.glob(f"{tarname}/deps/v8/test/**", recursive=True) + ), + only_files=True + ) + + for file in os.walk(tarname): + if os.path.islink(file): + os.remove(file) + + shutil.make_archive(tarname, "tar", tarname) + self.remove(tarname) + # convert the tar to a gzip w/ level 9 compression + with open(f"{tarname}.tar", "rb") as f: + with gzip.open(f"{tarname}.tar.gz", "wb", compresslevel=9) as f_out: + shutil.copyfileobj(f, f_out) + f_out.close() + f.close() + + self.remove(f"{tarname}.tar") + return 0 + + def target_tar_upload(self, target, options): + self.dependencies(['tar'], options=options) + self.exec(['ssh', options.get('staging_server'), f'mkdir -p nodejs/{options.get("distribution_type")}/{options.get("full_version")}'], options=options) + self.exec(['chmod', '664', f'{options.get("tar_name")}.tar.gz'], options) + self.exec([ + 'scp', + f'{options.get("tar_name")}.tar.gz', + f'{options.get("staging_server")}:nodejs/{options.get("distribution_type")}/{options.get("full_version")}/'], + options + ) + return self.exec([ + 'ssh', + options.get('staging_server'), + f'touch nodejs/{options.get("distribution_type")}/{options.get("full_version")}/{options.get("tar_name")}.tar.gz.done'], + options + ) + + def target_doc_upload(self, target, options): + self.dependencies(['doc'], options=options) + self.exec(['ssh', options.get('staging_server'), f'mkdir -p nodejs/{options.get("distribution_type")}/{options.get("full_version")}/docs/'], options=options) + self.exec(['chmod', '-R', 'ug=rw-x=X,o=r+X', 'out/doc'], options) + self.exec(['scp', '-pr', 'out/doc/*', f'{options.get("staging_server")}:nodejs/{options.get("distribution_type")}/{options.get("full_version")}/docs/'], options) + return self.exec(['ssh', options.get('staging_server'), f'touch nodejs/{options.get("distribution_type")}/{options.get("full_version")}/docs.done'], options) + + def target_tarball_headers(self, target, options): + self.dependencies(['release-only'], options=options) + tarname = options.get('tar_name') + self.exec([ + sys.executable, + './configure.py', + '--prefix=/', + f'--dest-cpu={options.get("arch")}', + f'--tag={options.get("tag")}', + f'--release-urlbase={options.get("release_urlbase")}', + ] + options.get('config_flags') + options.get('build_release_flags'), options=options) + self.exec([ + sys.executable, + os.path.join('tools', 'install.py'), + 'install', '--headers-only', + '--dest-dir', tarname, + '--prefix', '/', + ]) + + for file in os.walk(tarname): + if os.path.islink(file): + os.remove(file) + + shutil.make_archive(f'{tarname}-headers', "tar", tarname) + self.remove(tarname) + # convert the tar to a gzip w/ level 9 compression + with open(f"{tarname}-headers.tar", "rb") as f: + with gzip.open(f"{tarname}-headers.tar.gz", "wb", compresslevel=9) as f_out: + shutil.copyfileobj(f, f_out) + f_out.close() + f.close() + + self.remove(f"{tarname}-headers.tar") + return 0 + + def target_tar_headers_upload(self, target, options): + self.dependencies(['tarball-headers'], options=options) + self.exec(['ssh', options.get('staging_server'), f'mkdir -p nodejs/{options.get("distribution_type")}/{options.get("full_version")}/'], options=options) + self.exec(['chmod', '664', f'{options.get("tar_name")}-headers.tar.gz'], options) + self.exec([ + 'scp', + f'{options.get("tar_name")}-headers.tar.gz', + f'{options.get("staging_server")}:nodejs/{options.get("distribution_type")}/{options.get("full_version")}/' + ], options) + return self.exec([ + 'ssh', + options.get('staging_server'), + f'touch nodejs/{options.get("distribution_type")}/{options.get("full_version")}/{options.get("tar_name")}-headers.tar.gz.done' + ], options) + + def target_binary_tar(self, target, options): + self.dependencies(['release-only'], options=options) + + binary_name = options.get('binary_name') + self.remove([binary_name, 'out/deps', 'out/Release']) + self.exec([ + sys.executable, + './configure.py', + f'--dest-cpu={options.get("arch")}', + f'--tag={options.get("tag")}', + f'--release-urlbase={options.get("release_urlbase")}', + ] + options.get('config_flags') + options.get('build_release_flags'), options=options) + + self.make('install', allow_remake=True, must_succeed=False, options=options.new(environ={'DESTDIR': binary_name, 'PORTABLE': '1'})) + shutil.copy('LICENSE', os.path.join(binary_name, 'LICENSE')) + shutil.copy('README.md', os.path.join(binary_name, 'README.md')) + + if os.path.exists(options.get('changelog')): + shutil.copy(options.get('changelog'), os.path.join(binary_name, 'CHANGELOG.md')) + else: + shutil.copy('CHANGELOG.md', os.path.join(binary_name, 'CHANGELOG.md')) + + if options.get('platform') == 'darwin': + self.exec(['sh', 'tools/osx-codesign.sh'], options=options.new(environ={ + 'SIGN': options.get('codesign_certificate'), + 'PKGDIR': binary_name, + })) + + shutil.make_archive(binary_name, "tar", binary_name) + self.remove(binary_name) + + with open(f"{binary_name}.tar", "rb") as f: + with gzip.open(f"{binary_name}.tar.gz", "wb", compresslevel=9) as f_out: + shutil.copyfileobj(f, f_out) + f_out.close() + f.close() + + self.remove(f"{binary_name}.tar") + return 0 + + def target_binary_upload(self, target, options): + self.dependencies(['binary'], options=options) + self.exec(['ssh', options.get('staging_server'), f'mkdir -p nodejs/{options.get("distribution_type")}/{options.get("full_version")}/'], options=options) + self.exec(['chmod', '664', f'{options.get("binary_name")}.tar.gz'], options) + self.exec([ + 'scp', + f'{options.get("binary_name")}.tar.gz', + f'{options.get("staging_server")}:nodejs/{options.get("distribution_type")}/{options.get("full_version")}/' + ], options) + return self.exec([ + 'ssh', + options.get('staging_server'), + f'touch nodejs/{options.get("distribution_type")}/{options.get("full_version")}/{options.get("binary_name")}.tar.gz.done' + ], options) + + def target_bench_addons_build(self, target, options): + self.dependencies([options.get('node_exe'), 'benchmark/napi/.buildstamp'], must_make=False, options=options) + return 0 + + def target_bench_addons_clean(self, target, options): + self.remove(['benchmark/napi/.buildstamp'] + glob.glob('benchmark/napi/*/build')) + return 0 + + def target_lint_md_rollup(self, target, options): + self.remove(glob.glob('tools/.*mdlintstamp')) + os.chdir(os.path.join('tools', 'lint-md')) + self.exec(['npm', 'ci'], options) + self.exec(['npm', 'run', 'build'], options) + os.chdir(os.path.join('..', '..')) + return 0 + + def target_lint_md_clean(self, target, options): + self.remove(glob.glob('tools/.*mdlintstamp') + glob.glob('tools/lint-md/node_modules')) + return 0 + + def target_tools_mdlintstamp(self, target, options): + self.try_node(os.path.join('tools', 'lint-md', 'lint-md.mjs'), *options.get('lint_markdown_files')) + open(os.path.join('tools', '.mdlintstamp'), 'w').close() + return 0 + + def target_lint_md(self, target, options): + self.dependencies(['tools/.mdlintstamp', 'lint-js-doc'], options=options) + return 0 + + def target_format_md(self, target, options): + self.try_node(os.path.join('tools', 'lint-md', 'lint-md.mjs'), '--format', *options.get('lint_markdown_files')) + return 0 + + def target_lint_js(self, target, options): + is_fix_mode = CLI.has('--fix') + + return self.exec([ + os.path.join('tools', 'node_modules', 'eslint', 'bin', 'eslint.js'), + '--cache', + '--max-warnings=0', + '--report-unused-disable-directives', + ] + options.get('lint_javascript_files') + (['--fix'] if is_fix_mode else []), options) + + def target_lint_js_ci(self, target, options): + return self.exec([ + os.path.join('tools', 'node_modules', 'eslint', 'bin', 'eslint.js'), + '--cache', + '--max-warnings=0', + '--report-unused-disable-directives', + '-f', 'tap', + '-o', 'test-eslint.tap', + ] + options.get('lint_javascript_files'), options) + + def target_format_cpp_build(self, target, options): + os.chdir('tools/clang-format') + self.exec([ + os.path.join(os.getcwd(), options.get('npm')), + 'ci', + ], options) + os.chdir(os.path.join('..', '..')) + return 0 + + def target_format_cpp_clean(self, target, options): + self.remove(glob.glob('tools/clang-format/node_modules')) + return 0 + + def target_format_cpp(self, target, options): + if not os.path.exists(os.path.join(os.getcwd(), "tools", "clang-format", "node_modules")): + self.logger.error("Please run 'format-cpp-build' first to install the necessary dependencies") + sys.exit(1) + + return self.exec([ + sys.executable, + os.path.join(os.getcwd(), "tools", "clang-format", "node_modules", ".bin", "git-clang-format"), + "--binary=tools/clang-format/node_modules/.bin/clang-format", + "--style=file", + options.get('clang_format_start'), "--", + ] + options.get('format_cpp_files'), options) + + def target_tools_cpplintstamp(self, target, options): + self.dependencies(options.get('lint_cpp_files'), options=options) + self.exec([sys.executable, os.path.join('tools', 'cpplint.py')] + options.get('lint_cpp_files'), options) + self.exec([sys.executable, os.path.join('tools', 'checkimports.py')] + options.get('lint_cpp_files'), options) + open(os.path.join('tools', '.cpplintstamp'), 'w').close() + + def target_tools_doclintstamp(self, target, options): + self.dependencies(['test/addons/.docbuildstamp'], options=options) + + return self.exec([ + sys.executable, + os.path.join(os.getcwd(), "tools", "cpplint.py"), + f"--filter={','.join(options.get('addon_doc_lint_flags'))}", + "test/addons/??_*/*.cc", + "test/addons/??_*/*.h" + ], options) + + def target_lint_py_build(self, target, options): + return self.exec([ + sys.executable, + "-m", "pip", + "install", "--upgrade", + "-t", "tools/pip/site-packages", + "ruff==0.3.4" + ], options) + + def target_lint_py(self, target, options): + if not os.path.exists(os.path.join(os.getcwd(), "tools", "pip", "site-packages", "ruff")): + self.logger.error("Please run 'lint-py-build' first to install the necessary dependencies") + return 1 + + self.exec([ + os.path.join(os.getcwd(), "tools", "pip", "site-packages", "bin", "ruff"), + "--version" + ], options) + + is_fix_mode = CLI.has('--fix') + + self.exec([ + os.path.join(os.getcwd(), "tools", "pip", "site-packages", "bin", "ruff"), + "check", + "." + ] + (["--fix"] if is_fix_mode else []), options) + + return 0 + + def target_lint_yaml_build(self, target, options): + return self.exec([ + sys.executable, + "-m", "pip", + "install", "--upgrade", + "-t", "tools/pip/site-packages", + "yamllint" + ], options) + + def target_lint_yaml(self, target, options): + if not os.path.exists(os.path.join(os.getcwd(), "tools", "pip", "site-packages", "yamllint")): + self.logger.error("Please run 'lint-yaml-build' first to install the necessary dependencies") + return 1 + + return self.exec([ + sys.executable, + "-m", "yamllint", + "." + ], options=options.new( + environ={ + 'PYTHONPATH': os.path.join(os.getcwd(), "tools", "pip") + } + )) + + def target_lint(self, target, options): + if not os.path.exists(os.path.join(os.getcwd(), "tools", "node_modules", "eslint")): + self.logger.error("Linting is not available through the source tarball") + self.logger.error("Use the git repo (https://github.com/nodejs/node) instead") + return 1 + + js_exit = self.make("lint-js", allow_remake=True, options=options) + cpp_exit = self.make("lint-cpp", allow_remake=True, options=options) + addon_docs_exit = self.make("lint-addon-docs", allow_remake=True, options=options) + md_exit = self.make("lint-md", allow_remake=True, options=options) + yaml_exit = self.make("lint-yaml", allow_remake=True, options=options) + + return js_exit + cpp_exit + addon_docs_exit + md_exit + yaml_exit + + def target_lint_ci(self, target, options): + self.dependencies(['lint-js-ci', 'lint-cpp', 'lint-py', 'lint-md', 'lint-addon-docs', 'lint-yaml-build', 'lint-yaml'], options=options) + if not os.path.exists(os.path.join(os.getcwd(), "tools", "node_modules", "eslint")): + self.logger.error("Linting is not available through the source tarball") + self.logger.error("Use the git repo (https://github.com/nodejs/node) instead") + return 1 + + conflicts = self.exec(["git", "diff", "--check"]) + conflicts = [conflict.split(":")[0] for conflict in conflicts.splitlines()] + + if conflicts: + self.logger.error("Found conflicts in the following files:") + for conflict in conflicts: + self.logger.error(conflict) + return 1 + + return 0 + + def target_lint_clean(self, target, options): + self.remove(glob.glob('tools/.*lintstamp') + ['.eslintcache']) + return 0 + + def target_gen_openssl(self, target, options): + self.exec(['docker', 'build', '-t', 'node-openssl-builder', 'deps/openssl/config'], options) + return self.exec(['docker', 'run', '-it', '-v', f'{os.getcwd()}:/node', 'node-openssl-builder', 'make', '-C', 'deps/openssl/config'], options) + +def main(): + option = CLI.unescape(CLI.get_target_arg() or 'all') + if option is None: + Logger.print("ERROR", 31, "Invalid target specified") + sys.exit(1) + builder = Builder() + sys.exit(builder.make(option)) + +if __name__ == "__main__": + main() diff --git a/common.gypi b/common.gypi index da9076c0044e..6670294dce81 100644 --- a/common.gypi +++ b/common.gypi @@ -13,7 +13,7 @@ 'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way 'enable_pgo_generate%': '0', 'enable_pgo_use%': '0', - 'python%': 'python', + 'python': 'python', 'node_shared%': 'false', 'force_dynamic_crt%': 0, diff --git a/doc/README.md b/doc/README.md index 3d8ad6246839..d2cf891e4655 100644 --- a/doc/README.md +++ b/doc/README.md @@ -16,7 +16,7 @@ this guide. * Documents should be word-wrapped at 80 characters. * `.editorconfig` describes the preferred formatting. * A [plugin][] is available for some editors to apply these rules. -* Check changes to documentation with `make test-doc -j` or `vcbuild test-doc`. +* Check changes to documentation with `python3 build.py test-doc` * [Use US spelling][]. * [Use serial commas][]. * Avoid first-person pronouns (_I_, _we_). diff --git a/vcbuild.bat b/vcbuild.bat deleted file mode 100644 index 6ec27b88b215..000000000000 --- a/vcbuild.bat +++ /dev/null @@ -1,803 +0,0 @@ -@if not defined DEBUG_HELPER @ECHO OFF - -:: Other scripts rely on the environment variables set in this script, so we -:: explicitly allow them to persist in the calling shell. -endlocal - -if /i "%1"=="help" goto help -if /i "%1"=="--help" goto help -if /i "%1"=="-help" goto help -if /i "%1"=="/help" goto help -if /i "%1"=="?" goto help -if /i "%1"=="-?" goto help -if /i "%1"=="--?" goto help -if /i "%1"=="/?" goto help - -cd %~dp0 - -set JS_SUITES=default -set NATIVE_SUITES=addons js-native-api node-api -@rem CI_* variables should be kept synchronized with the ones in Makefile -set "CI_NATIVE_SUITES=%NATIVE_SUITES% benchmark" -set "CI_JS_SUITES=%JS_SUITES% pummel" -set CI_DOC=doctool -@rem Same as the test-ci target in Makefile -set "common_test_suites=%JS_SUITES% %NATIVE_SUITES%&set build_addons=1&set build_js_native_api_tests=1&set build_node_api_tests=1" - -@rem Process arguments. -set config=Release -set target=Build -set target_arch=x64 -set ltcg= -set target_env= -set noprojgen= -set projgen= -set nobuild= -set sign= -set nosnapshot= -set nonpm= -set nocorepack= -set cctest_args= -set test_args= -set stage_package= -set package= -set msi= -set upload= -set licensertf= -set lint_js= -set lint_cpp= -set lint_md= -set lint_md_build= -set format_md= -set i18n_arg= -set download_arg= -set build_release= -set configure_flags= -set enable_vtune_arg= -set build_addons= -set dll= -set enable_static= -set build_js_native_api_tests= -set build_node_api_tests= -set test_node_inspect= -set test_check_deopts= -set v8_test_options= -set v8_build_options= -set http2_debug= -set nghttp2_debug= -set link_module= -set no_cctest= -set cctest= -set openssl_no_asm= -set no_shared_roheap= -set doc= -set extra_msbuild_args= -set exit_code=0 - -:next-arg -if "%1"=="" goto args-done -if /i "%1"=="debug" set config=Debug&goto arg-ok -if /i "%1"=="release" set config=Release&set ltcg=1&set cctest=1&goto arg-ok -if /i "%1"=="clean" set target=Clean&goto arg-ok -if /i "%1"=="testclean" set target=TestClean&goto arg-ok -if /i "%1"=="ia32" set target_arch=x86&goto arg-ok -if /i "%1"=="x86" set target_arch=x86&goto arg-ok -if /i "%1"=="x64" set target_arch=x64&goto arg-ok -if /i "%1"=="arm64" set target_arch=arm64&goto arg-ok -if /i "%1"=="vs2022" set target_env=vs2022&goto arg-ok -if /i "%1"=="noprojgen" set noprojgen=1&goto arg-ok -if /i "%1"=="projgen" set projgen=1&goto arg-ok -if /i "%1"=="nobuild" set nobuild=1&goto arg-ok -if /i "%1"=="nosign" set "sign="&echo Note: vcbuild no longer signs by default. "nosign" is redundant.&goto arg-ok -if /i "%1"=="sign" set sign=1&goto arg-ok -if /i "%1"=="nosnapshot" set nosnapshot=1&goto arg-ok -if /i "%1"=="nonpm" set nonpm=1&goto arg-ok -if /i "%1"=="nocorepack" set nocorepack=1&goto arg-ok -if /i "%1"=="ltcg" set ltcg=1&goto arg-ok -if /i "%1"=="licensertf" set licensertf=1&goto arg-ok -if /i "%1"=="test" set test_args=%test_args% %common_test_suites%&set lint_cpp=1&set lint_js=1&set lint_md=1&goto arg-ok -if /i "%1"=="test-ci-native" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap %CI_NATIVE_SUITES% %CI_DOC%&set build_addons=1&set build_js_native_api_tests=1&set build_node_api_tests=1&set cctest_args=%cctest_args% --gtest_output=xml:cctest.junit.xml&goto arg-ok -if /i "%1"=="test-ci-js" set test_args=%test_args% %test_ci_args% -p tap --logfile test.tap %CI_JS_SUITES%&set no_cctest=1&goto arg-ok -if /i "%1"=="build-addons" set build_addons=1&goto arg-ok -if /i "%1"=="build-js-native-api-tests" set build_js_native_api_tests=1&goto arg-ok -if /i "%1"=="build-node-api-tests" set build_node_api_tests=1&goto arg-ok -if /i "%1"=="test-addons" set test_args=%test_args% addons&set build_addons=1&goto arg-ok -if /i "%1"=="test-doc" set test_args=%test_args% %CI_DOC%&set doc=1&&set lint_js=1&set lint_md=1&goto arg-ok -if /i "%1"=="test-js-native-api" set test_args=%test_args% js-native-api&set build_js_native_api_tests=1&goto arg-ok -if /i "%1"=="test-node-api" set test_args=%test_args% node-api&set build_node_api_tests=1&goto arg-ok -if /i "%1"=="test-tick-processor" set test_args=%test_args% tick-processor&goto arg-ok -if /i "%1"=="test-internet" set test_args=%test_args% internet&goto arg-ok -if /i "%1"=="test-known-issues" set test_args=%test_args% known_issues&goto arg-ok -if /i "%1"=="test-all" set test_args=%test_args% gc internet pummel %common_test_suites%&set lint_cpp=1&set lint_js=1&goto arg-ok -if /i "%1"=="test-node-inspect" set test_node_inspect=1&goto arg-ok -if /i "%1"=="test-check-deopts" set test_check_deopts=1&goto arg-ok -if /i "%1"=="test-npm" set test_npm=1&goto arg-ok -if /i "%1"=="test-v8" set test_v8=1&set custom_v8_test=1&goto arg-ok -if /i "%1"=="test-v8-intl" set test_v8_intl=1&set custom_v8_test=1&goto arg-ok -if /i "%1"=="test-v8-benchmarks" set test_v8_benchmarks=1&set custom_v8_test=1&goto arg-ok -if /i "%1"=="test-v8-all" set test_v8=1&set test_v8_intl=1&set test_v8_benchmarks=1&set custom_v8_test=1&goto arg-ok -if /i "%1"=="lint-cpp" set lint_cpp=1&goto arg-ok -if /i "%1"=="lint-js" set lint_js=1&goto arg-ok -if /i "%1"=="jslint" set lint_js=1&echo Please use lint-js instead of jslint&goto arg-ok -if /i "%1"=="lint-md" set lint_md=1&goto arg-ok -if /i "%1"=="lint-md-build" set lint_md_build=1&goto arg-ok -if /i "%1"=="lint" set lint_cpp=1&set lint_js=1&set lint_md=1&goto arg-ok -if /i "%1"=="lint-ci" set lint_cpp=1&set lint_js_ci=1&goto arg-ok -if /i "%1"=="format-md" set format_md=1&goto arg-ok -if /i "%1"=="package" set package=1&goto arg-ok -if /i "%1"=="msi" set msi=1&set licensertf=1&set download_arg="--download=all"&set i18n_arg=full-icu&goto arg-ok -if /i "%1"=="build-release" set build_release=1&set sign=1&goto arg-ok -if /i "%1"=="upload" set upload=1&goto arg-ok -if /i "%1"=="small-icu" set i18n_arg=%1&goto arg-ok -if /i "%1"=="full-icu" set i18n_arg=%1&goto arg-ok -if /i "%1"=="intl-none" set i18n_arg=none&goto arg-ok -if /i "%1"=="without-intl" set i18n_arg=none&goto arg-ok -if /i "%1"=="download-all" set download_arg="--download=all"&goto arg-ok -if /i "%1"=="ignore-flaky" set test_args=%test_args% --flaky-tests=dontcare&goto arg-ok -if /i "%1"=="dll" set dll=1&goto arg-ok -if /i "%1"=="enable-vtune" set enable_vtune_arg=1&goto arg-ok -if /i "%1"=="static" set enable_static=1&goto arg-ok -if /i "%1"=="no-NODE-OPTIONS" set no_NODE_OPTIONS=1&goto arg-ok -if /i "%1"=="debug-nghttp2" set debug_nghttp2=1&goto arg-ok -if /i "%1"=="link-module" set "link_module= --link-module=%2%link_module%"&goto arg-ok-2 -if /i "%1"=="no-cctest" set no_cctest=1&goto arg-ok -if /i "%1"=="cctest" set cctest=1&goto arg-ok -if /i "%1"=="openssl-no-asm" set openssl_no_asm=1&goto arg-ok -if /i "%1"=="no-shared-roheap" set no_shared_roheap=1&goto arg-ok -if /i "%1"=="doc" set doc=1&goto arg-ok -if /i "%1"=="binlog" set extra_msbuild_args=/binaryLogger:%config%\node.binlog&goto arg-ok - -echo Error: invalid command line option `%1`. -exit /b 1 - -:arg-ok-2 -shift -:arg-ok -shift -goto next-arg - -:args-done - -if defined build_release ( - set config=Release - set package=1 - set msi=1 - set licensertf=1 - set download_arg="--download=all" - set i18n_arg=full-icu - set projgen=1 - set cctest=1 - set ltcg=1 -) - -if defined msi set stage_package=1 -if defined package set stage_package=1 - -:: assign path to node_exe -set "node_exe=%config%\node.exe" -set "node_gyp_exe="%node_exe%" deps\npm\node_modules\node-gyp\bin\node-gyp" -set "npm_exe="%~dp0%node_exe%" %~dp0deps\npm\bin\npm-cli.js" -if "%target_env%"=="vs2022" set "node_gyp_exe=%node_gyp_exe% --msvs_version=2022" - -:: skip building if the only argument received was lint -if "%*"=="lint" if exist "%node_exe%" goto lint-cpp - -:: skip building if the only argument received was format-md -if "%*"=="format-md" if exist "%node_exe%" goto format-md - -if "%config%"=="Debug" set configure_flags=%configure_flags% --debug -if defined nosnapshot set configure_flags=%configure_flags% --without-snapshot -if defined nonpm set configure_flags=%configure_flags% --without-npm -if defined nocorepack set configure_flags=%configure_flags% --without-corepack -if defined ltcg set configure_flags=%configure_flags% --with-ltcg -if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase% -if defined download_arg set configure_flags=%configure_flags% %download_arg% -if defined enable_vtune_arg set configure_flags=%configure_flags% --enable-vtune-profiling -if defined dll set configure_flags=%configure_flags% --shared -if defined enable_static set configure_flags=%configure_flags% --enable-static -if defined no_NODE_OPTIONS set configure_flags=%configure_flags% --without-node-options -if defined link_module set configure_flags=%configure_flags% %link_module% -if defined i18n_arg set configure_flags=%configure_flags% --with-intl=%i18n_arg% -if defined config_flags set configure_flags=%configure_flags% %config_flags% -if defined target_arch set configure_flags=%configure_flags% --dest-cpu=%target_arch% -if defined debug_nghttp2 set configure_flags=%configure_flags% --debug-nghttp2 -if defined openssl_no_asm set configure_flags=%configure_flags% --openssl-no-asm -if defined no_shared_roheap set configure_flags=%configure_flags% --disable-shared-readonly-heap -if defined DEBUG_HELPER set configure_flags=%configure_flags% --verbose -if "%target_arch%"=="x86" if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set configure_flags=%configure_flags% --no-cross-compiling - -if not exist "%~dp0deps\icu" goto no-depsicu -if "%target%"=="Clean" echo deleting %~dp0deps\icu -if "%target%"=="Clean" rmdir /S /Q %~dp0deps\icu -:no-depsicu - -if "%target%"=="TestClean" ( - echo deleting test/.tmp* - if exist "test\.tmp*" for /f %%i in ('dir /a:d /s /b test\.tmp*') do rmdir /S /Q "%%i" - goto exit -) - - -call tools\msvs\find_python.cmd -if errorlevel 1 goto :exit - -REM NASM is only needed on IA32 and x86_64. -if not defined openssl_no_asm if "%target_arch%" NEQ "arm64" call tools\msvs\find_nasm.cmd -if errorlevel 1 echo Could not find NASM, install it or build with openssl-no-asm. See BUILDING.md. - -call :getnodeversion || exit /b 1 - -if defined TAG set configure_flags=%configure_flags% --tag=%TAG% - -if not "%target%"=="Clean" goto skip-clean -rmdir /Q /S "%~dp0%config%\%TARGET_NAME%" > nul 2> nul -:skip-clean - -if defined noprojgen if defined nobuild goto :after-build - -@rem Set environment for msbuild - -set msvs_host_arch=x86 -if _%PROCESSOR_ARCHITECTURE%_==_AMD64_ set msvs_host_arch=amd64 -if _%PROCESSOR_ARCHITEW6432%_==_AMD64_ set msvs_host_arch=amd64 -if _%PROCESSOR_ARCHITECTURE%_==_ARM64_ set msvs_host_arch=arm64 -@rem usually vcvarsall takes an argument: host + '_' + target -set vcvarsall_arg=%msvs_host_arch%_%target_arch% -@rem unless both the host and the target are the same -if %target_arch%==x64 if %msvs_host_arch%==amd64 set vcvarsall_arg=amd64 -if %target_arch%==%msvs_host_arch% set vcvarsall_arg=%target_arch% - -@rem Look for Visual Studio 2022 -:vs-set-2022 -if defined target_env if "%target_env%" NEQ "vs2022" goto msbuild-not-found -echo Looking for Visual Studio 2022 -@rem VCINSTALLDIR may be set if run from a VS Command Prompt and needs to be -@rem cleared first as vswhere_usability_wrapper.cmd doesn't when it fails to -@rem detect the version searched for -if not defined target_env set "VCINSTALLDIR=" -call tools\msvs\vswhere_usability_wrapper.cmd "[17.6,18.0)" %target_arch% "prerelease" -if "_%VCINSTALLDIR%_" == "__" goto msbuild-not-found -@rem check if VS2022 is already setup, and for the requested arch -if "_%VisualStudioVersion%_" == "_17.0_" if "_%VSCMD_ARG_TGT_ARCH%_"=="_%target_arch%_" goto found_vs2022 -@rem need to clear VSINSTALLDIR for vcvarsall to work as expected -set "VSINSTALLDIR=" -@rem prevent VsDevCmd.bat from changing the current working directory -set "VSCMD_START_DIR=%CD%" -set vcvars_call="%VCINSTALLDIR%\Auxiliary\Build\vcvarsall.bat" %vcvarsall_arg% -echo calling: %vcvars_call% -call %vcvars_call% -if errorlevel 1 goto msbuild-not-found -if defined DEBUG_HELPER @ECHO ON -:found_vs2022 -echo Found MSVS version %VisualStudioVersion% -set GYP_MSVS_VERSION=2022 -set PLATFORM_TOOLSET=v143 -goto msbuild-found - -:msbuild-not-found -echo Failed to find a suitable Visual Studio installation. -echo Try to run in a "Developer Command Prompt" or consult -echo https://github.com/nodejs/node/blob/HEAD/BUILDING.md#windows -goto exit - -:msbuild-found - -set project_generated= -:project-gen -@rem Skip project generation if requested. -if defined noprojgen goto msbuild -if defined projgen goto run-configure -if not exist node.sln goto run-configure -if not exist .gyp_configure_stamp goto run-configure -echo %configure_flags% > .tmp_gyp_configure_stamp -where /R . /T *.gyp* >> .tmp_gyp_configure_stamp -fc .gyp_configure_stamp .tmp_gyp_configure_stamp >NUL 2>&1 -if errorlevel 1 goto run-configure - -:skip-configure -del .tmp_gyp_configure_stamp 2> NUL -echo Reusing solution generated with %configure_flags% -goto msbuild - -:run-configure -del .tmp_gyp_configure_stamp 2> NUL -del .gyp_configure_stamp 2> NUL -@rem Generate the VS project. -echo configure %configure_flags% -echo %configure_flags%> .used_configure_flags -python configure %configure_flags% -if errorlevel 1 goto create-msvs-files-failed -if not exist node.sln goto create-msvs-files-failed -set project_generated=1 -echo Project files generated. -echo %configure_flags% > .gyp_configure_stamp -where /R . /T *.gyp* >> .gyp_configure_stamp - -:msbuild -@rem Skip build if requested. -if defined nobuild goto :after-build - -@rem Build the sln with msbuild. -set "msbcpu=/m:2" -if "%NUMBER_OF_PROCESSORS%"=="1" set "msbcpu=/m:1" -set "msbplatform=Win32" -if "%target_arch%"=="x64" set "msbplatform=x64" -if "%target_arch%"=="arm64" set "msbplatform=ARM64" -if "%target%"=="Build" ( - if defined no_cctest set target=node - if "%test_args%"=="" set target=node - if defined cctest set target="Build" -) -if "%target%"=="node" if exist "%config%\cctest.exe" del "%config%\cctest.exe" -if defined msbuild_args set "extra_msbuild_args=%extra_msbuild_args% %msbuild_args%" -@rem Setup env variables to use multiprocessor build -set UseMultiToolTask=True -set EnforceProcessCountAcrossBuilds=True -set MultiProcMaxCount=%NUMBER_OF_PROCESSORS% -msbuild node.sln %msbcpu% /t:%target% /p:Configuration=%config% /p:Platform=%msbplatform% /clp:NoItemAndPropertyList;Verbosity=minimal /nologo %extra_msbuild_args% -if errorlevel 1 ( - if not defined project_generated echo Building Node with reused solution failed. To regenerate project files use "vcbuild projgen" - exit /B 1 -) -if "%target%" == "Clean" goto exit - -:after-build -:: Check existence of %config% before removing it. -if exist %config% rd %config% -if errorlevel 1 echo "Old build output exists at 'out\%config%'. Please remove." & exit /B -:: Use /J because /D (symlink) requires special permissions. -if EXIST out\%config% mklink /J %config% out\%config% -if errorlevel 1 echo "Could not create junction to 'out\%config%'." & exit /B - -:sign -@rem Skip signing unless the `sign` option was specified. -if not defined sign goto licensertf - -call tools\sign.bat Release\node.exe -if errorlevel 1 echo Failed to sign exe, got error code %errorlevel%&goto exit - -:licensertf -@rem Skip license.rtf generation if not requested. -if not defined licensertf goto stage_package - -set "use_x64_node_exe=false" -if "%target_arch%"=="arm64" if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set "use_x64_node_exe=true" -set "x64_node_exe=temp-vcbuild\node-x64-cross-compiling.exe" -if "%use_x64_node_exe%"=="true" ( - echo Cross-compilation to ARM64 detected. We'll use the x64 Node executable for license2rtf. - if not exist "%x64_node_exe%" ( - echo Downloading x64 node.exe... - if not exist "temp-vcbuild" mkdir temp-vcbuild - powershell -c "Invoke-WebRequest -Uri 'https://nodejs.org/dist/latest/win-x64/node.exe' -OutFile '%x64_node_exe%'" - ) - if not exist "%x64_node_exe%" ( - echo Could not find the Node executable at the given x64_node_exe path. Aborting. - set exit_code=1 - goto exit - ) - %x64_node_exe% tools\license2rtf.mjs < LICENSE > %config%\license.rtf -) else ( - %node_exe% tools\license2rtf.mjs < LICENSE > %config%\license.rtf -) - -if errorlevel 1 echo Failed to generate license.rtf, got error code %errorlevel%&goto exit - -:stage_package -if not defined stage_package goto install-doctools - -echo Creating package... -cd Release -rmdir /S /Q %TARGET_NAME% > nul 2> nul -mkdir %TARGET_NAME% > nul 2> nul -mkdir %TARGET_NAME%\node_modules > nul 2>nul - -copy /Y node.exe %TARGET_NAME%\ > nul -if errorlevel 1 echo Cannot copy node.exe && goto package_error -copy /Y ..\LICENSE %TARGET_NAME%\ > nul -if errorlevel 1 echo Cannot copy LICENSE && goto package_error -copy /Y ..\README.md %TARGET_NAME%\ > nul -if errorlevel 1 echo Cannot copy README.md && goto package_error -copy /Y ..\CHANGELOG.md %TARGET_NAME%\ > nul -if errorlevel 1 echo Cannot copy CHANGELOG.md && goto package_error - -if not defined nonpm ( - robocopy ..\deps\npm %TARGET_NAME%\node_modules\npm /e /xd test > nul - if errorlevel 8 echo Cannot copy npm package && goto package_error - copy /Y ..\deps\npm\bin\npm %TARGET_NAME%\ > nul - if errorlevel 1 echo Cannot copy npm && goto package_error - copy /Y ..\deps\npm\bin\npm.cmd %TARGET_NAME%\ > nul - if errorlevel 1 echo Cannot copy npm.cmd && goto package_error - copy /Y ..\deps\npm\bin\npx %TARGET_NAME%\ > nul - if errorlevel 1 echo Cannot copy npx && goto package_error - copy /Y ..\deps\npm\bin\npx.cmd %TARGET_NAME%\ > nul - if errorlevel 1 echo Cannot copy npx.cmd && goto package_error - copy /Y ..\deps\npm\bin\npm.ps1 %TARGET_NAME%\ > nul - if errorlevel 1 echo Cannot copy npm.ps1 && goto package_error - copy /Y ..\deps\npm\bin\npx.ps1 %TARGET_NAME%\ > nul - if errorlevel 1 echo Cannot copy npx.ps1 && goto package_error -) - -if not defined nocorepack ( - robocopy ..\deps\corepack %TARGET_NAME%\node_modules\corepack /e /xd test > nul - if errorlevel 8 echo Cannot copy corepack package && goto package_error - copy /Y ..\deps\corepack\shims\nodewin\corepack %TARGET_NAME%\ > nul - if errorlevel 1 echo Cannot copy corepack && goto package_error - copy /Y ..\deps\corepack\shims\nodewin\corepack.cmd %TARGET_NAME%\ > nul - if errorlevel 1 echo Cannot copy corepack.cmd && goto package_error -) - -copy /Y ..\tools\msvs\nodevars.bat %TARGET_NAME%\ > nul -if errorlevel 1 echo Cannot copy nodevars.bat && goto package_error -copy /Y ..\tools\msvs\install_tools\*.* %TARGET_NAME%\ > nul -if errorlevel 1 echo Cannot copy install_tools scripts && goto package_error -if defined dll ( - copy /Y libnode.dll %TARGET_NAME%\ > nul - if errorlevel 1 echo Cannot copy libnode.dll && goto package_error - - copy /Y libnode.lib %TARGET_NAME%\ > nul - if errorlevel 1 echo Cannot copy libnode.lib && goto package_error - - mkdir %TARGET_NAME%\Release > nul - copy /Y node.def %TARGET_NAME%\Release\ > nul - if errorlevel 1 echo Cannot copy node.def && goto package_error - - python ..\tools\install.py install --root-dir .. --config-gypi-path %CD%\..\config.gypi --dest-dir %CD%\%TARGET_NAME% --prefix \ --headers-only - if errorlevel 1 echo Cannot install headers && goto package_error - - if exist ..\Debug ( - mkdir %TARGET_NAME%\Debug > nul - - copy /Y ..\Debug\libnode.dll %TARGET_NAME%\Debug\ > nul - if errorlevel 1 echo Cannot copy libnode.dll && goto package_error - - copy /Y ..\Debug\libnode.lib %TARGET_NAME%\Debug\ > nul - if errorlevel 1 echo Cannot copy libnode.lib && goto package_error - - copy /Y ..\Debug\node.def %TARGET_NAME%\Debug\ > nul - if errorlevel 1 echo Cannot copy node.def && goto package_error - ) -) -cd .. - -:package -if not defined package goto msi -cd Release -echo Creating %TARGET_NAME%.7z -del %TARGET_NAME%.7z > nul 2> nul -7z a -r -mx9 -t7z %TARGET_NAME%.7z %TARGET_NAME% > nul -if errorlevel 1 echo Cannot create %TARGET_NAME%.7z && goto package_error - -echo Creating %TARGET_NAME%.zip -del %TARGET_NAME%.zip > nul 2> nul -7z a -r -mx9 -tzip %TARGET_NAME%.zip %TARGET_NAME% > nul -if errorlevel 1 echo Cannot create %TARGET_NAME%.zip && goto package_error - -echo Creating node_pdb.7z -del node_pdb.7z > nul 2> nul -7z a -mx9 -t7z node_pdb.7z node.pdb > nul - -echo Creating node_pdb.zip -del node_pdb.zip > nul 2> nul -7z a -mx9 -tzip node_pdb.zip node.pdb > nul - -cd .. -echo Package created! -goto package_done -:package_error -cd .. -exit /b 1 -:package_done - -:msi -@rem Skip msi generation if not requested -if not defined msi goto install-doctools - -:msibuild -echo Building node-v%FULLVERSION%-%target_arch%.msi -set "msbsdk=" -if defined WindowsSDKVersion set "msbsdk=/p:WindowsTargetPlatformVersion=%WindowsSDKVersion:~0,-1%" -msbuild "%~dp0tools\msvs\msi\nodemsi.sln" /m /t:Restore,Clean,Build %msbsdk% /p:PlatformToolset=%PLATFORM_TOOLSET% /p:Configuration=%config% /p:Platform=%target_arch% /p:NodeVersion=%NODE_VERSION% /p:FullVersion=%FULLVERSION% /p:DistTypeDir=%DISTTYPEDIR% /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo -if errorlevel 1 goto exit - -if not defined sign goto upload -call tools\sign.bat node-v%FULLVERSION%-%target_arch%.msi -if errorlevel 1 echo Failed to sign msi, got error code %errorlevel%&goto exit - -:upload -@rem Skip upload if not requested -if not defined upload goto install-doctools - -if not defined SSHCONFIG ( - echo SSHCONFIG is not set for upload - exit /b 1 -) - -if not defined STAGINGSERVER set STAGINGSERVER=node-www -ssh -F %SSHCONFIG% %STAGINGSERVER% "mkdir -p nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%" -if errorlevel 1 goto exit -scp -F %SSHCONFIG% Release\node.exe %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node.exe -if errorlevel 1 goto exit -scp -F %SSHCONFIG% Release\node.lib %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node.lib -if errorlevel 1 goto exit -scp -F %SSHCONFIG% Release\node_pdb.zip %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node_pdb.zip -if errorlevel 1 goto exit -scp -F %SSHCONFIG% Release\node_pdb.7z %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%/node_pdb.7z -if errorlevel 1 goto exit -scp -F %SSHCONFIG% Release\%TARGET_NAME%.7z %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/%TARGET_NAME%.7z -if errorlevel 1 goto exit -scp -F %SSHCONFIG% Release\%TARGET_NAME%.zip %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/%TARGET_NAME%.zip -if errorlevel 1 goto exit -scp -F %SSHCONFIG% node-v%FULLVERSION%-%target_arch%.msi %STAGINGSERVER%:nodejs/%DISTTYPEDIR%/v%FULLVERSION%/ -if errorlevel 1 goto exit -ssh -F %SSHCONFIG% %STAGINGSERVER% "touch nodejs/%DISTTYPEDIR%/v%FULLVERSION%/node-v%FULLVERSION%-%target_arch%.msi.done nodejs/%DISTTYPEDIR%/v%FULLVERSION%/%TARGET_NAME%.zip.done nodejs/%DISTTYPEDIR%/v%FULLVERSION%/%TARGET_NAME%.7z.done nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%.done && chmod -R ug=rw-x+X,o=r+X nodejs/%DISTTYPEDIR%/v%FULLVERSION%/node-v%FULLVERSION%-%target_arch%.* nodejs/%DISTTYPEDIR%/v%FULLVERSION%/win-%target_arch%*" -if errorlevel 1 goto exit - - -:install-doctools -REM only install if building doc OR testing doctool OR building addons -if not defined doc if not defined build_addons ( - echo.%test_args% | findstr doctool 1>nul - if errorlevel 1 goto :skip-install-doctools -) -if exist "tools\doc\node_modules\unified\package.json" goto skip-install-doctools -SETLOCAL -cd tools\doc -%npm_exe% ci -cd ..\.. -if errorlevel 1 goto exit -ENDLOCAL -:skip-install-doctools -@rem Clear errorlevel from echo.%test_args% | findstr doctool 1>nul -cd . - -:build-doc -@rem Build documentation if requested -if not defined doc goto run -if not exist %node_exe% ( - echo Failed to find node.exe - goto run -) -mkdir %config%\doc -robocopy /e doc\api %config%\doc\api -robocopy /e doc\api_assets %config%\doc\api\assets - -for %%F in (%config%\doc\api\*.md) do ( - %node_exe% tools\doc\generate.mjs --node-version=v%FULLVERSION% %%F --output-directory=%%~dF%%~pF -) - -:run -@rem Run tests if requested. - -if not defined build_addons goto build-js-native-api-tests -if not exist "%node_exe%" ( - echo Failed to find node.exe - goto build-js-native-api-tests -) -echo Building addons -:: clear -for /d %%F in (test\addons\??_*) do ( - rd /s /q %%F -) -:: generate -"%node_exe%" tools\doc\addon-verify.mjs -if %errorlevel% neq 0 exit /b %errorlevel% -:: building addons -setlocal -python "%~dp0tools\build_addons.py" "%~dp0test\addons" --config %config% -if errorlevel 1 exit /b 1 -endlocal - -:build-js-native-api-tests -if not defined build_js_native_api_tests goto build-node-api-tests -if not exist "%node_exe%" ( - echo Failed to find node.exe - goto build-node-api-tests -) -echo Building js-native-api -:: clear -for /d %%F in (test\js-native-api\??_*) do ( - rd /s /q %%F -) -:: building js-native-api -setlocal -python "%~dp0tools\build_addons.py" "%~dp0test\js-native-api" --config %config% -if errorlevel 1 exit /b 1 -endlocal -goto build-node-api-tests - -:build-node-api-tests -if not defined build_node_api_tests goto run-tests -if not exist "%node_exe%" ( - echo Failed to find node.exe - goto run-tests -) -echo Building node-api -:: clear -for /d %%F in (test\node-api\??_*) do ( - rd /s /q %%F -) -:: building node-api -setlocal -python "%~dp0tools\build_addons.py" "%~dp0test\node-api" --config %config% -if errorlevel 1 exit /b 1 -endlocal -goto run-tests - -:run-tests -if defined test_check_deopts goto node-check-deopts -if defined test_node_inspect goto node-test-inspect -goto node-tests - -:node-check-deopts -python tools\test.py --mode=release --check-deopts parallel sequential -if defined test_node_inspect goto node-test-inspect -goto node-tests - -:node-test-inspect -set USE_EMBEDDED_NODE_INSPECT=1 -%node_exe% tools\test-npm-package.js --install deps\node-inspect test -goto node-tests - -:node-tests -if not defined test_npm goto no-test-npm -set npm_test_cmd="%node_exe%" tools\test-npm-package.js --install --logfile=test-npm.tap deps\npm test-node -echo %npm_test_cmd% -%npm_test_cmd% -if errorlevel 1 goto exit -:no-test-npm - -if "%test_args%"=="" goto test-v8 -if "%config%"=="Debug" set test_args=--mode=debug %test_args% -if "%config%"=="Release" set test_args=--mode=release %test_args% -if defined no_cctest echo Skipping cctest because no-cctest was specified && goto run-test-py -if not exist "%config%\cctest.exe" echo cctest.exe not found. Run "vcbuild test" or "vcbuild cctest" to build it. && goto run-test-py -echo running 'cctest %cctest_args%' -"%config%\cctest" %cctest_args% -if %errorlevel% neq 0 set exit_code=%errorlevel% -:run-test-py -echo running 'python tools\test.py %test_args%' -python tools\test.py %test_args% -if %errorlevel% neq 0 set exit_code=%errorlevel% -goto test-v8 - -:test-v8 -if not defined custom_v8_test goto lint-cpp -call tools/test-v8.bat -if errorlevel 1 goto exit -goto lint-cpp - -:lint-cpp -if not defined lint_cpp goto lint-js -if defined NODEJS_MAKE goto run-make-lint -where make > NUL 2>&1 && make -v | findstr /C:"GNU Make" 1> NUL -if "%ERRORLEVEL%"=="0" set "NODEJS_MAKE=make PYTHON=python" & goto run-make-lint -where wsl > NUL 2>&1 -if "%ERRORLEVEL%"=="0" set "NODEJS_MAKE=wsl make" & goto run-make-lint -echo Could not find GNU Make, needed for linting C/C++ -echo Alternatively, you can use WSL -goto lint-js - -:run-make-lint -%NODEJS_MAKE% lint-cpp -goto lint-js - -:lint-js -if not defined lint_js goto lint-md-build -if not exist tools\node_modules\eslint goto no-lint -echo running lint-js -%node_exe% tools\node_modules\eslint\bin\eslint.js --cache --max-warnings=0 --report-unused-disable-directives --rule "linebreak-style: 0" .eslintrc.js benchmark doc lib test tools -goto lint-md-build - -:no-lint -echo Linting is not available through the source tarball. -echo Use the git repo instead: $ git clone https://github.com/nodejs/node.git -goto lint-md-build - -:lint-md-build -if not defined lint_md_build goto lint-md -echo "Deprecated no-op target 'lint_md_build'" -goto lint-md - -:lint-md -if not defined lint_md goto format-md -echo Running Markdown linter on docs... -SETLOCAL ENABLEDELAYEDEXPANSION -set lint_md_files= -for /D %%D IN (doc\*) do ( - for %%F IN (%%D\*.md) do ( - set "lint_md_files="%%F" !lint_md_files!" - ) -) -%node_exe% tools\lint-md\lint-md.mjs %lint_md_files% -ENDLOCAL -goto format-md - -:format-md -if not defined format_md goto exit -echo Running Markdown formatter on docs... -SETLOCAL ENABLEDELAYEDEXPANSION -set lint_md_files= -for /D %%D IN (doc\*) do ( - for %%F IN (%%D\*.md) do ( - set "lint_md_files="%%F" !lint_md_files!" - ) -) -%node_exe% tools\lint-md\lint-md.mjs --format %lint_md_files% -ENDLOCAL -goto exit - -:create-msvs-files-failed -echo Failed to create vc project files. -del .used_configure_flags -set exit_code=1 -goto exit - -:help -echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [nocorepack] [ltcg] [licensetf] [sign] [ia32/x86/x64/arm64] [vs2022] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm] -echo Examples: -echo vcbuild.bat : builds release build -echo vcbuild.bat debug : builds debug build -echo vcbuild.bat release msi : builds release build and MSI installer package -echo vcbuild.bat test : builds debug build and runs tests -echo vcbuild.bat build-release : builds the release distribution as used by nodejs.org -echo vcbuild.bat enable-vtune : builds Node.js with Intel VTune profiling support to profile JavaScript -echo vcbuild.bat link-module my_module.js : bundles my_module as built-in module -echo vcbuild.bat lint : runs the C++, documentation and JavaScript linter -echo vcbuild.bat no-cctest : skip building cctest.exe -goto exit - -:exit -if %errorlevel% neq 0 exit /b %errorlevel% -exit /b %exit_code% - - -rem *************** -rem Subroutines -rem *************** - -:getnodeversion -set NODE_VERSION= -set TAG= -set FULLVERSION= - -for /F "usebackq tokens=*" %%i in (`python "%~dp0tools\getnodeversion.py"`) do set NODE_VERSION=%%i -if not defined NODE_VERSION ( - echo Cannot determine current version of Node.js - exit /b 1 -) - -if not defined DISTTYPE set DISTTYPE=release -if "%DISTTYPE%"=="release" ( - set FULLVERSION=%NODE_VERSION% - goto distexit -) -if "%DISTTYPE%"=="custom" ( - if not defined CUSTOMTAG ( - echo "CUSTOMTAG is not set for DISTTYPE=custom" - exit /b 1 - ) - set TAG=%CUSTOMTAG% -) -if not "%DISTTYPE%"=="custom" ( - if not defined DATESTRING ( - echo "DATESTRING is not set for nightly" - exit /b 1 - ) - if not defined COMMIT ( - echo "COMMIT is not set for nightly" - exit /b 1 - ) - if not "%DISTTYPE%"=="nightly" ( - if not "%DISTTYPE%"=="next-nightly" ( - echo "DISTTYPE is not release, custom, nightly or next-nightly" - exit /b 1 - ) - ) - set TAG=%DISTTYPE%%DATESTRING%%COMMIT% -) -set FULLVERSION=%NODE_VERSION%-%TAG% - -:distexit -if not defined DISTTYPEDIR set DISTTYPEDIR=%DISTTYPE% -set TARGET_NAME=node-v%FULLVERSION%-win-%target_arch% -goto :EOF