Skip to content
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

add python script to track warnings #1

Merged
merged 1 commit into from
Jul 25, 2017
Merged
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
47 changes: 47 additions & 0 deletions warn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import re
import sys
import operator
from subprocess import check_output, STDOUT, CalledProcessError

def process_output(command_output):
warnings = {}
regex = r"(.*):\swarning:\s(.*)"
lines = command_output.split("\n")
for line in lines[:-3]:
matches = re.finditer(regex, line)
for matchNum, match in enumerate(matches):
try:
warnings[match.group()] +=1
except KeyError:
warnings[match.group()] =1
time = lines[-3].split('\t')[1]
return time, warnings

def generate_stats(warnings):
total_count = sum(warnings.values())
sorted_warnings = sorted(warnings.items(), key=operator.itemgetter(1), reverse=True)
return sorted_warnings, total_count

def print_summary(time, warnings):
sorted_warnings, total_count = generate_stats(warnings)
print "START - Compilation warnings count"
print total_count
print "END - Compilation warnings count"
print 'START - Compilation warnings summary'
print 'Time taken to compile:', time
print 'Total number of warnings:', total_count, '\n'
print 'Given below is the list of unique warnings and the number of occurences of that warning'
for warning, count in sorted_warnings:
print count, ': ', warning
print 'END - Compilation warnings summary'

try:
check_output(['make','clean'], stderr=STDOUT, shell=True)
command_output = check_output(['time','make','-j8'], stderr=STDOUT, shell=True)
time, warnings = process_output(command_output)
print_summary(time, warnings)
except CalledProcessError as ex:
if ex.returncode > 1:
print 'Compilation failed'
print ex.output
sys.exit(ex.returncode)