Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: scripts/slave/slave_utils.py

Issue 2330133002: Updating the SwarmingIsolatedScriptTest to upload chartjson results to the (Closed)
Patch Set: Expecations Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 GetPerfDashboardRevisions(
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 """
790 TODO(eyaich): Blink's now folded into Chromium and doesn't have a separate
791 revision. Use main_revision and delete GetBlinkRevision and uses.
792 """
793 if webkit_revision:
794 webkit_revision = webkit_revision
795 else:
796 try:
797 webkit_dir = chromium_utils.FindUpward(
798 os.path.abspath(build_dir), 'third_party', 'WebKit', 'Source')
799 webkit_revision = slave_utils.GetRevision(webkit_dir)
800 except Exception:
801 webkit_revision = None
802 return webkit_revision
803
804
805 def GetRevision(in_directory):
806 """Returns the SVN revision, git commit position, or git hash.
807
808 Args:
809 in_directory: A directory in the repository to be checked.
810
811 Returns:
812 An SVN revision as a string if the given directory is in a SVN repository,
813 or a git commit position number, or if that's not available, a git hash.
814 If all of that fails, an empty string is returned.
815 """
816 import xml.dom.minidom
817 if not os.path.exists(os.path.join(in_directory, '.svn')):
818 if _IsGitDirectory(in_directory):
819 svn_rev = _GetGitCommitPosition(in_directory)
820 if svn_rev:
821 return svn_rev
822 return _GetGitRevision(in_directory)
823 else:
824 return ''
825
826 def _GetCommitPos(build_properties):
827 """Extracts the commit position from the build properties, if its there."""
828 if 'got_revision_cp' not in build_properties:
829 return None
830 commit_pos = build_properties['got_revision_cp']
831 return int(re.search(r'{#(\d+)}', commit_pos).group(1))
832
833
834 def _GetGitCommitPositionFromLog(log):
835 """Returns either the commit position or svn rev from a git log."""
836 # Parse from the bottom up, in case the commit message embeds the message
837 # from a different commit (e.g., for a revert).
838 for r in [GIT_CR_POS_RE, GIT_SVN_ID_RE]:
839 for line in reversed(log.splitlines()):
840 m = r.match(line.strip())
841 if m:
842 return m.group(1)
843 return None
844
845
846 def _GetGitCommitPosition(dir_path):
847 """Extracts the commit position or svn revision number of the HEAD commit."""
848 git_exe = 'git.bat' if sys.platform.startswith('win') else 'git'
849 p = subprocess.Popen(
850 [git_exe, 'log', '-n', '1', '--pretty=format:%B', 'HEAD'],
851 cwd=dir_path, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
852 (log, _) = p.communicate()
853 if p.returncode != 0:
854 return None
855 return _GetGitCommitPositionFromLog(log)
856
857
858 def _GetGitRevision(in_directory):
859 """Returns the git hash tag for the given directory.
860
861 Args:
862 in_directory: The directory where git is to be run.
863
864 Returns:
865 The git SHA1 hash string.
866 """
867 git_exe = 'git.bat' if sys.platform.startswith('win') else 'git'
868 p = subprocess.Popen(
869 [git_exe, 'rev-parse', 'HEAD'],
870 cwd=in_directory, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
871 (stdout, _) = p.communicate()
872 return stdout.strip()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698