Skip to content

Commit f27623f

Browse files
lovellmhdawson
authored andcommitted
build: introduce include_dir
Introduce `include_dir` for use with gyp in a scalar context Deprecate use of `include` in an gyp array context, which happens to work when paths are absolute, but can fail on Windows when paths are relative and a gyp file contains multiple entries in its `include_dirs` directive. This change corrects documentation and tooling, adds support for relative paths (e.g. those containing whitespace) in a backwards compatible manner and makes the approach holistically consistent with that used by nan. PR-URL: #766 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent 9aceea7 commit f27623f

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
}]
1717
],
18-
'include_dirs': ["<!@(node -p \"require('../').include\")"],
18+
'include_dirs': ["<!(node -p \"require('../').include_dir\")"],
1919
'cflags': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ],
2020
'cflags_cc': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ]
2121
}

doc/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ To use **N-API** in a native module:
2626
2. Reference this package's include directory and gyp file in `binding.gyp`:
2727

2828
```gyp
29-
'include_dirs': ["<!@(node -p \"require('node-addon-api').include\")"],
29+
'include_dirs': ["<!(node -p \"require('node-addon-api').include_dir\")"],
3030
```
3131

3232
3. Decide whether the package will enable C++ exceptions in the N-API wrapper.

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const path = require('path');
22

3-
const include = path.relative('.', __dirname);
3+
const include_dir = path.relative('.', __dirname);
44

55
module.exports = {
6-
include: include,
7-
gyp: path.join(include, 'node_api.gyp:nothing'),
6+
include: `"${__dirname}"`, // deprecated, can be removed as part of 4.0.0
7+
include_dir,
8+
gyp: path.join(include_dir, 'node_api.gyp:nothing'),
89
isNodeApiBuiltin: true,
910
needsFlag: false
1011
};

tools/conversion.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ if (disable != "--disable" && dir != "--disable") {
2222
[ /[ ]*"nan": *"[^"]+"(,|)[\n\r]/g, '' ]
2323
],
2424
'binding.gyp': [
25-
[ /([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'<!@(node -p "require(\\\'node-addon-api\\\').include")\',' ],
26-
[ /([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "<!@(node -p \\"require(\'node-addon-api\').include\\")",' ],
25+
[ /([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'<!(node -p "require(\\\'node-addon-api\\\').include_dir")\',' ],
26+
[ /([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "<!(node -p \\"require(\'node-addon-api\').include_dir\\")",' ],
2727
[ /[ ]*("|')<!\(node -e ("|'|\\"|\\')require\(("|'|\\"|\\')nan("|'|\\"|\\')\)("|'|\\"|\\')\)("|')(,|)[\r\n]/g, '' ],
2828
[ /([ ]*)("|')target_name("|'): ("|')(.+?)("|'),/g, '$1$2target_name$2: $4$5$6,\n $2cflags!$2: [ $2-fno-exceptions$2 ],\n $2cflags_cc!$2: [ $2-fno-exceptions$2 ],\n $2xcode_settings$2: { $2GCC_ENABLE_CPP_EXCEPTIONS$2: $2YES$2,\n $2CLANG_CXX_LIBRARY$2: $2libc++$2,\n $2MACOSX_DEPLOYMENT_TARGET$2: $210.7$2,\n },\n $2msvs_settings$2: {\n $2VCCLCompilerTool$2: { $2ExceptionHandling$2: 1 },\n },' ],
2929
]
@@ -35,8 +35,8 @@ if (disable != "--disable" && dir != "--disable") {
3535
[ /[ ]*"nan": *"[^"]+"(,|)[\n\r]/g, '' ]
3636
],
3737
'binding.gyp': [
38-
[ /([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'<!@(node -p "require(\\\'node-addon-api\\\').include")\',' ],
39-
[ /([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "<!@(node -p \'require(\\\"node-addon-api\\\").include\')",' ],
38+
[ /([ ]*)'include_dirs': \[/g, '$1\'include_dirs\': [\n$1 \'<!(node -p "require(\\\'node-addon-api\\\').include_dir")\',' ],
39+
[ /([ ]*)"include_dirs": \[/g, '$1"include_dirs": [\n$1 "<!(node -p \'require(\\\"node-addon-api\\\").include_dir\')",' ],
4040
[ /[ ]*("|')<!\(node -e ("|'|\\"|\\')require\(("|'|\\"|\\')nan("|'|\\"|\\')\)("|'|\\"|\\')\)("|')(,|)[\r\n]/g, '' ],
4141
[ /([ ]*)("|')target_name("|'): ("|')(.+?)("|'),/g, '$1$2target_name$2: $4$5$6,\n $2cflags!$2: [ $2-fno-exceptions$2 ],\n $2cflags_cc!$2: [ $2-fno-exceptions$2 ],\n $2defines$2: [ $2NAPI_DISABLE_CPP_EXCEPTIONS$2 ],\n $2conditions$2: [\n [\'OS==\"win\"\', { $2defines$2: [ $2_HAS_EXCEPTIONS=1$2 ] }]\n ]' ],
4242
]

0 commit comments

Comments
 (0)