tools: add tool to check for N-API modules#346
tools: add tool to check for N-API modules#346gabrielschulhof wants to merge 3 commits intonodejs:masterfrom
Conversation
| { | ||
| 'target_name': 'nothing' | ||
| 'target_name': 'nothing', | ||
| 'type': 'static_library' |
There was a problem hiding this comment.
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.
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
| 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.
Wouldn't returning from here and changing the condition at 41 to !soFar be better?
There was a problem hiding this comment.
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.
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.
| 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.
I think this can be removed as it is not used.
There was a problem hiding this comment.
Is the chunk guaranteed to end on a line boundary?
There was a problem hiding this comment.
Oh, NM. You meant the variable, not the rest of the logic. You're right.
| 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.
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.
Nit: Generally strict mode is preferred.
There was a problem hiding this comment.
@thefourtheye fixed, and a good thing too, because it had implications for the rest of the code. Thanks!
| // 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.
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) => { |
|
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. |
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 <thechargingvolcano@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
|
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 <thechargingvolcano@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
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 <thechargingvolcano@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
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 <thechargingvolcano@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
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 <thechargingvolcano@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Adds tools/check-napi.js which uses
nm -aon UNIX anddumpbin /importson Windows to check whether a given.nodefileis an N-API module or not. Intentionally ignores files named
nothing.nodebecause 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.nodefiles which incorrectly end up showing up inthe output of
check-napi.jsas non-N-API modules.