blob: 3ca858cd315700a475fab7395e5d2ef9681e9891 [file] [log] [blame]
Simon Glassefeac062019-10-31 07:42:52 -06001#!/usr/bin/env python3
Tom Rini10e47792018-05-06 17:58:06 -04002# SPDX-License-Identifier: GPL-2.0+
Simon Glass26132882012-01-14 15:12:45 +00003#
4# Copyright (c) 2011 The Chromium OS Authors.
5#
Simon Glass26132882012-01-14 15:12:45 +00006
7"""See README for more information"""
8
Jan Kiszka6d7c40c2023-04-22 16:42:48 +02009try:
10 import importlib.resources
11except ImportError:
12 # for Python 3.6
13 import importlib_resources
Simon Glass26132882012-01-14 15:12:45 +000014import os
15import re
16import sys
Simon Glassdbac7162020-07-05 21:41:59 -060017import traceback
Simon Glass26132882012-01-14 15:12:45 +000018
Simon Glassd1b6ecf2023-11-04 10:25:22 -060019# Allow 'from patman import xxx to work'
20# pylint: disable=C0413
21our_path = os.path.dirname(os.path.realpath(__file__))
22sys.path.append(os.path.join(our_path, '..'))
Simon Glassbdaad402020-04-17 18:08:52 -060023
Simon Glass26132882012-01-14 15:12:45 +000024# Our modules
Simon Glass22ce6412023-11-04 10:25:20 -060025from patman import cmdline
Simon Glass24725af2020-07-05 21:41:49 -060026from patman import control
Maxim Cournoyercda00122022-12-19 17:32:43 -050027from patman import func_test
Simon Glass131444f2023-02-23 18:18:04 -070028from u_boot_pylib import terminal
29from u_boot_pylib import test_util
30from u_boot_pylib import tools
Simon Glass26132882012-01-14 15:12:45 +000031
Simon Glass26132882012-01-14 15:12:45 +000032
Simon Glassf42ad6a2023-11-04 10:25:21 -060033def run_patman():
34 """Run patamn
Simon Glass2b68b362015-07-30 13:47:41 -060035
Simon Glassf42ad6a2023-11-04 10:25:21 -060036 This is the main program. It collects arguments and runs either the tests or
37 the control module.
38 """
39 args = cmdline.parse_args()
Simon Glass22ce6412023-11-04 10:25:20 -060040
Simon Glassf42ad6a2023-11-04 10:25:21 -060041 if not args.debug:
42 sys.tracebacklimit = 0
Simon Glassdbac7162020-07-05 21:41:59 -060043
Simon Glassf42ad6a2023-11-04 10:25:21 -060044 # Run our meagre tests
45 if args.cmd == 'test':
Simon Glassd1b6ecf2023-11-04 10:25:22 -060046 # pylint: disable=C0415
Simon Glassf42ad6a2023-11-04 10:25:21 -060047 from patman import func_test
48 from patman import test_checkpatch
Simon Glass26132882012-01-14 15:12:45 +000049
Simon Glassf42ad6a2023-11-04 10:25:21 -060050 result = test_util.run_test_suites(
51 'patman', False, False, False, None, None, None,
52 [test_checkpatch.TestPatch, func_test.TestFunctional,
53 'gitutil', 'settings'])
Simon Glass26132882012-01-14 15:12:45 +000054
Simon Glassf42ad6a2023-11-04 10:25:21 -060055 sys.exit(0 if result.wasSuccessful() else 1)
Tom Rini5a9ecb22020-07-24 08:42:06 -040056
Simon Glassf42ad6a2023-11-04 10:25:21 -060057 # Process commits, produce patches files, check them, email them
58 elif args.cmd == 'send':
59 # Called from git with a patch filename as argument
60 # Printout a list of additional CC recipients for this patch
61 if args.cc_cmd:
Simon Glassd1b6ecf2023-11-04 10:25:22 -060062 re_line = re.compile(r'(\S*) (.*)')
63 with open(args.cc_cmd, 'r', encoding='utf-8') as inf:
64 for line in inf.readlines():
65 match = re_line.match(line)
66 if match and match.group(1) == args.patchfiles[0]:
67 for cca in match.group(2).split('\0'):
68 cca = cca.strip()
69 if cca:
70 print(cca)
Tom Rini5a9ecb22020-07-24 08:42:06 -040071
Simon Glassf42ad6a2023-11-04 10:25:21 -060072 elif args.full_help:
73 with importlib.resources.path('patman', 'README.rst') as readme:
74 tools.print_full_help(str(readme))
75 else:
76 # If we are not processing tags, no need to warning about bad ones
77 if not args.process_tags:
78 args.ignore_bad_tags = True
79 control.send(args)
80
81 # Check status of patches in patchwork
82 elif args.cmd == 'status':
83 ret_code = 0
84 try:
85 control.patchwork_status(args.branch, args.count, args.start, args.end,
86 args.dest_branch, args.force,
87 args.show_comments, args.patchwork_url)
Simon Glassd1b6ecf2023-11-04 10:25:22 -060088 except Exception as exc:
89 terminal.tprint(f'patman: {type(exc).__name__}: {exc}',
Simon Glassf42ad6a2023-11-04 10:25:21 -060090 colour=terminal.Color.RED)
91 if args.debug:
92 print()
93 traceback.print_exc()
94 ret_code = 1
95 sys.exit(ret_code)
96
Simon Glass3db916d2020-10-29 21:46:35 -060097
Simon Glassf42ad6a2023-11-04 10:25:21 -060098if __name__ == "__main__":
99 sys.exit(run_patman())