diff --git a/tools/warn/java_warn_patterns.py b/tools/warn/java_warn_patterns.py index 3a3a676e2..0a443d483 100644 --- a/tools/warn/java_warn_patterns.py +++ b/tools/warn/java_warn_patterns.py @@ -93,6 +93,8 @@ warn_patterns = [ [r".*: warning: \[MultipleTopLevelClasses\] .+"]), java_low('Avoid having multiple unary operators acting on the same variable in a method call', [r".*: warning: \[MultipleUnaryOperatorsInMethodCall\] .+"]), + java_low('OnNameExpected naming style', + [r".*\.java:.*: warning: .+ \[OnNameExpected\]$"]), java_low('Package names should match the directory they are declared in', [r".*: warning: \[PackageLocation\] .+"]), java_low('Non-standard parameter comment; prefer `/* paramName= */ arg`', diff --git a/tools/warn/other_warn_patterns.py b/tools/warn/other_warn_patterns.py index 1331bc603..19a4e3862 100644 --- a/tools/warn/other_warn_patterns.py +++ b/tools/warn/other_warn_patterns.py @@ -46,6 +46,10 @@ def kotlin(description, pattern_list): return warn('Kotlin', Severity.MEDIUM, description, pattern_list) +def yacc(description, pattern_list): + return warn('yacc', Severity.MEDIUM, description, pattern_list) + + warn_patterns = [ # pylint:disable=line-too-long,g-inconsistent-quotes # aapt warnings @@ -115,6 +119,14 @@ warn_patterns = [ kotlin('library has Kotlin runtime', [r".*: warning: library has Kotlin runtime bundled into it", r".*: warning: some JAR files .* have the Kotlin Runtime library"]), + # Yacc warnings + yacc('deprecate directive', + [r".*\.yy?:.*: warning: deprecated directive: "]), + yacc('shift/reduce conflicts', + [r".*\.yy?: warning: .+ shift/reduce conflicts "]), + {'category': 'yacc', 'severity': Severity.SKIP, + 'description': 'yacc: fix-its can be applied', + 'patterns': [r".*\.yy?: warning: fix-its can be applied."]}, # Rust warnings {'category': 'Rust', 'severity': Severity.HIGH, 'description': 'Rust: Does not derive Copy', diff --git a/tools/warn/warn_common.py b/tools/warn/warn_common.py index b885ad2f6..0c9d9efbb 100755 --- a/tools/warn/warn_common.py +++ b/tools/warn/warn_common.py @@ -199,22 +199,30 @@ 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): - print('\n') - print('' + title + '') - print(html_head_scripts) - emit_stats_by_project() - print('\n') - print(html_big(title)) - print('

') +def dump_html_prologue(title, writer): + writer('\n') + writer('' + title + '') + writer(html_head_scripts) + emit_stats_by_project(writer) + writer('\n') + writer(html_big(title)) + writer('

') -def dump_html_epilogue(): - print('\n\n') +def dump_html_epilogue(writer): + writer('\n\n') def sort_warnings(): @@ -222,7 +230,7 @@ def sort_warnings(): i['members'] = sorted(set(i['members'])) -def emit_stats_by_project(): +def emit_stats_by_project(writer): """Dump a google chart table of warnings per project and severity.""" # warnings[p][s] is number of warnings in project p of severity s. # pylint:disable=g-complex-comprehension @@ -277,14 +285,14 @@ def emit_stats_by_project(): total_all_severities += total_by_severity[s.value] one_row.append(total_all_projects) stats_rows.append(one_row) - print('') + writer('') -def dump_stats(): +def dump_stats(writer): """Dump some stats about total number of warnings and such.""" known = 0 skipped = 0 @@ -297,14 +305,14 @@ def dump_stats(): skipped += len(i['members']) else: known += len(i['members']) - print('Number of classified warnings: ' + str(known) + '
') - print('Number of skipped warnings: ' + str(skipped) + '
') - print('Number of unclassified warnings: ' + str(unknown) + '
') + writer('Number of classified warnings: ' + str(known) + '
') + writer('Number of skipped warnings: ' + str(skipped) + '
') + writer('Number of unclassified warnings: ' + str(unknown) + '
') total = unknown + known + skipped extra_msg = '' if total < 1000: extra_msg = ' (low count may indicate incremental build)' - print('Total number of warnings: ' + str(total) + '' + extra_msg) + writer('Total number of warnings: ' + str(total) + '' + extra_msg) # New base table of warnings, [severity, warn_id, project, warning_message] @@ -317,15 +325,15 @@ def dump_stats(): # (3) New, group by project + severity, # id for each warning pattern # sort by project, severity, warn_id, warning_message -def emit_buttons(): - print('\n' - '\n' - '\n' - '
') +def emit_buttons(writer): + writer('\n' + '\n' + '\n' + '
') def all_patterns(category): @@ -336,33 +344,32 @@ def all_patterns(category): return patterns -def dump_fixed(): +def dump_fixed(writer): """Show which warnings no longer occur.""" anchor = 'fixed_warnings' mark = anchor + '_mark' - print('\n

' - ' Fixed warnings. ' - 'No more occurrences. Please consider turning these into ' - 'errors if possible, before they are reintroduced in to the build' - ':

') - print('
') + writer('\n

' + ' Fixed warnings. ' + 'No more occurrences. Please consider turning these into ' + 'errors if possible, before they are reintroduced in to the build' + ':

') + writer('
') fixed_patterns = [] for i in warn_patterns: if not i['members']: - fixed_patterns.append(i['description'] + ' (' + - all_patterns(i) + ')') + fixed_patterns.append(i['description'] + ' (' + all_patterns(i) + ')') fixed_patterns = sorted(fixed_patterns) - print('') - print('
') + writer('' + t + '') + writer('') + writer('
') def find_project_index(line): @@ -540,6 +547,7 @@ def parse_input_file(infile): prev_warning = 'unknown_source_file: ' + prev_warning warning_lines.add(normalize_warning_line(prev_warning)) prev_warning = '' + if warning_pattern.match(line): if warning_without_file.match(line): # save this line and combine it with the next line @@ -547,6 +555,7 @@ def parse_input_file(infile): else: warning_lines.add(normalize_warning_line(line)) continue + if line_counter < 100: # save a little bit of time by only doing this for the first few lines line_counter += 1 @@ -580,22 +589,22 @@ def strip_escape_string(s): return escape_string(s) -def emit_warning_array(name): - print('var warning_{} = ['.format(name)) +def emit_warning_array(name, writer): + writer('var warning_{} = ['.format(name)) for i in range(len(warn_patterns)): - print('{},'.format(warn_patterns[i][name])) - print('];') + writer('{},'.format(warn_patterns[i][name])) + writer('];') -def emit_warning_arrays(): - emit_warning_array('severity') - print('var warning_description = [') +def emit_warning_arrays(writer): + emit_warning_array('severity', writer) + writer('var warning_description = [') for i in range(len(warn_patterns)): if warn_patterns[i]['members']: - print('"{}",'.format(escape_string(warn_patterns[i]['description']))) + writer('"{}",'.format(escape_string(warn_patterns[i]['description']))) else: - print('"",') # no such warning - print('];') + writer('"",') # no such warning + writer('];') scripts_for_warning_groups = """ @@ -701,7 +710,8 @@ scripts_for_warning_groups = """ var result = ""; var groups = groupWarningsBySeverity(); for (s=0; s

') - print('\n') - emit_buttons() + target_product + ' - ' + target_variant, writer) + dump_stats(writer) + writer('

') + writer('\n') + emit_buttons(writer) # Warning messages are grouped by severities or project names. - print('
') + writer('
') if args.byproject: - print('') + writer('') else: - print('') - dump_fixed() - dump_html_epilogue() + writer('') + dump_fixed(writer) + dump_html_epilogue(writer) ##### Functions to count warnings and dump csv file. ######################### @@ -884,4 +900,4 @@ def common_main(parallel_process): if args.gencsv: dump_csv(csv.writer(sys.stdout, lineterminator='\n')) else: - dump_html() + dump_html(sys.stdout)