2018-07-25 23:58:41 +02:00
|
|
|
// doc/api/addons.md has a bunch of code. Extract it for verification
|
|
|
|
// that the C++ code compiles and the js code runs.
|
|
|
|
// Add .gyp files which will be used to compile the C++ code.
|
|
|
|
// Modify the require paths in the js code to pull from the build tree.
|
|
|
|
// Triggered from the build-addons target in the Makefile and vcbuild.bat.
|
|
|
|
|
2021-06-08 12:44:33 +02:00
|
|
|
import { mkdir, writeFile } from 'fs/promises';
|
|
|
|
|
|
|
|
import gfm from 'remark-gfm';
|
|
|
|
import remarkParse from 'remark-parse';
|
2023-06-18 03:43:27 +02:00
|
|
|
import { readSync } from 'to-vfile';
|
2021-09-08 21:49:55 +02:00
|
|
|
import { unified } from 'unified';
|
2014-01-18 23:49:18 +01:00
|
|
|
|
2021-06-08 12:44:33 +02:00
|
|
|
const rootDir = new URL('../../', import.meta.url);
|
|
|
|
const doc = new URL('./doc/api/addons.md', rootDir);
|
|
|
|
const verifyDir = new URL('./test/addons/', rootDir);
|
2014-01-18 23:49:18 +01:00
|
|
|
|
2023-06-18 03:43:27 +02:00
|
|
|
const file = readSync(doc, 'utf8');
|
2020-11-09 14:45:59 +01:00
|
|
|
const tree = unified().use(remarkParse).use(gfm).parse(file);
|
2018-04-21 04:41:16 +02:00
|
|
|
const addons = {};
|
2015-12-24 03:56:03 +01:00
|
|
|
let id = 0;
|
2018-01-24 00:49:45 +01:00
|
|
|
let currentHeader;
|
2018-04-21 04:41:16 +02:00
|
|
|
|
|
|
|
const validNames = /^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/;
|
2018-07-25 23:58:41 +02:00
|
|
|
tree.children.forEach((node) => {
|
|
|
|
if (node.type === 'heading') {
|
2021-06-08 12:44:33 +02:00
|
|
|
currentHeader = file.value.slice(
|
2018-07-25 23:58:41 +02:00
|
|
|
node.children[0].position.start.offset,
|
|
|
|
node.position.end.offset);
|
2018-04-21 04:41:16 +02:00
|
|
|
addons[currentHeader] = { files: {} };
|
2018-07-25 23:58:41 +02:00
|
|
|
} else if (node.type === 'code') {
|
|
|
|
const match = node.value.match(validNames);
|
2017-07-03 06:27:58 +02:00
|
|
|
if (match !== null) {
|
2018-07-25 23:58:41 +02:00
|
|
|
addons[currentHeader].files[match[1]] = node.value;
|
2017-07-03 06:27:58 +02:00
|
|
|
}
|
2014-01-18 23:49:18 +01:00
|
|
|
}
|
2018-01-24 00:49:45 +01:00
|
|
|
});
|
2014-01-18 23:49:18 +01:00
|
|
|
|
2021-06-08 12:44:33 +02:00
|
|
|
await Promise.all(
|
|
|
|
Object.keys(addons).flatMap(
|
2022-12-18 17:39:39 +01:00
|
|
|
(header) => verifyFiles(addons[header].files, header),
|
2021-06-08 12:44:33 +02:00
|
|
|
));
|
2018-04-21 04:41:16 +02:00
|
|
|
|
|
|
|
function verifyFiles(files, blockName) {
|
|
|
|
const fileNames = Object.keys(files);
|
2014-01-18 23:49:18 +01:00
|
|
|
|
2018-03-30 12:38:45 +02:00
|
|
|
// Must have a .cc and a .js to be a valid test.
|
2018-04-21 04:41:16 +02:00
|
|
|
if (!fileNames.some((name) => name.endsWith('.cc')) ||
|
|
|
|
!fileNames.some((name) => name.endsWith('.js'))) {
|
2021-06-08 12:44:33 +02:00
|
|
|
return [];
|
2015-12-24 03:34:59 +01:00
|
|
|
}
|
|
|
|
|
2018-04-21 04:41:16 +02:00
|
|
|
blockName = blockName.toLowerCase().replace(/\s/g, '_').replace(/\W/g, '');
|
2021-06-08 12:44:33 +02:00
|
|
|
const dir = new URL(
|
|
|
|
`./${String(++id).padStart(2, '0')}_${blockName}/`,
|
2016-01-30 19:17:57 +01:00
|
|
|
verifyDir,
|
|
|
|
);
|
2015-12-24 03:56:03 +01:00
|
|
|
|
2018-04-21 04:41:16 +02:00
|
|
|
files = fileNames.map((name) => {
|
2018-01-24 00:49:45 +01:00
|
|
|
if (name === 'test.js') {
|
|
|
|
files[name] = `'use strict';
|
|
|
|
const common = require('../../common');
|
|
|
|
${files[name].replace(
|
2024-11-06 00:37:39 +01:00
|
|
|
"'./build/Release/addon'",
|
|
|
|
// eslint-disable-next-line no-template-curly-in-string
|
|
|
|
'`./build/${common.buildType}/addon`')}
|
2018-01-24 00:49:45 +01:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
return {
|
2021-06-08 12:44:33 +02:00
|
|
|
content: files[name],
|
|
|
|
name,
|
|
|
|
url: new URL(`./${name}`, dir),
|
2018-01-24 00:49:45 +01:00
|
|
|
};
|
2014-01-18 23:49:18 +01:00
|
|
|
});
|
2015-12-24 03:34:59 +01:00
|
|
|
|
2014-01-18 23:49:18 +01:00
|
|
|
files.push({
|
2021-06-08 12:44:33 +02:00
|
|
|
url: new URL('./binding.gyp', dir),
|
2018-01-23 11:49:25 +01:00
|
|
|
content: JSON.stringify({
|
2014-01-18 23:49:18 +01:00
|
|
|
targets: [
|
|
|
|
{
|
2018-01-24 00:49:45 +01:00
|
|
|
target_name: 'addon',
|
test, tools: suppress addon function cast warnings
Currently, there are a number of compiler warnings generated when
building the addons on Linux, for example:
make[1]: Entering directory '/node/test/addons/zlib-binding/build'
CXX(target) Release/obj.target/binding/binding.o
SOLINK_MODULE(target) Release/obj.target/binding.node
COPY Release/binding.node
make[1]: Leaving directory '/node/test/addons/zlib-binding/build'
In file included from ../binding.cc:1:
/node/src/node.h:515:51: warning:
cast between incompatible function types from
'void (*)(v8::Local<v8::Object>,
v8::Local<v8::Value>,
v8::Local<v8::Context>)' to
'node::addon_context_register_func' {aka
'void (*)(v8::Local<v8::Object>,
v8::Local<v8::Value>,
v8::Local<v8::Context>,
void*)'} [-Wcast-function-type]
(node::addon_context_register_func) (regfunc), \
^
/node/src/node.h:533:3:
note: in expansion of macro 'NODE_MODULE_CONTEXT_AWARE_X'
NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, 0)
^~~~~~~~~~~~~~~~~~~~~~~~~~~
../binding.cc:58:1:
note: in expansion of macro 'NODE_MODULE_CONTEXT_AWARE'
NODE_MODULE_CONTEXT_AWARE(NODE_GYP_MODULE_NAME, Initialize)
^~~~~~~~~~~~~~~~~~~~~~~~~
This commit adds the flag -Wno-cast-function-type to suppress these
warnings. With this change the warnings are not displayed anymore and
the output matches that of osx when running
'make -j8 test/addons/.buildstamp'.
PR-URL: https://github.com/nodejs/node/pull/25663
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2019-01-23 12:01:01 +01:00
|
|
|
sources: files.map(({ name }) => name),
|
|
|
|
includes: ['../common.gypi'],
|
2019-03-02 07:47:47 +01:00
|
|
|
},
|
2022-12-18 17:39:39 +01:00
|
|
|
],
|
|
|
|
}),
|
2014-01-18 23:49:18 +01:00
|
|
|
});
|
|
|
|
|
2021-06-08 12:44:33 +02:00
|
|
|
const dirCreation = mkdir(dir);
|
2018-01-23 11:48:49 +01:00
|
|
|
|
2021-06-08 12:44:33 +02:00
|
|
|
return files.map(({ url, content }) =>
|
|
|
|
dirCreation.then(() => writeFile(url, content)));
|
2014-01-18 23:49:18 +01:00
|
|
|
}
|