diff --git a/tools/warn.py b/tools/warn.py index d8dbd1c04..c223d9ee7 100755 --- a/tools/warn.py +++ b/tools/warn.py @@ -1,17 +1,24 @@ -#!/usr/bin/env python +#!/usr/bin/python # This file uses the following encoding: utf-8 +"""Grep warnings messages and output HTML tables or warning counts in CSV. + +Default is to output warnings in HTML tables grouped by warning severity. +Use option --byproject to output tables grouped by source file projects. +Use option --gencsv to output warning counts in CSV format. +""" + import argparse import re parser = argparse.ArgumentParser(description='Convert a build log into HTML') parser.add_argument('--gencsv', help='Generate a CSV file with number of various warnings', - action="store_true", + action='store_true', default=False) parser.add_argument('--byproject', help='Separate warnings in HTML output by project names', - action="store_true", + action='store_true', default=False) parser.add_argument('--url', help='Root URL of an Android source code tree prefixed ' @@ -23,33 +30,39 @@ 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: - UNKNOWN = 0 - FIXMENOW = 1 - HIGH = 2 - MEDIUM = 3 - LOW = 4 - TIDY = 5 - HARMLESS = 6 - SKIP = 7 - attributes = [ - ['lightblue', 'Unknown', 'Unknown warnings'], - ['fuchsia', 'FixNow', 'Critical warnings, fix me now'], - ['red', 'High', 'High severity warnings'], - ['orange', 'Medium', 'Medium severity warnings'], - ['yellow', 'Low', 'Low severity warnings'], - ['peachpuff', 'Tidy', 'Clang-Tidy warnings'], - ['limegreen', 'Harmless', 'Harmless warnings'], - ['grey', 'Unhandled', 'Unhandled warnings'] - ] - color = [a[0] for a in attributes] - columnheader = [a[1] for a in attributes] - header = [a[2] for a in attributes] - # order to dump by severity - kinds = [FIXMENOW, HIGH, MEDIUM, LOW, TIDY, HARMLESS, UNKNOWN, SKIP] -warnpatterns = [ +# if you add another level, don't forget to give it a color below +class severity: # pylint:disable=invalid-name,old-style-class + """Severity levels and attributes.""" + UNKNOWN = 0 + FIXMENOW = 1 + HIGH = 2 + MEDIUM = 3 + LOW = 4 + TIDY = 5 + HARMLESS = 6 + SKIP = 7 + attributes = [ + # pylint:disable=bad-whitespace + ['lightblue', 'Unknown', 'Unknown warnings'], + ['fuchsia', 'FixNow', 'Critical warnings, fix me now'], + ['red', 'High', 'High severity warnings'], + ['orange', 'Medium', 'Medium severity warnings'], + ['yellow', 'Low', 'Low severity warnings'], + ['peachpuff', 'Tidy', 'Clang-Tidy warnings'], + ['limegreen', 'Harmless', 'Harmless warnings'], + ['grey', 'Unhandled', 'Unhandled warnings'] + ] + color = [a[0] for a in attributes] + column_headers = [a[1] for a in attributes] + header = [a[2] for a in attributes] + # order to dump by severity + kinds = [FIXMENOW, HIGH, MEDIUM, LOW, TIDY, HARMLESS, UNKNOWN, SKIP] + +warn_patterns = [ + # TODO(chh): fix pylint space and indentation warnings + # pylint:disable=bad-whitespace,bad-continuation, + # pylint:disable=line-too-long,g-inconsistent-quotes { 'category':'make', 'severity':severity.MEDIUM, 'description':'make: overriding commands/ignoring old commands', 'patterns':[r".*: warning: overriding commands for target .+", @@ -1158,6 +1171,8 @@ warnpatterns = [ { 'category':'C/C++', 'severity':severity.MEDIUM, 'option':'-Wmissing-noreturn', 'description':'Missing noreturn', 'patterns':[r".*: warning: function '.*' could be declared with attribute 'noreturn'"] }, + # pylint:disable=anomalous-backslash-in-string + # TODO(chh): fix the backslash pylint warning. { 'category':'gcc', 'severity':severity.MEDIUM, 'description':'Invalid option for C file', 'patterns':[r".*: warning: command line option "".+"" is valid for C\+\+\/ObjC\+\+ but not for C"] }, @@ -1577,14 +1592,11 @@ warnpatterns = [ 'patterns':[r".*: warning: .+"] }, ] -for w in warnpatterns: - w['members'] = [] - if 'option' not in w: - w['option'] = '' # A list of [project_name, file_path_pattern]. # project_name should not contain comma, to be used in CSV output. -projectlist = [ +project_list = [ + # pylint:disable=bad-whitespace,g-inconsistent-quotes,line-too-long ['art', r"(^|.*/)art/.*: warning:"], ['bionic', r"(^|.*/)bionic/.*: warning:"], ['bootable', r"(^|.*/)bootable/.*: warning:"], @@ -1619,24 +1631,37 @@ projectlist = [ ['other', r".*: warning:"], ] -projectpatterns = [] -for p in projectlist: - projectpatterns.append({'description':p[0], 'members':[], 'pattern':re.compile(p[1])}) +project_patterns = [] +project_names = [] -projectnames = [p[0] for p in projectlist] -# Each warning pattern has 3 dictionaries: -# (1) 'projects' maps a project name to number of warnings in that project. -# (2) 'projectanchor' maps a project name to its anchor number for HTML. -# (3) 'projectwarning' maps a project name to a list of warning of that project. -for w in warnpatterns: +def initialize_arrays(): + """Complete global arrays before they are used.""" + global project_names + project_names = [p[0] for p in project_list] + for p in project_list: + project_patterns.append({'description': p[0], + 'members': [], + 'pattern': re.compile(p[1])}) + # Each warning pattern has 3 dictionaries: + # (1) 'projects' maps a project name to number of warnings in that project. + # (2) 'project_anchor' maps a project name to its anchor number for HTML. + # (3) 'project_warnings' maps a project name to a list of warning messages. + for w in warn_patterns: + w['members'] = [] + if 'option' not in w: + w['option'] = '' w['projects'] = {} - w['projectanchor'] = {} - w['projectwarning'] = {} + w['project_anchor'] = {} + w['project_warnings'] = {} -platformversion = 'unknown' -targetproduct = 'unknown' -targetvariant = 'unknown' + +initialize_arrays() + + +platform_version = 'unknown' +target_product = 'unknown' +target_variant = 'unknown' ##### Data and functions to dump html file. ################################## @@ -1680,363 +1705,391 @@ html_script_style = """\ def output(text): - print text, + print text, -def htmlbig(param): - return '' + param + '' -def dumphtmlprologue(title): - output('\n
\n') - output('\n') +def html_big(param): + return '' + param + '' -def dumphtmlepilogue(): - output('\n\n