# 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. """ # 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_records array of [idx to warn_patterns, # idx to project_names, # idx to warning_messages] # android_root # platform_version # target_product # target_variant # 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. # FlagURL args.url # FlagSeparator args.separator # 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 signal import sys # pylint:disable=relative-beyond-top-level from . import cpp_warn_patterns from . import java_warn_patterns from . import make_warn_patterns from . import other_warn_patterns from . import tidy_warn_patterns # pylint:disable=g-importing-member from .android_project_list import project_list from .severity import Severity parser = argparse.ArgumentParser(description='Convert a build log into HTML') parser.add_argument('--csvpath', help='Save CSV warning file to the passed absolute path', default=None) parser.add_argument('--gencsv', help='Generate a CSV file with number of various warnings', action='store_true', default=False) parser.add_argument('--byproject', help='Separate warnings in HTML output by project names', action='store_true', default=False) 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('--processes', type=int, default=multiprocessing.cpu_count(), help='Number of parallel processes to process warnings') parser.add_argument(dest='buildlog', metavar='build.log', help='Path to build.log file') args = parser.parse_args() warn_patterns = make_warn_patterns.warn_patterns warn_patterns.extend(cpp_warn_patterns.warn_patterns) warn_patterns.extend(java_warn_patterns.warn_patterns) warn_patterns.extend(tidy_warn_patterns.warn_patterns) warn_patterns.extend(other_warn_patterns.warn_patterns) project_patterns = [] project_names = [] warning_messages = [] warning_records = [] def initialize_arrays(): """Complete global arrays before they are used.""" global project_names, project_patterns project_names = [p[0] for p in project_list] project_patterns = [re.compile(p[1]) for p in project_list] for w in warn_patterns: w['members'] = [] # Each warning pattern has a 'projects' dictionary, that # maps a project name to number of warnings in that project. w['projects'] = {} initialize_arrays() android_root = '' platform_version = 'unknown' target_product = 'unknown' target_variant = 'unknown' ##### Data and functions to dump html file. ################################## 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): writer('\n
') writer('') def dump_html_epilogue(writer): writer('\n\n