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 = FetchGitCommitPosition() | 31 info = FetchCommitPosition() |
32 if info.url == 'git': | 32 _, ref, revision = ParseCommitPosition(info.revision) |
33 _, ref, revision = ParseCommitPosition(info.revision) | 33 if ref == 'refs/heads/master': |
34 if ref == 'refs/heads/master': | 34 return 'trunk.%s' % revision |
35 return 'trunk.%s' % revision | |
36 return ChromeVersionNoTrunk() | 35 return ChromeVersionNoTrunk() |
37 | 36 |
38 | 37 |
39 def ChromeVersionNoTrunk(): | 38 def ChromeVersionNoTrunk(): |
40 '''Extract the chrome version from src/chrome/VERSION. | 39 '''Extract the chrome version from src/chrome/VERSION. |
41 Ignore whether this is a trunk build. | 40 Ignore whether this is a trunk build. |
42 | 41 |
43 Returns: | 42 Returns: |
44 Chrome version string. | 43 Chrome version string. |
45 ''' | 44 ''' |
(...skipping 14 matching lines...) Expand all Loading... |
60 def ChromeRevision(): | 59 def ChromeRevision(): |
61 '''Extract chrome revision from svn. | 60 '''Extract chrome revision from svn. |
62 | 61 |
63 Now that the Chrome source-of-truth is git, this will return the | 62 Now that the Chrome source-of-truth is git, this will return the |
64 Cr-Commit-Position instead. Fortunately, this value is equal to the SVN | 63 Cr-Commit-Position instead. Fortunately, this value is equal to the SVN |
65 revision if one exists. | 64 revision if one exists. |
66 | 65 |
67 Returns: | 66 Returns: |
68 The Chrome revision as a string. e.g. "12345" | 67 The Chrome revision as a string. e.g. "12345" |
69 ''' | 68 ''' |
70 version = FetchGitCommitPosition() | 69 version = FetchCommitPosition() |
71 return ParseCommitPosition(version.revision)[2] | 70 return ParseCommitPosition(version.revision)[2] |
72 | 71 |
73 | 72 |
74 def ChromeCommitPosition(): | 73 def ChromeCommitPosition(): |
75 '''Return the full git sha and commit position. | 74 '''Return the full git sha and commit position. |
76 | 75 |
77 Returns: | 76 Returns: |
78 A value like: | 77 A value like: |
79 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238} | 78 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238} |
80 ''' | 79 ''' |
81 return FetchGitCommitPosition().revision | 80 return FetchCommitPosition().revision |
82 | 81 |
83 | 82 |
84 def NaClRevision(): | 83 def NaClRevision(): |
85 '''Extract NaCl revision from svn. | 84 '''Extract NaCl revision from svn. |
86 | 85 |
87 Returns: | 86 Returns: |
88 The NaCl revision as a string. e.g. "12345" | 87 The NaCl revision as a string. e.g. "12345" |
89 ''' | 88 ''' |
90 nacl_dir = os.path.join(SRC_DIR, 'native_client') | 89 nacl_dir = os.path.join(SRC_DIR, 'native_client') |
91 return lastchange.FetchVersionInfo(None, nacl_dir, 'native_client').revision | 90 return lastchange.FetchVersionInfo(nacl_dir).revision |
92 | 91 |
93 | 92 |
94 def FetchGitCommitPosition(directory=None): | 93 def FetchCommitPosition(directory=None): |
95 '''Return the "commit-position" of the Chromium git repo. This should be | 94 '''Return the "commit-position" of the Chromium git repo. This should be |
96 equivalent to the SVN revision if one exists. | 95 equivalent to the SVN revision if one exists. |
97 ''' | 96 ''' |
98 SEARCH_LIMIT = 100 | 97 SEARCH_LIMIT = 100 |
99 for i in xrange(SEARCH_LIMIT): | 98 for i in xrange(SEARCH_LIMIT): |
100 cmd = ['show', '-s', '--format=%H%n%B', 'HEAD~%d' % i] | 99 cmd = ['show', '-s', '--format=%H%n%B', 'HEAD~%d' % i] |
101 proc = lastchange.RunGitCommand(directory, cmd) | 100 proc = lastchange.RunGitCommand(directory, cmd) |
102 if not proc: | 101 if not proc: |
103 break | 102 break |
104 | 103 |
105 output = proc.communicate()[0] | 104 output = proc.communicate()[0] |
106 if not (proc.returncode == 0 and output): | 105 if not (proc.returncode == 0 and output): |
107 break | 106 break |
108 | 107 |
109 lines = output.splitlines() | 108 lines = output.splitlines() |
110 | 109 |
111 # First line is the hash. | 110 # First line is the hash. |
112 hsh = lines[0] | 111 hsh = lines[0] |
113 if not re.match(r'[0-9a-fA-F]+', hsh): | 112 if not re.match(r'[0-9a-fA-F]+', hsh): |
114 break | 113 break |
115 | 114 |
116 for line in reversed(lines): | 115 for line in reversed(lines): |
117 if line.startswith('Cr-Commit-Position:'): | 116 if line.startswith('Cr-Commit-Position:'): |
118 pos = line.rsplit()[-1].strip() | 117 pos = line.rsplit()[-1].strip() |
119 return lastchange.VersionInfo('git', '%s-%s' % (hsh, pos)) | 118 return lastchange.VersionInfo('%s-%s' % (hsh, pos)) |
120 | 119 |
121 raise Exception('Unable to fetch a Git Commit Position.') | 120 raise Exception('Unable to fetch a Git Commit Position.') |
122 | 121 |
123 | 122 |
124 | 123 |
125 def ParseCommitPosition(commit_position): | 124 def ParseCommitPosition(commit_position): |
126 '''Parse a Chrome commit position into its components. | 125 '''Parse a Chrome commit position into its components. |
127 | 126 |
128 Given a commit position like: | 127 Given a commit position like: |
129 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238} | 128 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238} |
130 Returns: | 129 Returns: |
131 ("0178d4831bd36b5fb9ff477f03dc43b11626a6dc", "refs/heads/master", "292238") | 130 ("0178d4831bd36b5fb9ff477f03dc43b11626a6dc", "refs/heads/master", "292238") |
132 ''' | 131 ''' |
133 m = re.match(r'([0-9a-fA-F]+)(?:-([^@]+)@{#(\d+)})?', commit_position) | 132 m = re.match(r'([0-9a-fA-F]+)(?:-([^@]+)@{#(\d+)})?', commit_position) |
134 if m: | 133 if m: |
135 return m.groups() | 134 return m.groups() |
136 return None | 135 return None |
OLD | NEW |