# python3 # Copyright (C) 2019 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """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. Default input file is build.log, which can be changed with the --log flag. """ # List of important data structures and functions in this script. # # To parse and keep warning message in the input file: # severity: classification of message severity # warn_patterns: # warn_patterns[w]['category'] tool that issued the warning, not used now # warn_patterns[w]['description'] table heading # warn_patterns[w]['members'] matched warnings from input # warn_patterns[w]['patterns'] regular expressions to match warnings # warn_patterns[w]['projects'][p] number of warnings of pattern w in p # warn_patterns[w]['severity'] severity tuple # project_list[p][0] project name # project_list[p][1] regular expression to match a project path # project_patterns[p] re.compile(project_list[p][1]) # project_names[p] project_list[p][0] # warning_messages array of each warning message, without source url # warning_links array of each warning code search link; for 'chrome' # warning_records array of [idx to warn_patterns, # idx to project_names, # idx to warning_messages, # idx to warning_links] # parse_input_file # # To emit html page of warning messages: # flags: --byproject, --url, --separator # Old stuff for static html components: # html_script_style: static html scripts and styles # htmlbig: # dump_stats, dump_html_prologue, dump_html_epilogue: # emit_buttons: # dump_fixed # sort_warnings: # emit_stats_by_project: # all_patterns, # findproject, classify_warning # dump_html # # New dynamic HTML page's static JavaScript data: # Some data are copied from Python to JavaScript, to generate HTML elements. # FlagPlatform flags.platform # FlagURL flags.url, used by 'android' # FlagSeparator flags.separator, used by 'android' # SeverityColors: list of colors for all severity levels # SeverityHeaders: list of headers for all severity levels # SeverityColumnHeaders: list of column_headers for all severity levels # ProjectNames: project_names, or project_list[*][0] # WarnPatternsSeverity: warn_patterns[*]['severity'] # WarnPatternsDescription: warn_patterns[*]['description'] # WarningMessages: warning_messages # Warnings: warning_records # StatsHeader: warning count table header row # StatsRows: array of warning count table rows # # New dynamic HTML page's dynamic JavaScript data: # # New dynamic HTML related function to emit data: # escape_string, strip_escape_string, emit_warning_arrays # emit_js_data(): from __future__ import print_function import argparse import cgi import csv import io import multiprocessing import os import re import sys # pylint:disable=relative-beyond-top-level from . import android_project_list from . import chrome_project_list from . import cpp_warn_patterns as cpp_patterns from . import java_warn_patterns as java_patterns from . import make_warn_patterns as make_patterns from . import other_warn_patterns as other_patterns from . import tidy_warn_patterns as tidy_patterns # pylint:disable=g-importing-member from .severity import Severity def parse_args(use_google3): """Define and parse the args. Return the parse_args() result.""" parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('--capacitor_path', default='', help='Save capacitor warning file to the passed absolute' ' path') # csvpath has a different naming than the above path because historically the # original Android script used csvpath, so other scripts rely on it parser.add_argument('--csvpath', default='', help='Save CSV warning file to the passed path') parser.add_argument('--gencsv', action='store_true', help='Generate CSV file with number of various warnings') parser.add_argument('--byproject', action='store_true', help='Separate warnings in HTML output by project names') parser.add_argument('--url', default='', help='Root URL of an Android source code tree prefixed ' 'before files in warnings') parser.add_argument('--separator', default='?l=', help='Separator between the end of a URL and the line ' 'number argument. e.g. #') parser.add_argument('--processes', default=multiprocessing.cpu_count(), type=int, help='Number of parallel processes to process warnings') # Old Android build scripts call warn.py without --platform, # so the default platform is set to 'android'. parser.add_argument('--platform', default='android', choices=['chrome', 'android'], help='Platform of the build log') # Old Android build scripts call warn.py with only a build.log file path. parser.add_argument('--log', help='Path to build log file') parser.add_argument(dest='buildlog', metavar='build.log', default='build.log', nargs='?', help='Path to build.log file') flags = parser.parse_args() if not flags.log: flags.log = flags.buildlog if not use_google3 and not os.path.exists(flags.log): sys.exit('Cannot find log file: ' + flags.log) return flags def get_project_names(project_list): """Get project_names from project_list.""" return [p[0] for p in project_list] html_head_scripts = """\ """ def make_writer(output_stream): def writer(text): return output_stream.write(text + '\n') return writer def html_big(param): return '' + param + '' def dump_html_prologue(title, writer, warn_patterns, project_names): writer('\n
') writer('') def dump_html_epilogue(writer): writer('\n\n