| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,7 +67,7 @@ subSystemLabels: | |||
| 67 | 67 | /^tools\/make-v8/: tools, v8 engine, needs-ci | |
| 68 | 68 | /^tools\/v8_gypfiles/: tools, v8 engine, needs-ci | |
| 69 | 69 | /^tools\/(code_cache|snapshot)/: needs-ci | |
| 70 | - /^tools\/build-addons.js/: needs-ci | ||
| 70 | + /^tools\/build-addons.mjs/: needs-ci | ||
| 71 | 71 | # all other tool changes should be marked as such | |
| 72 | 72 | /^tools\//: tools | |
| 73 | 73 | /^\.eslint|\.remark|\.editorconfig/: tools | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -366,13 +366,13 @@ ADDONS_BINDING_SOURCES := \ | |||
| 366 | 366 | $(filter-out test/addons/??_*/*.h, $(wildcard test/addons/*/*.h)) | |
| 367 | 367 | ||
| 368 | 368 | ADDONS_PREREQS := config.gypi \ | |
| 369 | - deps/npm/node_modules/node-gyp/package.json tools/build-addons.js \ | ||
| 369 | + deps/npm/node_modules/node-gyp/package.json tools/build-addons.mjs \ | ||
| 370 | 370 | deps/uv/include/*.h deps/v8/include/*.h \ | |
| 371 | 371 | src/node.h src/node_buffer.h src/node_object_wrap.h src/node_version.h | |
| 372 | 372 | ||
| 373 | 373 | define run_build_addons | |
| 374 | 374 | env npm_config_loglevel=$(LOGLEVEL) npm_config_nodedir="$$PWD" \ | |
| 375 | - npm_config_python="$(PYTHON)" $(NODE) "$$PWD/tools/build-addons" \ | ||
| 375 | + npm_config_python="$(PYTHON)" $(NODE) "$$PWD/tools/build-addons.mjs" \ | ||
| 376 | 376 | "$$PWD/deps/npm/node_modules/node-gyp/bin/node-gyp.js" \ | |
| 377 | 377 | $1 | |
| 378 | 378 | touch $2 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -232,7 +232,7 @@ There are some other files that touch the build chain. Changes in the following | |||
| 232 | 232 | files also qualify as affecting the `node` binary: | |
| 233 | 233 | ||
| 234 | 234 | * `tools/*.py` | |
| 235 | - * `tools/build-addons.js` | ||
| 235 | + * `tools/build-addons.mjs` | ||
| 236 | 236 | * `*.gyp` | |
| 237 | 237 | * `*.gypi` | |
| 238 | 238 | * `configure` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,63 @@ | |||
| 1 | + #!/usr/bin/env node | ||
| 2 | + | ||
| 3 | + // Usage: e.g. node build-addons.mjs <path to node-gyp> <directory> | ||
| 4 | + | ||
| 5 | + import child_process from 'node:child_process'; | ||
| 6 | + import path from 'node:path'; | ||
| 7 | + import fs from 'node:fs/promises'; | ||
| 8 | + import util from 'node:util'; | ||
| 9 | + import process from 'node:process'; | ||
| 10 | + import os from 'node:os'; | ||
| 11 | + | ||
| 12 | + const execFile = util.promisify(child_process.execFile); | ||
| 13 | + | ||
| 14 | + const parallelization = +process.env.JOBS || os.cpus().length; | ||
| 15 | + const nodeGyp = process.argv[2]; | ||
| 16 | + const directory = process.argv[3]; | ||
| 17 | + | ||
| 18 | + async function buildAddon(dir) { | ||
| 19 | + try { | ||
| 20 | + // Only run for directories that have a `binding.gyp`. | ||
| 21 | + // (https://github.com/nodejs/node/issues/14843) | ||
| 22 | + await fs.stat(path.join(dir, 'binding.gyp')); | ||
| 23 | + } catch (err) { | ||
| 24 | + if (err.code === 'ENOENT' || err.code === 'ENOTDIR') | ||
| 25 | + return; | ||
| 26 | + throw err; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + console.log(`Building addon in ${dir}`); | ||
| 30 | + const { stdout, stderr } = | ||
| 31 | + await execFile(process.execPath, [nodeGyp, 'rebuild', `--directory=${dir}`], | ||
| 32 | + { | ||
| 33 | + stdio: 'inherit', | ||
| 34 | + env: { ...process.env, MAKEFLAGS: '-j1' } | ||
| 35 | + }); | ||
| 36 | + | ||
| 37 | + // We buffer the output and print it out once the process is done in order | ||
| 38 | + // to avoid interleaved output from multiple builds running at once. | ||
| 39 | + process.stdout.write(stdout); | ||
| 40 | + process.stderr.write(stderr); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + async function parallel(jobQueue, limit) { | ||
| 44 | + const next = async () => { | ||
| 45 | + if (jobQueue.length === 0) { | ||
| 46 | + return; | ||
| 47 | + } | ||
| 48 | + const job = jobQueue.shift(); | ||
| 49 | + await job(); | ||
| 50 | + await next(); | ||
| 51 | + }; | ||
| 52 | + | ||
| 53 | + const workerCnt = Math.min(limit, jobQueue.length); | ||
| 54 | + await Promise.all(Array.from({ length: workerCnt }, next)); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + const jobs = []; | ||
| 58 | + for await (const dirent of await fs.opendir(directory)) { | ||
| 59 | + if (dirent.isDirectory()) { | ||
| 60 | + jobs.push(() => buildAddon(path.join(directory, dirent.name))); | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + await parallel(jobs, parallelization); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -608,7 +608,7 @@ if %errorlevel% neq 0 exit /b %errorlevel% | |||
| 608 | 608 | :: building addons | |
| 609 | 609 | setlocal | |
| 610 | 610 | set npm_config_nodedir=%~dp0 | |
| 611 | - "%node_exe%" "%~dp0tools\build-addons.js" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\addons" | ||
| 611 | + "%node_exe%" "%~dp0tools\build-addons.mjs" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\addons" | ||
| 612 | 612 | if errorlevel 1 exit /b 1 | |
| 613 | 613 | endlocal | |
| 614 | 614 | ||
@@ -626,7 +626,7 @@ for /d %%F in (test\js-native-api\??_*) do ( | |||
| 626 | 626 | :: building js-native-api | |
| 627 | 627 | setlocal | |
| 628 | 628 | set npm_config_nodedir=%~dp0 | |
| 629 | - "%node_exe%" "%~dp0tools\build-addons.js" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\js-native-api" | ||
| 629 | + "%node_exe%" "%~dp0tools\build-addons.mjs" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\js-native-api" | ||
| 630 | 630 | if errorlevel 1 exit /b 1 | |
| 631 | 631 | endlocal | |
| 632 | 632 | goto build-node-api-tests | |
@@ -645,7 +645,7 @@ for /d %%F in (test\node-api\??_*) do ( | |||
| 645 | 645 | :: building node-api | |
| 646 | 646 | setlocal | |
| 647 | 647 | set npm_config_nodedir=%~dp0 | |
| 648 | - "%node_exe%" "%~dp0tools\build-addons.js" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\node-api" | ||
| 648 | + "%node_exe%" "%~dp0tools\build-addons.mjs" "%~dp0deps\npm\node_modules\node-gyp\bin\node-gyp.js" "%~dp0test\node-api" | ||
| 649 | 649 | if errorlevel 1 exit /b 1 | |
| 650 | 650 | endlocal | |
| 651 | 651 | goto run-tests | |
| Back | FazBrowse Home | New Git URL |
0 commit comments