OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Functions specific to build slaves, shared by several buildbot scripts. | 5 """Functions specific to build slaves, shared by several buildbot scripts. |
6 """ | 6 """ |
7 | 7 |
8 import datetime | 8 import datetime |
9 import glob | 9 import glob |
10 import os | 10 import os |
11 import re | 11 import re |
12 import shutil | 12 import shutil |
13 import sys | 13 import sys |
14 import tempfile | 14 import tempfile |
15 import time | 15 import time |
16 | 16 |
17 from common import chromium_utils | 17 from common import chromium_utils |
18 from slave.bootstrap import ImportMasterConfigs # pylint: disable=W0611 | 18 from slave.bootstrap import ImportMasterConfigs # pylint: disable=W0611 |
19 from common.chromium_utils import GetActiveMaster # pylint: disable=W0611 | 19 from common.chromium_utils import GetActiveMaster # pylint: disable=W0611 |
20 | 20 |
21 # These codes used to distinguish true errors from script warnings. | 21 # These codes used to distinguish true errors from script warnings. |
22 ERROR_EXIT_CODE = 1 | 22 ERROR_EXIT_CODE = 1 |
23 WARNING_EXIT_CODE = 88 | 23 WARNING_EXIT_CODE = 88 |
24 | 24 |
25 | 25 |
| 26 # Regex matching git comment lines containing svn revision info. |
| 27 GIT_SVN_ID_RE = re.compile(r'^git-svn-id: .*@([0-9]+) .*$') |
| 28 # Regex for the master branch commit position. |
| 29 GIT_CR_POS_RE = re.compile(r'^Cr-Commit-Position: refs/heads/master@{#(\d+)}$') |
| 30 |
| 31 |
26 # Local errors. | 32 # Local errors. |
27 class PageHeapError(Exception): | 33 class PageHeapError(Exception): |
28 pass | 34 pass |
29 | 35 |
30 | 36 |
31 # Cache the path to gflags.exe. | 37 # Cache the path to gflags.exe. |
32 _gflags_exe = None | 38 _gflags_exe = None |
33 | 39 |
34 | 40 |
35 def SubversionExe(): | 41 def SubversionExe(): |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 '--filesync', | 735 '--filesync', |
730 '--recurse-paths', | 736 '--recurse-paths', |
731 '--symlinks', | 737 '--symlinks', |
732 local_archive, | 738 local_archive, |
733 ] | 739 ] |
734 zip_cmd.extend(targets) | 740 zip_cmd.extend(targets) |
735 | 741 |
736 chromium_utils.RunCommand(zip_cmd) | 742 chromium_utils.RunCommand(zip_cmd) |
737 GSUtilCopy(local_archive, 'gs://%s/%s' % (bucket, archive)) | 743 GSUtilCopy(local_archive, 'gs://%s/%s' % (bucket, archive)) |
738 return 'https://storage.cloud.google.com/%s/%s' % (bucket, archive) | 744 return 'https://storage.cloud.google.com/%s/%s' % (bucket, archive) |
| 745 |
| 746 |
| 747 def GetTelemetryRevisions( |
| 748 build_properties, main_revision, blink_revision, point_id=None): |
| 749 """Fills in the same revisions fields that process_log_utils does.""" |
| 750 |
| 751 versions = {} |
| 752 versions['rev'] = main_revision |
| 753 versions['webkit_rev'] = blink_revision |
| 754 versions['webrtc_rev'] = build_properties.get('got_webrtc_revision') |
| 755 versions['v8_rev'] = build_properties.get('got_v8_revision') |
| 756 versions['ver'] = build_properties.get('version') |
| 757 versions['git_revision'] = build_properties.get('git_revision') |
| 758 versions['point_id'] = point_id |
| 759 # There are a lot of "bad" revisions to check for, so clean them all up here. |
| 760 for key in versions.keys(): |
| 761 if not versions[key] or versions[key] == 'undefined': |
| 762 del versions[key] |
| 763 return versions |
| 764 |
| 765 |
| 766 def GetMainRevision(build_properties, build_dir, revision=None): |
| 767 """Return revision to use as the numerical x-value in the perf dashboard. |
| 768 |
| 769 This will be used as the value of "rev" in the data passed to |
| 770 results_dashboard.SendResults. |
| 771 |
| 772 In order or priority, this function could return: |
| 773 1. The value of the --revision flag (IF it can be parsed as an int). |
| 774 2. The value of "got_revision_cp" in build properties. |
| 775 3. An SVN number, git commit position, or git commit hash. |
| 776 """ |
| 777 if revision and revision.isdigit(): |
| 778 return revision |
| 779 commit_pos_num = _GetCommitPos(build_properties) |
| 780 if commit_pos_num is not None: |
| 781 return commit_pos_num |
| 782 # TODO(sullivan,qyearsley): Don't fall back to _GetRevision if it returns |
| 783 # a git commit, since this should be a numerical revision. Instead, abort |
| 784 # and fail. |
| 785 return GetRevision(os.path.dirname(os.path.abspath(build_dir))) |
| 786 |
| 787 |
| 788 def GetBlinkRevision(build_dir, webkit_revision=None): |
| 789 if webkit_revision: |
| 790 webkit_revision = webkit_revision |
| 791 else: |
| 792 try: |
| 793 webkit_dir = chromium_utils.FindUpward( |
| 794 os.path.abspath(build_dir), 'third_party', 'WebKit', 'Source') |
| 795 webkit_revision = slave_utils.GetRevision(webkit_dir) |
| 796 except Exception: |
| 797 webkit_revision = None |
| 798 return webkit_revision |
| 799 |
| 800 |
| 801 def GetRevision(in_directory): |
| 802 """Returns the SVN revision, git commit position, or git hash. |
| 803 |
| 804 Args: |
| 805 in_directory: A directory in the repository to be checked. |
| 806 |
| 807 Returns: |
| 808 An SVN revision as a string if the given directory is in a SVN repository, |
| 809 or a git commit position number, or if that's not available, a git hash. |
| 810 If all of that fails, an empty string is returned. |
| 811 """ |
| 812 import xml.dom.minidom |
| 813 if not os.path.exists(os.path.join(in_directory, '.svn')): |
| 814 if _IsGitDirectory(in_directory): |
| 815 svn_rev = _GetGitCommitPosition(in_directory) |
| 816 if svn_rev: |
| 817 return svn_rev |
| 818 return _GetGitRevision(in_directory) |
| 819 else: |
| 820 return '' |
| 821 |
| 822 def _GetCommitPos(build_properties): |
| 823 """Extracts the commit position from the build properties, if its there.""" |
| 824 if 'got_revision_cp' not in build_properties: |
| 825 return None |
| 826 commit_pos = build_properties['got_revision_cp'] |
| 827 return int(re.search(r'{#(\d+)}', commit_pos).group(1)) |
| 828 |
| 829 |
| 830 def _GetGitCommitPositionFromLog(log): |
| 831 """Returns either the commit position or svn rev from a git log.""" |
| 832 # Parse from the bottom up, in case the commit message embeds the message |
| 833 # from a different commit (e.g., for a revert). |
| 834 for r in [GIT_CR_POS_RE, GIT_SVN_ID_RE]: |
| 835 for line in reversed(log.splitlines()): |
| 836 m = r.match(line.strip()) |
| 837 if m: |
| 838 return m.group(1) |
| 839 return None |
| 840 |
| 841 |
| 842 def _GetGitCommitPosition(dir_path): |
| 843 """Extracts the commit position or svn revision number of the HEAD commit.""" |
| 844 git_exe = 'git.bat' if sys.platform.startswith('win') else 'git' |
| 845 p = subprocess.Popen( |
| 846 [git_exe, 'log', '-n', '1', '--pretty=format:%B', 'HEAD'], |
| 847 cwd=dir_path, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 848 (log, _) = p.communicate() |
| 849 if p.returncode != 0: |
| 850 return None |
| 851 return _GetGitCommitPositionFromLog(log) |
| 852 |
| 853 |
| 854 def _GetGitRevision(in_directory): |
| 855 """Returns the git hash tag for the given directory. |
| 856 |
| 857 Args: |
| 858 in_directory: The directory where git is to be run. |
| 859 |
| 860 Returns: |
| 861 The git SHA1 hash string. |
| 862 """ |
| 863 git_exe = 'git.bat' if sys.platform.startswith('win') else 'git' |
| 864 p = subprocess.Popen( |
| 865 [git_exe, 'rev-parse', 'HEAD'], |
| 866 cwd=in_directory, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 867 (stdout, _) = p.communicate() |
| 868 return stdout.strip() |
OLD | NEW |