Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cd71aad

Browse filesBrowse files
NickNasotargos
authored andcommitted
build: expose napi_build_version variable
Expose `napi_build_version` to allow `node-gyp` to make it available for building native addons. Fixes: nodejs/node-gyp#1745 Refs: nodejs/abi-stable-node#371 PR-URL: #27835 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent 8a64b70 commit cd71aad
Copy full SHA for cd71aad

File tree

Expand file treeCollapse file tree

6 files changed

+44
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+44
-2
lines changed
Open diff view settings
Collapse file

‎configure.py‎

Copy file name to clipboardExpand all lines: configure.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
# imports in tools/
3535
sys.path.insert(0, 'tools')
3636
import getmoduleversion
37+
import getnapibuildversion
3738
from gyp_node import run_gyp
3839

3940
# imports in deps/v8/tools/node
@@ -1147,6 +1148,10 @@ def configure_node(o):
11471148
else:
11481149
o['variables']['node_target_type'] = 'executable'
11491150

1151+
def configure_napi(output):
1152+
version = getnapibuildversion.get_napi_version()
1153+
output['variables']['napi_build_version'] = version
1154+
11501155
def configure_library(lib, output):
11511156
shared_lib = 'shared_' + lib
11521157
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
@@ -1626,6 +1631,7 @@ def make_bin_override():
16261631
flavor = GetFlavor(flavor_params)
16271632

16281633
configure_node(output)
1634+
configure_napi(output)
16291635
configure_library('zlib', output)
16301636
configure_library('http_parser', output)
16311637
configure_library('libuv', output)
Collapse file

‎doc/api/process.md‎

Copy file name to clipboardExpand all lines: doc/api/process.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ An example of the possible output looks like:
662662
variables:
663663
{
664664
host_arch: 'x64',
665+
napi_build_version: 4,
665666
node_install_npm: 'true',
666667
node_prefix: '',
667668
node_shared_cares: 'false',
Collapse file

‎src/js_native_api.h‎

Copy file name to clipboardExpand all lines: src/js_native_api.h
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
#ifdef NAPI_EXPERIMENTAL
1313
#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL
1414
#else
15-
// The baseline version for N-API
15+
// The baseline version for N-API.
16+
// The NAPI_VERSION controls which version will be used by default when
17+
// compilling a native addon. If the addon developer specifically wants to use
18+
// functions available in a new version of N-API that is not yet ported in all
19+
// LTS versions, they can set NAPI_VERSION knowing that they have specifically
20+
// depended on that version.
1621
#define NAPI_VERSION 4
1722
#endif
1823
#endif
Collapse file

‎src/node_version.h‎

Copy file name to clipboardExpand all lines: src/node_version.h
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
*/
9292
#define NODE_MODULE_VERSION 72
9393

94-
// the NAPI_VERSION provided by this version of the runtime
94+
// The NAPI_VERSION provided by this version of the runtime. This is the version
95+
// which the Node binary being built supports.
9596
#define NAPI_VERSION 4
9697

9798
#endif // SRC_NODE_VERSION_H_
Collapse file

‎test/parallel/test-process-versions.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-process-versions.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ for (let i = 0; i < expected_keys.length; i++) {
4545
const descriptor = Object.getOwnPropertyDescriptor(process.versions, key);
4646
assert.strictEqual(descriptor.writable, false);
4747
}
48+
49+
assert.strictEqual(process.config.variables.napi_build_version,
50+
process.versions.napi);
Collapse file

‎tools/getnapibuildversion.py‎

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import print_function
2+
import os
3+
import re
4+
5+
6+
def get_napi_version():
7+
napi_version_h = os.path.join(
8+
os.path.dirname(__file__),
9+
'..',
10+
'src',
11+
'node_version.h')
12+
13+
f = open(napi_version_h)
14+
15+
regex = '^#define NAPI_VERSION'
16+
17+
for line in f:
18+
if re.match(regex, line):
19+
napi_version = line.split()[2]
20+
return napi_version
21+
22+
raise Exception('Could not find pattern matching %s' % regex)
23+
24+
25+
if __name__ == '__main__':
26+
print(get_napi_version())

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.