From f38297325073f2c5f109175bf0270d43d282bda7 Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Tue, 10 May 2016 12:06:01 -0700 Subject: [PATCH] Add code search links to warnings. Add argument parsing using the argparse library. Make HTML easier to read by adding a \n after each table row. Change-Id: I6b745fc60afb96fb51e5f69df7d607b5fb8da0e5 --- tools/warn.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/tools/warn.py b/tools/warn.py index d4b2f57c10..135cd51630 100755 --- a/tools/warn.py +++ b/tools/warn.py @@ -1,12 +1,20 @@ #!/usr/bin/env python # This file uses the following encoding: utf-8 +import argparse import sys import re -if len(sys.argv) == 1: - print 'usage: ' + sys.argv[0] + ' ' - sys.exit() +parser = argparse.ArgumentParser(description='Convert a build log into HTML') +parser.add_argument('--url', + help='Root URL of an Android source code tree prefixed ' + 'before files in warnings') +parser.add_argument('--separator', + help='Separator between the end of a URL and the line ' + 'number argument. e.g. #') +parser.add_argument(dest='buildlog', metavar='build.log', + help='Path to build.log file') +args = parser.parse_args() # if you add another level, don't forget to give it a color below class severity: @@ -781,7 +789,7 @@ def tablerow(text): output('',) cur_row_color = 1 - cur_row_color output(text,) - output('') + output('\n') def begintable(text, backgroundcolor, extraanchor): global anchor @@ -879,6 +887,19 @@ def dumpfixed(): if tablestarted: endtable() +def warningwithurl(line): + if not args.url: + return line + m = re.search( r'^([^ :]+):(\d+):(.+)', line, re.M|re.I) + if not m: + return line + filepath = m.group(1) + linenumber = m.group(2) + warning = m.group(3) + if args.separator: + return '' + filepath + ':' + linenumber + ':' + warning + else: + return '' + filepath + ':' + linenumber + ':' + warning # dump a category, provided it is not marked as 'SKIP' and has more than 0 occurrences def dumpcategory(cat): @@ -888,7 +909,7 @@ def dumpcategory(cat): header[1:1] = [' (related option: ' + cat['option'] +')'] begintable(header, colorforseverity(cat['severity']), cat['anchor']) for i in cat['members']: - tablerow(i) + tablerow(warningwithurl(i)) endtable() @@ -918,7 +939,7 @@ def compilepatterns(): for pat in i['patterns']: i['compiledpatterns'].append(re.compile(pat)) -infile = open(sys.argv[1], 'r') +infile = open(args.buildlog, 'r') warnings = [] platformversion = 'unknown'