summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNickNaso <nicoladelgobbo@gmail.com>2019-05-23 11:57:31 +0200
committerRichard Lau <rlau@redhat.com>2020-10-07 06:59:44 -0400
commitb83f9a56fc3e3b507dee17c00958c001b6f427f1 (patch)
tree259ae59b56834c86b9beacffbd1cee846c6ec88b
parent2eb627301c1f6681ec51f43b84e37f3908514853 (diff)
downloadnode-new-b83f9a56fc3e3b507dee17c00958c001b6f427f1.tar.gz
build: expose napi_build_version variable
Expose `napi_build_version` to allow `node-gyp` to make it available for building native addons. Fixes: https://github.com/nodejs/node-gyp/issues/1745 Refs: https://github.com/nodejs/abi-stable-node/issues/371 PR-URL: https://github.com/nodejs/node/pull/27835 Backport-PR-URL: https://github.com/nodejs/node/pull/35266 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>
-rwxr-xr-xconfigure.py6
-rw-r--r--doc/api/process.md1
-rw-r--r--src/node_api.h7
-rw-r--r--test/parallel/test-process-versions.js3
-rw-r--r--tools/getnapibuildversion.py26
5 files changed, 42 insertions, 1 deletions
diff --git a/configure.py b/configure.py
index 89f7bf5b7b..380e8bb392 100755
--- a/configure.py
+++ b/configure.py
@@ -34,6 +34,7 @@ import nodedownload
# imports in tools/
sys.path.insert(0, 'tools')
import getmoduleversion
+import getnapibuildversion
from gyp_node import run_gyp
# imports in deps/v8/tools/node
@@ -1131,6 +1132,10 @@ def configure_node(o):
else:
o['variables']['node_target_type'] = 'executable'
+def configure_napi(output):
+ version = getnapibuildversion.get_napi_version()
+ output['variables']['napi_build_version'] = version
+
def configure_library(lib, output):
shared_lib = 'shared_' + lib
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
@@ -1603,6 +1608,7 @@ if (options.dest_os):
flavor = GetFlavor(flavor_params)
configure_node(output)
+configure_napi(output)
configure_library('zlib', output)
configure_library('http_parser', output)
configure_library('libuv', output)
diff --git a/doc/api/process.md b/doc/api/process.md
index 2a91ca5732..23e07dda86 100644
--- a/doc/api/process.md
+++ b/doc/api/process.md
@@ -661,6 +661,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',
diff --git a/src/node_api.h b/src/node_api.h
index 3b1ee6eaf6..c3bd4da123 100644
--- a/src/node_api.h
+++ b/src/node_api.h
@@ -9,7 +9,12 @@
// Use INT_MAX, this should only be consumed by the pre-processor anyway.
#define NAPI_VERSION 2147483647
#else
-// The baseline version for N-API
+// The baseline version for N-API.
+// The NAPI_VERSION controls which version will be used by default when
+// compilling a native addon. If the addon developer specifically wants to use
+// functions available in a new version of N-API that is not yet ported in all
+// LTS versions, they can set NAPI_VERSION knowing that they have specifically
+// depended on that version.
#define NAPI_VERSION 6
#endif
#endif
diff --git a/test/parallel/test-process-versions.js b/test/parallel/test-process-versions.js
index d04748517f..0badfbc28e 100644
--- a/test/parallel/test-process-versions.js
+++ b/test/parallel/test-process-versions.js
@@ -43,3 +43,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);
diff --git a/tools/getnapibuildversion.py b/tools/getnapibuildversion.py
new file mode 100644
index 0000000000..de1de676d3
--- /dev/null
+++ b/tools/getnapibuildversion.py
@@ -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',
+ 'node_version.h')
+
+ f = open(napi_version_h)
+
+ regex = '^#define NAPI_VERSION'
+
+ 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())