Revert "tools: simplify tools/doc/addon-verify.js"
This reverts commit c6682636be4955e2181c00e7d4868fbf6682a5c5. Reverted along with d9b59def7 as this breaks compilation from downloadable source tarballs. Ref: https://github.com/nodejs/node/pull/17407 PR-URL: https://github.com/nodejs/node/pull/18287 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
57bd27eda8
commit
90f882e50d
@ -1,6 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { strictEqual } = require('assert');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const marked = require('marked');
|
const marked = require('marked');
|
||||||
@ -9,36 +8,52 @@ const rootDir = path.resolve(__dirname, '..', '..');
|
|||||||
const doc = path.resolve(rootDir, 'doc', 'api', 'addons.md');
|
const doc = path.resolve(rootDir, 'doc', 'api', 'addons.md');
|
||||||
const verifyDir = path.resolve(rootDir, 'test', 'addons');
|
const verifyDir = path.resolve(rootDir, 'test', 'addons');
|
||||||
|
|
||||||
let id = 0;
|
const contents = fs.readFileSync(doc).toString();
|
||||||
let currentHeader;
|
|
||||||
|
|
||||||
|
const tokens = marked.lexer(contents);
|
||||||
|
let id = 0;
|
||||||
|
|
||||||
|
let currentHeader;
|
||||||
const addons = {};
|
const addons = {};
|
||||||
const content = fs.readFileSync(doc, 'utf8');
|
tokens.forEach((token) => {
|
||||||
for (const { text, type } of marked.lexer(content)) {
|
if (token.type === 'heading' && token.text) {
|
||||||
if (type === 'heading' && text) {
|
currentHeader = token.text;
|
||||||
currentHeader = text;
|
|
||||||
addons[currentHeader] = {
|
addons[currentHeader] = {
|
||||||
files: {}
|
files: {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (type === 'code') {
|
if (token.type === 'code') {
|
||||||
const match = text.match(/^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/);
|
var match = token.text.match(/^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/);
|
||||||
if (match !== null) {
|
if (match !== null) {
|
||||||
addons[currentHeader].files[match[1]] = text;
|
addons[currentHeader].files[match[1]] = token.text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
for (var header in addons) {
|
||||||
|
verifyFiles(addons[header].files,
|
||||||
|
header,
|
||||||
|
console.log.bind(null, 'wrote'),
|
||||||
|
function(err) { if (err) throw err; });
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const header in addons) {
|
function once(fn) {
|
||||||
let { files } = addons[header];
|
var once = false;
|
||||||
|
return function() {
|
||||||
|
if (once)
|
||||||
|
return;
|
||||||
|
once = true;
|
||||||
|
fn.apply(this, arguments);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function verifyFiles(files, blockName, onprogress, ondone) {
|
||||||
// must have a .cc and a .js to be a valid test
|
// must have a .cc and a .js to be a valid test
|
||||||
if (!Object.keys(files).some((name) => /\.cc$/.test(name)) ||
|
if (!Object.keys(files).some((name) => /\.cc$/.test(name)) ||
|
||||||
!Object.keys(files).some((name) => /\.js$/.test(name))) {
|
!Object.keys(files).some((name) => /\.js$/.test(name))) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const blockName = header
|
blockName = blockName
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/\s/g, '_')
|
.replace(/\s/g, '_')
|
||||||
.replace(/[^a-z\d_]/g, '');
|
.replace(/[^a-z\d_]/g, '');
|
||||||
@ -47,9 +62,21 @@ for (const header in addons) {
|
|||||||
`${(++id < 10 ? '0' : '') + id}_${blockName}`
|
`${(++id < 10 ? '0' : '') + id}_${blockName}`
|
||||||
);
|
);
|
||||||
|
|
||||||
files = Object.entries(files).map(([name, content]) => {
|
files = Object.keys(files).map(function(name) {
|
||||||
if (name === 'test.js') content = boilerplate(name, content);
|
if (name === 'test.js') {
|
||||||
return { name, content, path: path.resolve(dir, name) };
|
files[name] = `'use strict';
|
||||||
|
const common = require('../../common');
|
||||||
|
${files[name].replace(
|
||||||
|
"'./build/Release/addon'",
|
||||||
|
// eslint-disable-next-line no-template-curly-in-string
|
||||||
|
'`./build/${common.buildType}/addon`')}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
path: path.resolve(dir, name),
|
||||||
|
name: name,
|
||||||
|
content: files[name]
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
files.push({
|
files.push({
|
||||||
@ -57,7 +84,7 @@ for (const header in addons) {
|
|||||||
content: JSON.stringify({
|
content: JSON.stringify({
|
||||||
targets: [
|
targets: [
|
||||||
{
|
{
|
||||||
target_name: 'binding',
|
target_name: 'addon',
|
||||||
defines: [ 'V8_DEPRECATION_WARNINGS=1' ],
|
defines: [ 'V8_DEPRECATION_WARNINGS=1' ],
|
||||||
sources: files.map(function(file) {
|
sources: files.map(function(file) {
|
||||||
return file.name;
|
return file.name;
|
||||||
@ -67,34 +94,22 @@ for (const header in addons) {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
fs.mkdir(dir, function() {
|
||||||
fs.mkdirSync(dir);
|
// Ignore errors
|
||||||
} catch (e) {
|
|
||||||
strictEqual(e.code, 'EEXIST');
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const file of files) {
|
const done = once(ondone);
|
||||||
let content;
|
var waiting = files.length;
|
||||||
try {
|
files.forEach(function(file) {
|
||||||
content = fs.readFileSync(file.path, 'utf8');
|
fs.writeFile(file.path, file.content, function(err) {
|
||||||
} catch (e) {
|
if (err)
|
||||||
strictEqual(e.code, 'ENOENT');
|
return done(err);
|
||||||
}
|
|
||||||
|
|
||||||
// Only update when file content has changed to prevent unneeded rebuilds.
|
if (onprogress)
|
||||||
if (content !== file.content) {
|
onprogress(file.path);
|
||||||
fs.writeFileSync(file.path, file.content);
|
|
||||||
console.log('wrote', file.path);
|
if (--waiting === 0)
|
||||||
}
|
done();
|
||||||
}
|
});
|
||||||
}
|
});
|
||||||
|
});
|
||||||
function boilerplate(name, content) {
|
|
||||||
return `'use strict';
|
|
||||||
const common = require('../../common');
|
|
||||||
${content.replace(
|
|
||||||
"'./build/Release/binding'",
|
|
||||||
// eslint-disable-next-line no-template-curly-in-string
|
|
||||||
'`./build/${common.buildType}/binding`')}
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user