-
Notifications
You must be signed in to change notification settings - Fork 10
/
base.py
41 lines (33 loc) · 1.35 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from collections import defaultdict
import re
class BaseCompiler():
ERROR_REGEX = None
CRASH_REGEX = None
def __init__(self, input_name, filter_patterns=None):
self.input_name = input_name
self.filter_patterns = filter_patterns or []
self.crash_msg = None
@classmethod
def get_compiler_version(cls):
raise NotImplementedError('get_compiler_version() must be implemented')
def get_compiler_cmd(self):
raise NotImplementedError('get_compiler_cmd() must be implemented')
def get_filename(self, match):
raise NotImplementedError('get_filename() must be implemented')
def get_error_msg(self, match):
raise NotImplementedError('get_error_msg() must be implemented')
def analyze_compiler_output(self, output):
crash_match = re.search(self.CRASH_REGEX, output)
if crash_match:
self.crash_msg = output
return None, []
failed = defaultdict(list)
filtered_output = output
for p in self.filter_patterns:
filtered_output = re.sub(p, '', filtered_output)
matches = re.findall(self.ERROR_REGEX, filtered_output)
for match in matches:
filename = self.get_filename(match)
error_msg = self.get_error_msg(match)
failed[filename].append(error_msg)
return failed, matches