Skip to content
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

build: expose napi_build_version variable to native addons #27835

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# imports in tools/
sys.path.insert(0, 'tools')
import getmoduleversion
import getnapibuildversion
from gyp_node import run_gyp

# imports in deps/v8/tools/node
Expand Down Expand Up @@ -1097,6 +1098,9 @@ def configure_node(o):
else:
o['variables']['node_target_type'] = 'executable'

def configure_napi(output):
output['variables']['napi_build_version'] = getnapibuildversion.get_napi_version()
NickNaso marked this conversation as resolved.
Show resolved Hide resolved

def configure_library(lib, output):
shared_lib = 'shared_' + lib
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
Expand Down Expand Up @@ -1576,6 +1580,7 @@ def make_bin_override():
flavor = GetFlavor(flavor_params)

configure_node(output)
configure_napi(output)
configure_library('zlib', output)
configure_library('http_parser', output)
configure_library('libuv', output)
Expand Down
1 change: 1 addition & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ An example of the possible output looks like:
variables:
{
host_arch: 'x64',
napi_build_version: 4,
node_install_npm: 'true',
node_prefix: '',
node_shared_cares: 'false',
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-process-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ for (let i = 0; i < expected_keys.length; i++) {
const descriptor = Object.getOwnPropertyDescriptor(process.versions, key);
assert.strictEqual(descriptor.writable, false);
}

assert.strictEqual(process.config.variables.napi_build_version,
process.versions.napi);
26 changes: 26 additions & 0 deletions tools/getnapibuildversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import print_function
import os
import re


def get_napi_version():
napi_version_h = os.path.join(
os.path.dirname(__file__),
'..',
'src',
'js_native_api.h')

f = open(napi_version_h)

regex = '^#define NAPI_VERSION [0-9]+'

for line in f:
if re.match(regex, line):
napi_version = line.split()[2]
return napi_version

raise Exception('Could not find pattern matching %s' % regex)


if __name__ == '__main__':
print(get_napi_version())