Skip to content

Commit 80677c9

Browse files
test: add bindings and logs for NAPI_EXPERIMENTAL warnings
1 parent 73a0592 commit 80677c9

File tree

6 files changed

+234
-0
lines changed

6 files changed

+234
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <node_api.h>
2+
3+
static napi_value Method(const napi_env env,
4+
const napi_callback_info info) {
5+
napi_value result;
6+
napi_create_string_utf8(env, "world", NAPI_AUTO_LENGTH, &result);
7+
return result;
8+
}
9+
10+
static napi_value InitModule(napi_env env, napi_value exports) {
11+
napi_value hello;
12+
napi_create_function(env, "hello", NAPI_AUTO_LENGTH, Method, nullptr, &hello);
13+
napi_set_named_property(env, exports, "hello", hello);
14+
return exports;
15+
}
16+
17+
NAPI_MODULE(NODE_GYP_MODULE_NAME, InitModule)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'binding',
5+
'sources': [ 'binding.cc' ],
6+
'defines': [ 'NAPI_EXPERIMENTAL' ],
7+
'cflags': ['-v'],
8+
'variables': {
9+
'CXX': '<!(echo $CXX)'
10+
}
11+
},
12+
{
13+
'target_name': 'binding2',
14+
'sources': [ 'binding2.cc' ],
15+
'defines': [ 'NAPI_EXPERIMENTAL', 'NODE_API_EXPERIMENTAL_NO_WARNING' ],
16+
'cflags': ['-v'],
17+
'variables': {
18+
'CXX': '<!(echo $CXX)'
19+
}
20+
}
21+
]
22+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <node_api.h>
2+
3+
static napi_value Method(const napi_env env,
4+
const napi_callback_info info) {
5+
napi_value result;
6+
napi_create_string_utf8(env, "world", NAPI_AUTO_LENGTH, &result);
7+
return result;
8+
}
9+
10+
static napi_value InitModule(napi_env env, napi_value exports) {
11+
napi_value hello;
12+
napi_create_function(env, "hello", NAPI_AUTO_LENGTH, Method, nullptr, &hello);
13+
napi_set_named_property(env, exports, "hello", hello);
14+
return exports;
15+
}
16+
17+
NAPI_MODULE(NODE_GYP_MODULE_NAME, InitModule)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
gyp info it worked if it ends with ok
2+
gyp verb cli [
3+
gyp verb cli '*/.nvm/versions/node/v22.15.0/bin/node',
4+
gyp verb cli '*/.nvm/versions/node/v22.15.0/bin/node-gyp',
5+
gyp verb cli 'rebuild',
6+
gyp verb cli '--verbose',
7+
gyp verb cli '--nodedir=*'
8+
gyp verb cli ]
9+
gyp info using [email protected]
10+
gyp info using [email protected] | darwin | arm64
11+
gyp verb clean removing "build" directory
12+
gyp verb find Python Python is not set from command line or npm configuration
13+
gyp verb find Python Python is not set from environment variable PYTHON
14+
gyp verb find Python checking if "python3" can be used
15+
gyp verb find Python - executing "python3" to get executable path
16+
gyp verb find Python - executable path is "/opt/homebrew/opt/[email protected]/bin/python3.13"
17+
gyp verb find Python - executing "/opt/homebrew/opt/[email protected]/bin/python3.13" to get version
18+
gyp verb find Python - version is "3.13.3"
19+
gyp info find Python using Python version 3.13.3 found at "/opt/homebrew/opt/[email protected]/bin/python3.13"
20+
gyp verb get node dir compiling against specified --nodedir dev files: *
21+
gyp verb build dir attempting to create "build" dir: */test/js-native-api/test_warning/build
22+
gyp verb build dir "build" dir needed to be created? Yes
23+
gyp verb build/config.gypi creating config file
24+
gyp WARN read config.gypi ENOENT: no such file or directory, open '*/include/node/config.gypi'
25+
gyp verb build/config.gypi writing out config file: */test/js-native-api/test_warning/build/config.gypi
26+
gyp verb config.gypi checking for gypi file: */test/js-native-api/test_warning/config.gypi
27+
gyp verb common.gypi checking for gypi file: */test/js-native-api/test_warning/common.gypi
28+
gyp verb gyp gyp format was not specified; forcing "make"
29+
gyp info spawn /opt/homebrew/opt/[email protected]/bin/python3.13
30+
gyp info spawn args [
31+
gyp info spawn args '*/.nvm/versions/node/v22.15.0/lib/node_modules/node-gyp/gyp/gyp_main.py',
32+
gyp info spawn args 'binding.gyp',
33+
gyp info spawn args '-f',
34+
gyp info spawn args 'make',
35+
gyp info spawn args '-I',
36+
gyp info spawn args '*/test/js-native-api/test_warning/build/config.gypi',
37+
gyp info spawn args '-I',
38+
gyp info spawn args '*/.nvm/versions/node/v22.15.0/lib/node_modules/node-gyp/addon.gypi',
39+
gyp info spawn args '-I',
40+
gyp info spawn args '*/common.gypi',
41+
gyp info spawn args '-Dlibrary=shared_library',
42+
gyp info spawn args '-Dvisibility=default',
43+
gyp info spawn args '-Dnode_root_dir=*',
44+
gyp info spawn args '-Dnode_gyp_dir=*/.nvm/versions/node/v22.15.0/lib/node_modules/node-gyp',
45+
gyp info spawn args '-Dnode_lib_file=*/$(Configuration)/node.lib',
46+
gyp info spawn args '-Dmodule_root_dir=*/test/js-native-api/test_warning',
47+
gyp info spawn args '-Dnode_engine=v8',
48+
gyp info spawn args '--depth=.',
49+
gyp info spawn args '--no-parallel',
50+
gyp info spawn args '--generator-output',
51+
gyp info spawn args 'build',
52+
gyp info spawn args '-Goutput_dir=.'
53+
gyp info spawn args ]
54+
gyp verb build type Release
55+
gyp verb architecture arm64
56+
gyp verb node dev dir *
57+
gyp verb python /opt/homebrew/opt/[email protected]/bin/python3.13
58+
gyp verb `which` succeeded for `make` /usr/bin/make
59+
gyp verb bin symlinks created symlink to "/opt/homebrew/opt/[email protected]/bin/python3.13" in "*/test/js-native-api/test_warning/build/node_gyp_bins" and added to PATH
60+
gyp info spawn make
61+
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
62+
clang++ -o Release/obj.target/binding/binding.o ../binding.cc '-DNODE_GYP_MODULE_NAME=binding' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_FILE_OFFSET_BITS=64' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DNAPI_EXPERIMENTAL' '-DBUILDING_NODE_EXTENSION' -I*/include/node -I*/src -I*/deps/openssl/config -I*/deps/openssl/openssl/include -I*/deps/uv/include -I*/deps/zlib -I*/deps/v8/include -O3 -gdwarf-2 -fno-strict-aliasing -mmacosx-version-min=13.5 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++20 -stdlib=libc++ -fno-rtti -fno-exceptions -MMD -MF ./Release/.deps/Release/obj.target/binding/binding.o.d.raw -c
63+
In file included from ../binding.cc:1:
64+
In file included from */src/node_api.h:12:
65+
*/src/js_native_api.h:25:2: warning: "NAPI_EXPERIMENTAL is enabled. Experimental features may be unstable." [-W#warnings]
66+
25 | #warning "NAPI_EXPERIMENTAL is enabled. Experimental features may be unstable."
67+
| ^
68+
1 warning generated.
69+
clang++ -bundle -undefined dynamic_lookup -Wl,-search_paths_first -mmacosx-version-min=13.5 -arch arm64 -L./Release -stdlib=libc++ -o Release/binding.node Release/obj.target/binding/binding.o
70+
clang++ -o Release/obj.target/binding2/binding2.o ../binding2.cc '-DNODE_GYP_MODULE_NAME=binding2' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_FILE_OFFSET_BITS=64' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DNAPI_EXPERIMENTAL' '-DNODE_API_EXPERIMENTAL_NO_WARNING' '-DBUILDING_NODE_EXTENSION' -I*/include/node -I*/src -I*/deps/openssl/config -I*/deps/openssl/openssl/include -I*/deps/uv/include -I*/deps/zlib -I*/deps/v8/include -O3 -gdwarf-2 -fno-strict-aliasing -mmacosx-version-min=13.5 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++20 -stdlib=libc++ -fno-rtti -fno-exceptions -MMD -MF ./Release/.deps/Release/obj.target/binding2/binding2.o.d.raw -c
71+
clang++ -bundle -undefined dynamic_lookup -Wl,-search_paths_first -mmacosx-version-min=13.5 -arch arm64 -L./Release -stdlib=libc++ -o Release/binding2.node Release/obj.target/binding2/binding2.o
72+
gyp info ok
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
gyp info it worked if it ends with ok
2+
gyp verb cli [
3+
gyp verb cli '*/.nvm/versions/node/v22.15.0/bin/node',
4+
gyp verb cli '*/.nvm/versions/node/v22.15.0/bin/node-gyp',
5+
gyp verb cli 'rebuild',
6+
gyp verb cli '--verbose',
7+
gyp verb cli '--nodedir=*'
8+
gyp verb cli ]
9+
gyp info using [email protected]
10+
gyp info using [email protected] | darwin | arm64
11+
gyp verb clean removing "build" directory
12+
gyp verb find Python Python is not set from command line or npm configuration
13+
gyp verb find Python Python is not set from environment variable PYTHON
14+
gyp verb find Python checking if "python3" can be used
15+
gyp verb find Python - executing "python3" to get executable path
16+
gyp verb find Python - executable path is "/opt/homebrew/opt/[email protected]/bin/python3.13"
17+
gyp verb find Python - executing "/opt/homebrew/opt/[email protected]/bin/python3.13" to get version
18+
gyp verb find Python - version is "3.13.3"
19+
gyp info find Python using Python version 3.13.3 found at "/opt/homebrew/opt/[email protected]/bin/python3.13"
20+
gyp verb get node dir compiling against specified --nodedir dev files: *
21+
gyp verb build dir attempting to create "build" dir: */test/js-native-api/test_warning/build
22+
gyp verb build dir "build" dir needed to be created? Yes
23+
gyp verb build/config.gypi creating config file
24+
gyp WARN read config.gypi ENOENT: no such file or directory, open '*/include/node/config.gypi'
25+
gyp verb build/config.gypi writing out config file: */test/js-native-api/test_warning/build/config.gypi
26+
gyp verb config.gypi checking for gypi file: */test/js-native-api/test_warning/config.gypi
27+
gyp verb common.gypi checking for gypi file: */test/js-native-api/test_warning/common.gypi
28+
gyp verb gyp gyp format was not specified; forcing "make"
29+
gyp info spawn /opt/homebrew/opt/[email protected]/bin/python3.13
30+
gyp info spawn args [
31+
gyp info spawn args '*/.nvm/versions/node/v22.15.0/lib/node_modules/node-gyp/gyp/gyp_main.py',
32+
gyp info spawn args 'binding.gyp',
33+
gyp info spawn args '-f',
34+
gyp info spawn args 'make',
35+
gyp info spawn args '-I',
36+
gyp info spawn args '*/test/js-native-api/test_warning/build/config.gypi',
37+
gyp info spawn args '-I',
38+
gyp info spawn args '*/.nvm/versions/node/v22.15.0/lib/node_modules/node-gyp/addon.gypi',
39+
gyp info spawn args '-I',
40+
gyp info spawn args '*/common.gypi',
41+
gyp info spawn args '-Dlibrary=shared_library',
42+
gyp info spawn args '-Dvisibility=default',
43+
gyp info spawn args '-Dnode_root_dir=*',
44+
gyp info spawn args '-Dnode_gyp_dir=*/.nvm/versions/node/v22.15.0/lib/node_modules/node-gyp',
45+
gyp info spawn args '-Dnode_lib_file=*/$(Configuration)/node.lib',
46+
gyp info spawn args '-Dmodule_root_dir=*/test/js-native-api/test_warning',
47+
gyp info spawn args '-Dnode_engine=v8',
48+
gyp info spawn args '--depth=.',
49+
gyp info spawn args '--no-parallel',
50+
gyp info spawn args '--generator-output',
51+
gyp info spawn args 'build',
52+
gyp info spawn args '-Goutput_dir=.'
53+
gyp info spawn args ]
54+
gyp verb build type Release
55+
gyp verb architecture arm64
56+
gyp verb node dev dir *
57+
gyp verb python /opt/homebrew/opt/[email protected]/bin/python3.13
58+
gyp verb `which` succeeded for `make` /usr/bin/make
59+
gyp verb bin symlinks created symlink to "/opt/homebrew/opt/[email protected]/bin/python3.13" in "*/test/js-native-api/test_warning/build/node_gyp_bins" and added to PATH
60+
gyp info spawn make
61+
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
62+
g++ -o Release/obj.target/binding/binding.o ../binding.cc '-DNODE_GYP_MODULE_NAME=binding' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_FILE_OFFSET_BITS=64' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DNAPI_EXPERIMENTAL' '-DBUILDING_NODE_EXTENSION' -I*/include/node -I*/src -I*/deps/openssl/config -I*/deps/openssl/openssl/include -I*/deps/uv/include -I*/deps/zlib -I*/deps/v8/include -O3 -gdwarf-2 -fno-strict-aliasing -mmacosx-version-min=13.5 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++20 -stdlib=libc++ -fno-rtti -fno-exceptions -MMD -MF ./Release/.deps/Release/obj.target/binding/binding.o.d.raw -c
63+
In file included from ../binding.cc:1:
64+
In file included from */src/node_api.h:12:
65+
*/src/js_native_api.h:25:2: warning: "NAPI_EXPERIMENTAL is enabled. Experimental features may be unstable." [-W#warnings]
66+
25 | #warning "NAPI_EXPERIMENTAL is enabled. Experimental features may be unstable."
67+
| ^
68+
1 warning generated.
69+
g++ -bundle -undefined dynamic_lookup -Wl,-search_paths_first -mmacosx-version-min=13.5 -arch arm64 -L./Release -stdlib=libc++ -o Release/binding.node Release/obj.target/binding/binding.o
70+
g++ -o Release/obj.target/binding2/binding2.o ../binding2.cc '-DNODE_GYP_MODULE_NAME=binding2' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_GLIBCXX_USE_CXX11_ABI=1' '-D_FILE_OFFSET_BITS=64' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DNAPI_EXPERIMENTAL' '-DNODE_API_EXPERIMENTAL_NO_WARNING' '-DBUILDING_NODE_EXTENSION' -I*/include/node -I*/src -I*/deps/openssl/config -I*/deps/openssl/openssl/include -I*/deps/uv/include -I*/deps/zlib -I*/deps/v8/include -O3 -gdwarf-2 -fno-strict-aliasing -mmacosx-version-min=13.5 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++20 -stdlib=libc++ -fno-rtti -fno-exceptions -MMD -MF ./Release/.deps/Release/obj.target/binding2/binding2.o.d.raw -c
71+
g++ -bundle -undefined dynamic_lookup -Wl,-search_paths_first -mmacosx-version-min=13.5 -arch arm64 -L./Release -stdlib=libc++ -o Release/binding2.node Release/obj.target/binding2/binding2.o
72+
gyp info ok
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
const common = require('../../common');
3+
const assert = require('assert');
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
const binding = require(require.resolve(`./build/${common.buildType}/binding`));
8+
assert.strictEqual(binding.hello(), 'world');
9+
10+
const binding2 = require(require.resolve(`./build/${common.buildType}/binding2`));
11+
assert.strictEqual(binding2.hello(), 'world');
12+
13+
// Checks if the NAPI_EXPERIMENTAL warning is emitted only once.
14+
{
15+
const warningMessage = '#warning "NAPI_EXPERIMENTAL is enabled. Experimental features may be unstable."';
16+
17+
const gccLogFilePath = path.resolve(__dirname, './build_logs/build_gcc.log');
18+
const gccLogContent = fs.readFileSync(gccLogFilePath, 'utf8');
19+
20+
const gccWarningCount = gccLogContent.split(warningMessage).length - 1;
21+
const gccHasWarning = gccLogContent.includes(warningMessage);
22+
23+
assert.strictEqual(gccHasWarning, true, `Expected warning not found: "${warningMessage}"`);
24+
assert.strictEqual(gccWarningCount, 1, `Expected warning to appear exactly once, but found ${gccWarningCount} occurrences.`);
25+
26+
const clangLogFilePath = path.resolve(__dirname, './build_logs/build_clang.log');
27+
const clangLogContent = fs.readFileSync(clangLogFilePath, 'utf8');
28+
29+
const clangWarningCount = clangLogContent.split(warningMessage).length - 1;
30+
const clangHasWarning = clangLogContent.includes(warningMessage);
31+
32+
assert.strictEqual(clangHasWarning, true, `Expected warning not found: "${warningMessage}"`);
33+
assert.strictEqual(clangWarningCount, 1, `Expected warning to appear exactly once, but found ${gccWarningCount} occurrences.`);
34+
}

0 commit comments

Comments
 (0)