OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Client-side script to send a try job to the try server. It communicates to | 6 """Client-side script to send a try job to the try server. It communicates to |
7 the try server by either writting to a svn/git repository or by directly | 7 the try server by either writting to a svn/git repository or by directly |
8 connecting to the server by HTTP. | 8 connecting to the server by HTTP. |
9 """ | 9 """ |
10 | 10 |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 masters = presubmit_support.DoGetTryMasters( | 391 masters = presubmit_support.DoGetTryMasters( |
392 change, | 392 change, |
393 checkouts[0].GetFileNames(), | 393 checkouts[0].GetFileNames(), |
394 checkouts[0].checkout_root, | 394 checkouts[0].checkout_root, |
395 root_presubmit, | 395 root_presubmit, |
396 options.project, | 396 options.project, |
397 options.verbose, | 397 options.verbose, |
398 sys.stdout) | 398 sys.stdout) |
399 | 399 |
400 # Compatibility for old checkouts and bots that were on tryserver.chromium. | 400 # Compatibility for old checkouts and bots that were on tryserver.chromium. |
401 trybots = masters.get('tryserver.chromium', []) | 401 try_bots = masters.get('tryserver.chromium', []) |
402 | 402 |
403 # Compatibility for checkouts that are not using tryserver.chromium | 403 # Compatibility for checkouts that are not using tryserver.chromium |
404 # but are stuck with git-try or gcl-try. | 404 # but are stuck with git-try or gcl-try. |
405 if not trybots and len(masters) == 1: | 405 if not try_bots and len(masters) == 1: |
406 trybots = masters.values()[0] | 406 try_bots = masters.values()[0] |
407 | 407 |
408 if trybots: | 408 if try_bots: |
409 old_style = filter(lambda x: isinstance(x, basestring), trybots) | 409 old_style = filter(lambda x: isinstance(x, basestring), try_bots) |
410 new_style = filter(lambda x: isinstance(x, tuple), trybots) | 410 new_style = filter(lambda x: isinstance(x, tuple), try_bots) |
411 | 411 |
412 # _ParseBotList's testfilter is set to None otherwise it will complain. | 412 # _ParseBotList's testfilter is set to None otherwise it will complain. |
413 bot_spec = _ApplyTestFilter(options.testfilter, | 413 bot_spec = _ApplyTestFilter(options.testfilter, |
414 _ParseBotList(old_style, None)) | 414 _ParseBotList(old_style, None)) |
415 | 415 |
416 bot_spec.extend(_ApplyTestFilter(options.testfilter, new_style)) | 416 bot_spec.extend(_ApplyTestFilter(options.testfilter, new_style)) |
417 | 417 |
418 except ImportError: | 418 except ImportError: |
419 pass | 419 pass |
420 | 420 |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 | 715 |
716 PrintSuccess(bot_spec, options) | 716 PrintSuccess(bot_spec, options) |
717 | 717 |
718 def _SendChangeGerrit(bot_spec, options): | 718 def _SendChangeGerrit(bot_spec, options): |
719 """Posts a try job to a Gerrit change. | 719 """Posts a try job to a Gerrit change. |
720 | 720 |
721 Reads Change-Id from the HEAD commit, resolves the current revision, checks | 721 Reads Change-Id from the HEAD commit, resolves the current revision, checks |
722 that local revision matches the uploaded one, posts a try job in form of a | 722 that local revision matches the uploaded one, posts a try job in form of a |
723 message, sets Tryjob-Request label to 1. | 723 message, sets Tryjob-Request label to 1. |
724 | 724 |
725 Gerrit message format: starts with !tryjob, optionally followed by a tryjob | 725 Gerrit message format: starts with !tryjob, optionally followed by a try job |
726 definition in JSON format: | 726 definition in JSON format: |
727 buildNames: list of strings specifying build names. | 727 buildNames: list of strings specifying build names. |
728 build_properties: a dict of build properties. | 728 build_properties: a dict of build properties. |
729 """ | 729 """ |
730 | 730 |
731 logging.info('Sending by Gerrit') | 731 logging.info('Sending by Gerrit') |
732 if not options.gerrit_url: | 732 if not options.gerrit_url: |
733 raise NoTryServerAccess('Please use --gerrit_url option to specify the ' | 733 raise NoTryServerAccess('Please use --gerrit_url option to specify the ' |
734 'Gerrit instance url to connect to') | 734 'Gerrit instance url to connect to') |
735 gerrit_host = urlparse.urlparse(options.gerrit_url).hostname | 735 gerrit_host = urlparse.urlparse(options.gerrit_url).hostname |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 change_id) | 795 change_id) |
796 logging.debug('Found Gerrit change: %s' % changes[0]) | 796 logging.debug('Found Gerrit change: %s' % changes[0]) |
797 if changes[0]['current_revision'] != head_sha: | 797 if changes[0]['current_revision'] != head_sha: |
798 raise Error('Please upload your latest local changes to Gerrit.') | 798 raise Error('Please upload your latest local changes to Gerrit.') |
799 | 799 |
800 # Post a try job. | 800 # Post a try job. |
801 message = FormatMessage() | 801 message = FormatMessage() |
802 PostTryjob(message) | 802 PostTryjob(message) |
803 change_url = urlparse.urljoin(options.gerrit_url, | 803 change_url = urlparse.urljoin(options.gerrit_url, |
804 '/#/c/%s' % changes[0]['_number']) | 804 '/#/c/%s' % changes[0]['_number']) |
805 print('A tryjob was posted on change %s' % change_url) | 805 print('A try job was posted on change %s' % change_url) |
806 | 806 |
807 def PrintSuccess(bot_spec, options): | 807 def PrintSuccess(bot_spec, options): |
808 if not options.dry_run: | 808 if not options.dry_run: |
809 text = 'Patch \'%s\' sent to try server' % options.name | 809 text = 'Patch \'%s\' sent to try server' % options.name |
810 if bot_spec: | 810 if bot_spec: |
811 text += ': %s' % ', '.join( | 811 text += ': %s' % ', '.join( |
812 '%s:%s' % (b[0], ','.join(b[1])) for b in bot_spec) | 812 '%s:%s' % (b[0], ','.join(b[1])) for b in bot_spec) |
813 print(text) | 813 print(text) |
814 | 814 |
815 | 815 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 parser.add_option_group(group) | 1019 parser.add_option_group(group) |
1020 | 1020 |
1021 group = optparse.OptionGroup(parser, "Access the try server with Gerrit") | 1021 group = optparse.OptionGroup(parser, "Access the try server with Gerrit") |
1022 group.add_option("--use_gerrit", | 1022 group.add_option("--use_gerrit", |
1023 action="store_const", | 1023 action="store_const", |
1024 const=_SendChangeGerrit, | 1024 const=_SendChangeGerrit, |
1025 dest="send_patch", | 1025 dest="send_patch", |
1026 help="Use Gerrit to talk to the try server") | 1026 help="Use Gerrit to talk to the try server") |
1027 group.add_option("--gerrit_url", | 1027 group.add_option("--gerrit_url", |
1028 metavar="GERRIT_URL", | 1028 metavar="GERRIT_URL", |
1029 help="Gerrit url to post a tryjob to; --use_gerrit is " | 1029 help="Gerrit url to post a try job to; --use_gerrit is " |
1030 "implied when using --gerrit_url") | 1030 "implied when using --gerrit_url") |
1031 parser.add_option_group(group) | 1031 parser.add_option_group(group) |
1032 | 1032 |
1033 return parser | 1033 return parser |
1034 | 1034 |
1035 | 1035 |
1036 def TryChange(argv, | 1036 def TryChange(argv, |
1037 change, | 1037 change, |
1038 swallow_exception, | 1038 swallow_exception, |
1039 prog=None, | 1039 prog=None, |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 return 1 | 1256 return 1 |
1257 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 1257 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
1258 print >> sys.stderr, e | 1258 print >> sys.stderr, e |
1259 return 1 | 1259 return 1 |
1260 return 0 | 1260 return 0 |
1261 | 1261 |
1262 | 1262 |
1263 if __name__ == "__main__": | 1263 if __name__ == "__main__": |
1264 fix_encoding.fix_encoding() | 1264 fix_encoding.fix_encoding() |
1265 sys.exit(TryChange(None, None, False)) | 1265 sys.exit(TryChange(None, None, False)) |
OLD | NEW |