From e9f8fc74da2e6f3f4849d5907071bcad7ca2ab78 Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Tue, 14 Jul 2020 13:34:32 +0100 Subject: [PATCH 1/4] 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. --- common.gypi | 2 +- doc/setup.md | 2 +- index.js | 7 ++++--- tools/conversion.js | 8 ++++---- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/common.gypi b/common.gypi index 088f961ea..9be254f0b 100644 --- a/common.gypi +++ b/common.gypi @@ -15,7 +15,7 @@ } }] ], - 'include_dirs': [" Date: Fri, 4 Sep 2020 02:41:14 +0200 Subject: [PATCH 2/4] Added tetes to check the building process. --- package.json | 1 + test/addon_build/index.js | 44 ++++++++++++++++++++++ test/addon_build/tpl/.npmrc | 1 + test/addon_build/tpl/addon.cc | 17 +++++++++ test/addon_build/tpl/binding.gyp | 62 +++++++++++++++++++++++++++++++ test/addon_build/tpl/index.js | 10 +++++ test/addon_build/tpl/package.json | 11 ++++++ test/index.js | 1 + 8 files changed, 147 insertions(+) create mode 100644 test/addon_build/index.js create mode 100644 test/addon_build/tpl/.npmrc create mode 100644 test/addon_build/tpl/addon.cc create mode 100644 test/addon_build/tpl/binding.gyp create mode 100644 test/addon_build/tpl/index.js create mode 100644 test/addon_build/tpl/package.json diff --git a/package.json b/package.json index 64a44f32a..0ec1d6ed6 100644 --- a/package.json +++ b/package.json @@ -252,6 +252,7 @@ "description": "Node.js API (N-API)", "devDependencies": { "benchmark": "^2.1.4", + "fs-extra": "^9.0.1", "bindings": "^1.5.0", "safe-buffer": "^5.1.1" }, diff --git a/test/addon_build/index.js b/test/addon_build/index.js new file mode 100644 index 000000000..763274092 --- /dev/null +++ b/test/addon_build/index.js @@ -0,0 +1,44 @@ +'use strict'; + +const { promisify } = require('util'); +const exec = promisify(require('child_process').exec); +const { copy, remove } = require('fs-extra'); +const path = require('path'); +const assert = require('assert') + +const addons = [ + 'echo addon', + 'echo-addon' +] + +async function before(addon) { + await copy(path.join(__dirname, 'tpl'), path.join(__dirname, addon)) +} + +async function after(addon) { + await remove(path.join(__dirname, addon)); +} + +async function test(addon) { + await before(addon) + const { stderr, stdout } = await exec('npm install', { + cwd: path.join(__dirname, addon) + }) + assert.strictEqual(stderr, ''); + assert.ok(stderr.length === 0); + assert.ok(stdout.length > 0); + const binding = require(`./${addon}`); + assert.strictEqual(binding.except.echo('except'), 'except'); + assert.strictEqual(binding.except.echo(101), 101); + assert.strictEqual(binding.noexcept.echo('noexcept'), 'noexcept'); + assert.strictEqual(binding.noexcept.echo(103), 103); + await after(addon); +} + + +module.exports = (async function() { + for (const addon of addons) { + await test(addon) + } + +})() diff --git a/test/addon_build/tpl/.npmrc b/test/addon_build/tpl/.npmrc new file mode 100644 index 000000000..9cf949503 --- /dev/null +++ b/test/addon_build/tpl/.npmrc @@ -0,0 +1 @@ +package-lock=false \ No newline at end of file diff --git a/test/addon_build/tpl/addon.cc b/test/addon_build/tpl/addon.cc new file mode 100644 index 000000000..1a86799c4 --- /dev/null +++ b/test/addon_build/tpl/addon.cc @@ -0,0 +1,17 @@ +#include + +Napi::Value Echo(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + if (info.Length() != 1) { + Napi::TypeError::New(env, "Wrong number of arguments. One argument expected.") + .ThrowAsJavaScriptException(); + } + return info[0].As(); +} + +Napi::Object Init(Napi::Env env, Napi::Object exports) { + exports.Set(Napi::String::New(env, "echo"), Napi::Function::New(env, Echo)); + return exports; +} + +NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init) diff --git a/test/addon_build/tpl/binding.gyp b/test/addon_build/tpl/binding.gyp new file mode 100644 index 000000000..96c1a02dc --- /dev/null +++ b/test/addon_build/tpl/binding.gyp @@ -0,0 +1,62 @@ +{ + 'target_defaults': { + 'include_dirs': [ + " Date: Mon, 7 Sep 2020 10:51:32 +0200 Subject: [PATCH 3/4] Fixed test ececuton on WIndows. --- .gitignore | 1 + test/addon_build/index.js | 26 ++++++++++++++------------ test/addon_build/tpl/binding.gyp | 2 +- test/addon_build/tpl/package.json | 2 +- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index c10f4dffc..c5b8bc871 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /build /benchmark/build /benchmark/src +/test/addon_build/addons diff --git a/test/addon_build/index.js b/test/addon_build/index.js index 763274092..fed4ac72a 100644 --- a/test/addon_build/index.js +++ b/test/addon_build/index.js @@ -6,39 +6,41 @@ const { copy, remove } = require('fs-extra'); const path = require('path'); const assert = require('assert') +const ADDONS_FOLDER = path.join(__dirname, 'addons'); + const addons = [ 'echo addon', 'echo-addon' ] -async function before(addon) { - await copy(path.join(__dirname, 'tpl'), path.join(__dirname, addon)) -} - -async function after(addon) { - await remove(path.join(__dirname, addon)); +async function beforeAll(addons) { + console.log(' >Preparing native addons to build') + for (const addon of addons) { + await remove(path.join(ADDONS_FOLDER, addon)); + await copy(path.join(__dirname, 'tpl'), path.join(ADDONS_FOLDER, addon)); + } } async function test(addon) { - await before(addon) + console.log(` >Building addon: '${addon}'`); const { stderr, stdout } = await exec('npm install', { - cwd: path.join(__dirname, addon) + cwd: path.join(ADDONS_FOLDER, addon) }) + console.log(` >Runting test for: '${addon}'`); assert.strictEqual(stderr, ''); assert.ok(stderr.length === 0); assert.ok(stdout.length > 0); - const binding = require(`./${addon}`); + const binding = require(`${ADDONS_FOLDER}/${addon}`); assert.strictEqual(binding.except.echo('except'), 'except'); assert.strictEqual(binding.except.echo(101), 101); assert.strictEqual(binding.noexcept.echo('noexcept'), 'noexcept'); assert.strictEqual(binding.noexcept.echo(103), 103); - await after(addon); } module.exports = (async function() { + await beforeAll(addons); for (const addon of addons) { - await test(addon) + await test(addon); } - })() diff --git a/test/addon_build/tpl/binding.gyp b/test/addon_build/tpl/binding.gyp index 96c1a02dc..18fa0d91b 100644 --- a/test/addon_build/tpl/binding.gyp +++ b/test/addon_build/tpl/binding.gyp @@ -1,7 +1,7 @@ { 'target_defaults': { 'include_dirs': [ - " Date: Tue, 8 Sep 2020 06:32:47 +0200 Subject: [PATCH 4/4] Disabled some checks because of issue on npm. --- test/addon_build/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/addon_build/index.js b/test/addon_build/index.js index fed4ac72a..dcfd2edf1 100644 --- a/test/addon_build/index.js +++ b/test/addon_build/index.js @@ -27,9 +27,13 @@ async function test(addon) { cwd: path.join(ADDONS_FOLDER, addon) }) console.log(` >Runting test for: '${addon}'`); - assert.strictEqual(stderr, ''); - assert.ok(stderr.length === 0); - assert.ok(stdout.length > 0); + // Disabled the checks on stderr and stdout because of this issuue on npm: + // Stop using process.umask(): https://github.com/npm/cli/issues/1103 + // We should enable the following checks again after the resolution of + // the reported issue. + // assert.strictEqual(stderr, ''); + // assert.ok(stderr.length === 0); + // assert.ok(stdout.length > 0); const binding = require(`${ADDONS_FOLDER}/${addon}`); assert.strictEqual(binding.except.echo('except'), 'except'); assert.strictEqual(binding.except.echo(101), 101);