Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Rolls DEPS controlled dependency. | 6 """Rolls DEPS controlled dependency. |
| 7 | 7 |
| 8 Works only with git checkout and git dependencies. | 8 Works only with git checkout and git dependencies. Currently this |
| 9 script will always roll to the tip of to origin/master. | |
| 9 """ | 10 """ |
| 10 | 11 |
| 11 import optparse | 12 import argparse |
| 12 import os | 13 import os |
| 13 import re | 14 import re |
| 14 import subprocess | 15 import subprocess |
| 15 import sys | 16 import sys |
| 16 | 17 |
| 17 NEED_SHELL = sys.platform.startswith('win') | 18 NEED_SHELL = sys.platform.startswith('win') |
| 18 | 19 |
| 19 | 20 |
| 20 class Error(Exception): | 21 class Error(Exception): |
| 21 pass | 22 pass |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 46 with open(deps, 'rb') as f: | 47 with open(deps, 'rb') as f: |
| 47 deps_content = f.read() | 48 deps_content = f.read() |
| 48 except (IOError, OSError): | 49 except (IOError, OSError): |
| 49 raise Error('Ensure the script is run in the directory ' | 50 raise Error('Ensure the script is run in the directory ' |
| 50 'containing DEPS file.') | 51 'containing DEPS file.') |
| 51 | 52 |
| 52 if not is_pristine(root): | 53 if not is_pristine(root): |
| 53 raise Error('Ensure %s is clean first.' % root) | 54 raise Error('Ensure %s is clean first.' % root) |
| 54 | 55 |
| 55 full_dir = os.path.normpath(os.path.join(os.path.dirname(root), deps_dir)) | 56 full_dir = os.path.normpath(os.path.join(os.path.dirname(root), deps_dir)) |
| 57 if not os.path.isdir(full_dir): | |
| 58 raise Error('Directory not found: %s' % deps_dir) | |
| 56 head = check_output(['git', 'rev-parse', 'HEAD'], cwd=full_dir).strip() | 59 head = check_output(['git', 'rev-parse', 'HEAD'], cwd=full_dir).strip() |
| 57 | 60 |
| 58 if not head in deps_content: | 61 if not head in deps_content: |
| 59 print('Warning: %s is not checked out at the expected revision in DEPS' % | 62 print('Warning: %s is not checked out at the expected revision in DEPS' % |
| 60 deps_dir) | 63 deps_dir) |
| 61 if key is None: | 64 if key is None: |
| 62 print("Warning: no key specified. Using '%s'." % deps_dir) | 65 print("Warning: no key specified. Using '%s'." % deps_dir) |
| 63 key = deps_dir | 66 key = deps_dir |
| 64 | 67 |
| 65 # It happens if the user checked out a branch in the dependency by himself. | 68 # It happens if the user checked out a branch in the dependency by himself. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 print('') | 118 print('') |
| 116 if not reviewers: | 119 if not reviewers: |
| 117 print('You forgot to pass -r, make sure to insert a R=foo@example.com line') | 120 print('You forgot to pass -r, make sure to insert a R=foo@example.com line') |
| 118 print('to the commit description before emailing.') | 121 print('to the commit description before emailing.') |
| 119 print('') | 122 print('') |
| 120 print('Run:') | 123 print('Run:') |
| 121 print(' git cl upload --send-mail') | 124 print(' git cl upload --send-mail') |
| 122 | 125 |
| 123 | 126 |
| 124 def main(): | 127 def main(): |
| 125 parser = optparse.OptionParser( | 128 parser = argparse.ArgumentParser(description=__doc__) |
| 126 description=sys.modules[__name__].__doc__, | 129 parser.add_argument( |
| 127 usage='roll-dep [flags] <dependency path> <variable>') | |
| 128 parser.add_option( | |
| 129 '-r', '--reviewer', default='', | 130 '-r', '--reviewer', default='', |
| 130 help='To specify multiple reviewers, use comma separated list, e.g. ' | 131 help='To specify multiple reviewers, use comma separated list, e.g. ' |
| 131 '-r joe,jane,john. Defaults to @chromium.org') | 132 '-r joe,jane,john. Defaults to @chromium.org') |
| 132 parser.add_option('-b', '--bug', default='') | 133 parser.add_argument('-b', '--bug', default='') |
| 133 options, args = parser.parse_args() | 134 parser.add_argument('dep_path', help='path to dependency') |
| 134 if not len(args) or len(args) > 2: | 135 parser.add_argument('key', nargs='?', |
| 135 parser.error('Expect one or two arguments' % args) | 136 help='regexp for dependency in DEPS file') |
| 137 args = parser.parse_args() | |
| 136 | 138 |
| 137 reviewers = None | 139 reviewers = None |
| 138 if options.reviewer: | 140 if args.reviewer is not None: |
|
M-A Ruel
2015/05/29 22:57:37
Actually default is ''.
I'd actually prefer to re
| |
| 139 reviewers = options.reviewer.split(',') | 141 reviewers = args.reviewer.split(',') |
| 140 for i, r in enumerate(reviewers): | 142 for i, r in enumerate(reviewers): |
| 141 if not '@' in r: | 143 if not '@' in r: |
| 142 reviewers[i] = r + '@chromium.org' | 144 reviewers[i] = r + '@chromium.org' |
| 143 | 145 |
| 144 try: | 146 try: |
| 145 roll( | 147 roll( |
| 146 os.getcwd(), | 148 os.getcwd(), |
| 147 deps_dir=args[0], | 149 args.dep_path, |
| 148 key=args[1] if len(args) > 1 else None, | 150 args.key, |
| 149 reviewers=reviewers, | 151 reviewers=reviewers, |
| 150 bug=options.bug) | 152 bug=args.bug) |
| 151 | 153 |
| 152 except Error as e: | 154 except Error as e: |
| 153 sys.stderr.write('error: %s\n' % e) | 155 sys.stderr.write('error: %s\n' % e) |
| 154 return 1 | 156 return 1 |
| 155 | 157 |
| 156 return 0 | 158 return 0 |
| 157 | 159 |
| 158 | 160 |
| 159 if __name__ == '__main__': | 161 if __name__ == '__main__': |
| 160 sys.exit(main()) | 162 sys.exit(main()) |
| OLD | NEW |