Parse stdout/stderr on the server side

dev/git-series/gccdum
Matt Godbolt 7 years ago
parent 444d75100d
commit a0be851fcb

@ -30,7 +30,8 @@ var child_process = require('child_process'),
fs = require('fs-extra'),
Promise = require('promise'), // jshint ignore:line
Queue = require('promise-queue'),
asm = require('./asm');
asm = require('./asm'),
utils = require('./utils');
Queue.configure(Promise);
temp.track();
@ -100,7 +101,8 @@ Compile.prototype.convert6g = function (code) {
var re = /^[0-9]+\s*\(([^:]+):([0-9]+)\)\s*([A-Z]+)(.*)/;
var prevLine = null;
var file = null;
return code.split('\n').map(function (line) {
return code.map(function (obj) {
var line = obj.line;
var match = line.match(re);
if (match) {
var res = "";
@ -179,7 +181,10 @@ Compile.prototype.runCompiler = function (compiler, options, needsMulti) {
// Why is this apparently needed in some cases (e.g. when I used to use this to do getMultiarch)?
// Without it, I apparently get stdout/stderr callbacks *after* the exit...
setTimeout(function () {
resolve({code: code, stdout: stdout, stderr: stderr, okToCache: okToCache});
resolve({
code: code, stdout: utils.parseOutput(stdout), stderr: utils.parseOutput(stderr),
okToCache: okToCache
});
}, 0);
});
child.stdin.end();
@ -298,7 +303,7 @@ Compile.prototype.compile = function (source, compiler, options, filters) {
}
if (compilerInfo.is6g) {
result.asm = self.convert6g(result.stdout);
result.stdout = "";
result.stdout = [];
return Promise.resolve(result);
}
if (filters.binary && !compilerInfo.isCl) {

@ -22,6 +22,8 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
var _ = require('underscore-node');
var tabsRe = /\t/g;
function expandTabs(line) {
@ -34,5 +36,26 @@ function expandTabs(line) {
return " ".substr(spacesNeeded);
});
}
exports.expandTabs = expandTabs;
exports.expandTabs = expandTabs;
function parseOutput(lines) {
// TODO: better splitting here; handle Windows; no hardcoded paths,
// maybe filter out the name itself if it matches
var re = /^\/tmp\/[^:]+:([0-9]+)(:([0-9]+))?:\s+(.*)/;
// var windowsRe = /^C:\\Users\\[^(]+\(([0-9]+)\):\s+(.*)/;
var result = [];
_.each(lines.split('\n'), function (line) {
line = line.trim();
if (line !== "") {
var match = line.match(re);
if (match) {
result.push({line: parseInt(match[1]), text: match[4].trim()});
} else {
// match = line.match(windowsRe);
result.push({text: line});
}
}
});
return result;
}
exports.parseOutput = parseOutput;

@ -116,7 +116,7 @@ define(function (require) {
}, this);
this.container.layoutManager.createDragSource(this.domRoot.find(".status").parent(), outputConfig);
this.domRoot.find(".status").parent().click(_.bind(function () {
var insertPoint = hub.findParentRowOrColumn(this.container) ||
var insertPoint = hub.findParentRowOrColumn(this.container) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(outputConfig());
}, this));
@ -132,7 +132,7 @@ define(function (require) {
this.container.layoutManager.createDragSource(
this.domRoot.find('.btn.add-compiler'), cloneComponent);
this.domRoot.find('.btn.add-compiler').click(_.bind(function () {
var insertPoint = hub.findParentRowOrColumn(this.container) ||
var insertPoint = hub.findParentRowOrColumn(this.container) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(cloneComponent());
}, this));
@ -291,7 +291,7 @@ define(function (require) {
}
}, this));
var status = this.domRoot.find(".status");
var allText = result.stdout + result.stderr;
var allText = _.pluck(result.stdout.concat(result.stderr), 'text').join("\n");
var failed = result.code !== 0;
var warns = !failed && !!allText;
status.toggleClass('error', failed);

@ -78,7 +78,7 @@ define(function (require) {
matchBrackets: true,
useCPP: true,
dragDrop: false,
extraKeys: { "Alt-F": false }, // see https://github.com/mattgodbolt/gcc-explorer/pull/131
extraKeys: {"Alt-F": false}, // see https://github.com/mattgodbolt/gcc-explorer/pull/131
mode: cmMode
});
@ -164,7 +164,7 @@ define(function (require) {
this.container.layoutManager.createDragSource(
this.domRoot.find('.btn.add-compiler'), compilerConfig);
this.domRoot.find('.btn.add-compiler').click(_.bind(function () {
var insertPoint = hub.findParentRowOrColumn(this.container) ||
var insertPoint = hub.findParentRowOrColumn(this.container) ||
this.container.layoutManager.root.contentItems[0];
insertPoint.addChild(compilerConfig);
}, this));
@ -218,21 +218,6 @@ define(function (require) {
return node[0];
}
function parseLines(lines, callback) {
var re = /^\/tmp\/[^:]+:([0-9]+)(:([0-9]+))?:\s+(.*)/;
$.each(lines.split('\n'), function (_, line) {
line = line.trim();
if (line !== "") {
var match = line.match(re);
if (match) {
callback(parseInt(match[1]), match[4].trim());
} else {
callback(null, line);
}
}
});
}
Editor.prototype.removeWidgets = function (widgets) {
var self = this;
_.each(widgets, function (widget) {
@ -275,19 +260,19 @@ define(function (require) {
};
Editor.prototype.onCompileResponse = function (compilerId, compiler, result) {
var output = (result.stdout || "") + (result.stderr || "");
var output = result.stdout.concat(result.stderr);
var self = this;
this.removeWidgets(this.widgetsByCompiler[compilerId]);
var widgets = [];
parseLines(output, function (lineNum, msg) {
if (lineNum) {
_.each(output, function (obj) {
if (obj.line) {
var widget = self.editor.addLineWidget(
lineNum - 1,
makeErrorNode(msg, compiler.name),
obj.line - 1,
makeErrorNode(obj.text, compiler.name),
{coverGutter: false, noHScroll: true});
widgets.push(widget);
}
});
}, this);
this.widgetsByCompiler[compilerId] = widgets;
this.asmByCompiler[compilerId] = result.asm;
this.numberUsedLines();

@ -45,31 +45,15 @@ define(function (require) {
this.updateCompilerName();
}
var lineRe = /^\/tmp\/[^:]+(:([0-9]+))?(:([0-9]+))?:\s*(.*)/;
function parseLines(lines, callback) {
_.each(lines.split('\n'), function (line) {
line = line.trim();
if (line !== "") {
var match = line.match(lineRe);
if (match) {
callback(parseInt(match[2]), match[5].trim());
} else {
callback(null, line);
}
}
});
}
Output.prototype.onCompileResult = function (id, compiler, result) {
if (id !== this.compilerId) return;
this.compiler = compiler;
this.contentRoot.empty();
parseLines(result.stdout + result.stderr, _.bind(function (lineNum, msg) {
this.add(msg, lineNum);
}, this));
_.each(result.stdout.concat(result.stderr), function (obj) {
this.add(obj.text, obj.line);
}, this);
this.add("Compiler exited with result code " + result.code);

Loading…
Cancel
Save