Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76d0065e authored by Chih-Hung Hsieh's avatar Chih-Hung Hsieh
Browse files

Separate parallel_classify_warnings out of parse_input_file.

* Allow other callers of this module to:
  * pass any input stream to parse_input_file,
  * pass any warning_lines to parallel_classify_warnings,
  * call dump_csv or dump_html to get output.
* No output change.
* Capture and ignore signal.SIGTERM at the end,
  to avoid bad warning/error messages from the exit clean-up process.

Test: run warn.py build.log.
Change-Id: I1414797a536c0ee622e2a34c226578621be1ddab
parent 98f15a70
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@ import argparse
import multiprocessing
import os
import re
import signal
import sys

parser = argparse.ArgumentParser(description='Convert a build log into HTML')
parser.add_argument('--gencsv',
@@ -2090,11 +2092,16 @@ def classify_warnings(lines):
  results = []
  for line in lines:
    classify_one_warning(line, results)
  # After the main work, ignore all other signals to a child process,
  # to avoid bad warning/error messages from the exit clean-up process.
  if args.processes > 1:
    signal.signal(signal.SIGTERM, lambda *args: sys.exit(-signal.SIGTERM))
  return results


def parallel_classify_warnings(warning_lines):
  """Classify all warning lines with num_cpu parallel processes."""
  compile_patterns()
  num_cpu = args.processes
  if num_cpu > 1:
    groups = [[] for x in range(num_cpu)]
@@ -2177,17 +2184,15 @@ def normalize_warning_line(line):
    return line


def parse_input_file():
def parse_input_file(infile):
  """Parse input file, match warning lines."""
  global platform_version
  global target_product
  global target_variant
  infile = open(args.buildlog, 'r')
  line_counter = 0

  # handle only warning messages with a file path
  warning_pattern = re.compile('^[^ ]*/[^ ]*: warning: .*')
  compile_patterns()

  # Collect all warnings into the warning_lines set.
  warning_lines = set()
@@ -2207,7 +2212,7 @@ def parse_input_file():
      m = re.search('(?<=^TARGET_BUILD_VARIANT=).*', line)
      if m is not None:
        target_variant = m.group(0)
  parallel_classify_warnings(warning_lines)
  return warning_lines


# Return s with escaped backslash and quotation characters.
@@ -2503,7 +2508,8 @@ def dump_csv():


def main():
  parse_input_file()
  warning_lines = parse_input_file(open(args.buildlog, 'r'))
  parallel_classify_warnings(warning_lines)
  if args.gencsv:
    dump_csv()
  else: