|
| 1 | +import re |
| 2 | +import sys |
| 3 | +import operator |
| 4 | +from subprocess import check_output, STDOUT, CalledProcessError |
| 5 | + |
| 6 | +def process_output(command_output): |
| 7 | + warnings = {} |
| 8 | + regex = r"(.*):\swarning:\s(.*)" |
| 9 | + lines = command_output.split("\n") |
| 10 | + for line in lines[:-3]: |
| 11 | + matches = re.finditer(regex, line) |
| 12 | + for matchNum, match in enumerate(matches): |
| 13 | + try: |
| 14 | + warnings[match.group()] +=1 |
| 15 | + except KeyError: |
| 16 | + warnings[match.group()] =1 |
| 17 | + time = lines[-3].split('\t')[1] |
| 18 | + return time, warnings |
| 19 | + |
| 20 | +def generate_stats(warnings): |
| 21 | + total_count = sum(warnings.values()) |
| 22 | + sorted_warnings = sorted(warnings.items(), key=operator.itemgetter(1), reverse=True) |
| 23 | + return sorted_warnings, total_count |
| 24 | + |
| 25 | +def print_summary(time, warnings): |
| 26 | + sorted_warnings, total_count = generate_stats(warnings) |
| 27 | + print "START - Compilation warnings count" |
| 28 | + print total_count |
| 29 | + print "END - Compilation warnings count" |
| 30 | + print 'START - Compilation warnings summary' |
| 31 | + print 'Time taken to compile:', time |
| 32 | + print 'Total number of warnings:', total_count, '\n' |
| 33 | + print 'Given below is the list of unique warnings and the number of occurences of that warning' |
| 34 | + for warning, count in sorted_warnings: |
| 35 | + print count, ': ', warning |
| 36 | + print 'END - Compilation warnings summary' |
| 37 | + |
| 38 | +try: |
| 39 | + check_output(['make','clean'], stderr=STDOUT, shell=True) |
| 40 | + command_output = check_output(['time','make','-j8'], stderr=STDOUT, shell=True) |
| 41 | + time, warnings = process_output(command_output) |
| 42 | + print_summary(time, warnings) |
| 43 | +except CalledProcessError as ex: |
| 44 | + if ex.returncode > 1: |
| 45 | + print 'Compilation failed' |
| 46 | + print ex.output |
| 47 | + sys.exit(ex.returncode) |
0 commit comments