diff options
Diffstat (limited to 'tools/patman')
-rw-r--r-- | tools/patman/control.py | 6 | ||||
-rw-r--r-- | tools/patman/func_test.py | 19 | ||||
-rw-r--r-- | tools/patman/gitutil.py | 9 | ||||
-rwxr-xr-x | tools/patman/main.py | 2 | ||||
-rw-r--r-- | tools/patman/series.py | 4 | ||||
-rw-r--r-- | tools/patman/settings.py | 12 | ||||
-rw-r--r-- | tools/patman/test_checkpatch.py | 28 | ||||
-rw-r--r-- | tools/patman/tools.py | 93 |
8 files changed, 67 insertions, 106 deletions
diff --git a/tools/patman/control.py b/tools/patman/control.py index 2330682df4..ee9717cbf6 100644 --- a/tools/patman/control.py +++ b/tools/patman/control.py @@ -20,7 +20,7 @@ def setup(): """Do required setup before doing anything""" gitutil.Setup() -def prepare_patches(col, branch, count, start, end, ignore_binary): +def prepare_patches(col, branch, count, start, end, ignore_binary, signoff): """Figure out what patches to generate, then generate them The patch files are written to the current directory, e.g. 0001_xxx.patch @@ -56,7 +56,7 @@ def prepare_patches(col, branch, count, start, end, ignore_binary): to_do = count - end series = patchstream.get_metadata(branch, start, to_do) cover_fname, patch_files = gitutil.CreatePatches( - branch, start, to_do, ignore_binary, series) + branch, start, to_do, ignore_binary, series, signoff) # Fix up the patch files to our liking, and insert the cover letter patchstream.fix_patches(series, patch_files) @@ -163,7 +163,7 @@ def send(args): col = terminal.Color() series, cover_fname, patch_files = prepare_patches( col, args.branch, args.count, args.start, args.end, - args.ignore_binary) + args.ignore_binary, args.add_signoff) ok = check_patches(series, patch_files, args.check_patch, args.verbose) diff --git a/tools/patman/func_test.py b/tools/patman/func_test.py index 74a144dc2d..89072b1ae7 100644 --- a/tools/patman/func_test.py +++ b/tools/patman/func_test.py @@ -237,27 +237,26 @@ class TestFunctional(unittest.TestCase): if 'Cc:' not in prev: break self.assertEqual('To: u-boot@lists.denx.de', prev) - self.assertEqual('Cc: %s' % tools.FromUnicode(stefan), next(lines)) + self.assertEqual('Cc: %s' % stefan, next(lines)) self.assertEqual('Version: 3', next(lines)) self.assertEqual('Prefix:\t RFC', next(lines)) self.assertEqual('Cover: 4 lines', next(lines)) self.assertEqual(' Cc: %s' % self.fred, next(lines)) - self.assertEqual(' Cc: %s' % tools.FromUnicode(self.leb), + self.assertEqual(' Cc: %s' % self.leb, next(lines)) - self.assertEqual(' Cc: %s' % tools.FromUnicode(mel), next(lines)) + self.assertEqual(' Cc: %s' % mel, next(lines)) self.assertEqual(' Cc: %s' % rick, next(lines)) expected = ('Git command: git send-email --annotate ' '--in-reply-to="%s" --to "u-boot@lists.denx.de" ' '--cc "%s" --cc-cmd "%s send --cc-cmd %s" %s %s' % (in_reply_to, stefan, sys.argv[0], cc_file, cover_fname, ' '.join(args))) - self.assertEqual(expected, tools.ToUnicode(next(lines))) + self.assertEqual(expected, next(lines)) - self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), - tools.ToUnicode(cc_lines[0])) + self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), cc_lines[0]) self.assertEqual( '%s %s\0%s\0%s\0%s' % (args[1], self.fred, self.leb, rick, stefan), - tools.ToUnicode(cc_lines[1])) + cc_lines[1]) expected = ''' This is a test of how the cover @@ -476,7 +475,7 @@ complicated as possible''') with capture_sys_output() as _: _, cover_fname, patch_files = control.prepare_patches( col, branch=None, count=-1, start=0, end=0, - ignore_binary=False) + ignore_binary=False, signoff=True) self.assertIsNone(cover_fname) self.assertEqual(2, len(patch_files)) @@ -485,7 +484,7 @@ complicated as possible''') with capture_sys_output() as _: _, cover_fname, patch_files = control.prepare_patches( col, branch='second', count=-1, start=0, end=0, - ignore_binary=False) + ignore_binary=False, signoff=True) self.assertIsNotNone(cover_fname) self.assertEqual(3, len(patch_files)) @@ -493,7 +492,7 @@ complicated as possible''') with capture_sys_output() as _: _, cover_fname, patch_files = control.prepare_patches( col, branch='second', count=-1, start=0, end=1, - ignore_binary=False) + ignore_binary=False, signoff=True) self.assertIsNotNone(cover_fname) self.assertEqual(2, len(patch_files)) finally: diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py index 31fb3b2829..bf1271ded7 100644 --- a/tools/patman/gitutil.py +++ b/tools/patman/gitutil.py @@ -305,7 +305,7 @@ def PruneWorktrees(git_dir): if result.return_code != 0: raise OSError('git worktree prune: %s' % result.stderr) -def CreatePatches(branch, start, count, ignore_binary, series): +def CreatePatches(branch, start, count, ignore_binary, series, signoff = True): """Create a series of patches from the top of the current branch. The patch files are written to the current directory using @@ -323,7 +323,9 @@ def CreatePatches(branch, start, count, ignore_binary, series): """ if series.get('version'): version = '%s ' % series['version'] - cmd = ['git', 'format-patch', '-M', '--signoff'] + cmd = ['git', 'format-patch', '-M' ] + if signoff: + cmd.append('--signoff') if ignore_binary: cmd.append('--no-binary') if series.get('cover'): @@ -383,7 +385,6 @@ def BuildEmailList(in_list, tag=None, alias=None, raise_on_error=True): raw += LookupEmail(item, alias, raise_on_error=raise_on_error) result = [] for item in raw: - item = tools.FromUnicode(item) if not item in result: result.append(item) if tag: @@ -494,7 +495,7 @@ send --cc-cmd cc-fname" cover p1 p2' if smtp_server: cmd.append('--smtp-server=%s' % smtp_server) if in_reply_to: - cmd.append('--in-reply-to="%s"' % tools.FromUnicode(in_reply_to)) + cmd.append('--in-reply-to="%s"' % in_reply_to) if thread: cmd.append('--thread') diff --git a/tools/patman/main.py b/tools/patman/main.py index 342fd446a1..c4e4d80d42 100755 --- a/tools/patman/main.py +++ b/tools/patman/main.py @@ -81,6 +81,8 @@ send.add_argument('--no-check', action='store_false', dest='check_patch', help="Don't check for patch compliance") send.add_argument('--no-tags', action='store_false', dest='process_tags', default=True, help="Don't process subject tags as aliases") +send.add_argument('--no-signoff', action='store_false', dest='add_signoff', + default=True, help="Don't add Signed-off-by to patches") send.add_argument('--smtp-server', type=str, help="Specify the SMTP server to 'git send-email'") diff --git a/tools/patman/series.py b/tools/patman/series.py index 1d92bdb910..a6746e87c4 100644 --- a/tools/patman/series.py +++ b/tools/patman/series.py @@ -272,7 +272,6 @@ class Series(dict): for x in set(cc) & set(settings.bounces): print(col.Color(col.YELLOW, 'Skipping "%s"' % x)) cc = set(cc) - set(settings.bounces) - cc = [tools.FromUnicode(m) for m in cc] if limit is not None: cc = cc[:limit] all_ccs += cc @@ -281,11 +280,10 @@ class Series(dict): if cover_fname: cover_cc = gitutil.BuildEmailList(self.get('cover_cc', '')) - cover_cc = [tools.FromUnicode(m) for m in cover_cc] cover_cc = list(set(cover_cc + all_ccs)) if limit is not None: cover_cc = cover_cc[:limit] - cc_list = '\0'.join([tools.ToUnicode(x) for x in sorted(cover_cc)]) + cc_list = '\0'.join([x for x in sorted(cover_cc)]) print(cover_fname, cc_list, file=fd) fd.close() diff --git a/tools/patman/settings.py b/tools/patman/settings.py index 8c10eab264..13c1ee4f56 100644 --- a/tools/patman/settings.py +++ b/tools/patman/settings.py @@ -23,7 +23,12 @@ _default_settings = { "u-boot": {}, "linux": { "process_tags": "False", - } + }, + "gcc": { + "process_tags": "False", + "add_signoff": "False", + "check_patch": "False", + }, } class _ProjectConfigParser(ConfigParser.SafeConfigParser): @@ -112,7 +117,7 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): val = ConfigParser.SafeConfigParser.get( self, section, option, *args, **kwargs ) - return tools.ToUnicode(val) + return val def items(self, section, *args, **kwargs): """Extend SafeConfigParser to add project_section to section. @@ -147,8 +152,7 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): item_dict = dict(top_items) item_dict.update(project_items) - return {(tools.ToUnicode(item), tools.ToUnicode(val)) - for item, val in item_dict.items()} + return {(item, val) for item, val in item_dict.items()} def ReadGitAliases(fname): """Read a git alias file. This is in the form used by git: diff --git a/tools/patman/test_checkpatch.py b/tools/patman/test_checkpatch.py index 1f7c38c4e9..a4fec1d4c1 100644 --- a/tools/patman/test_checkpatch.py +++ b/tools/patman/test_checkpatch.py @@ -411,6 +411,34 @@ index 0000000..2234c87 pm.add_line('common/main.c', 'if (CONFIG_IS_ENABLED(CONFIG_CLK))') self.checkSingleMessage(pm, 'CONFIG_IS_ENABLED_CONFIG', 'error') + def check_struct(self, auto, suffix, warning): + """Check one of the warnings for struct naming + + Args: + auto: Auto variable name, e.g. 'per_child_auto' + suffix: Suffix to expect on member, e.g. '_priv' + warning: Warning name, e.g. 'PRIV_AUTO' + """ + pm = PatchMaker() + pm.add_line('common/main.c', '.%s = sizeof(struct(fred)),' % auto) + pm.add_line('common/main.c', '.%s = sizeof(struct(mary%s)),' % + (auto, suffix)) + self.checkSingleMessage( + pm, warning, "struct 'fred' should have a %s suffix" % suffix) + + def testDmDriverAuto(self): + """Check for the correct suffix on 'struct driver' auto members""" + self.check_struct('priv_auto', '_priv', 'PRIV_AUTO') + self.check_struct('plat_auto', '_plat', 'PLAT_AUTO') + self.check_struct('per_child_auto', '_priv', 'CHILD_PRIV_AUTO') + self.check_struct('per_child_plat_auto', '_plat', 'CHILD_PLAT_AUTO') + + def testDmUclassAuto(self): + """Check for the correct suffix on 'struct uclass' auto members""" + # Some of these are omitted since they match those from struct driver + self.check_struct('per_device_auto', '_priv', 'DEVICE_PRIV_AUTO') + self.check_struct('per_device_plat_auto', '_plat', 'DEVICE_PLAT_AUTO') + if __name__ == "__main__": unittest.main() diff --git a/tools/patman/tools.py b/tools/patman/tools.py index 05b1a1d4b0..d8e01a3e60 100644 --- a/tools/patman/tools.py +++ b/tools/patman/tools.py @@ -94,6 +94,14 @@ def GetOutputFilename(fname): """ return os.path.join(outdir, fname) +def GetOutputDir(): + """Return the current output directory + + Returns: + str: The output directory + """ + return outdir + def _FinaliseForTest(): """Remove the output directory (for use by tests)""" global outdir @@ -415,8 +423,6 @@ def WriteFile(fname, data, binary=True): def GetBytes(byte, size): """Get a string of bytes of a given size - This handles the unfortunate different between Python 2 and Python 2. - Args: byte: Numeric byte value to use size: Size of bytes/string to return @@ -424,81 +430,7 @@ def GetBytes(byte, size): Returns: A bytes type with 'byte' repeated 'size' times """ - if sys.version_info[0] >= 3: - data = bytes([byte]) * size - else: - data = chr(byte) * size - return data - -def ToUnicode(val): - """Make sure a value is a unicode string - - This allows some amount of compatibility between Python 2 and Python3. For - the former, it returns a unicode object. - - Args: - val: string or unicode object - - Returns: - unicode version of val - """ - if sys.version_info[0] >= 3: - return val - return val if isinstance(val, unicode) else val.decode('utf-8') - -def FromUnicode(val): - """Make sure a value is a non-unicode string - - This allows some amount of compatibility between Python 2 and Python3. For - the former, it converts a unicode object to a string. - - Args: - val: string or unicode object - - Returns: - non-unicode version of val - """ - if sys.version_info[0] >= 3: - return val - return val if isinstance(val, str) else val.encode('utf-8') - -def ToByte(ch): - """Convert a character to an ASCII value - - This is useful because in Python 2 bytes is an alias for str, but in - Python 3 they are separate types. This function converts the argument to - an ASCII value in either case. - - Args: - ch: A string (Python 2) or byte (Python 3) value - - Returns: - integer ASCII value for ch - """ - return ord(ch) if type(ch) == str else ch - -def ToChar(byte): - """Convert a byte to a character - - This is useful because in Python 2 bytes is an alias for str, but in - Python 3 they are separate types. This function converts an ASCII value to - a value with the appropriate type in either case. - - Args: - byte: A byte or str value - """ - return chr(byte) if type(byte) != str else byte - -def ToChars(byte_list): - """Convert a list of bytes to a str/bytes type - - Args: - byte_list: List of ASCII values representing the string - - Returns: - string made by concatenating all the ASCII values - """ - return ''.join([chr(byte) for byte in byte_list]) + return bytes([byte]) * size def ToBytes(string): """Convert a str type into a bytes type @@ -507,12 +439,9 @@ def ToBytes(string): string: string to convert Returns: - Python 3: A bytes type - Python 2: A string type + A bytes type """ - if sys.version_info[0] >= 3: - return string.encode('utf-8') - return string + return string.encode('utf-8') def ToString(bval): """Convert a bytes type into a str type |