-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
test: build test add-ons like third-party add-ons #12231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
.buildstamp | ||
.docbuildstamp | ||
Makefile | ||
*.Makefile | ||
*.mk | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.buildstamp | ||
.docbuildstamp | ||
Makefile | ||
*.Makefile | ||
*.mk | ||
gyp-mac-tool | ||
/*/build | ||
/Release/ | ||
/include/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
{ | ||
'target_name': 'binding', | ||
'sources': ['binding.cc'], | ||
'include_dirs': ['../../../deps/zlib'], | ||
}, | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const os = require('os'); | ||
const { spawn, spawnSync } = require('child_process'); | ||
const { resolve } = require('path'); | ||
|
||
const kTopLevelDirectory = resolve(__dirname, '..'); | ||
const kAddonsDirectory = resolve(kTopLevelDirectory, 'test/addons'); | ||
const kNapiAddonsDirectory = resolve(kTopLevelDirectory, 'test/addons-napi'); | ||
|
||
// Location where the headers are installed to. | ||
const kIncludeDirectory = kAddonsDirectory; | ||
|
||
const kPython = process.env.PYTHON || 'python'; | ||
const kNodeGyp = | ||
resolve(kTopLevelDirectory, 'deps/npm/node_modules/node-gyp/bin/node-gyp'); | ||
|
||
process.chdir(kTopLevelDirectory); | ||
|
||
// Copy headers to `${kIncludeDirectory}/include`. install.py preserves | ||
// timestamps so this won't cause unnecessary rebuilds. | ||
{ | ||
const args = [ 'tools/install.py', 'install', kIncludeDirectory, '/' ]; | ||
const env = Object.assign({}, process.env); | ||
env.HEADERS_ONLY = 'yes, please'; // Ask nicely. | ||
env.LOGLEVEL = 'WARNING'; | ||
|
||
const options = { env, stdio: 'inherit' }; | ||
const result = spawnSync(kPython, args, options); | ||
if (result.status !== 0) process.exit(1); | ||
} | ||
|
||
// Scrape embedded add-ons from doc/api/addons.md. | ||
require('./doc/addon-verify.js'); | ||
|
||
// Regenerate build files and rebuild if necessary. | ||
let failures = 0; | ||
process.on('exit', () => process.exit(failures > 0)); | ||
|
||
const jobs = []; | ||
|
||
// test/gc contains a single add-on to build. | ||
{ | ||
const path = resolve(kTopLevelDirectory, 'test/gc'); | ||
exec(path, 'configure', () => exec(path, 'build')); | ||
} | ||
|
||
for (const directory of [kAddonsDirectory, kNapiAddonsDirectory]) { | ||
for (const basedir of fs.readdirSync(directory)) { | ||
const path = resolve(directory, basedir); | ||
const gypfile = resolve(path, 'binding.gyp'); | ||
if (!fs.existsSync(gypfile)) continue; | ||
exec(path, 'configure', () => exec(path, 'build')); | ||
} | ||
} | ||
|
||
// FIXME(bnoordhuis) I would have liked to derive the desired level of | ||
// parallelism from MAKEFLAGS but it's missing the actual -j<jobs> flag. | ||
for (const _ of os.cpus()) next(); // eslint-disable-line no-unused-vars | ||
|
||
function next() { | ||
const job = jobs.shift(); | ||
if (job) job(); | ||
} | ||
|
||
function exec(path, command, done) { | ||
jobs.push(() => { | ||
if (failures > 0) return; | ||
|
||
const args = [kNodeGyp, | ||
'--loglevel=silent', | ||
'--directory=' + path, | ||
'--nodedir=' + kIncludeDirectory, | ||
'--python=' + kPython, | ||
command]; | ||
|
||
const env = Object.assign({}, process.env); | ||
env.MAKEFLAGS = '-j1'; | ||
|
||
const options = { env, stdio: 'inherit' }; | ||
const proc = spawn(process.execPath, args, options); | ||
|
||
proc.on('exit', (exitCode) => { | ||
if (exitCode !== 0) ++failures; | ||
if (done) done(); | ||
next(); | ||
}); | ||
|
||
console.log(command, path); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could console.log call perhaps be removed in favour of just printing |
||
}); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps
--silent
could be added to this to avoid extra output?