diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/fdt_host.h | 1 | ||||
-rw-r--r-- | tools/imls/imls.c | 1 | ||||
-rw-r--r-- | tools/patman/README | 43 | ||||
-rw-r--r-- | tools/patman/checkpatch.py | 14 | ||||
-rw-r--r-- | tools/patman/get_maintainer.py | 63 | ||||
-rw-r--r-- | tools/patman/gitutil.py | 13 | ||||
-rwxr-xr-x | tools/patman/patman.py | 29 | ||||
-rw-r--r-- | tools/patman/project.py | 43 | ||||
-rw-r--r-- | tools/patman/series.py | 27 | ||||
-rw-r--r-- | tools/patman/settings.py | 180 | ||||
-rw-r--r-- | tools/patman/test.py | 6 |
11 files changed, 389 insertions, 31 deletions
diff --git a/tools/fdt_host.h b/tools/fdt_host.h index 085013e..b08bf86 100644 --- a/tools/fdt_host.h +++ b/tools/fdt_host.h @@ -21,7 +21,6 @@ #define __FDT_HOST_H__ /* Make sure to include u-boot version of libfdt include files */ -#include "../include/fdt.h" #include "../include/libfdt.h" #include "../include/fdt_support.h" diff --git a/tools/imls/imls.c b/tools/imls/imls.c index b21c505..a982a13 100644 --- a/tools/imls/imls.c +++ b/tools/imls/imls.c @@ -38,7 +38,6 @@ #endif #include <sha1.h> -#include <fdt.h> #include <libfdt.h> #include <fdt_support.h> #include <image.h> diff --git a/tools/patman/README b/tools/patman/README index dc3957c..1832ebd 100644 --- a/tools/patman/README +++ b/tools/patman/README @@ -43,6 +43,9 @@ Series-to: fred.blogs@napier.co.nz in one of your commits, the series will be sent there. +In Linux this will also call get_maintainer.pl on each of your +patches automatically. + How to use this tool ==================== @@ -65,8 +68,12 @@ will get a consistent result each time. How to configure it =================== -For most cases patman will locate and use the file 'doc/git-mailrc' in -your U-Boot directory. This contains most of the aliases you will need. +For most cases of using patman for U-Boot developement patman will +locate and use the file 'doc/git-mailrc' in your U-Boot directory. +This contains most of the aliases you will need. + +For Linux the 'scripts/get_maintainer.pl' handles figuring out where +to send patches pretty well. During the first run patman creates a config file for you by taking the default user name and email address from the global .gitconfig file. @@ -91,6 +98,35 @@ The checkpatch.pl in the U-Boot tools/ subdirectory will be located and used. Failing that you can put it into your path or ~/bin/checkpatch.pl +If you want to change the defaults for patman's command-line arguments, +you can add a [settings] section to your .patman file. This can be used +for any command line option by referring to the "dest" for the option in +patman.py. For reference, the useful ones (at the moment) shown below +(all with the non-default setting): + +>>> + +[settings] +ignore_errors: True +process_tags: False +verbose: True + +<<< + + +If you want to adjust settings (or aliases) that affect just a single +project you can add a section that looks like [project_settings] or +[project_alias]. If you want to use tags for your linux work, you could +do: + +>>> + +[linux_settings] +process_tags: True + +<<< + + How to run it ============= @@ -226,6 +262,9 @@ Date: Mon Nov 7 23:18:44 2011 -0500 will create a patch which is copied to x86, arm, sandbox, mikef, ag and afleming. +If you have a cover letter it will get sent to the union of the CC lists of +all of the other patches. + Example Work Flow ================= diff --git a/tools/patman/checkpatch.py b/tools/patman/checkpatch.py index d831087..d3a0477 100644 --- a/tools/patman/checkpatch.py +++ b/tools/patman/checkpatch.py @@ -23,13 +23,16 @@ import command import gitutil import os import re +import sys import terminal def FindCheckPatch(): + top_level = gitutil.GetTopLevel() try_list = [ os.getcwd(), os.path.join(os.getcwd(), '..', '..'), - os.path.join(gitutil.GetTopLevel(), 'tools'), + os.path.join(top_level, 'tools'), + os.path.join(top_level, 'scripts'), '%s/bin' % os.getenv('HOME'), ] # Look in current dir @@ -45,8 +48,10 @@ def FindCheckPatch(): if os.path.isfile(fname): return fname path = os.path.dirname(path) - print 'Could not find checkpatch.pl' - return None + + print >> sys.stderr, ('Cannot find checkpatch.pl - please put it in your ' + + '~/bin directory or use --no-check') + sys.exit(1) def CheckPatch(fname, verbose=False): """Run checkpatch.pl on a file. @@ -65,9 +70,6 @@ def CheckPatch(fname, verbose=False): error_count, warning_count, lines = 0, 0, 0 problems = [] chk = FindCheckPatch() - if not chk: - raise OSError, ('Cannot find checkpatch.pl - please put it in your ' + - '~/bin directory') item = {} stdout = command.Output(chk, '--no-tree', fname) #pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE) diff --git a/tools/patman/get_maintainer.py b/tools/patman/get_maintainer.py new file mode 100644 index 0000000..cb11373 --- /dev/null +++ b/tools/patman/get_maintainer.py @@ -0,0 +1,63 @@ +# Copyright (c) 2012 The Chromium OS Authors. +# +# See file CREDITS for list of people who contributed to this +# project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +import command +import gitutil +import os + +def FindGetMaintainer(): + """Look for the get_maintainer.pl script. + + Returns: + If the script is found we'll return a path to it; else None. + """ + try_list = [ + os.path.join(gitutil.GetTopLevel(), 'scripts'), + ] + # Look in the list + for path in try_list: + fname = os.path.join(path, 'get_maintainer.pl') + if os.path.isfile(fname): + return fname + + return None + +def GetMaintainer(fname, verbose=False): + """Run get_maintainer.pl on a file if we find it. + + We look for get_maintainer.pl in the 'scripts' directory at the top of + git. If we find it we'll run it. If we don't find get_maintainer.pl + then we fail silently. + + Args: + fname: Path to the patch file to run get_maintainer.pl on. + + Returns: + A list of email addresses to CC to. + """ + get_maintainer = FindGetMaintainer() + if not get_maintainer: + if verbose: + print "WARNING: Couldn't find get_maintainer.pl" + return [] + + stdout = command.Output(get_maintainer, '--norolestats', fname) + return stdout.splitlines() diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py index 72d37a0..ca3ba4a 100644 --- a/tools/patman/gitutil.py +++ b/tools/patman/gitutil.py @@ -217,6 +217,10 @@ def EmailPatches(series, cover_fname, args, dry_run, cc_fname, Returns: Git command that was/would be run + # For the duration of this doctest pretend that we ran patman with ./patman + >>> _old_argv0 = sys.argv[0] + >>> sys.argv[0] = './patman' + >>> alias = {} >>> alias['fred'] = ['f.bloggs@napier.co.nz'] >>> alias['john'] = ['j.bloggs@napier.co.nz'] @@ -244,6 +248,9 @@ def EmailPatches(series, cover_fname, args, dry_run, cc_fname, 'git send-email --annotate --to "f.bloggs@napier.co.nz" --cc \ "f.bloggs@napier.co.nz" --cc "j.bloggs@napier.co.nz" --cc \ "m.poppins@cloud.net" --cc-cmd "./patman --cc-cmd cc-fname" cover p1 p2' + + # Restore argv[0] since we clobbered it. + >>> sys.argv[0] = _old_argv0 """ to = BuildEmailList(series.get('to'), '--to', alias) if not to: @@ -340,8 +347,8 @@ def GetTopLevel(): This test makes sure that we are running tests in the right subdir - >>> os.path.realpath(os.getcwd()) == \ - os.path.join(GetTopLevel(), 'tools', 'scripts', 'patman') + >>> os.path.realpath(os.path.dirname(__file__)) == \ + os.path.join(GetTopLevel(), 'tools', 'patman') True """ return command.OutputOneLine('git', 'rev-parse', '--show-toplevel') @@ -377,8 +384,6 @@ def GetDefaultUserEmail(): def Setup(): """Set up git utils, by reading the alias files.""" - settings.Setup('') - # Check for a git alias file also alias_fname = GetAliasFile() if alias_fname: diff --git a/tools/patman/patman.py b/tools/patman/patman.py index cfe06d0..e049081 100755 --- a/tools/patman/patman.py +++ b/tools/patman/patman.py @@ -34,6 +34,8 @@ import checkpatch import command import gitutil import patchstream +import project +import settings import terminal import test @@ -48,6 +50,9 @@ parser.add_option('-i', '--ignore-errors', action='store_true', help='Send patches email even if patch errors are found') parser.add_option('-n', '--dry-run', action='store_true', dest='dry_run', default=False, help="Do a try run (create but don't email patches)") +parser.add_option('-p', '--project', default=project.DetectProject(), + help="Project name; affects default option values and " + "aliases [default: %default]") parser.add_option('-s', '--start', dest='start', type='int', default=0, help='Commit to start creating patches from (0 = HEAD)') parser.add_option('-t', '--test', action='store_true', dest='test', @@ -56,6 +61,9 @@ parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False, help='Verbose output of errors and warnings') parser.add_option('--cc-cmd', dest='cc_cmd', type='string', action='store', default=None, help='Output cc list for patch file (used by git)') +parser.add_option('--no-check', action='store_false', dest='check_patch', + default=True, + help="Don't check for patch compliance") parser.add_option('--no-tags', action='store_false', dest='process_tags', default=True, help="Don't process subject tags as aliaes") @@ -64,6 +72,11 @@ parser.usage = """patman [options] Create patches from commits in a branch, check them and email them as specified by tags you place in the commits. Use -n to """ + +# Parse options twice: first to get the project and second to handle +# defaults properly (which depends on project). +(options, args) = parser.parse_args() +settings.Setup(parser, options.project, '') (options, args) = parser.parse_args() # Run our meagre tests @@ -75,8 +88,9 @@ if options.test: result = unittest.TestResult() suite.run(result) - suite = doctest.DocTestSuite('gitutil') - suite.run(result) + for module in ['gitutil', 'settings']: + suite = doctest.DocTestSuite(module) + suite.run(result) # TODO: Surely we can just 'print' result? print result @@ -135,19 +149,24 @@ else: series.DoChecks() # Check the patches, and run them through 'git am' just to be sure - ok = checkpatch.CheckPatches(options.verbose, args) + if options.check_patch: + ok = checkpatch.CheckPatches(options.verbose, args) + else: + ok = True if not gitutil.ApplyPatches(options.verbose, args, options.count + options.start): ok = False + cc_file = series.MakeCcFile(options.process_tags, cover_fname) + # Email the patches out (giving the user time to check / cancel) cmd = '' if ok or options.ignore_errors: - cc_file = series.MakeCcFile(options.process_tags) cmd = gitutil.EmailPatches(series, cover_fname, args, options.dry_run, cc_file) - os.remove(cc_file) # For a dry run, just show our actions as a sanity check if options.dry_run: series.ShowActions(args, cmd, options.process_tags) + + os.remove(cc_file) diff --git a/tools/patman/project.py b/tools/patman/project.py new file mode 100644 index 0000000..4f7b2b3 --- /dev/null +++ b/tools/patman/project.py @@ -0,0 +1,43 @@ +# Copyright (c) 2012 The Chromium OS Authors. +# +# See file CREDITS for list of people who contributed to this +# project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +import os.path + +import gitutil + +def DetectProject(): + """Autodetect the name of the current project. + + This looks for signature files/directories that are unlikely to exist except + in the given project. + + Returns: + The name of the project, like "linux" or "u-boot". Returns "unknown" + if we can't detect the project. + """ + top_level = gitutil.GetTopLevel() + + if os.path.exists(os.path.join(top_level, "include", "u-boot")): + return "u-boot" + elif os.path.exists(os.path.join(top_level, "kernel")): + return "linux" + + return "unknown" diff --git a/tools/patman/series.py b/tools/patman/series.py index d2971f4..6c5c570 100644 --- a/tools/patman/series.py +++ b/tools/patman/series.py @@ -19,8 +19,10 @@ # MA 02111-1307 USA # +import itertools import os +import get_maintainer import gitutil import terminal @@ -46,6 +48,11 @@ class Series(dict): self.notes = [] self.changes = {} + # Written in MakeCcFile() + # key: name of patch file + # value: list of email addresses + self._generated_cc = {} + # These make us more like a dictionary def __setattr__(self, name, value): self[name] = value @@ -109,10 +116,7 @@ class Series(dict): for upto in range(len(args)): commit = self.commits[upto] print col.Color(col.GREEN, ' %s' % args[upto]) - cc_list = [] - if process_tags: - cc_list += gitutil.BuildEmailList(commit.tags) - cc_list += gitutil.BuildEmailList(commit.cc_list) + cc_list = list(self._generated_cc[commit.patch]) # Skip items in To list if 'to' in self: @@ -136,6 +140,9 @@ class Series(dict): print 'Prefix:\t ', self.get('prefix') if self.cover: print 'Cover: %d lines' % len(self.cover) + all_ccs = itertools.chain(*self._generated_cc.values()) + for email in set(all_ccs): + print ' Cc: ',email if cmd: print 'Git command: %s' % cmd @@ -199,23 +206,33 @@ class Series(dict): str = 'Change log exists, but no version is set' print col.Color(col.RED, str) - def MakeCcFile(self, process_tags): + def MakeCcFile(self, process_tags, cover_fname): """Make a cc file for us to use for per-commit Cc automation + Also stores in self._generated_cc to make ShowActions() faster. + Args: process_tags: Process tags as if they were aliases + cover_fname: If non-None the name of the cover letter. Return: Filename of temp file created """ # Look for commit tags (of the form 'xxx:' at the start of the subject) fname = '/tmp/patman.%d' % os.getpid() fd = open(fname, 'w') + all_ccs = [] for commit in self.commits: list = [] if process_tags: list += gitutil.BuildEmailList(commit.tags) list += gitutil.BuildEmailList(commit.cc_list) + list += get_maintainer.GetMaintainer(commit.patch) + all_ccs += list print >>fd, commit.patch, ', '.join(list) + self._generated_cc[commit.patch] = list + + if cover_fname: + print >>fd, cover_fname, ', '.join(set(all_ccs)) fd.close() return fname diff --git a/tools/patman/settings.py b/tools/patman/settings.py index 4dda17b..084d1b8 100644 --- a/tools/patman/settings.py +++ b/tools/patman/settings.py @@ -26,6 +26,140 @@ import re import command import gitutil +"""Default settings per-project. + +These are used by _ProjectConfigParser. Settings names should match +the "dest" of the option parser from patman.py. +""" +_default_settings = { + "u-boot": {}, + "linux": { + "process_tags": "False", + } +} + +class _ProjectConfigParser(ConfigParser.SafeConfigParser): + """ConfigParser that handles projects. + + There are two main goals of this class: + - Load project-specific default settings. + - Merge general default settings/aliases with project-specific ones. + + # Sample config used for tests below... + >>> import StringIO + >>> sample_config = ''' + ... [alias] + ... me: Peter P. <likesspiders@example.com> + ... enemies: Evil <evil@example.com> + ... + ... [sm_alias] + ... enemies: Green G. <ugly@example.com> + ... + ... [sm2_alias] + ... enemies: Doc O. <pus@example.com> + ... + ... [settings] + ... am_hero: True + ... ''' + + # Check to make sure that bogus project gets general alias. + >>> config = _ProjectConfigParser("zzz") + >>> config.readfp(StringIO.StringIO(sample_config)) + >>> config.get("alias", "enemies") + 'Evil <evil@example.com>' + + # Check to make sure that alias gets overridden by project. + >>> config = _ProjectConfigParser("sm") + >>> config.readfp(StringIO.StringIO(sample_config)) + >>> config.get("alias", "enemies") + 'Green G. <ugly@example.com>' + + # Check to make sure that settings get merged with project. + >>> config = _ProjectConfigParser("linux") + >>> config.readfp(StringIO.StringIO(sample_config)) + >>> sorted(config.items("settings")) + [('am_hero', 'True'), ('process_tags', 'False')] + + # Check to make sure that settings works with unknown project. + >>> config = _ProjectConfigParser("unknown") + >>> config.readfp(StringIO.StringIO(sample_config)) + >>> sorted(config.items("settings")) + [('am_hero', 'True')] + """ + def __init__(self, project_name): + """Construct _ProjectConfigParser. + + In addition to standard SafeConfigParser initialization, this also loads + project defaults. + + Args: + project_name: The name of the project. + """ + self._project_name = project_name + ConfigParser.SafeConfigParser.__init__(self) + + # Update the project settings in the config based on + # the _default_settings global. + project_settings = "%s_settings" % project_name + if not self.has_section(project_settings): + self.add_section(project_settings) + project_defaults = _default_settings.get(project_name, {}) + for setting_name, setting_value in project_defaults.iteritems(): + self.set(project_settings, setting_name, setting_value) + + def get(self, section, option, *args, **kwargs): + """Extend SafeConfigParser to try project_section before section. + + Args: + See SafeConfigParser. + Returns: + See SafeConfigParser. + """ + try: + return ConfigParser.SafeConfigParser.get( + self, "%s_%s" % (self._project_name, section), option, + *args, **kwargs + ) + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): + return ConfigParser.SafeConfigParser.get( + self, section, option, *args, **kwargs + ) + + def items(self, section, *args, **kwargs): + """Extend SafeConfigParser to add project_section to section. + + Args: + See SafeConfigParser. + Returns: + See SafeConfigParser. + """ + project_items = [] + has_project_section = False + top_items = [] + + # Get items from the project section + try: + project_items = ConfigParser.SafeConfigParser.items( + self, "%s_%s" % (self._project_name, section), *args, **kwargs + ) + has_project_section = True + except ConfigParser.NoSectionError: + pass + + # Get top-level items + try: + top_items = ConfigParser.SafeConfigParser.items( + self, section, *args, **kwargs + ) + except ConfigParser.NoSectionError: + # If neither section exists raise the error on... + if not has_project_section: + raise + + item_dict = dict(top_items) + item_dict.update(project_items) + return item_dict.items() + def ReadGitAliases(fname): """Read a git alias file. This is in the form used by git: @@ -88,13 +222,45 @@ def CreatePatmanConfigFile(config_fname): print >>f, "[alias]\nme: %s <%s>" % (name, email) f.close(); -def Setup(config_fname=''): +def _UpdateDefaults(parser, config): + """Update the given OptionParser defaults based on config. + + We'll walk through all of the settings from the parser + For each setting we'll look for a default in the option parser. + If it's found we'll update the option parser default. + + The idea here is that the .patman file should be able to update + defaults but that command line flags should still have the final + say. + + Args: + parser: An instance of an OptionParser whose defaults will be + updated. + config: An instance of _ProjectConfigParser that we will query + for settings. + """ + defaults = parser.get_default_values() + for name, val in config.items('settings'): + if hasattr(defaults, name): + default_val = getattr(defaults, name) + if isinstance(default_val, bool): + val = config.getboolean('settings', name) + elif isinstance(default_val, int): + val = config.getint('settings', name) + parser.set_default(name, val) + else: + print "WARNING: Unknown setting %s" % name + +def Setup(parser, project_name, config_fname=''): """Set up the settings module by reading config files. Args: + parser: The parser to update + project_name: Name of project that we're working on; we'll look + for sections named "project_section" as well. config_fname: Config filename to read ('' for default) """ - settings = ConfigParser.SafeConfigParser() + config = _ProjectConfigParser(project_name) if config_fname == '': config_fname = '%s/.patman' % os.getenv('HOME') @@ -102,11 +268,17 @@ def Setup(config_fname=''): print "No config file found ~/.patman\nCreating one...\n" CreatePatmanConfigFile(config_fname) - settings.read(config_fname) + config.read(config_fname) - for name, value in settings.items('alias'): + for name, value in config.items('alias'): alias[name] = value.split(',') + _UpdateDefaults(parser, config) # These are the aliases we understand, indexed by alias. Each member is a list. alias = {} + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/tools/patman/test.py b/tools/patman/test.py index cf42480..f801ced 100644 --- a/tools/patman/test.py +++ b/tools/patman/test.py @@ -119,8 +119,8 @@ index 6f3748d..f9e4e65 100644 --- a/README +++ b/README @@ -2026,6 +2026,17 @@ The following options need to be configured: - example, some LED's) on your board. At the moment, - the following checkpoints are implemented: + example, some LED's) on your board. At the moment, + the following checkpoints are implemented: +- Time boot progress + CONFIG_BOOTSTAGE @@ -134,7 +134,7 @@ index 6f3748d..f9e4e65 100644 + You can add calls to bootstage_mark() to set time markers. + - Standalone program support: - CONFIG_STANDALONE_LOAD_ADDR + CONFIG_STANDALONE_LOAD_ADDR diff --git a/common/bootstage.c b/common/bootstage.c new file mode 100644 |