blob: 56e8787d99a56da7132e6e80a5c34f8229e9d4ea [file] [log] [blame]
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -08001#!/usr/bin/python
2#
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
23# pylint:disable=relative-beyond-top-level
Chih-Hung Hsieh5ae55192020-02-24 10:20:36 -080024from . import warn_common as common
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080025
26
Chih-Hung Hsieh5ae55192020-02-24 10:20:36 -080027def classify_warnings(args):
28 """Classify a list of warning lines.
29
30 Args:
31 args: dictionary {
32 'group': list of (warning, link),
33 'project_patterns': re.compile(project_list[p][1]),
34 'warn_patterns': list of warn_pattern,
35 'num_processes': number of processes being used for multiprocessing }
36 Returns:
37 results: a list of the classified warnings.
38 """
39 results = []
40 for line, link in args['group']:
41 common.classify_one_warning(line, link, results, args['project_patterns'],
42 args['warn_patterns'])
43
44 # After the main work, ignore all other signals to a child process,
45 # to avoid bad warning/error messages from the exit clean-up process.
46 if args['num_processes'] > 1:
47 signal.signal(signal.SIGTERM, lambda *args: sys.exit(-signal.SIGTERM))
48 return results
49
50
51def create_and_launch_subprocesses(num_cpu, classify_warnings_fn, arg_groups,
52 group_results):
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080053 pool = multiprocessing.Pool(num_cpu)
Chih-Hung Hsieh5ae55192020-02-24 10:20:36 -080054 for cpu in range(num_cpu):
55 proc_result = pool.map(classify_warnings_fn, arg_groups[cpu])
56 if proc_result is not None:
57 group_results.append(proc_result)
58 return group_results
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080059
60
61def main():
Chih-Hung Hsieh5ae55192020-02-24 10:20:36 -080062 use_google3 = False
63 common.common_main(use_google3, create_and_launch_subprocesses,
64 classify_warnings)
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080065
66
67if __name__ == '__main__':
68 main()