forked from openkylin/platform_build
Merge "Fix more pylint warnings." am: 73524b6bdd
am: dbc7c7cfa9
Original change: https://android-review.googlesource.com/c/platform/build/+/1691596 Change-Id: I8575e11302f55daa5e7bed70b4e5a8aacce0bce4
This commit is contained in:
commit
56a8948fbc
|
@ -0,0 +1,4 @@
|
||||||
|
[FORMAT]
|
||||||
|
|
||||||
|
# Two spaces for each indentation level.
|
||||||
|
indent-string=' '
|
|
@ -144,12 +144,11 @@ def create_warnings(warn_patterns, project_names):
|
||||||
2D warnings array where warnings[p][s] is # of warnings in project name p of
|
2D warnings array where warnings[p][s] is # of warnings in project name p of
|
||||||
severity level s
|
severity level s
|
||||||
"""
|
"""
|
||||||
# pylint:disable=invalid-name
|
|
||||||
warnings = {p: {s.value: 0 for s in Severity.levels} for p in project_names}
|
warnings = {p: {s.value: 0 for s in Severity.levels} for p in project_names}
|
||||||
for i in warn_patterns:
|
for pattern in warn_patterns:
|
||||||
s = i['severity'].value
|
value = pattern['severity'].value
|
||||||
for p in i['projects']:
|
for project in pattern['projects']:
|
||||||
warnings[p][s] += i['projects'][p]
|
warnings[project][value] += pattern['projects'][project]
|
||||||
return warnings
|
return warnings
|
||||||
|
|
||||||
|
|
||||||
|
@ -173,11 +172,11 @@ def emit_table_header(total_by_severity):
|
||||||
"""Returns list of HTML-formatted content for severity stats."""
|
"""Returns list of HTML-formatted content for severity stats."""
|
||||||
|
|
||||||
stats_header = ['Project']
|
stats_header = ['Project']
|
||||||
for s in Severity.levels:
|
for severity in Severity.levels:
|
||||||
if total_by_severity[s.value]:
|
if total_by_severity[severity.value]:
|
||||||
stats_header.append(
|
stats_header.append(
|
||||||
'<span style=\'background-color:{}\'>{}</span>'.format(
|
'<span style=\'background-color:{}\'>{}</span>'.format(
|
||||||
s.color, s.column_header))
|
severity.color, severity.column_header))
|
||||||
stats_header.append('TOTAL')
|
stats_header.append('TOTAL')
|
||||||
return stats_header
|
return stats_header
|
||||||
|
|
||||||
|
@ -200,15 +199,15 @@ def emit_row_counts_per_project(warnings, total_by_project, total_by_severity,
|
||||||
|
|
||||||
total_all_projects = 0
|
total_all_projects = 0
|
||||||
stats_rows = []
|
stats_rows = []
|
||||||
for p in project_names:
|
for p_name in project_names:
|
||||||
if total_by_project[p]:
|
if total_by_project[p_name]:
|
||||||
one_row = [p]
|
one_row = [p_name]
|
||||||
for s in Severity.levels:
|
for severity in Severity.levels:
|
||||||
if total_by_severity[s.value]:
|
if total_by_severity[severity.value]:
|
||||||
one_row.append(warnings[p][s.value])
|
one_row.append(warnings[p_name][severity.value])
|
||||||
one_row.append(total_by_project[p])
|
one_row.append(total_by_project[p_name])
|
||||||
stats_rows.append(one_row)
|
stats_rows.append(one_row)
|
||||||
total_all_projects += total_by_project[p]
|
total_all_projects += total_by_project[p_name]
|
||||||
return total_all_projects, stats_rows
|
return total_all_projects, stats_rows
|
||||||
|
|
||||||
|
|
||||||
|
@ -226,10 +225,10 @@ def emit_row_counts_per_severity(total_by_severity, stats_header, stats_rows,
|
||||||
|
|
||||||
total_all_severities = 0
|
total_all_severities = 0
|
||||||
one_row = ['<b>TOTAL</b>']
|
one_row = ['<b>TOTAL</b>']
|
||||||
for s in Severity.levels:
|
for severity in Severity.levels:
|
||||||
if total_by_severity[s.value]:
|
if total_by_severity[severity.value]:
|
||||||
one_row.append(total_by_severity[s.value])
|
one_row.append(total_by_severity[severity.value])
|
||||||
total_all_severities += total_by_severity[s.value]
|
total_all_severities += total_by_severity[severity.value]
|
||||||
one_row.append(total_all_projects)
|
one_row.append(total_all_projects)
|
||||||
stats_rows.append(one_row)
|
stats_rows.append(one_row)
|
||||||
writer('<script>')
|
writer('<script>')
|
||||||
|
@ -328,8 +327,8 @@ def dump_fixed(writer, warn_patterns):
|
||||||
for text in fixed_patterns:
|
for text in fixed_patterns:
|
||||||
cur_row_class = 1 - cur_row_class
|
cur_row_class = 1 - cur_row_class
|
||||||
# remove last '\n'
|
# remove last '\n'
|
||||||
t = text[:-1] if text[-1] == '\n' else text
|
out_text = text[:-1] if text[-1] == '\n' else text
|
||||||
writer('<tr><td class="c' + str(cur_row_class) + '">' + t + '</td></tr>')
|
writer('<tr><td class="c' + str(cur_row_class) + '">' + out_text + '</td></tr>')
|
||||||
writer('</table></div>')
|
writer('</table></div>')
|
||||||
writer('</blockquote>')
|
writer('</blockquote>')
|
||||||
|
|
||||||
|
@ -339,10 +338,10 @@ def write_severity(csvwriter, sev, kind, warn_patterns):
|
||||||
total = 0
|
total = 0
|
||||||
for pattern in warn_patterns:
|
for pattern in warn_patterns:
|
||||||
if pattern['severity'] == sev and pattern['members']:
|
if pattern['severity'] == sev and pattern['members']:
|
||||||
n = len(pattern['members'])
|
num_members = len(pattern['members'])
|
||||||
total += n
|
total += num_members
|
||||||
warning = kind + ': ' + (pattern['description'] or '?')
|
warning = kind + ': ' + (pattern['description'] or '?')
|
||||||
csvwriter.writerow([n, '', warning])
|
csvwriter.writerow([num_members, '', warning])
|
||||||
# print number of warnings for each project, ordered by project name
|
# print number of warnings for each project, ordered by project name
|
||||||
projects = sorted(pattern['projects'].keys())
|
projects = sorted(pattern['projects'].keys())
|
||||||
for project in projects:
|
for project in projects:
|
||||||
|
@ -355,8 +354,8 @@ def dump_csv(csvwriter, warn_patterns):
|
||||||
"""Dump number of warnings in CSV format to writer."""
|
"""Dump number of warnings in CSV format to writer."""
|
||||||
sort_warnings(warn_patterns)
|
sort_warnings(warn_patterns)
|
||||||
total = 0
|
total = 0
|
||||||
for s in Severity.levels:
|
for severity in Severity.levels:
|
||||||
total += write_severity(csvwriter, s, s.column_header, warn_patterns)
|
total += write_severity(csvwriter, severity, severity.column_header, warn_patterns)
|
||||||
csvwriter.writerow([total, '', 'All warnings'])
|
csvwriter.writerow([total, '', 'All warnings'])
|
||||||
|
|
||||||
|
|
||||||
|
@ -379,35 +378,35 @@ def dump_csv_with_description(csvwriter, warning_records, warning_messages,
|
||||||
csvwriter.writerow(output)
|
csvwriter.writerow(output)
|
||||||
|
|
||||||
|
|
||||||
# Return s with escaped backslash and quotation characters.
|
# Return line with escaped backslash and quotation characters.
|
||||||
def escape_string(s):
|
def escape_string(line):
|
||||||
return s.replace('\\', '\\\\').replace('"', '\\"')
|
return line.replace('\\', '\\\\').replace('"', '\\"')
|
||||||
|
|
||||||
|
|
||||||
# Return s without trailing '\n' and escape the quotation characters.
|
# Return line without trailing '\n' and escape the quotation characters.
|
||||||
def strip_escape_string(s):
|
def strip_escape_string(line):
|
||||||
if not s:
|
if not line:
|
||||||
return s
|
return line
|
||||||
s = s[:-1] if s[-1] == '\n' else s
|
line = line[:-1] if line[-1] == '\n' else line
|
||||||
return escape_string(s)
|
return escape_string(line)
|
||||||
|
|
||||||
|
|
||||||
def emit_warning_array(name, writer, warn_patterns):
|
def emit_warning_array(name, writer, warn_patterns):
|
||||||
writer('var warning_{} = ['.format(name))
|
writer('var warning_{} = ['.format(name))
|
||||||
for w in warn_patterns:
|
for pattern in warn_patterns:
|
||||||
if name == 'severity':
|
if name == 'severity':
|
||||||
writer('{},'.format(w[name].value))
|
writer('{},'.format(pattern[name].value))
|
||||||
else:
|
else:
|
||||||
writer('{},'.format(w[name]))
|
writer('{},'.format(pattern[name]))
|
||||||
writer('];')
|
writer('];')
|
||||||
|
|
||||||
|
|
||||||
def emit_warning_arrays(writer, warn_patterns):
|
def emit_warning_arrays(writer, warn_patterns):
|
||||||
emit_warning_array('severity', writer, warn_patterns)
|
emit_warning_array('severity', writer, warn_patterns)
|
||||||
writer('var warning_description = [')
|
writer('var warning_description = [')
|
||||||
for w in warn_patterns:
|
for pattern in warn_patterns:
|
||||||
if w['members']:
|
if pattern['members']:
|
||||||
writer('"{}",'.format(escape_string(w['description'])))
|
writer('"{}",'.format(escape_string(pattern['description'])))
|
||||||
else:
|
else:
|
||||||
writer('"",') # no such warning
|
writer('"",') # no such warning
|
||||||
writer('];')
|
writer('];')
|
||||||
|
@ -566,32 +565,32 @@ def emit_const_string(name, value, writer):
|
||||||
# Emit a JavaScript const integer array.
|
# Emit a JavaScript const integer array.
|
||||||
def emit_const_int_array(name, array, writer):
|
def emit_const_int_array(name, array, writer):
|
||||||
writer('const ' + name + ' = [')
|
writer('const ' + name + ' = [')
|
||||||
for n in array:
|
for item in array:
|
||||||
writer(str(n) + ',')
|
writer(str(item) + ',')
|
||||||
writer('];')
|
writer('];')
|
||||||
|
|
||||||
|
|
||||||
# Emit a JavaScript const string array.
|
# Emit a JavaScript const string array.
|
||||||
def emit_const_string_array(name, array, writer):
|
def emit_const_string_array(name, array, writer):
|
||||||
writer('const ' + name + ' = [')
|
writer('const ' + name + ' = [')
|
||||||
for s in array:
|
for item in array:
|
||||||
writer('"' + strip_escape_string(s) + '",')
|
writer('"' + strip_escape_string(item) + '",')
|
||||||
writer('];')
|
writer('];')
|
||||||
|
|
||||||
|
|
||||||
# Emit a JavaScript const string array for HTML.
|
# Emit a JavaScript const string array for HTML.
|
||||||
def emit_const_html_string_array(name, array, writer):
|
def emit_const_html_string_array(name, array, writer):
|
||||||
writer('const ' + name + ' = [')
|
writer('const ' + name + ' = [')
|
||||||
for s in array:
|
for item in array:
|
||||||
writer('"' + html.escape(strip_escape_string(s)) + '",')
|
writer('"' + html.escape(strip_escape_string(item)) + '",')
|
||||||
writer('];')
|
writer('];')
|
||||||
|
|
||||||
|
|
||||||
# Emit a JavaScript const object array.
|
# Emit a JavaScript const object array.
|
||||||
def emit_const_object_array(name, array, writer):
|
def emit_const_object_array(name, array, writer):
|
||||||
writer('const ' + name + ' = [')
|
writer('const ' + name + ' = [')
|
||||||
for x in array:
|
for item in array:
|
||||||
writer(str(x) + ',')
|
writer(str(item) + ',')
|
||||||
writer('];')
|
writer('];')
|
||||||
|
|
||||||
|
|
||||||
|
@ -671,8 +670,8 @@ def write_html(flags, project_names, warn_patterns, html_path, warning_messages,
|
||||||
warning_links, warning_records, header_str):
|
warning_links, warning_records, header_str):
|
||||||
"""Write warnings html file."""
|
"""Write warnings html file."""
|
||||||
if html_path:
|
if html_path:
|
||||||
with open(html_path, 'w') as f:
|
with open(html_path, 'w') as outf:
|
||||||
dump_html(flags, f, warning_messages, warning_links, warning_records,
|
dump_html(flags, outf, warning_messages, warning_links, warning_records,
|
||||||
header_str, warn_patterns, project_names)
|
header_str, warn_patterns, project_names)
|
||||||
|
|
||||||
|
|
||||||
|
@ -680,12 +679,12 @@ def write_out_csv(flags, warn_patterns, warning_messages, warning_links,
|
||||||
warning_records, header_str, project_names):
|
warning_records, header_str, project_names):
|
||||||
"""Write warnings csv file."""
|
"""Write warnings csv file."""
|
||||||
if flags.csvpath:
|
if flags.csvpath:
|
||||||
with open(flags.csvpath, 'w') as f:
|
with open(flags.csvpath, 'w') as outf:
|
||||||
dump_csv(csv.writer(f, lineterminator='\n'), warn_patterns)
|
dump_csv(csv.writer(outf, lineterminator='\n'), warn_patterns)
|
||||||
|
|
||||||
if flags.csvwithdescription:
|
if flags.csvwithdescription:
|
||||||
with open(flags.csvwithdescription, 'w') as f:
|
with open(flags.csvwithdescription, 'w') as outf:
|
||||||
dump_csv_with_description(csv.writer(f, lineterminator='\n'),
|
dump_csv_with_description(csv.writer(outf, lineterminator='\n'),
|
||||||
warning_records, warning_messages,
|
warning_records, warning_messages,
|
||||||
warn_patterns, project_names)
|
warn_patterns, project_names)
|
||||||
|
|
||||||
|
|
|
@ -116,22 +116,20 @@ def get_project_names(project_list):
|
||||||
|
|
||||||
def find_project_index(line, project_patterns):
|
def find_project_index(line, project_patterns):
|
||||||
"""Return the index to the project pattern array."""
|
"""Return the index to the project pattern array."""
|
||||||
# pylint:disable=invalid-name
|
for idx, pattern in enumerate(project_patterns):
|
||||||
for i, p in enumerate(project_patterns):
|
if pattern.match(line):
|
||||||
if p.match(line):
|
return idx
|
||||||
return i
|
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
def classify_one_warning(warning, link, results, project_patterns,
|
def classify_one_warning(warning, link, results, project_patterns,
|
||||||
warn_patterns):
|
warn_patterns):
|
||||||
"""Classify one warning line."""
|
"""Classify one warning line."""
|
||||||
# pylint:disable=invalid-name
|
for idx, pattern in enumerate(warn_patterns):
|
||||||
for i, w in enumerate(warn_patterns):
|
for cpat in pattern['compiled_patterns']:
|
||||||
for cpat in w['compiled_patterns']:
|
|
||||||
if cpat.match(warning):
|
if cpat.match(warning):
|
||||||
p = find_project_index(warning, project_patterns)
|
project_idx = find_project_index(warning, project_patterns)
|
||||||
results.append([warning, link, i, p])
|
results.append([warning, link, idx, project_idx])
|
||||||
return
|
return
|
||||||
# If we end up here, there was a problem parsing the log
|
# If we end up here, there was a problem parsing the log
|
||||||
# probably caused by 'make -j' mixing the output from
|
# probably caused by 'make -j' mixing the output from
|
||||||
|
@ -310,7 +308,6 @@ def parse_input_file_chrome(infile, flags):
|
||||||
# Remove the duplicated warnings save ~8% of time when parsing
|
# Remove the duplicated warnings save ~8% of time when parsing
|
||||||
# one typical build log than before
|
# one typical build log than before
|
||||||
unique_warnings = dict()
|
unique_warnings = dict()
|
||||||
# pylint:disable=invalid-name
|
|
||||||
for line in infile:
|
for line in infile:
|
||||||
if warning_pattern.match(line):
|
if warning_pattern.match(line):
|
||||||
normalized_line = normalize_warning_line(line, flags)
|
normalized_line = normalize_warning_line(line, flags)
|
||||||
|
@ -318,17 +315,17 @@ def parse_input_file_chrome(infile, flags):
|
||||||
unique_warnings[normalized_line] = generate_cs_link(line, flags)
|
unique_warnings[normalized_line] = generate_cs_link(line, flags)
|
||||||
elif (platform_version == 'unknown' or board_name == 'unknown' or
|
elif (platform_version == 'unknown' or board_name == 'unknown' or
|
||||||
architecture == 'unknown'):
|
architecture == 'unknown'):
|
||||||
m = re.match(r'.+Package:.+chromeos-base/chromeos-chrome-', line)
|
result = re.match(r'.+Package:.+chromeos-base/chromeos-chrome-', line)
|
||||||
if m is not None:
|
if result is not None:
|
||||||
platform_version = 'R' + line.split('chrome-')[1].split('_')[0]
|
platform_version = 'R' + line.split('chrome-')[1].split('_')[0]
|
||||||
continue
|
continue
|
||||||
m = re.match(r'.+Source\sunpacked\sin\s(.+)', line)
|
result = re.match(r'.+Source\sunpacked\sin\s(.+)', line)
|
||||||
if m is not None:
|
if result is not None:
|
||||||
board_name = m.group(1).split('/')[2]
|
board_name = result.group(1).split('/')[2]
|
||||||
continue
|
continue
|
||||||
m = re.match(r'.+USE:\s*([^\s]*).*', line)
|
result = re.match(r'.+USE:\s*([^\s]*).*', line)
|
||||||
if m is not None:
|
if result is not None:
|
||||||
architecture = m.group(1)
|
architecture = result.group(1)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
header_str = '%s - %s - %s' % (platform_version, board_name, architecture)
|
header_str = '%s - %s - %s' % (platform_version, board_name, architecture)
|
||||||
|
@ -396,22 +393,21 @@ def parse_input_file_android(infile, flags):
|
||||||
line, flags, android_root, unique_warnings)
|
line, flags, android_root, unique_warnings)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# pylint:disable=invalid-name
|
|
||||||
if line_counter < 100:
|
if line_counter < 100:
|
||||||
# save a little bit of time by only doing this for the first few lines
|
# save a little bit of time by only doing this for the first few lines
|
||||||
line_counter += 1
|
line_counter += 1
|
||||||
m = re.search('(?<=^PLATFORM_VERSION=).*', line)
|
result = re.search('(?<=^PLATFORM_VERSION=).*', line)
|
||||||
if m is not None:
|
if result is not None:
|
||||||
platform_version = m.group(0)
|
platform_version = result.group(0)
|
||||||
m = re.search('(?<=^TARGET_PRODUCT=).*', line)
|
result = re.search('(?<=^TARGET_PRODUCT=).*', line)
|
||||||
if m is not None:
|
if result is not None:
|
||||||
target_product = m.group(0)
|
target_product = result.group(0)
|
||||||
m = re.search('(?<=^TARGET_BUILD_VARIANT=).*', line)
|
result = re.search('(?<=^TARGET_BUILD_VARIANT=).*', line)
|
||||||
if m is not None:
|
if result is not None:
|
||||||
target_variant = m.group(0)
|
target_variant = result.group(0)
|
||||||
m = re.search('(?<=^TOP=).*', line)
|
result = re.search('(?<=^TOP=).*', line)
|
||||||
if m is not None:
|
if result is not None:
|
||||||
android_root = m.group(1)
|
android_root = result.group(1)
|
||||||
|
|
||||||
if android_root:
|
if android_root:
|
||||||
new_unique_warnings = dict()
|
new_unique_warnings = dict()
|
||||||
|
@ -458,12 +454,11 @@ def get_warn_patterns(platform):
|
||||||
other_patterns.warn_patterns)
|
other_patterns.warn_patterns)
|
||||||
else:
|
else:
|
||||||
raise Exception('platform name %s is not valid' % platform)
|
raise Exception('platform name %s is not valid' % platform)
|
||||||
# pylint:disable=invalid-name
|
for pattern in warn_patterns:
|
||||||
for w in warn_patterns:
|
pattern['members'] = []
|
||||||
w['members'] = []
|
|
||||||
# Each warning pattern has a 'projects' dictionary, that
|
# Each warning pattern has a 'projects' dictionary, that
|
||||||
# maps a project name to number of warnings in that project.
|
# maps a project name to number of warnings in that project.
|
||||||
w['projects'] = {}
|
pattern['projects'] = {}
|
||||||
return warn_patterns
|
return warn_patterns
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue