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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 | 105 |
106 version_info = (lastchange.FetchSVNRevision(directory, svn_url_regex) or | 106 version_info = (lastchange.FetchSVNRevision(directory, svn_url_regex) or |
107 lastchange.FetchGitSVNRevision(directory, svn_url_regex) or | 107 lastchange.FetchGitSVNRevision(directory, svn_url_regex) or |
108 FetchGitCommitPosition(directory)) | 108 FetchGitCommitPosition(directory)) |
109 if not version_info: | 109 if not version_info: |
110 version_info = lastchange.VersionInfo(None, None) | 110 version_info = lastchange.VersionInfo(None, None) |
111 return version_info | 111 return version_info |
112 | 112 |
113 | 113 |
114 def FetchGitCommitPosition(directory=None): | 114 def FetchGitCommitPosition(directory=None): |
115 ''' | 115 ''' |
Sam Clegg
2014/08/29 11:51:45
I think the first line of the docstring should be
binji
2014/08/29 16:01:28
Done.
| |
116 Return the "commit-position" of the Chromium git repo. This should be | 116 Return the "commit-position" of the Chromium git repo. This should be |
117 equivalent to the SVN revision if one eixsts. | 117 equivalent to the SVN revision if one exists. |
118 ''' | |
119 SEARCH_LIMIT = 100 | |
120 for i in xrange(SEARCH_LIMIT): | |
121 cmd = ['show', '-s', '--format=%H%n%B', 'HEAD~%d' % i] | |
122 proc = lastchange.RunGitCommand(directory, cmd) | |
123 if not proc: | |
124 break | |
118 | 125 |
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] | 126 output = proc.communicate()[0] |
136 if proc.returncode == 0 and output: | 127 if not (proc.returncode == 0 and output): |
137 for line in reversed(output.splitlines()): | 128 break |
138 if line.startswith('Cr-Commit-Position:'): | 129 |
139 pos = line.rsplit()[-1].strip() | 130 lines = output.splitlines() |
140 break | 131 |
141 if not pos: | 132 # First line is the hash. |
142 return lastchange.VersionInfo('git', hsh) | 133 hsh = lines[0] |
143 return lastchange.VersionInfo('git', '%s-%s' % (hsh, pos)) | 134 if not re.match(r'[0-9a-fA-F]+', hsh): |
135 break | |
136 | |
137 for line in reversed(lines): | |
138 if line.startswith('Cr-Commit-Position:'): | |
139 pos = line.rsplit()[-1].strip() | |
140 return lastchange.VersionInfo('git', '%s-%s' % (hsh, pos)) | |
141 | |
142 return lastchange.VersionInfo(None, None) | |
Sam Clegg
2014/08/29 11:51:45
Should we assert / raise here?
binji
2014/08/29 16:01:28
Done.
| |
143 | |
144 | 144 |
145 | 145 |
146 def ParseCommitPosition(commit_position): | 146 def ParseCommitPosition(commit_position): |
147 ''' | 147 ''' |
148 Parse a Chrome commit position into its components. | 148 Parse a Chrome commit position into its components. |
149 | 149 |
150 Given a commit position like: | 150 Given a commit position like: |
151 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238} | 151 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238} |
152 Returns: | 152 Returns: |
153 ("0178d4831bd36b5fb9ff477f03dc43b11626a6dc", "refs/heads/master", "292238") | 153 ("0178d4831bd36b5fb9ff477f03dc43b11626a6dc", "refs/heads/master", "292238") |
154 ''' | 154 ''' |
155 m = re.match(r'([0-9a-fA-F]+)-([^@]+)@{#(\d+)}', commit_position) | 155 m = re.match(r'([0-9a-fA-F]+)(?:-([^@]+)@{#(\d+)})?', commit_position) |
156 if m: | 156 if m: |
157 return m.groups() | 157 return m.groups() |
158 return None | 158 return None |
OLD | NEW |