diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-06-06 00:18:55 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-06-11 20:09:28 +0200 |
commit | cea10baa221e7ed3c5408d526dcec4fb7a6e99fa (patch) | |
tree | a416bb6ba1b1bdcd2a9d463e0409568bb7c44cb6 /tools | |
parent | fa2d0a117e0882c5f5d9e0e9b596b8628b6b533f (diff) | |
download | android-node-v8-cea10baa221e7ed3c5408d526dcec4fb7a6e99fa.tar.gz android-node-v8-cea10baa221e7ed3c5408d526dcec4fb7a6e99fa.tar.bz2 android-node-v8-cea10baa221e7ed3c5408d526dcec4fb7a6e99fa.zip |
build: build addon tests in parallel
Use a JS script to build addons rather than a shell command
embedded in the Makefile, because parallelizing is hard in sh
and easy in JS.
PR-URL: https://github.com/nodejs/node/pull/21155
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/build-addons.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tools/build-addons.js b/tools/build-addons.js new file mode 100644 index 0000000000..1d4bcbc917 --- /dev/null +++ b/tools/build-addons.js @@ -0,0 +1,58 @@ +'use strict'; + +// Usage: e.g. node build-addons.js <path to node-gyp> <directory> + +const child_process = require('child_process'); +const path = require('path'); +const fs = require('fs').promises; +const util = require('util'); + +const execFile = util.promisify(child_process.execFile); + +const parallelization = +process.env.JOBS || require('os').cpus().length; +const nodeGyp = process.argv[2]; + +async function runner(directoryQueue) { + if (directoryQueue.length === 0) + return; + + const dir = directoryQueue.shift(); + const next = () => runner(directoryQueue); + + try { + // Only run for directories that have a `binding.gyp`. + // (https://github.com/nodejs/node/issues/14843) + await fs.stat(path.join(dir, 'binding.gyp')); + } catch (err) { + if (err.code === 'ENOENT' || err.code === 'ENOTDIR') + return next(); + throw err; + } + + console.log(`Building addon in ${dir}`); + const { stdout, stderr } = + await execFile(process.execPath, [nodeGyp, 'rebuild', `--directory=${dir}`], + { + stdio: 'inherit', + env: { ...process.env, MAKEFLAGS: '-j1' } + }); + + // We buffer the output and print it out once the process is done in order + // to avoid interleaved output from multiple builds running at once. + process.stdout.write(stdout); + process.stderr.write(stderr); + + return next(); +} + +async function main(directory) { + const directoryQueue = (await fs.readdir(directory)) + .map((subdir) => path.join(directory, subdir)); + + const runners = []; + for (let i = 0; i < parallelization; ++i) + runners.push(runner(directoryQueue)); + return Promise.all(runners); +} + +main(process.argv[3]).catch((err) => setImmediate(() => { throw err; })); |