blob: 0e559b5810be40450b1225d4a045ed74b920f734 [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 Glassbdaad402020-04-17 18:08:52 -060019if __name__ == "__main__":
Simon Glass42143162020-04-17 18:09:05 -060020 # Allow 'from patman import xxx to work'
Simon Glassbdaad402020-04-17 18:08:52 -060021 our_path = os.path.dirname(os.path.realpath(__file__))
22 sys.path.append(os.path.join(our_path, '..'))
23
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 Glass2b68b362015-07-30 13:47:41 -060033if __name__ != "__main__":
34 pass
35
Simon Glass22ce6412023-11-04 10:25:20 -060036args = cmdline.parse_args()
37
Simon Glassdbac7162020-07-05 21:41:59 -060038if not args.debug:
39 sys.tracebacklimit = 0
40
Simon Glass26132882012-01-14 15:12:45 +000041# Run our meagre tests
Simon Glass109e84e2020-07-05 21:41:55 -060042if args.cmd == 'test':
Simon Glassa997ea52020-04-17 18:09:04 -060043 from patman import func_test
Simon Glassc92395b2023-02-23 18:18:07 -070044 from patman import test_checkpatch
Simon Glass26132882012-01-14 15:12:45 +000045
Alper Nebi Yasakca1c5882022-04-02 20:06:06 +030046 result = test_util.run_test_suites(
47 'patman', False, False, False, None, None, None,
Simon Glassc27d22d2022-01-22 05:07:28 -070048 [test_checkpatch.TestPatch, func_test.TestFunctional,
Simon Glass131444f2023-02-23 18:18:04 -070049 'gitutil', 'settings'])
Simon Glass26132882012-01-14 15:12:45 +000050
Alper Nebi Yasakca1c5882022-04-02 20:06:06 +030051 sys.exit(0 if result.wasSuccessful() else 1)
Tom Rini5a9ecb22020-07-24 08:42:06 -040052
Simon Glass109e84e2020-07-05 21:41:55 -060053# Process commits, produce patches files, check them, email them
54elif args.cmd == 'send':
55 # Called from git with a patch filename as argument
56 # Printout a list of additional CC recipients for this patch
57 if args.cc_cmd:
58 fd = open(args.cc_cmd, 'r')
59 re_line = re.compile('(\S*) (.*)')
60 for line in fd.readlines():
61 match = re_line.match(line)
62 if match and match.group(1) == args.patchfiles[0]:
63 for cc in match.group(2).split('\0'):
64 cc = cc.strip()
65 if cc:
66 print(cc)
67 fd.close()
Tom Rini5a9ecb22020-07-24 08:42:06 -040068
Simon Glass109e84e2020-07-05 21:41:55 -060069 elif args.full_help:
Maxim Cournoyer124acc92022-12-16 20:45:29 -050070 with importlib.resources.path('patman', 'README.rst') as readme:
71 tools.print_full_help(str(readme))
Simon Glass109e84e2020-07-05 21:41:55 -060072 else:
Simon Glass1f975b92021-01-23 08:56:15 -070073 # If we are not processing tags, no need to warning about bad ones
74 if not args.process_tags:
75 args.ignore_bad_tags = True
Simon Glass109e84e2020-07-05 21:41:55 -060076 control.send(args)
Simon Glass3db916d2020-10-29 21:46:35 -060077
78# Check status of patches in patchwork
79elif args.cmd == 'status':
80 ret_code = 0
81 try:
Simon Glassd0a0a582020-10-29 21:46:36 -060082 control.patchwork_status(args.branch, args.count, args.start, args.end,
Simon Glass2112d072020-10-29 21:46:38 -060083 args.dest_branch, args.force,
Simon Glass3d80d792020-11-03 13:54:15 -070084 args.show_comments, args.patchwork_url)
Simon Glass3db916d2020-10-29 21:46:35 -060085 except Exception as e:
Simon Glass02811582022-01-29 14:14:18 -070086 terminal.tprint('patman: %s: %s' % (type(e).__name__, e),
Maxim Cournoyerfcf2e852022-12-16 20:45:27 -050087 colour=terminal.Color.RED)
Simon Glass3db916d2020-10-29 21:46:35 -060088 if args.debug:
89 print()
90 traceback.print_exc()
91 ret_code = 1
92 sys.exit(ret_code)