blob: 2432d31871ca27b92d10aeeb9926d48702d5af4d [file] [log] [blame]
Simon Glasse3986d92019-10-31 07:42:52 -06001#!/usr/bin/env python3
Tom Rini83d290c2018-05-06 17:58:06 -04002# SPDX-License-Identifier: GPL-2.0+
Simon Glass0d24de92012-01-14 15:12:45 +00003#
4# Copyright (c) 2011 The Chromium OS Authors.
5#
Simon Glass0d24de92012-01-14 15:12:45 +00006
7"""See README for more information"""
8
Tom Rini72083962020-07-24 08:42:06 -04009from optparse import OptionParser
Simon Glass0d24de92012-01-14 15:12:45 +000010import os
11import re
12import sys
13import unittest
14
Simon Glass0d7a8c42020-04-17 18:08:52 -060015if __name__ == "__main__":
Simon Glassb4fa9492020-04-17 18:09:05 -060016 # Allow 'from patman import xxx to work'
Simon Glass0d7a8c42020-04-17 18:08:52 -060017 our_path = os.path.dirname(os.path.realpath(__file__))
18 sys.path.append(os.path.join(our_path, '..'))
19
Simon Glass0d24de92012-01-14 15:12:45 +000020# Our modules
Simon Glassbf776672020-04-17 18:09:04 -060021from patman import command
Simon Glass7d5b04e2020-07-05 21:41:49 -060022from patman import control
Simon Glassbf776672020-04-17 18:09:04 -060023from patman import gitutil
Simon Glassbf776672020-04-17 18:09:04 -060024from patman import project
25from patman import settings
26from patman import terminal
Simon Glass0b3d24a2020-07-05 21:41:48 -060027from patman import test_util
Simon Glass40d97342020-06-14 10:54:04 -060028from patman import test_checkpatch
Simon Glass0d24de92012-01-14 15:12:45 +000029
Simon Glass57374b02020-07-05 21:41:55 -060030
Tom Rini72083962020-07-24 08:42:06 -040031parser = OptionParser()
32parser.add_option('-H', '--full-help', action='store_true', dest='full_help',
Simon Glass0d24de92012-01-14 15:12:45 +000033 default=False, help='Display the README file')
Tom Rini72083962020-07-24 08:42:06 -040034parser.add_option('-c', '--count', dest='count', type='int',
35 default=-1, help='Automatically create patches from top n commits')
36parser.add_option('-i', '--ignore-errors', action='store_true',
Simon Glass0d24de92012-01-14 15:12:45 +000037 dest='ignore_errors', default=False,
38 help='Send patches email even if patch errors are found')
Tom Rini72083962020-07-24 08:42:06 -040039parser.add_option('-l', '--limit-cc', dest='limit', type='int',
40 default=None, help='Limit the cc list to LIMIT entries [default: %default]')
41parser.add_option('-m', '--no-maintainers', action='store_false',
Simon Glass983a2742014-09-14 20:23:17 -060042 dest='add_maintainers', default=True,
43 help="Don't cc the file maintainers automatically")
Tom Rini72083962020-07-24 08:42:06 -040044parser.add_option('-n', '--dry-run', action='store_true', dest='dry_run',
Simon Glassca706e72013-03-26 13:09:45 +000045 default=False, help="Do a dry run (create but don't email patches)")
Tom Rini72083962020-07-24 08:42:06 -040046parser.add_option('-p', '--project', default=project.DetectProject(),
Simon Glass4806fa32020-07-05 21:41:54 -060047 help="Project name; affects default option values and "
Tom Rini72083962020-07-24 08:42:06 -040048 "aliases [default: %default]")
49parser.add_option('-r', '--in-reply-to', type='string', action='store',
Doug Anderson6d819922013-03-17 10:31:04 +000050 help="Message ID that this series is in reply to")
Tom Rini72083962020-07-24 08:42:06 -040051parser.add_option('-s', '--start', dest='start', type='int',
52 default=0, help='Commit to start creating patches from (0 = HEAD)')
53parser.add_option('-t', '--ignore-bad-tags', action='store_true',
Simon Glass4806fa32020-07-05 21:41:54 -060054 default=False, help='Ignore bad tags / aliases')
Tom Rini72083962020-07-24 08:42:06 -040055parser.add_option('-v', '--verbose', action='store_true', dest='verbose',
Simon Glass0d24de92012-01-14 15:12:45 +000056 default=False, help='Verbose output of errors and warnings')
Tom Rini72083962020-07-24 08:42:06 -040057parser.add_option('-T', '--thread', action='store_true', dest='thread',
Simon Glass4806fa32020-07-05 21:41:54 -060058 default=False, help='Create patches as a single thread')
Tom Rini72083962020-07-24 08:42:06 -040059parser.add_option('--cc-cmd', dest='cc_cmd', type='string', action='store',
Simon Glass0d24de92012-01-14 15:12:45 +000060 default=None, help='Output cc list for patch file (used by git)')
Tom Rini72083962020-07-24 08:42:06 -040061parser.add_option('--no-binary', action='store_true', dest='ignore_binary',
Simon Glass4806fa32020-07-05 21:41:54 -060062 default=False,
63 help="Do not output contents of changes in binary files")
Tom Rini72083962020-07-24 08:42:06 -040064parser.add_option('--no-check', action='store_false', dest='check_patch',
Simon Glass4806fa32020-07-05 21:41:54 -060065 default=True,
66 help="Don't check for patch compliance")
Tom Rini72083962020-07-24 08:42:06 -040067parser.add_option('--no-tags', action='store_false', dest='process_tags',
Simon Glass4806fa32020-07-05 21:41:54 -060068 default=True, help="Don't process subject tags as aliases")
Tom Rini72083962020-07-24 08:42:06 -040069parser.add_option('--smtp-server', type='str',
Simon Glass4806fa32020-07-05 21:41:54 -060070 help="Specify the SMTP server to 'git send-email'")
Tom Rini72083962020-07-24 08:42:06 -040071parser.add_option('--test', action='store_true', dest='test',
72 default=False, help='run tests')
Simon Glass0d24de92012-01-14 15:12:45 +000073
Tom Rini72083962020-07-24 08:42:06 -040074parser.usage += """
Doug Anderson8568bae2012-12-03 14:43:17 +000075
Tom Rini72083962020-07-24 08:42:06 -040076Create patches from commits in a branch, check them and email them as
77specified by tags you place in the commits. Use -n to do a dry run first."""
78
Simon Glass57374b02020-07-05 21:41:55 -060079
Doug Andersona1dcee82012-12-03 14:43:18 +000080# Parse options twice: first to get the project and second to handle
81# defaults properly (which depends on project).
Tom Rini72083962020-07-24 08:42:06 -040082(options, args) = parser.parse_args()
83settings.Setup(gitutil, parser, options.project, '')
84(options, args) = parser.parse_args()
Simon Glass0d24de92012-01-14 15:12:45 +000085
Simon Glass9649e152015-07-30 13:47:41 -060086if __name__ != "__main__":
87 pass
88
Simon Glass0d24de92012-01-14 15:12:45 +000089# Run our meagre tests
Tom Rini72083962020-07-24 08:42:06 -040090elif options.test:
Simon Glass0d24de92012-01-14 15:12:45 +000091 import doctest
Simon Glassbf776672020-04-17 18:09:04 -060092 from patman import func_test
Simon Glass0d24de92012-01-14 15:12:45 +000093
94 sys.argv = [sys.argv[0]]
Simon Glass0d24de92012-01-14 15:12:45 +000095 result = unittest.TestResult()
Simon Glass40d97342020-06-14 10:54:04 -060096 for module in (test_checkpatch.TestPatch, func_test.TestFunctional):
Simon Glass6e87ae12017-05-29 15:31:31 -060097 suite = unittest.TestLoader().loadTestsFromTestCase(module)
98 suite.run(result)
Simon Glass0d24de92012-01-14 15:12:45 +000099
Simon Glass37b224f2020-04-09 15:08:40 -0600100 for module in ['gitutil', 'settings', 'terminal']:
Doug Anderson656cffe2012-12-03 14:43:19 +0000101 suite = doctest.DocTestSuite(module)
102 suite.run(result)
Simon Glass0d24de92012-01-14 15:12:45 +0000103
Simon Glass0b3d24a2020-07-05 21:41:48 -0600104 sys.exit(test_util.ReportResult('patman', None, result))
Tom Rini72083962020-07-24 08:42:06 -0400105
106# Called from git with a patch filename as argument
107# Printout a list of additional CC recipients for this patch
108elif options.cc_cmd:
109 fd = open(options.cc_cmd, 'r')
110 re_line = re.compile('(\S*) (.*)')
111 for line in fd.readlines():
112 match = re_line.match(line)
113 if match and match.group(1) == args[0]:
114 for cc in match.group(2).split('\0'):
115 cc = cc.strip()
116 if cc:
117 print(cc)
118 fd.close()
119
120elif options.full_help:
121 pager = os.getenv('PAGER')
122 if not pager:
123 pager = 'more'
124 fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
125 'README')
126 command.Run(pager, fname)
Simon Glass0d24de92012-01-14 15:12:45 +0000127
Simon Glass0d24de92012-01-14 15:12:45 +0000128# Process commits, produce patches files, check them, email them
Tom Rini72083962020-07-24 08:42:06 -0400129else:
Simon Glass7d5b04e2020-07-05 21:41:49 -0600130 control.send(options)