rewritten spawn to show last 30 lines if error happens
This commit is contained in:
parent
572a1a9ec9
commit
565fab253a
@ -1,4 +1,5 @@
|
||||
.eslintignore
|
||||
.gitignore
|
||||
/lib
|
||||
/patches/*.patch
|
||||
/test
|
||||
|
||||
@ -18,7 +18,7 @@ async function gitClone () {
|
||||
log.info('Cloning Node.js from GitHub');
|
||||
const args = [ 'clone', '--bare', '--progress', nodeRepo, 'node/.git' ];
|
||||
const promise = spawn('git', args, { cwd: buildPath });
|
||||
progress(promise.child, thresholds('clone'));
|
||||
progress(promise, thresholds('clone'));
|
||||
await promise;
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ async function compileOnWindows (nodeVersion, targetArch) {
|
||||
const args = [];
|
||||
args.push('/c', 'vcbuild.bat', targetArch, 'nosign');
|
||||
const promise = spawn('cmd', args, { cwd: nodePath });
|
||||
progress(promise.child, thresholds('vcbuild', nodeVersion));
|
||||
progress(promise, thresholds('vcbuild', nodeVersion));
|
||||
await promise;
|
||||
return path.join(nodePath, 'Release/node.exe');
|
||||
}
|
||||
@ -54,7 +54,7 @@ async function compileOnUnix (nodeVersion, targetArch) {
|
||||
args.push('--dest-cpu', cpu);
|
||||
await spawn('./configure', args, { cwd: nodePath });
|
||||
const promise = spawn('make', [], { cwd: nodePath });
|
||||
progress(promise.child, thresholds('make', nodeVersion));
|
||||
progress(promise, thresholds('make', nodeVersion));
|
||||
await promise;
|
||||
return path.join(nodePath, 'out/Release/node');
|
||||
}
|
||||
|
||||
87
lib/spawn.js
87
lib/spawn.js
@ -1,35 +1,78 @@
|
||||
import byline from 'byline';
|
||||
import chipo from 'child_process';
|
||||
import fs from 'fs';
|
||||
import log from './log.js';
|
||||
|
||||
const MAX_LINES = 20;
|
||||
const DEBUG = false;
|
||||
|
||||
function errorLines (lines) {
|
||||
return lines.slice(-MAX_LINES)
|
||||
.map((line) => line[1]).join('\n');
|
||||
}
|
||||
|
||||
export function spawn (cmd, args, opts) {
|
||||
const child = chipo.spawn(cmd, args, opts);
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
child.on('error', reject);
|
||||
child.on('close', function (code) {
|
||||
if (code) return reject(new Error(`${cmd} failed with code ${code}`));
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
promise.child = child;
|
||||
return promise;
|
||||
}
|
||||
const stdout = byline(child.stdout);
|
||||
const stderr = byline(child.stderr);
|
||||
const lines = [];
|
||||
|
||||
export function progress (child, thresholds) {
|
||||
log.enableProgress();
|
||||
log.showProgress('0%', 0);
|
||||
const onData = (data) => {
|
||||
for (const key in thresholds) {
|
||||
if (data.indexOf(key) >= 0) {
|
||||
const p = thresholds[key];
|
||||
log.showProgress(p + '%', p / 100);
|
||||
let onData = function (data) {
|
||||
const time = (new Date()).getTime();
|
||||
lines.push([ time, data.toString() ]); // TODO chalk stdout/stderr?
|
||||
const { thresholds } = this; // eslint-disable-line no-invalid-this
|
||||
if (thresholds) {
|
||||
for (const key in thresholds) {
|
||||
if (data.indexOf(key) >= 0) {
|
||||
const p = thresholds[key];
|
||||
log.showProgress(p + '%', p / 100);
|
||||
if (DEBUG) {
|
||||
lines.push([ time, '************' ]);
|
||||
lines.push([ time, p + ': ' + key ]);
|
||||
lines.push([ time, '************' ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
child.stdout.setEncoding('utf8');
|
||||
child.stdout.on('data', onData);
|
||||
child.stderr.setEncoding('utf8');
|
||||
child.stderr.on('data', onData);
|
||||
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
child.on('error', (error) => {
|
||||
console.error(errorLines(lines));
|
||||
reject(error);
|
||||
});
|
||||
child.on('close', (code) => {
|
||||
if (code) {
|
||||
console.error(errorLines(lines));
|
||||
return reject(new Error(`${cmd} failed with code ${code}`));
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
onData = onData.bind(promise);
|
||||
if (stdout) stdout.on('data', onData);
|
||||
if (stderr) stderr.on('data', onData);
|
||||
|
||||
promise.child = child;
|
||||
promise.lines = lines;
|
||||
return promise;
|
||||
}
|
||||
|
||||
export function progress (promise, thresholds) {
|
||||
promise.thresholds = thresholds;
|
||||
log.enableProgress();
|
||||
log.showProgress('0%', 0);
|
||||
const start = (new Date()).getTime();
|
||||
const { child, lines } = promise;
|
||||
child.on('close', () => {
|
||||
if (DEBUG) {
|
||||
const finish = (new Date()).getTime();
|
||||
const content = lines.map((line) =>
|
||||
((100 * (line[0] - start) / (finish - start)) | 0) + ': ' + line[1]
|
||||
).join('\n');
|
||||
fs.writeFileSync(child.spawnfile + '.debug', content);
|
||||
}
|
||||
log.disableProgress();
|
||||
});
|
||||
}
|
||||
|
||||
@ -6,28 +6,34 @@ import assert from 'assert';
|
||||
export default function thresholds (cmd, nodeVersion) {
|
||||
if (cmd === 'clone') {
|
||||
return {
|
||||
'ving objects: 0%': 0, 'ving objects: 1%': 1, 'ving objects: 5%': 5,
|
||||
'ving objects: 10%': 10, 'ving objects: 20%': 20, 'ving objects: 40%': 40,
|
||||
'ving objects: 61%': 60, 'ving objects: 81%': 80, 'deltas: 0%': 98
|
||||
'ving objects: 0%': 0, 'ving objects: 1%': 1, 'ving objects: 6%': 5,
|
||||
'ving objects: 12%': 10, 'ving objects: 25%': 20, 'ving objects: 50%': 40,
|
||||
'ving objects: 75%': 60, 'deltas: 0%': 80, 'deltas: 50%': 90
|
||||
};
|
||||
} else
|
||||
if (cmd === 'vcbuild') {
|
||||
if (/^v?0/.test(nodeVersion)) {
|
||||
return {
|
||||
'http_parser.vcxproj ->': 1, 'openssl.vcxproj ->': 9,
|
||||
'v8_base.vcxproj ->': 55, 'mksnapshot.vcxproj ->': 76,
|
||||
'node\\Release\\node.exp': 90
|
||||
};
|
||||
} else
|
||||
if (/^v?4/.test(nodeVersion)) {
|
||||
return {
|
||||
'http_parser.vcxproj ->': 1, 'openssl.vcxproj ->': 3,
|
||||
'icudata.vcxproj ->': 13, 'hydrogen-representation-changes.cc': 20,
|
||||
'interface-descriptors-x64.cc': 30, 'v8_base_0.vcxproj ->': 44,
|
||||
'build\\Release\\mksnapshot.lib': 57, 'mksnapshot.vcxproj ->': 69,
|
||||
'http_parser.vcxproj ->': 1, 'hydrogen-representation-changes.cc': 13,
|
||||
'openssl.vcxproj ->': 21, 'v8_base_0.vcxproj ->': 35,
|
||||
'build\\Release\\mksnapshot.lib': 57, 'mksnapshot.vcxproj ->': 67,
|
||||
'node\\Release\\node.exp': 85, 'cctest.vcxproj ->': 97
|
||||
};
|
||||
} else
|
||||
if (/^v?6/.test(nodeVersion)) {
|
||||
return {
|
||||
'http_parser.vcxproj ->': 1, 'openssl.vcxproj ->': 3,
|
||||
'icudata.vcxproj ->': 13, 'hydrogen-representation-changes.cc': 20,
|
||||
'interface-descriptors-x64.cc': 30, 'v8_base_0.vcxproj ->': 44,
|
||||
'build\\Release\\mksnapshot.lib': 57, 'mksnapshot.vcxproj ->': 69,
|
||||
'node\\Release\\node.exp': 85, 'cctest.vcxproj ->': 97
|
||||
'http_parser.vcxproj ->': 1, 'openssl.vcxproj ->': 4,
|
||||
'icudata.vcxproj ->': 10, 'hydrogen-representation-changes.cc': 15,
|
||||
'interface-descriptors-x64.cc': 27, 'v8_base_0.vcxproj ->': 41,
|
||||
'build\\Release\\mksnapshot.lib': 55, 'mksnapshot.vcxproj ->': 66,
|
||||
'node\\Release\\node.exp': 82, 'cctest.vcxproj ->': 95
|
||||
};
|
||||
} else {
|
||||
return {};
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-runtime": "6.11.6",
|
||||
"byline": "5.0.0",
|
||||
"expand-template": "1.0.2",
|
||||
"fs-promise": "0.5.0",
|
||||
"minimist": "1.2.0",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user