Skip to content

Properly enter dir when error matching #31

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 53 additions & 14 deletions lib/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import os from 'os';
import { exec } from 'child_process';
import voucher from 'voucher';
import { EventEmitter } from 'events';
import XRegExp from 'xregexp';

export const config = {
jobs: {
Expand All @@ -27,18 +28,58 @@ export const config = {
};

export function provideBuilder() {
const gccErrorMatch = '(?<file>([A-Za-z]:[\\/])?[^:\\n]+):(?<line>\\d+):(?<col>\\d+):\\s*(fatal error|error):\\s*(?<message>.+)';
const ocamlErrorMatch = '(?<file>[\\/0-9a-zA-Z\\._\\-]+)", line (?<line>\\d+), characters (?<col>\\d+)-(?<col_end>\\d+):\\n(?<message>.+)';
const golangErrorMatch = '(?<file>([A-Za-z]:[\\/])?[^:\\n]+):(?<line>\\d+):\\s*(?<message>.*error.+)';
const errorMatch = [
gccErrorMatch, ocamlErrorMatch, golangErrorMatch
];
const gccErrorExpr = new XRegExp('(?<file>([A-Za-z]:[\\/])?[^:\\n]+):(?<line>\\d+):(?<col>\\d+):\\s*(fatal error|error):\\s*(?<message>.+)');
const ocamlErrorExpr = new XRegExp('(?<file>[\\/0-9a-zA-Z\\._\\-]+)", line (?<line>\\d+), characters (?<col>\\d+)-(?<col_end>\\d+):\\n(?<message>.+)');
const golangErrorExpr = new XRegExp('(?<file>([A-Za-z]:[\\/])?[^:\\n]+):(?<line>\\d+):\\s*(?<message>.*error.+)');
const errorExpr = [ gccErrorExpr, ocamlErrorExpr, golangErrorExpr ];

const gccWarningMatch = '(?<file>([A-Za-z]:[\\/])?[^:\\n]+):(?<line>\\d+):(?<col>\\d+):\\s*(warning):\\s*(?<message>.+)';
const warningMatch = [
gccWarningMatch
const gccWarningExpr = new XRegExp('(?<file>([A-Za-z]:[\\/])?[^:\\n]+):(?<line>\\d+):(?<col>\\d+):\\s*(warning):\\s*(?<message>.+)');
const warningExpr = [
gccWarningExpr
];

function eMatch(regexList, dir, matchObjects, string, type) {
regexList.forEach(function (regex) {
XRegExp.forEach(string, regex, function (match) {
// map the regex match to the error object that atom-build expects
matchObjects.push({
file: dir ? dir + '/' + match.file : match.file,
line: match.line,
col: match.col,
col_end: match.col_end,
type: type,
message: match.message
});
});
});
}

function functionMatch(o) {
const enterDir = /^make\[\d+\]: Entering directory [`']([^']+)[`']$/;
const matchObjects = [];
let scopeBuffer = '';
// stores the current directory
let dir = null;
// iterate over the output by lines
o.split(/\r?\n/).forEach(line => {
// update the current directory on lines with `Entering directory`
const dirMatch = enterDir.exec(line);
if (dirMatch) {
// flush buffer
eMatch(errorExpr, dir, matchObjects, scopeBuffer, 'Error');
eMatch(warningExpr, dir, matchObjects, scopeBuffer, 'Warning');
scopeBuffer = '';
// Update dir
dir = dirMatch[1];
} else {
scopeBuffer += line + '\n';
}
});
eMatch(errorExpr, dir, matchObjects, scopeBuffer, 'Error');
eMatch(warningExpr, dir, matchObjects, scopeBuffer, 'Warning');
return matchObjects;
}

return class MakeBuildProvider extends EventEmitter {
constructor(cwd) {
super();
Expand All @@ -65,8 +106,7 @@ export function provideBuilder() {
name: 'GNU Make: default (no target)',
args: args,
sh: false,
errorMatch: errorMatch,
warningMatch: warningMatch
functionMatch: functionMatch
};

const promise = atom.config.get('build-make.useMake') ?
Expand All @@ -75,7 +115,7 @@ export function provideBuilder() {

return promise.then(output => {
return [ defaultTarget ].concat(output.toString('utf8')
.split(/[\r\n]{1,2}/)
.split(/[\r?\n]{1,2}/)
.filter(line => /^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/.test(line))
.map(targetLine => targetLine.split(':').shift())
.filter( (elem, pos, array) => (array.indexOf(elem) === pos) )
Expand All @@ -84,8 +124,7 @@ export function provideBuilder() {
args: args.concat([ target ]),
name: `GNU Make: ${target}`,
sh: false,
errorMatch: errorMatch,
warningMatch: warningMatch
functionMatch: functionMatch
})));
}).catch(e => [ defaultTarget ]);
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
],
"main": "lib/make.js",
"dependencies": {
"voucher": "^0.1.2"
"voucher": "^0.1.2",
"xregexp": "^3.1.0"
}
}