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 12 matching lines...) Expand all Loading... |
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 = FetchVersionInfo() |
32 if info.url == 'git': | 32 if info.url == 'git': |
33 _, ref, revision = ParseCommitPosition(info) | 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. |
42 | 42 |
43 Returns: | 43 Returns: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 FetchVersionInfo(nacl_dir, 'native_client').revision |
92 | 92 |
93 | 93 |
94 def FetchVersionInfo(directory=None, | 94 def FetchVersionInfo(directory=None, |
95 directory_regex_prior_to_src_url='chrome|blink|svn'): | 95 directory_regex_prior_to_src_url='chrome|blink|svn'): |
96 ''' | 96 '''Returns the last change (in the form of a branch, revision tuple), |
97 Returns the last change (in the form of a branch, revision tuple), | |
98 from some appropriate revision control system. | 97 from some appropriate revision control system. |
99 | 98 |
100 TODO(binji): This is copied from lastchange.py. Remove this function and use | 99 TODO(binji): This is copied from lastchange.py. Remove this function and use |
101 lastchange.py directly when the dust settles. (see crbug.com/406783) | 100 lastchange.py directly when the dust settles. (see crbug.com/406783) |
102 ''' | 101 ''' |
103 svn_url_regex = re.compile( | 102 svn_url_regex = re.compile( |
104 r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)') | 103 r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)') |
105 | 104 |
106 version_info = (lastchange.FetchSVNRevision(directory, svn_url_regex) or | 105 version_info = (lastchange.FetchSVNRevision(directory, svn_url_regex) or |
107 lastchange.FetchGitSVNRevision(directory, svn_url_regex) or | 106 lastchange.FetchGitSVNRevision(directory, svn_url_regex) or |
108 FetchGitCommitPosition(directory)) | 107 FetchGitCommitPosition(directory)) |
109 if not version_info: | 108 if not version_info: |
110 version_info = lastchange.VersionInfo(None, None) | 109 version_info = lastchange.VersionInfo(None, None) |
111 return version_info | 110 return version_info |
112 | 111 |
113 | 112 |
114 def FetchGitCommitPosition(directory=None): | 113 def FetchGitCommitPosition(directory=None): |
| 114 '''Return the "commit-position" of the Chromium git repo. This should be |
| 115 equivalent to the SVN revision if one exists. |
115 ''' | 116 ''' |
116 Return the "commit-position" of the Chromium git repo. This should be | 117 SEARCH_LIMIT = 100 |
117 equivalent to the SVN revision if one eixsts. | 118 for i in xrange(SEARCH_LIMIT): |
| 119 cmd = ['show', '-s', '--format=%H%n%B', 'HEAD~%d' % i] |
| 120 proc = lastchange.RunGitCommand(directory, cmd) |
| 121 if not proc: |
| 122 break |
118 | 123 |
119 This is a copy of the (recently reverted) change in lastchange.py. | |
120 TODO(binji): Move this logic to lastchange.py when the dust settles. | |
121 (see crbug.com/406783) | |
122 ''' | |
123 hsh = '' | |
124 proc = lastchange.RunGitCommand(directory, ['rev-parse', 'HEAD']) | |
125 if proc: | |
126 output = proc.communicate()[0].strip() | |
127 if proc.returncode == 0 and output: | |
128 hsh = output | |
129 if not hsh: | |
130 return None | |
131 pos = '' | |
132 proc = lastchange.RunGitCommand(directory, | |
133 ['show', '-s', '--format=%B', 'HEAD']) | |
134 if proc: | |
135 output = proc.communicate()[0] | 124 output = proc.communicate()[0] |
136 if proc.returncode == 0 and output: | 125 if not (proc.returncode == 0 and output): |
137 for line in reversed(output.splitlines()): | 126 break |
138 if line.startswith('Cr-Commit-Position:'): | 127 |
139 pos = line.rsplit()[-1].strip() | 128 lines = output.splitlines() |
140 break | 129 |
141 if not pos: | 130 # First line is the hash. |
142 return lastchange.VersionInfo('git', hsh) | 131 hsh = lines[0] |
143 return lastchange.VersionInfo('git', '%s-%s' % (hsh, pos)) | 132 if not re.match(r'[0-9a-fA-F]+', hsh): |
| 133 break |
| 134 |
| 135 for line in reversed(lines): |
| 136 if line.startswith('Cr-Commit-Position:'): |
| 137 pos = line.rsplit()[-1].strip() |
| 138 return lastchange.VersionInfo('git', '%s-%s' % (hsh, pos)) |
| 139 |
| 140 raise Exception('Unable to fetch a Git Commit Position.') |
| 141 |
144 | 142 |
145 | 143 |
146 def ParseCommitPosition(commit_position): | 144 def ParseCommitPosition(commit_position): |
147 ''' | 145 '''Parse a Chrome commit position into its components. |
148 Parse a Chrome commit position into its components. | |
149 | 146 |
150 Given a commit position like: | 147 Given a commit position like: |
151 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238} | 148 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238} |
152 Returns: | 149 Returns: |
153 ("0178d4831bd36b5fb9ff477f03dc43b11626a6dc", "refs/heads/master", "292238") | 150 ("0178d4831bd36b5fb9ff477f03dc43b11626a6dc", "refs/heads/master", "292238") |
154 ''' | 151 ''' |
155 m = re.match(r'([0-9a-fA-F]+)-([^@]+)@{#(\d+)}', commit_position) | 152 m = re.match(r'([0-9a-fA-F]+)(?:-([^@]+)@{#(\d+)})?', commit_position) |
156 if m: | 153 if m: |
157 return m.groups() | 154 return m.groups() |
158 return None | 155 return None |
OLD | NEW |