-
Notifications
You must be signed in to change notification settings - Fork 465
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
tools: add tool to check for N-API modules #346
Conversation
src/node_api.gyp
Outdated
@@ -1,7 +1,8 @@ | |||
{ | |||
'targets': [ | |||
{ | |||
'target_name': 'nothing' | |||
'target_name': 'nothing', | |||
'type': 'static_library' |
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.
Is this part of the intended change? Does not seem related to adding the script to check if modules are N-API or not.
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.
It kind of is. We need this so that node-addon-api might stop creating nothing.node
files in other projects. I did change the script to ignore nothing.node
files, but that's kind of a kludge. There's nothing stopping module authors from calling their module nothing
, and the script would ignore it.
I'll PR it separately.
Adds tools/check-napi.js which uses `nm -a` on UNIX and `dumpbin /imports` on Windows to check whether a given `.node` file is an N-API module or not. Intentionally ignores files named `nothing.node` because they are node-addon-api build artefacts. Sets the target type for `nothing` (which gets built when a built-in N-API is found to be present) to `'static_library'` so as to avoid the creation of `nothing.node` files which incorrectly end up showing up in the output of `check-napi.js` as non-N-API modules.
357cd28
to
882be6d
Compare
tools/check-napi.js
Outdated
line = line.match(/([0-9a-f]*)? ([a-zA-Z]) (.*$)/); | ||
line.shift(); | ||
if (line[1] === 'U') { | ||
if (line[2].match(/^napi/)) { |
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.
Wouldn't returning from here and changing the condition at 41 to !soFar
be better?
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.
Also, if we don't want to get the matches but need to check if the string matches the format, then I believe RegExp#test
would be better.
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.
I don't like having return true
up here and then return soFar
at the bottom. I'd rather have one return statement for the whole function.
The reason I don't have !soFar
at the top is so if, in the future, we add a check that will disqualify a file from being N-API, we can set soFar to false
and have the rest short-circuit.
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.
Fair enough 👍
tools/check-napi.js
Outdated
child.stdout.on('data', (chunk) => { | ||
if (isNapi === undefined) { | ||
chunk = leftover + chunk.toString(); | ||
const haveLeftover = !!chunk.match(/[\r\n]+$/); |
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.
I think this can be removed as it is not used.
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.
Is the chunk guaranteed to end on a line boundary?
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.
Oh, NM. You meant the variable, not the rest of the logic. You're right.
tools/check-napi.js
Outdated
const haveLeftover = !!chunk.match(/[\r\n]+$/); | ||
chunk = chunk.split(/[\r\n]+/); | ||
leftover = chunk.pop(); | ||
isNapi = chunk.reduce(reducer, isNapi); |
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.
At this point, we can kill the child process if isNapi
is true
, right?
6b52ecc
to
94c44e3
Compare
94c44e3
to
9c81e5f
Compare
@@ -0,0 +1,96 @@ | |||
// Descend into a directory structure and, for each file matching *.node, output | |||
// based on the imports found in the file whether it's an N-API module or not. | |||
|
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.
Nit: Generally strict mode is preferred.
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.
@thefourtheye fixed, and a good thing too, because it had implications for the rest of the code. Thanks!
tools/check-napi.js
Outdated
// Use nm -a to list symbols. | ||
function checkFileUNIX(file) { | ||
checkFile(file, 'nm', ['-a', file], (soFar, line) => { | ||
if (soFar === undefined) { |
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.
Nit: Indentation is not consistent in this and the other two functions as well.
// Descend into a directory structure and pass each file ending in '.node' to | ||
// one of the above checks, depending on the OS. | ||
function recurse(top) { | ||
fs.readdir(top, (error, items) => { |
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.
Nit: This error is ignored.
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.
Fixed.
I'll assume the script does what it needs to, but I think we should also add some doc somewhere that explains how it is used. |
@mhdawson I added a document that explains the workings of the script, and I linked it off the main README.md – just like the documentation for the conversion script, after which I modelled it. |
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.
LGTM
Adds tools/check-napi.js which uses `nm -a` on UNIX and `dumpbin /imports` on Windows to check whether a given `.node` file is an N-API module or not. Intentionally ignores files named `nothing.node` because they are node-addon-api build artefacts. Sets the target type for `nothing` (which gets built when a built-in N-API is found to be present) to `'static_library'` so as to avoid the creation of `nothing.node` files which incorrectly end up showing up in the output of `check-napi.js` as non-N-API modules. PR-URL: #346 Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Landed as fd3c37b |
Adds tools/check-napi.js which uses `nm -a` on UNIX and `dumpbin /imports` on Windows to check whether a given `.node` file is an N-API module or not. Intentionally ignores files named `nothing.node` because they are node-addon-api build artefacts. Sets the target type for `nothing` (which gets built when a built-in N-API is found to be present) to `'static_library'` so as to avoid the creation of `nothing.node` files which incorrectly end up showing up in the output of `check-napi.js` as non-N-API modules. PR-URL: nodejs/node-addon-api#346 Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Adds tools/check-napi.js which uses `nm -a` on UNIX and `dumpbin /imports` on Windows to check whether a given `.node` file is an N-API module or not. Intentionally ignores files named `nothing.node` because they are node-addon-api build artefacts. Sets the target type for `nothing` (which gets built when a built-in N-API is found to be present) to `'static_library'` so as to avoid the creation of `nothing.node` files which incorrectly end up showing up in the output of `check-napi.js` as non-N-API modules. PR-URL: nodejs/node-addon-api#346 Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Adds tools/check-napi.js which uses `nm -a` on UNIX and `dumpbin /imports` on Windows to check whether a given `.node` file is an N-API module or not. Intentionally ignores files named `nothing.node` because they are node-addon-api build artefacts. Sets the target type for `nothing` (which gets built when a built-in N-API is found to be present) to `'static_library'` so as to avoid the creation of `nothing.node` files which incorrectly end up showing up in the output of `check-napi.js` as non-N-API modules. PR-URL: nodejs/node-addon-api#346 Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Adds tools/check-napi.js which uses `nm -a` on UNIX and `dumpbin /imports` on Windows to check whether a given `.node` file is an N-API module or not. Intentionally ignores files named `nothing.node` because they are node-addon-api build artefacts. Sets the target type for `nothing` (which gets built when a built-in N-API is found to be present) to `'static_library'` so as to avoid the creation of `nothing.node` files which incorrectly end up showing up in the output of `check-napi.js` as non-N-API modules. PR-URL: nodejs/node-addon-api#346 Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
Adds tools/check-napi.js which uses
nm -a
on UNIX anddumpbin /imports
on Windows to check whether a given.node
fileis an N-API module or not. Intentionally ignores files named
nothing.node
because they are node-addon-api build artefacts.Sets the target type for
nothing
(which gets built when a built-inN-API is found to be present) to
'static_library'
so as to avoid thecreation of
nothing.node
files which incorrectly end up showing up inthe output of
check-napi.js
as non-N-API modules.