Index: scripts/slave/slave_utils.py |
diff --git a/scripts/slave/slave_utils.py b/scripts/slave/slave_utils.py |
index 2571bbacb290136e8a54eb1ebb3b36be221f1c6e..2c68b88599481306179efa9d72549566060beecd 100644 |
--- a/scripts/slave/slave_utils.py |
+++ b/scripts/slave/slave_utils.py |
@@ -23,6 +23,12 @@ ERROR_EXIT_CODE = 1 |
WARNING_EXIT_CODE = 88 |
+# Regex matching git comment lines containing svn revision info. |
+GIT_SVN_ID_RE = re.compile(r'^git-svn-id: .*@([0-9]+) .*$') |
+# Regex for the master branch commit position. |
+GIT_CR_POS_RE = re.compile(r'^Cr-Commit-Position: refs/heads/master@{#(\d+)}$') |
+ |
+ |
# Local errors. |
class PageHeapError(Exception): |
pass |
@@ -736,3 +742,127 @@ def ZipAndUpload(bucket, archive, *targets): |
chromium_utils.RunCommand(zip_cmd) |
GSUtilCopy(local_archive, 'gs://%s/%s' % (bucket, archive)) |
return 'https://storage.cloud.google.com/%s/%s' % (bucket, archive) |
+ |
+ |
+def GetTelemetryRevisions( |
+ build_properties, main_revision, blink_revision, point_id=None): |
+ """Fills in the same revisions fields that process_log_utils does.""" |
+ |
+ versions = {} |
+ versions['rev'] = main_revision |
+ versions['webkit_rev'] = blink_revision |
+ versions['webrtc_rev'] = build_properties.get('got_webrtc_revision') |
+ versions['v8_rev'] = build_properties.get('got_v8_revision') |
+ versions['ver'] = build_properties.get('version') |
+ versions['git_revision'] = build_properties.get('git_revision') |
+ versions['point_id'] = point_id |
+ # There are a lot of "bad" revisions to check for, so clean them all up here. |
+ for key in versions.keys(): |
+ if not versions[key] or versions[key] == 'undefined': |
+ del versions[key] |
+ return versions |
+ |
+ |
+def GetMainRevision(build_properties, build_dir, revision=None): |
+ """Return revision to use as the numerical x-value in the perf dashboard. |
+ |
+ This will be used as the value of "rev" in the data passed to |
+ results_dashboard.SendResults. |
+ |
+ In order or priority, this function could return: |
+ 1. The value of the --revision flag (IF it can be parsed as an int). |
+ 2. The value of "got_revision_cp" in build properties. |
+ 3. An SVN number, git commit position, or git commit hash. |
+ """ |
+ if revision and revision.isdigit(): |
+ return revision |
+ commit_pos_num = _GetCommitPos(build_properties) |
+ if commit_pos_num is not None: |
+ return commit_pos_num |
+ # TODO(sullivan,qyearsley): Don't fall back to _GetRevision if it returns |
+ # a git commit, since this should be a numerical revision. Instead, abort |
+ # and fail. |
+ return GetRevision(os.path.dirname(os.path.abspath(build_dir))) |
+ |
+ |
+def GetBlinkRevision(build_dir, webkit_revision=None): |
+ if webkit_revision: |
+ webkit_revision = webkit_revision |
+ else: |
+ try: |
+ webkit_dir = chromium_utils.FindUpward( |
+ os.path.abspath(build_dir), 'third_party', 'WebKit', 'Source') |
+ webkit_revision = slave_utils.GetRevision(webkit_dir) |
+ except Exception: |
+ webkit_revision = None |
+ return webkit_revision |
+ |
+ |
+def GetRevision(in_directory): |
+ """Returns the SVN revision, git commit position, or git hash. |
+ |
+ Args: |
+ in_directory: A directory in the repository to be checked. |
+ |
+ Returns: |
+ An SVN revision as a string if the given directory is in a SVN repository, |
+ or a git commit position number, or if that's not available, a git hash. |
+ If all of that fails, an empty string is returned. |
+ """ |
+ import xml.dom.minidom |
+ if not os.path.exists(os.path.join(in_directory, '.svn')): |
+ if _IsGitDirectory(in_directory): |
+ svn_rev = _GetGitCommitPosition(in_directory) |
+ if svn_rev: |
+ return svn_rev |
+ return _GetGitRevision(in_directory) |
+ else: |
+ return '' |
+ |
+def _GetCommitPos(build_properties): |
+ """Extracts the commit position from the build properties, if its there.""" |
+ if 'got_revision_cp' not in build_properties: |
+ return None |
+ commit_pos = build_properties['got_revision_cp'] |
+ return int(re.search(r'{#(\d+)}', commit_pos).group(1)) |
+ |
+ |
+def _GetGitCommitPositionFromLog(log): |
+ """Returns either the commit position or svn rev from a git log.""" |
+ # Parse from the bottom up, in case the commit message embeds the message |
+ # from a different commit (e.g., for a revert). |
+ for r in [GIT_CR_POS_RE, GIT_SVN_ID_RE]: |
+ for line in reversed(log.splitlines()): |
+ m = r.match(line.strip()) |
+ if m: |
+ return m.group(1) |
+ return None |
+ |
+ |
+def _GetGitCommitPosition(dir_path): |
+ """Extracts the commit position or svn revision number of the HEAD commit.""" |
+ git_exe = 'git.bat' if sys.platform.startswith('win') else 'git' |
+ p = subprocess.Popen( |
+ [git_exe, 'log', '-n', '1', '--pretty=format:%B', 'HEAD'], |
+ cwd=dir_path, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
+ (log, _) = p.communicate() |
+ if p.returncode != 0: |
+ return None |
+ return _GetGitCommitPositionFromLog(log) |
+ |
+ |
+def _GetGitRevision(in_directory): |
+ """Returns the git hash tag for the given directory. |
+ |
+ Args: |
+ in_directory: The directory where git is to be run. |
+ |
+ Returns: |
+ The git SHA1 hash string. |
+ """ |
+ git_exe = 'git.bat' if sys.platform.startswith('win') else 'git' |
+ p = subprocess.Popen( |
+ [git_exe, 'rev-parse', 'HEAD'], |
+ cwd=in_directory, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
+ (stdout, _) = p.communicate() |
+ return stdout.strip() |