Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use spawn to check perl scripts #3368

Merged
merged 2 commits into from
May 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 26 additions & 18 deletions scripts/check_perl.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
/*eslint no-console: "off"*/
/*eslint no-await-in-loop: "off"*/

const process = require('process');
const util = require('util');
const glob = util.promisify(require('glob').glob);
const execFile = util.promisify(require('child_process').execFile);
const process = require("process");
const util = require("util");
const glob = util.promisify(require("glob").glob);
const { spawn } = require("child_process");

function checkFile(path, doneCallback) {
console.log(`Checking ${path}`);
try {
const child = spawn(`perl`, ["-c", "-CS", "-Ilib", path]);
child.stdout.on("data", (data) => console.log("[" + path + "] " + data));
child.stderr.on("data", (data) => console.error("[" + path + "] " + data));
child.on("close", (code) => {
console.log("[" + path + "] result: " + code);
process.exitCode = code;
doneCallback();
});
} catch (e) {
console.error("[" + path + "] " + e);
process.exitCode = e.code;
throw e;
}
}

const check = util.promisify(checkFile);

async function main() {
// 0 = node; 1 = check_perl.js
for (const arg of process.argv.slice(2)) {
const files = await glob(arg);
for (var i = 0; i < files.length; ++i) {
const path = files[i];
console.log(`Checking ${path}`);
try {
const { stdout, stderr } = await execFile(`perl`, ['-c', '-CS', '-Ilib', files[i]]);
if (stderr) {
console.error(stderr);
}

console.log(stdout);
} catch (e) {
console.error(e);
process.exitCode = e.code;
throw e;
}
await check(path);
}
}

console.log('Done!');
console.log("Done!");
}

main();