diff options
Diffstat (limited to 'tools/warn/warn.py')
-rwxr-xr-x | tools/warn/warn.py | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/tools/warn/warn.py b/tools/warn/warn.py index bdfd489847..acfbb55928 100755 --- a/tools/warn/warn.py +++ b/tools/warn/warn.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # Copyright (C) 2019 The Android Open Source Project # @@ -17,21 +17,54 @@ """Simple wrapper to run warn_common with Python standard Pool.""" import multiprocessing +import signal +import sys -# pylint:disable=relative-beyond-top-level -# pylint:disable=g-importing-member -from .warn_common import common_main +# pylint:disable=relative-beyond-top-level,no-name-in-module +# suppress false positive of no-name-in-module warnings +from . import warn_common as common -# This parallel_process could be changed depending on platform -# and availability of multi-process library functions. -def parallel_process(num_cpu, classify_warnings, groups): +def classify_warnings(args): + """Classify a list of warning lines. + + Args: + args: dictionary { + 'group': list of (warning, link), + 'project_patterns': re.compile(project_list[p][1]), + 'warn_patterns': list of warn_pattern, + 'num_processes': number of processes being used for multiprocessing } + Returns: + results: a list of the classified warnings. + """ + results = [] + for line, link in args['group']: + common.classify_one_warning(line, link, results, args['project_patterns'], + args['warn_patterns']) + + # 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['num_processes'] > 1: + signal.signal(signal.SIGTERM, lambda *args: sys.exit(-signal.SIGTERM)) + return results + + +def create_and_launch_subprocesses(num_cpu, classify_warnings_fn, arg_groups, + group_results): + """Fork num_cpu processes to classify warnings.""" pool = multiprocessing.Pool(num_cpu) - return pool.map(classify_warnings, groups) + for cpu in range(num_cpu): + proc_result = pool.map(classify_warnings_fn, arg_groups[cpu]) + if proc_result is not None: + group_results.append(proc_result) + return group_results def main(): - common_main(parallel_process) + """Old main() calls new common_main.""" + use_google3 = False + common.common_main(use_google3, create_and_launch_subprocesses, + classify_warnings) if __name__ == '__main__': |