| 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 """Small utility library of python functions used during SDK building. | 5 """Small utility library of python functions used during SDK building. |
| 6 """ | 6 """ |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import re | 9 import re |
| 10 import sys | 10 import sys |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 # Location of chrome's version file. | 21 # Location of chrome's version file. |
| 22 VERSION_PATH = os.path.join(SRC_DIR, 'chrome', 'VERSION') | 22 VERSION_PATH = os.path.join(SRC_DIR, 'chrome', 'VERSION') |
| 23 | 23 |
| 24 | 24 |
| 25 def ChromeVersion(): | 25 def ChromeVersion(): |
| 26 '''Extract chrome version from src/chrome/VERSION + svn. | 26 '''Extract chrome version from src/chrome/VERSION + svn. |
| 27 | 27 |
| 28 Returns: | 28 Returns: |
| 29 Chrome version string or trunk + svn rev. | 29 Chrome version string or trunk + svn rev. |
| 30 ''' | 30 ''' |
| 31 info = FetchVersionInfo() | 31 info = FetchGitCommitPosition() |
| 32 if info.url == 'git': | 32 if info.url == 'git': |
| 33 _, ref, revision = ParseCommitPosition(info.revision) | 33 _, ref, revision = ParseCommitPosition(info.revision) |
| 34 if ref == 'refs/heads/master': | 34 if ref == 'refs/heads/master': |
| 35 return 'trunk.%s' % revision | 35 return 'trunk.%s' % revision |
| 36 return ChromeVersionNoTrunk() | 36 return ChromeVersionNoTrunk() |
| 37 | 37 |
| 38 | 38 |
| 39 def ChromeVersionNoTrunk(): | 39 def ChromeVersionNoTrunk(): |
| 40 '''Extract the chrome version from src/chrome/VERSION. | 40 '''Extract the chrome version from src/chrome/VERSION. |
| 41 Ignore whether this is a trunk build. | 41 Ignore whether this is a trunk build. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 return FetchGitCommitPosition().revision | 81 return FetchGitCommitPosition().revision |
| 82 | 82 |
| 83 | 83 |
| 84 def NaClRevision(): | 84 def NaClRevision(): |
| 85 '''Extract NaCl revision from svn. | 85 '''Extract NaCl revision from svn. |
| 86 | 86 |
| 87 Returns: | 87 Returns: |
| 88 The NaCl revision as a string. e.g. "12345" | 88 The NaCl revision as a string. e.g. "12345" |
| 89 ''' | 89 ''' |
| 90 nacl_dir = os.path.join(SRC_DIR, 'native_client') | 90 nacl_dir = os.path.join(SRC_DIR, 'native_client') |
| 91 return FetchVersionInfo(nacl_dir, 'native_client').revision | 91 return lastchange.FetchVersionInfo(None, nacl_dir, 'native_client').revision |
| 92 | |
| 93 | |
| 94 def FetchVersionInfo(directory=None, | |
| 95 directory_regex_prior_to_src_url='chrome|blink|svn'): | |
| 96 '''Returns the last change (in the form of a branch, revision tuple), | |
| 97 from some appropriate revision control system. | |
| 98 | |
| 99 TODO(binji): This is copied from lastchange.py. Remove this function and use | |
| 100 lastchange.py directly when the dust settles. (see crbug.com/406783) | |
| 101 ''' | |
| 102 svn_url_regex = re.compile( | |
| 103 r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)') | |
| 104 | |
| 105 version_info = (lastchange.FetchSVNRevision(directory, svn_url_regex) or | |
| 106 lastchange.FetchGitSVNRevision(directory, svn_url_regex) or | |
| 107 FetchGitCommitPosition(directory)) | |
| 108 if not version_info: | |
| 109 version_info = lastchange.VersionInfo(None, None) | |
| 110 return version_info | |
| 111 | 92 |
| 112 | 93 |
| 113 def FetchGitCommitPosition(directory=None): | 94 def FetchGitCommitPosition(directory=None): |
| 114 '''Return the "commit-position" of the Chromium git repo. This should be | 95 '''Return the "commit-position" of the Chromium git repo. This should be |
| 115 equivalent to the SVN revision if one exists. | 96 equivalent to the SVN revision if one exists. |
| 116 ''' | 97 ''' |
| 117 SEARCH_LIMIT = 100 | 98 SEARCH_LIMIT = 100 |
| 118 for i in xrange(SEARCH_LIMIT): | 99 for i in xrange(SEARCH_LIMIT): |
| 119 cmd = ['show', '-s', '--format=%H%n%B', 'HEAD~%d' % i] | 100 cmd = ['show', '-s', '--format=%H%n%B', 'HEAD~%d' % i] |
| 120 proc = lastchange.RunGitCommand(directory, cmd) | 101 proc = lastchange.RunGitCommand(directory, cmd) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 146 | 127 |
| 147 Given a commit position like: | 128 Given a commit position like: |
| 148 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238} | 129 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238} |
| 149 Returns: | 130 Returns: |
| 150 ("0178d4831bd36b5fb9ff477f03dc43b11626a6dc", "refs/heads/master", "292238") | 131 ("0178d4831bd36b5fb9ff477f03dc43b11626a6dc", "refs/heads/master", "292238") |
| 151 ''' | 132 ''' |
| 152 m = re.match(r'([0-9a-fA-F]+)(?:-([^@]+)@{#(\d+)})?', commit_position) | 133 m = re.match(r'([0-9a-fA-F]+)(?:-([^@]+)@{#(\d+)})?', commit_position) |
| 153 if m: | 134 if m: |
| 154 return m.groups() | 135 return m.groups() |
| 155 return None | 136 return None |
| OLD | NEW |