-
Notifications
You must be signed in to change notification settings - Fork 7
/
check_error.py
executable file
·125 lines (114 loc) · 4.72 KB
/
check_error.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python3
import re
import mmap
import os
import sys
import io
import argparse
import magic
import gzip
import struct
err_type = ['Segmentation fault',
'A fatal error has been detected by the Java Runtime Environment',
'error:(.*)field(.*)has incomplete type',
'error:(.*)conflicting types for',
'No rule to make target (.*)',
'failed to allocate (.*) bytes for output file: Cannot allocate memory',
'cp: cannot stat (.*):(.*)',
'can\'t find file to patch at input line (.*)',
'No matching package to install: (.*)',
'package (.*) requires (.*) but none of the providers can be installed$',
'unable to execute command: (.*)',
'(.*) is a protected member of (.*)',
'undefined reference to (.*)',
'no matching function for call to (.*)',
'bytecode stream in file (.*) generated with (.*)',
'Could not find a configuration file for package (.*)',
'variable has incomplete type (.*)',
'File must begin with (.*)', 'Bad source: (.*)',
'File not found: (.*)', 'Installed \(but unpackaged\) file\(s\) found',
'cannot find -l(.*)', 'implicit declaration of function (.*)',
'\'(.*)\' file not found', 'use of undeclared identifier (.*)',
'function cannot return function type (.*)',
'unknown type name (.*)', 'incomplete definition of type (.*)',
'Problem encountered: Man pages cannot be built: (.*)',
'format string is not a string literal (.*)',
'Failed to find required (.*) component (.*)',
'Package (.*), required by (.*), not found',
'CMake Error at (.*)',
'error: (.*)',
"Couldn't find include (.*)",
'(.*) Stop']
# Common "errors" from chroot install scripts while inside a container...
not_an_error = ['error: lua script failed:']
def is_excluded(x):
excluded = False
for n in not_an_error:
if re.findall(('(' + n + ')').encode('utf-8'), x):
excluded = True
break
return excluded
def write_log(message, fail_log):
try:
logger = open(fail_log, 'a')
logger.write(message + '\n')
logger.close()
except IOError:
print("Can't write to log file: " + fail_log)
print(message)
def known_errors(logfile, fail_log):
sz = os.path.getsize(logfile)
if os.path.exists(logfile) and sz > 0:
if magic.detect_from_filename(logfile).mime_type == 'application/gzip':
handle = open(logfile, "r")
# let's mmap piece of memory
# as we unpacked gzip
tmp_mm = mmap.mmap(handle.fileno(), sz, access=mmap.ACCESS_READ)
real_sz = struct.unpack("@I", tmp_mm[-4:])[0]
mm = mmap.mmap(-1, real_sz, prot=mmap.PROT_READ | mmap.PROT_WRITE)
gz = gzip.GzipFile(fileobj=tmp_mm)
for line in gz:
mm.write(line)
tmp_mm.close()
gz.close()
handle.close
else:
msgf = io.open(logfile, "r", encoding="utf-8")
mm = mmap.mmap(msgf.fileno(), sz, access=mmap.ACCESS_READ)
msgf.close()
for pat in err_type:
errors = re.findall(('(' + pat + ')').encode('utf-8'), mm)
for error in errors:
if not is_excluded(error[0]):
print(error[0])
write_log(str(error[0]), fail_log)
mm.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Run me over the buildlog')
parser.add_argument('-f', '--file', help='build.log requires', required=True)
args = vars(parser.parse_args())
if args['file']:
try:
known_errors(args['file'], 'fail.log')
except OSError as o:
print('Sorry the file you asked does not exists!')
print(str(o))
# known_errors('build.log.gz', 'fail.log')
# known_errors('build.log', 'fail.log')
# known_errors('no_file_topatch.log')
# known_errors('no_package_to_install.log')
# known_errors('no_such_package_in_repo.log')
# known_errors('unable_to_execute.log')
# known_errors('protected_member.log')
# known_errors('undef_reference_to.log')
# known_errors('no_matching_func_to_call.log')
# known_errors('bytecode_generated_with_lto.log')
# known_errors('config_cmake_not_found.log')
# known_errors('variable_incompl_type.log')
# known_errors('file_must_begin.log')
# known_errors('file_not_found.log')
# known_errors('cannot_find_lib.log')
# known_errors('header_not_found.log')
# known_errors('func_cant_return_some_shit.log')
# known_errors('unknown_type_name.log')
# known_errors('installed_but_unpkgd.log')