You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.7 KiB

'use strict';
const fs = require('fs');
const path = require('path');
const marked = require('marked');
const rootDir = path.resolve(__dirname, '..', '..');
const doc = path.resolve(rootDir, 'doc', 'api', 'addons.md');
const verifyDir = path.resolve(rootDir, 'test', 'addons');
const contents = fs.readFileSync(doc).toString();
const tokens = marked.lexer(contents);
let id = 0;
let currentHeader;
const addons = {};
tokens.forEach((token) => {
if (token.type === 'heading' && token.text) {
currentHeader = token.text;
addons[currentHeader] = {
files: {}
};
}
if (token.type === 'code') {
var match = token.text.match(/^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/);
if (match !== null) {
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; });
}
function once(fn) {
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
if (!Object.keys(files).some((name) => /\.cc$/.test(name)) ||
!Object.keys(files).some((name) => /\.js$/.test(name))) {
return;
}
blockName = blockName
.toLowerCase()
.replace(/\s/g, '_')
.replace(/[^a-z\d_]/g, '');
const dir = path.resolve(
verifyDir,
`${(++id < 10 ? '0' : '') + id}_${blockName}`
);
files = Object.keys(files).map(function(name) {
if (name === 'test.js') {
files[name] = `'use strict';
test: enable addons test to pass with debug build Currently when running configure with the --debug option in combination with the tests (./configure --debug &amp;&amp; make -j8 test) there are a few addon tests that fail with error messages similar to this: === release test === Path: addons/load-long-path/test fs.js:558 return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode); ^ Error: ENOENT: no such file or directory, open &#39;/nodejs/node/test/addons/load-long-path/build/Release/binding.node&#39; at Object.fs.openSync (fs.js:558:18) at Object.fs.readFileSync (fs.js:468:33) at Object.&lt;anonymous&gt; (/nodejs/node/test/addons/load-long-path/test.js:28:19) at Module._compile (module.js:560:32) at Object.Module._extensions..js (module.js:569:10) at Module.load (module.js:477:32) at tryModuleLoad (module.js:436:12) at Function.Module._load (module.js:428:3) at Module.runMain (module.js:594:10) at run (bootstrap_node.js:382:7) Command: out/Release/node /nodejs/node/test/addons/load-long-path/test.js This commit allows for the tests to pass even if the configured build type is of type debug. PR-URL: https://github.com/nodejs/node/pull/8836 Reviewed-By: James M Snell &lt;jasnell@gmail.com&gt; Reviewed-By: Anna Henningsen &lt;anna@addaleax.net&gt; Reviewed-By: Ben Noordhuis &lt;info@bnoordhuis.nl&gt; Reviewed-By: Ilkka Myller &lt;ilkka.myller@nodefield.com&gt; Reviewed-By: Luigi Pinca &lt;luigipinca@gmail.com&gt; Reviewed-By: Colin Ihrig &lt;cjihrig@gmail.com&gt;
8 years ago
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({
path: path.resolve(dir, 'binding.gyp'),
content: JSON.stringify({
targets: [
{
target_name: 'addon',
defines: [ 'V8_DEPRECATION_WARNINGS=1' ],
sources: files.map(function(file) {
return file.name;
})
}
]
})
});
fs.mkdir(dir, function() {
// Ignore errors
const done = once(ondone);
var waiting = files.length;
files.forEach(function(file) {
fs.writeFile(file.path, file.content, function(err) {
if (err)
return done(err);
if (onprogress)
onprogress(file.path);
if (--waiting === 0)
done();
});
});
});
}