Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import argparse | 5 import argparse |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import platform | 9 import platform |
| 10 import re | 10 import re |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 439 if branch_name == 'HEAD': | 439 if branch_name == 'HEAD': |
| 440 raise TrybotError('Not on a valid branch, looks like branch ' | 440 raise TrybotError('Not on a valid branch, looks like branch ' |
| 441 'is dettached. [branch:%s]' % branch_name) | 441 'is dettached. [branch:%s]' % branch_name) |
| 442 | 442 |
| 443 # Check if the tree is dirty: make sure the index is up to date and then | 443 # Check if the tree is dirty: make sure the index is up to date and then |
| 444 # run diff-index | 444 # run diff-index |
| 445 RunGit(['update-index', '--refresh', '-q'], ignore_return_code=True) | 445 RunGit(['update-index', '--refresh', '-q'], ignore_return_code=True) |
| 446 output = RunGit(['diff-index', 'HEAD']) | 446 output = RunGit(['diff-index', 'HEAD']) |
| 447 if output: | 447 if output: |
| 448 raise TrybotError( | 448 raise TrybotError( |
| 449 'Cannot send a try job with a dirty tree. Please commit ' | 449 'Cannot send a try job with a dirty tree.\nPlease commit locally and ' |
| 450 'your changes locally first in %s repository.' % repo_path) | 450 'upload your changes to rietveld in %s repository.' % repo_path) |
| 451 | 451 |
| 452 # Make sure the tree does have local commits. | 452 # Make sure the tree does have local commits. |
|
sullivan
2016/10/07 14:50:07
I think we actually don't care about this now as l
prasadv1
2016/10/07 23:06:09
Done.
| |
| 453 output = RunGit(['footers', 'HEAD']) | 453 output = RunGit(['footers', 'HEAD']) |
| 454 if output: | 454 if output: |
| 455 raise TrybotError('No local changes found in %s repository.' % repo_path) | 455 raise TrybotError('No local changes found in %s repository.' % repo_path) |
| 456 | 456 |
| 457 return (repo_name, branch_name) | 457 return (repo_name, branch_name) |
| 458 | 458 |
| 459 def _GetBaseGitHashForRepo(self, branch_name, git_url): | 459 def _GetBaseGitHashForRepo(self, branch_name, git_url): |
| 460 """Gets the base revision for the repo on which local changes are made. | 460 """Gets the base revision for the repo on which local changes are made. |
| 461 | 461 |
| 462 Finds the upstream of the current branch that it is set to and gets | 462 Finds the upstream of the current branch that it is set to and gets |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 if cur_remote == '.': | 494 if cur_remote == '.': |
| 495 return False | 495 return False |
| 496 cur_remote_url = RunGit( | 496 cur_remote_url = RunGit( |
| 497 ['config', 'remote.%s.url' % cur_remote], | 497 ['config', 'remote.%s.url' % cur_remote], |
| 498 'Failed to get remote.%s.url from git config' % cur_remote) | 498 'Failed to get remote.%s.url from git config' % cur_remote) |
| 499 if cur_remote_url.lower() == repo_git_url: | 499 if cur_remote_url.lower() == repo_git_url: |
| 500 return True | 500 return True |
| 501 raise TrybotError('URL %s on remote %s is not recognized on branch.'% ( | 501 raise TrybotError('URL %s on remote %s is not recognized on branch.'% ( |
| 502 cur_remote_url, cur_remote)) | 502 cur_remote_url, cur_remote)) |
| 503 | 503 |
| 504 def _GetChangeList(self): | |
| 505 """Gets the codereview URL for the current changes.""" | |
| 506 output = RunGit(['cl', 'issue'], | |
| 507 'Failed to run "git cl issue" command.') | |
| 508 match = re.search(r'https://codereview.chromium.org/[\d]+', output) | |
|
Michael Achenbach
2016/10/07 15:31:12
This looks like it is rietveld only. Please make s
tandrii(chromium)
2016/10/07 15:41:51
Please, use --json flag and don't parse human mess
prasadv1
2016/10/07 23:06:09
Done.
prasadv1
2016/10/07 23:06:09
Done. Now using git cl issue --json arg to get the
| |
| 509 # Make sure the local commits are uploaded to rietveld. | |
| 510 if not match: | |
| 511 raise TrybotError( | |
| 512 'PLEASE NOTE: The workflow for Perf Try jobs is changed. ' | |
| 513 'In order to run the perf try job, you must first upload your ' | |
| 514 'changes to rietveld.') | |
| 515 return match.group(0) | |
| 516 | |
| 504 def _AttemptTryjob(self, options, extra_args): | 517 def _AttemptTryjob(self, options, extra_args): |
| 505 """Attempts to run a tryjob from a repo directory. | 518 """Attempts to run a tryjob from a repo directory. |
| 506 | 519 |
| 507 Args: | 520 Args: |
| 508 options: Command line arguments to run benchmark. | 521 options: Command line arguments to run benchmark. |
| 509 extra_args: Extra arugments to run benchmark. | 522 extra_args: Extra arugments to run benchmark. |
| 510 | 523 |
| 511 Returns: | 524 Returns: |
| 512 If successful returns 0, otherwise 1. | 525 If successful returns 0, otherwise 1. |
| 513 """ | 526 """ |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 526 if not repo_info: | 539 if not repo_info: |
| 527 raise TrybotError('Unsupported repository %s' % repo_name) | 540 raise TrybotError('Unsupported repository %s' % repo_name) |
| 528 | 541 |
| 529 deps_override = None | 542 deps_override = None |
| 530 if repo_name != 'src': | 543 if repo_name != 'src': |
| 531 if not options.deps_revision: | 544 if not options.deps_revision: |
| 532 options.deps_revision = self._GetBaseGitHashForRepo( | 545 options.deps_revision = self._GetBaseGitHashForRepo( |
| 533 branch_name, repo_info.get('url')) | 546 branch_name, repo_info.get('url')) |
| 534 deps_override = {repo_info.get('src'): options.deps_revision} | 547 deps_override = {repo_info.get('src'): options.deps_revision} |
| 535 | 548 |
| 536 arguments = [options.benchmark_name] + extra_args | 549 rietveld_url = self._GetChangeList() |
| 537 | 550 print ('\nRunning try job....\nview progress here %s.' |
| 538 rietveld_url = self._UploadPatchToRietveld(repo_name, options) | |
| 539 print ('\nUploaded try job to rietveld.\nview progress here %s.' | |
| 540 '\n\tRepo Name: %s\n\tPath: %s\n\tBranch: %s' % ( | 551 '\n\tRepo Name: %s\n\tPath: %s\n\tBranch: %s' % ( |
| 541 rietveld_url, repo_name, repo_path, branch_name)) | 552 rietveld_url, repo_name, repo_path, branch_name)) |
| 542 | 553 |
| 543 for bot_platform in self._builder_names: | 554 for bot_platform in self._builder_names: |
| 544 if not self._builder_names[bot_platform]: | 555 if not self._builder_names[bot_platform]: |
| 545 logging.warning('No builder is found for %s', bot_platform) | 556 logging.warning('No builder is found for %s', bot_platform) |
| 546 continue | 557 continue |
| 547 try: | 558 try: |
| 559 arguments = [options.benchmark_name] + extra_args | |
| 548 self._RunTryJob(bot_platform, arguments, deps_override) | 560 self._RunTryJob(bot_platform, arguments, deps_override) |
| 549 # Even if git cl try throws TrybotError exception for any platform, | 561 # Even if git cl try throws TrybotError exception for any platform, |
| 550 # keep sending try jobs to other platforms. | 562 # keep sending try jobs to other platforms. |
| 551 except TrybotError, err: | 563 except TrybotError, err: |
| 552 print err | 564 print err |
| 553 except TrybotError, error: | 565 except TrybotError, error: |
| 554 print error | 566 print error |
| 555 return 1 | 567 return 1 |
| 556 finally: | 568 finally: |
| 557 # Restore to original working directory. | 569 # Restore to original working directory. |
| 558 os.chdir(original_workdir) | 570 os.chdir(original_workdir) |
| 559 return 0 | 571 return 0 |
| 560 | 572 |
| 561 def _UploadPatchToRietveld(self, repo_name, options): | |
| 562 """Uploads the patch to rietveld and returns rietveld URL.""" | |
| 563 output = RunGit(['cl', 'upload', '-f', '--bypass-hooks', '-m', | |
| 564 ('CL for %s perf tryjob to run %s benchmark ' | |
| 565 'on %s platform(s)' % ( | |
| 566 repo_name, options.benchmark_name, options.trybot))], | |
| 567 'Could not upload to rietveld for %s' % repo_name) | |
| 568 | |
| 569 match = re.search(r'https://codereview.chromium.org/[\d]+', output) | |
| 570 if not match: | |
| 571 raise TrybotError('Could not upload CL to rietveld for %s! Output %s' % | |
| 572 (repo_name, output)) | |
| 573 return match.group(0) | |
| 574 | |
| 575 def _RunTryJob(self, bot_platform, arguments, deps_override): | 573 def _RunTryJob(self, bot_platform, arguments, deps_override): |
|
tandrii(chromium)
2016/10/07 15:44:36
this code as is will work with Gerrit too (support
| |
| 576 """Executes perf try job with benchmark test properties. | 574 """Executes perf try job with benchmark test properties. |
| 577 | 575 |
| 578 Args: | 576 Args: |
| 579 bot_platform: Name of the platform to be generated. | 577 bot_platform: Name of the platform to be generated. |
| 580 arguments: Command line arguments. | 578 arguments: Command line arguments. |
| 581 deps_override: DEPS revision if needs to be overridden. | 579 deps_override: DEPS revision if needs to be overridden. |
| 582 | 580 |
| 583 Raises: | 581 Raises: |
| 584 TrybotError: When trybot fails to upload CL or run git try. | 582 TrybotError: When trybot fails to upload CL or run git try. |
| 585 """ | 583 """ |
| 586 config = self._GetPerfConfig(bot_platform, arguments) | 584 config = self._GetPerfConfig(bot_platform, arguments) |
| 587 | 585 |
| 588 # Generate git try command for available bots. | 586 # Generate git try command for available bots. |
| 589 git_try_command = ['cl', 'try', '-m', 'tryserver.chromium.perf'] | 587 git_try_command = ['cl', 'try', '-m', 'tryserver.chromium.perf'] |
| 590 | 588 |
| 591 # Add Perf Test config to git try --properties arg. | 589 # Add Perf Test config to git try --properties arg. |
| 592 git_try_command.extend(['-p', 'perf_try_config=%s' % json.dumps(config)]) | 590 git_try_command.extend(['-p', 'perf_try_config=%s' % json.dumps(config)]) |
| 593 | 591 |
| 594 error_msg_on_fail = 'Could not try CL for %s' % bot_platform | 592 error_msg_on_fail = 'Could not try CL for %s' % bot_platform |
| 595 # Add deps overrides to git try --properties arg. | 593 # Add deps overrides to git try --properties arg. |
| 596 if deps_override: | 594 if deps_override: |
| 597 git_try_command.extend([ | 595 git_try_command.extend([ |
| 598 '-p', 'deps_revision_overrides=%s' % json.dumps(deps_override)]) | 596 '-p', 'deps_revision_overrides=%s' % json.dumps(deps_override)]) |
| 599 error_msg_on_fail += ' with DEPS override (%s)' % deps_override | 597 error_msg_on_fail += ' with DEPS override (%s)' % deps_override |
| 600 for bot in self._builder_names[bot_platform]: | 598 for bot in self._builder_names[bot_platform]: |
| 601 git_try_command.extend(['-b', bot]) | 599 git_try_command.extend(['-b', bot]) |
| 602 | 600 |
| 603 RunGit(git_try_command, error_msg_on_fail) | 601 RunGit(git_try_command, error_msg_on_fail) |
| 604 print 'Perf Try job sent to rietveld for %s platform.' % bot_platform | 602 print 'Perf Try job sent to rietveld for %s platform.' % bot_platform |
| OLD | NEW |