[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 1 | #!/usr/bin/env python |
[email protected] | 34f6855 | 2012-05-09 19:18:36 | [diff] [blame] | 2 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Applies an issue from Rietveld. |
| 7 | """ |
[email protected] | a3d7c4b | 2013-11-20 02:14:08 | [diff] [blame] | 8 | import json |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 9 | import logging |
| 10 | import optparse |
[email protected] | 3cdb7f3 | 2011-05-05 16:37:24 | [diff] [blame] | 11 | import os |
[email protected] | 1833e57 | 2012-09-17 13:21:13 | [diff] [blame] | 12 | import subprocess |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 13 | import sys |
[email protected] | 9dbbe54 | 2012-08-31 15:33:23 | [diff] [blame] | 14 | import urllib2 |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 15 | |
[email protected] | 3cdb7f3 | 2011-05-05 16:37:24 | [diff] [blame] | 16 | |
[email protected] | a3d7c4b | 2013-11-20 02:14:08 | [diff] [blame] | 17 | import annotated_gclient |
[email protected] | cf6a5d2 | 2015-04-09 22:02:00 | [diff] [blame] | 18 | import auth |
[email protected] | 3cdb7f3 | 2011-05-05 16:37:24 | [diff] [blame] | 19 | import checkout |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 20 | import fix_encoding |
[email protected] | 1833e57 | 2012-09-17 13:21:13 | [diff] [blame] | 21 | import gclient_utils |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 22 | import rietveld |
[email protected] | 3cdb7f3 | 2011-05-05 16:37:24 | [diff] [blame] | 23 | import scm |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 24 | |
[email protected] | 6afd0c3 | 2012-09-18 10:34:25 | [diff] [blame] | 25 | BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 26 | |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 27 | |
[email protected] | 69c68c3 | 2015-10-05 21:54:29 | [diff] [blame] | 28 | RETURN_CODE_OK = 0 |
[email protected] | cd95805 | 2015-10-05 19:17:37 | [diff] [blame] | 29 | RETURN_CODE_OTHER_FAILURE = 1 # any other failure, likely patch apply one. |
| 30 | RETURN_CODE_ARGPARSE_FAILURE = 2 # default in python. |
| 31 | RETURN_CODE_INFRA_FAILURE = 3 # considered as infra failure. |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 32 | |
| 33 | |
[email protected] | fc490ff | 2012-11-07 20:02:01 | [diff] [blame] | 34 | class Unbuffered(object): |
| 35 | """Disable buffering on a file object.""" |
| 36 | def __init__(self, stream): |
| 37 | self.stream = stream |
| 38 | |
| 39 | def write(self, data): |
| 40 | self.stream.write(data) |
| 41 | self.stream.flush() |
| 42 | |
| 43 | def __getattr__(self, attr): |
| 44 | return getattr(self.stream, attr) |
| 45 | |
| 46 | |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 47 | def _get_arg_parser(): |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 48 | parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) |
| 49 | parser.add_option( |
[email protected] | 58fe662 | 2011-06-03 20:59:27 | [diff] [blame] | 50 | '-v', '--verbose', action='count', default=0, |
| 51 | help='Prints debugging infos') |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 52 | parser.add_option( |
[email protected] | 9d5f4ad | 2012-10-01 15:03:27 | [diff] [blame] | 53 | '-e', '--email', |
[email protected] | 33578fe | 2012-09-18 14:49:43 | [diff] [blame] | 54 | help='Email address to access rietveld. If not specified, anonymous ' |
| 55 | 'access will be used.') |
| 56 | parser.add_option( |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 57 | '-E', '--email-file', |
| 58 | help='File containing the email address to access rietveld. ' |
| 59 | 'If not specified, anonymous access will be used.') |
| 60 | parser.add_option( |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 61 | '-k', '--private-key-file', |
| 62 | help='Path to file containing a private key in p12 format for OAuth2 ' |
[email protected] | cf6a5d2 | 2015-04-09 22:02:00 | [diff] [blame] | 63 | 'authentication with "notasecret" password (as generated by Google ' |
| 64 | 'Cloud Console).') |
[email protected] | ed23325 | 2012-07-06 17:25:11 | [diff] [blame] | 65 | parser.add_option( |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 66 | '-i', '--issue', type='int', help='Rietveld issue number') |
| 67 | parser.add_option( |
| 68 | '-p', '--patchset', type='int', help='Rietveld issue\'s patchset number') |
| 69 | parser.add_option( |
| 70 | '-r', |
| 71 | '--root_dir', |
[email protected] | 3cdb7f3 | 2011-05-05 16:37:24 | [diff] [blame] | 72 | default=os.getcwd(), |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 73 | help='Root directory to apply the patch') |
| 74 | parser.add_option( |
| 75 | '-s', |
| 76 | '--server', |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 77 | default='http://codereview.chromium.org', |
| 78 | help='Rietveld server') |
[email protected] | 9414599 | 2013-07-27 02:32:11 | [diff] [blame] | 79 | parser.add_option('--no-auth', action='store_true', |
| 80 | help='Do not attempt authenticated requests.') |
[email protected] | a3d7c4b | 2013-11-20 02:14:08 | [diff] [blame] | 81 | parser.add_option('--revision-mapping', default='{}', |
| 82 | help='When running gclient, annotate the got_revisions ' |
| 83 | 'using the revision-mapping.') |
[email protected] | d067d81 | 2014-02-21 02:23:14 | [diff] [blame] | 84 | parser.add_option('-f', '--force', action='store_true', |
| 85 | help='Really run apply_issue, even if .update.flag ' |
| 86 | 'is detected.') |
[email protected] | c4396a1 | 2014-05-10 02:19:27 | [diff] [blame] | 87 | parser.add_option('-b', '--base_ref', help='DEPRECATED do not use.') |
[email protected] | b1d0cc1 | 2014-05-06 19:46:14 | [diff] [blame] | 88 | parser.add_option('--whitelist', action='append', default=[], |
| 89 | help='Patch only specified file(s).') |
| 90 | parser.add_option('--blacklist', action='append', default=[], |
| 91 | help='Don\'t patch specified file(s).') |
[email protected] | 98e82e1 | 2014-04-21 18:47:32 | [diff] [blame] | 92 | parser.add_option('-d', '--ignore_deps', action='store_true', |
| 93 | help='Don\'t run gclient sync on DEPS changes.') |
[email protected] | d461faa | 2016-05-17 07:15:41 | [diff] [blame] | 94 | parser.add_option('--extra_patchlevel', type='int', |
| 95 | help='Number of directories the patch level number should ' |
| 96 | 'be incremented (useful for patches from repos with ' |
| 97 | 'different directory hierarchies).') |
[email protected] | cf6a5d2 | 2015-04-09 22:02:00 | [diff] [blame] | 98 | |
| 99 | auth.add_auth_options(parser) |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 100 | return parser |
| 101 | |
| 102 | |
| 103 | def main(): |
| 104 | # TODO(pgervais,tandrii): split this func, it's still too long. |
| 105 | sys.stdout = Unbuffered(sys.stdout) |
| 106 | parser = _get_arg_parser() |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 107 | options, args = parser.parse_args() |
[email protected] | cf6a5d2 | 2015-04-09 22:02:00 | [diff] [blame] | 108 | auth_config = auth.extract_auth_config_from_options(options) |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 109 | |
[email protected] | b1d0cc1 | 2014-05-06 19:46:14 | [diff] [blame] | 110 | if options.whitelist and options.blacklist: |
| 111 | parser.error('Cannot specify both --whitelist and --blacklist') |
| 112 | |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 113 | if options.email and options.email_file: |
| 114 | parser.error('-e and -E options are incompatible') |
| 115 | |
[email protected] | d067d81 | 2014-02-21 02:23:14 | [diff] [blame] | 116 | if (os.path.isfile(os.path.join(os.getcwd(), 'update.flag')) |
| 117 | and not options.force): |
| 118 | print 'update.flag file found: bot_update has run and checkout is already ' |
| 119 | print 'in a consistent state. No actions will be performed in this step.' |
| 120 | return 0 |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 121 | |
[email protected] | 58fe662 | 2011-06-03 20:59:27 | [diff] [blame] | 122 | logging.basicConfig( |
[email protected] | 5e97563 | 2011-09-29 18:07:06 | [diff] [blame] | 123 | format='%(levelname)5s %(module)11s(%(lineno)4d): %(message)s', |
[email protected] | 58fe662 | 2011-06-03 20:59:27 | [diff] [blame] | 124 | level=[logging.WARNING, logging.INFO, logging.DEBUG][ |
| 125 | min(2, options.verbose)]) |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 126 | if args: |
| 127 | parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) |
| 128 | if not options.issue: |
| 129 | parser.error('Require --issue') |
[email protected] | 9dbbe54 | 2012-08-31 15:33:23 | [diff] [blame] | 130 | options.server = options.server.rstrip('/') |
| 131 | if not options.server: |
| 132 | parser.error('Require a valid server') |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 133 | |
[email protected] | a3d7c4b | 2013-11-20 02:14:08 | [diff] [blame] | 134 | options.revision_mapping = json.loads(options.revision_mapping) |
| 135 | |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 136 | # read email if needed |
| 137 | if options.email_file: |
| 138 | if not os.path.exists(options.email_file): |
| 139 | parser.error('file does not exist: %s' % options.email_file) |
| 140 | with open(options.email_file, 'rb') as f: |
| 141 | options.email = f.read().strip() |
| 142 | |
[email protected] | 370a623 | 2012-10-22 19:41:31 | [diff] [blame] | 143 | print('Connecting to %s' % options.server) |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 144 | # Always try un-authenticated first, except for OAuth2 |
| 145 | if options.private_key_file: |
| 146 | # OAuth2 authentication |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 147 | rietveld_obj = rietveld.JwtOAuth2Rietveld(options.server, |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 148 | options.email, |
[email protected] | cf6a5d2 | 2015-04-09 22:02:00 | [diff] [blame] | 149 | options.private_key_file) |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 150 | try: |
| 151 | properties = rietveld_obj.get_issue_properties(options.issue, False) |
| 152 | except urllib2.URLError: |
| 153 | logging.exception('failed to fetch issue properties') |
| 154 | sys.exit(RETURN_CODE_INFRA_FAILURE) |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 155 | else: |
[email protected] | cf6a5d2 | 2015-04-09 22:02:00 | [diff] [blame] | 156 | # Passing None as auth_config disables authentication. |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 157 | rietveld_obj = rietveld.Rietveld(options.server, None) |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 158 | properties = None |
| 159 | # Bad except clauses order (HTTPError is an ancestor class of |
| 160 | # ClientLoginError) |
Quinten Yearsley | b2cc4a9 | 2016-12-15 21:53:26 | [diff] [blame] | 161 | # pylint: disable=bad-except-order |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 162 | try: |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 163 | properties = rietveld_obj.get_issue_properties(options.issue, False) |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 164 | except urllib2.HTTPError as e: |
| 165 | if e.getcode() != 302: |
| 166 | raise |
| 167 | if options.no_auth: |
| 168 | exit('FAIL: Login detected -- is issue private?') |
| 169 | # TODO(maruel): A few 'Invalid username or password.' are printed first, |
| 170 | # we should get rid of those. |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 171 | except urllib2.URLError: |
| 172 | logging.exception('failed to fetch issue properties') |
| 173 | return RETURN_CODE_INFRA_FAILURE |
[email protected] | cf6a5d2 | 2015-04-09 22:02:00 | [diff] [blame] | 174 | except rietveld.upload.ClientLoginError as e: |
[email protected] | 9979824 | 2014-03-26 18:44:43 | [diff] [blame] | 175 | # Fine, we'll do proper authentication. |
| 176 | pass |
| 177 | if properties is None: |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 178 | rietveld_obj = rietveld.Rietveld(options.server, auth_config, |
| 179 | options.email) |
[email protected] | cf6a5d2 | 2015-04-09 22:02:00 | [diff] [blame] | 180 | try: |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 181 | properties = rietveld_obj.get_issue_properties(options.issue, False) |
[email protected] | cf6a5d2 | 2015-04-09 22:02:00 | [diff] [blame] | 182 | except rietveld.upload.ClientLoginError as e: |
| 183 | print('Accessing the issue requires proper credentials.') |
[email protected] | cd95805 | 2015-10-05 19:17:37 | [diff] [blame] | 184 | return RETURN_CODE_OTHER_FAILURE |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 185 | except urllib2.URLError: |
| 186 | logging.exception('failed to fetch issue properties') |
| 187 | return RETURN_CODE_INFRA_FAILURE |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 188 | |
| 189 | if not options.patchset: |
[email protected] | 3bf4b3c | 2012-09-03 15:53:02 | [diff] [blame] | 190 | options.patchset = properties['patchsets'][-1] |
[email protected] | 38ab82d | 2012-08-29 19:34:45 | [diff] [blame] | 191 | print('No patchset specified. Using patchset %d' % options.patchset) |
| 192 | |
[email protected] | d91b7e3 | 2015-06-23 11:24:07 | [diff] [blame] | 193 | issues_patchsets_to_apply = [(options.issue, options.patchset)] |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 194 | try: |
| 195 | depends_on_info = rietveld_obj.get_depends_on_patchset( |
| 196 | options.issue, options.patchset) |
| 197 | except urllib2.URLError: |
| 198 | logging.exception('failed to fetch depends_on_patchset') |
| 199 | return RETURN_CODE_INFRA_FAILURE |
| 200 | |
[email protected] | 56445e8 | 2015-07-15 12:04:42 | [diff] [blame] | 201 | while depends_on_info: |
| 202 | depends_on_issue = int(depends_on_info['issue']) |
| 203 | depends_on_patchset = int(depends_on_info['patchset']) |
| 204 | try: |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 205 | depends_on_info = rietveld_obj.get_depends_on_patchset(depends_on_issue, |
[email protected] | 56445e8 | 2015-07-15 12:04:42 | [diff] [blame] | 206 | depends_on_patchset) |
| 207 | issues_patchsets_to_apply.insert(0, (depends_on_issue, |
| 208 | depends_on_patchset)) |
| 209 | except urllib2.HTTPError: |
| 210 | print ('The patchset that was marked as a dependency no longer ' |
| 211 | 'exists: %s/%d/#ps%d' % ( |
| 212 | options.server, depends_on_issue, depends_on_patchset)) |
| 213 | print 'Therefore it is likely that this patch will not apply cleanly.' |
| 214 | print |
| 215 | depends_on_info = None |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 216 | except urllib2.URLError: |
| 217 | logging.exception('failed to fetch dependency issue') |
| 218 | return RETURN_CODE_INFRA_FAILURE |
[email protected] | 3cdb7f3 | 2011-05-05 16:37:24 | [diff] [blame] | 219 | |
[email protected] | d91b7e3 | 2015-06-23 11:24:07 | [diff] [blame] | 220 | num_issues_patchsets_to_apply = len(issues_patchsets_to_apply) |
| 221 | if num_issues_patchsets_to_apply > 1: |
| 222 | print |
| 223 | print 'apply_issue.py found %d dependent CLs.' % ( |
| 224 | num_issues_patchsets_to_apply - 1) |
| 225 | print 'They will be applied in the following order:' |
| 226 | num = 1 |
| 227 | for issue_to_apply, patchset_to_apply in issues_patchsets_to_apply: |
| 228 | print ' #%d %s/%d/#ps%d' % ( |
| 229 | num, options.server, issue_to_apply, patchset_to_apply) |
| 230 | num += 1 |
| 231 | print |
[email protected] | 9d72d2b | 2012-09-07 22:23:21 | [diff] [blame] | 232 | |
[email protected] | d91b7e3 | 2015-06-23 11:24:07 | [diff] [blame] | 233 | for issue_to_apply, patchset_to_apply in issues_patchsets_to_apply: |
| 234 | issue_url = '%s/%d/#ps%d' % (options.server, issue_to_apply, |
| 235 | patchset_to_apply) |
| 236 | print('Downloading patch from %s' % issue_url) |
| 237 | try: |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 238 | patchset = rietveld_obj.get_patch(issue_to_apply, patchset_to_apply) |
[email protected] | 95a3849 | 2015-10-02 17:21:52 | [diff] [blame] | 239 | except urllib2.HTTPError: |
[email protected] | d91b7e3 | 2015-06-23 11:24:07 | [diff] [blame] | 240 | print( |
| 241 | 'Failed to fetch the patch for issue %d, patchset %d.\n' |
| 242 | 'Try visiting %s/%d') % ( |
| 243 | issue_to_apply, patchset_to_apply, |
| 244 | options.server, issue_to_apply) |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 245 | # If we got this far, then this is likely missing patchset. |
| 246 | # Thus, it's not infra failure. |
[email protected] | cd95805 | 2015-10-05 19:17:37 | [diff] [blame] | 247 | return RETURN_CODE_OTHER_FAILURE |
[email protected] | 15af77d | 2015-10-05 15:59:32 | [diff] [blame] | 248 | except urllib2.URLError: |
| 249 | logging.exception( |
| 250 | 'Failed to fetch the patch for issue %d, patchset %d', |
| 251 | issue_to_apply, patchset_to_apply) |
| 252 | return RETURN_CODE_INFRA_FAILURE |
[email protected] | d91b7e3 | 2015-06-23 11:24:07 | [diff] [blame] | 253 | if options.whitelist: |
| 254 | patchset.patches = [patch for patch in patchset.patches |
| 255 | if patch.filename in options.whitelist] |
| 256 | if options.blacklist: |
| 257 | patchset.patches = [patch for patch in patchset.patches |
| 258 | if patch.filename not in options.blacklist] |
| 259 | for patch in patchset.patches: |
| 260 | print(patch) |
[email protected] | d461faa | 2016-05-17 07:15:41 | [diff] [blame] | 261 | if options.extra_patchlevel: |
| 262 | patch.patchlevel += options.extra_patchlevel |
[email protected] | d91b7e3 | 2015-06-23 11:24:07 | [diff] [blame] | 263 | full_dir = os.path.abspath(options.root_dir) |
| 264 | scm_type = scm.determine_scm(full_dir) |
agable | 037edb8 | 2016-10-24 21:35:12 | [diff] [blame] | 265 | if scm_type == 'git': |
[email protected] | d91b7e3 | 2015-06-23 11:24:07 | [diff] [blame] | 266 | scm_obj = checkout.GitCheckout(full_dir, None, None, None, None) |
[email protected] | d91b7e3 | 2015-06-23 11:24:07 | [diff] [blame] | 267 | else: |
| 268 | parser.error('Couldn\'t determine the scm') |
| 269 | |
[email protected] | d91b7e3 | 2015-06-23 11:24:07 | [diff] [blame] | 270 | print('\nApplying the patch from %s' % issue_url) |
| 271 | try: |
| 272 | scm_obj.apply_patch(patchset, verbose=True) |
| 273 | except checkout.PatchApplicationFailed as e: |
| 274 | print(str(e)) |
| 275 | print('CWD=%s' % os.getcwd()) |
| 276 | print('Checkout path=%s' % scm_obj.project_path) |
[email protected] | cd95805 | 2015-10-05 19:17:37 | [diff] [blame] | 277 | return RETURN_CODE_OTHER_FAILURE |
[email protected] | 1833e57 | 2012-09-17 13:21:13 | [diff] [blame] | 278 | |
[email protected] | 98e82e1 | 2014-04-21 18:47:32 | [diff] [blame] | 279 | if ('DEPS' in map(os.path.basename, patchset.filenames) |
| 280 | and not options.ignore_deps): |
[email protected] | 0aca0f9 | 2012-10-01 16:39:45 | [diff] [blame] | 281 | gclient_root = gclient_utils.FindGclientRoot(full_dir) |
[email protected] | 1833e57 | 2012-09-17 13:21:13 | [diff] [blame] | 282 | if gclient_root and scm_type: |
| 283 | print( |
| 284 | 'A DEPS file was updated inside a gclient checkout, running gclient ' |
| 285 | 'sync.') |
[email protected] | 6afd0c3 | 2012-09-18 10:34:25 | [diff] [blame] | 286 | gclient_path = os.path.join(BASE_DIR, 'gclient') |
| 287 | if sys.platform == 'win32': |
| 288 | gclient_path += '.bat' |
[email protected] | a3d7c4b | 2013-11-20 02:14:08 | [diff] [blame] | 289 | with annotated_gclient.temp_filename(suffix='gclient') as f: |
| 290 | cmd = [ |
[email protected] | 7e79d37 | 2013-04-29 18:01:49 | [diff] [blame] | 291 | gclient_path, 'sync', |
[email protected] | 7e79d37 | 2013-04-29 18:01:49 | [diff] [blame] | 292 | '--nohooks', |
| 293 | '--delete_unversioned_trees', |
[email protected] | a3d7c4b | 2013-11-20 02:14:08 | [diff] [blame] | 294 | ] |
| 295 | if options.revision_mapping: |
| 296 | cmd.extend(['--output-json', f]) |
| 297 | |
| 298 | retcode = subprocess.call(cmd, cwd=gclient_root) |
| 299 | |
| 300 | if retcode == 0 and options.revision_mapping: |
| 301 | revisions = annotated_gclient.parse_got_revision( |
| 302 | f, options.revision_mapping) |
| 303 | annotated_gclient.emit_buildprops(revisions) |
| 304 | |
| 305 | return retcode |
[email protected] | cd95805 | 2015-10-05 19:17:37 | [diff] [blame] | 306 | return RETURN_CODE_OK |
[email protected] | 61e0b69 | 2011-04-12 21:01:01 | [diff] [blame] | 307 | |
| 308 | |
| 309 | if __name__ == "__main__": |
| 310 | fix_encoding.fix_encoding() |
[email protected] | 013731e | 2015-02-26 18:28:43 | [diff] [blame] | 311 | try: |
| 312 | sys.exit(main()) |
| 313 | except KeyboardInterrupt: |
| 314 | sys.stderr.write('interrupted\n') |
[email protected] | cd95805 | 2015-10-05 19:17:37 | [diff] [blame] | 315 | sys.exit(RETURN_CODE_OTHER_FAILURE) |