blob: acfbb559283c8ef3ae0a94e55aa033d751bc16fc [file] [log] [blame]
Chih-Hung Hsieh7cc0e152021-04-26 17:09:36 -07001#!/usr/bin/env python3
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -08002#
3# Copyright (C) 2019 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""Simple wrapper to run warn_common with Python standard Pool."""
18
19import multiprocessing
Chih-Hung Hsieh5ae55192020-02-24 10:20:36 -080020import signal
21import sys
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080022
Chih-Hung Hsieh98b285d2021-04-28 14:49:32 -070023# pylint:disable=relative-beyond-top-level,no-name-in-module
24# suppress false positive of no-name-in-module warnings
Chih-Hung Hsieh5ae55192020-02-24 10:20:36 -080025from . import warn_common as common
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080026
27
Chih-Hung Hsieh5ae55192020-02-24 10:20:36 -080028def classify_warnings(args):
29 """Classify a list of warning lines.
30
31 Args:
32 args: dictionary {
33 'group': list of (warning, link),
34 'project_patterns': re.compile(project_list[p][1]),
35 'warn_patterns': list of warn_pattern,
36 'num_processes': number of processes being used for multiprocessing }
37 Returns:
38 results: a list of the classified warnings.
39 """
40 results = []
41 for line, link in args['group']:
42 common.classify_one_warning(line, link, results, args['project_patterns'],
43 args['warn_patterns'])
44
45 # After the main work, ignore all other signals to a child process,
46 # to avoid bad warning/error messages from the exit clean-up process.
47 if args['num_processes'] > 1:
48 signal.signal(signal.SIGTERM, lambda *args: sys.exit(-signal.SIGTERM))
49 return results
50
51
52def create_and_launch_subprocesses(num_cpu, classify_warnings_fn, arg_groups,
53 group_results):
Chih-Hung Hsieh98b285d2021-04-28 14:49:32 -070054 """Fork num_cpu processes to classify warnings."""
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080055 pool = multiprocessing.Pool(num_cpu)
Chih-Hung Hsieh5ae55192020-02-24 10:20:36 -080056 for cpu in range(num_cpu):
57 proc_result = pool.map(classify_warnings_fn, arg_groups[cpu])
58 if proc_result is not None:
59 group_results.append(proc_result)
60 return group_results
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080061
62
63def main():
Chih-Hung Hsieh98b285d2021-04-28 14:49:32 -070064 """Old main() calls new common_main."""
Chih-Hung Hsieh5ae55192020-02-24 10:20:36 -080065 use_google3 = False
66 common.common_main(use_google3, create_and_launch_subprocesses,
67 classify_warnings)
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080068
69
70if __name__ == '__main__':
71 main()