Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: native_client_sdk/src/build_tools/build_version.py

Issue 495423010: [NaCl SDK] Update build_sdk.py to display Cr-Commit-Position in README. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « native_client_sdk/src/build_tools/build_sdk.py ('k') | native_client_sdk/src/tools/getos.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
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 = FetchVersionInfo()
32 if info.url == 'refs/heads/master': 32 if info.url == 'git':
33 return 'trunk.%s' % info.revision 33 _, ref, revision = ParseCommitPosition(info)
34 else: 34 if ref == 'refs/heads/master':
35 return ChromeVersionNoTrunk() 35 return 'trunk.%s' % revision
36 return ChromeVersionNoTrunk()
36 37
37 38
38 def ChromeVersionNoTrunk(): 39 def ChromeVersionNoTrunk():
39 '''Extract the chrome version from src/chrome/VERSION. 40 '''Extract the chrome version from src/chrome/VERSION.
40 Ignore whether this is a trunk build. 41 Ignore whether this is a trunk build.
41 42
42 Returns: 43 Returns:
43 Chrome version string. 44 Chrome version string.
44 ''' 45 '''
45 exec(open(VERSION_PATH).read()) 46 exec(open(VERSION_PATH).read())
46 return '%s.%s.%s.%s' % (MAJOR, MINOR, BUILD, PATCH) 47 return '%s.%s.%s.%s' % (MAJOR, MINOR, BUILD, PATCH)
47 48
48 49
49 def ChromeMajorVersion(): 50 def ChromeMajorVersion():
50 '''Extract chrome major version from src/chrome/VERSION. 51 '''Extract chrome major version from src/chrome/VERSION.
51 52
52 Returns: 53 Returns:
53 Chrome major version. 54 Chrome major version.
54 ''' 55 '''
55 exec(open(VERSION_PATH, 'r').read()) 56 exec(open(VERSION_PATH, 'r').read())
56 return str(MAJOR) 57 return str(MAJOR)
57 58
58 59
59 def ChromeRevision(): 60 def ChromeRevision():
60 '''Extract chrome revision from svn. 61 '''Extract chrome revision from svn.
61 62
62 Now that the Chrome source-of-truth is git, this will return the 63 Now that the Chrome source-of-truth is git, this will return the
63 Cr-Commit-Position instead. fortunately, this value is equal to the SVN 64 Cr-Commit-Position instead. Fortunately, this value is equal to the SVN
64 revision if one exists. 65 revision if one exists.
65 66
66 Returns: 67 Returns:
67 The Chrome revision as a string. e.g. "12345" 68 The Chrome revision as a string. e.g. "12345"
68 ''' 69 '''
69 return FetchVersionInfo().revision 70 version = FetchGitCommitPosition()
71 return ParseCommitPosition(version.revision)[2]
72
73
74 def ChromeCommitPosition():
75 '''Return the full git sha and commit position.
76
77 Returns:
78 A value like:
79 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238}
80 '''
81 return FetchGitCommitPosition().revision
70 82
71 83
72 def NaClRevision(): 84 def NaClRevision():
73 '''Extract NaCl revision from svn. 85 '''Extract NaCl revision from svn.
74 86
75 Returns: 87 Returns:
76 The NaCl revision as a string. e.g. "12345" 88 The NaCl revision as a string. e.g. "12345"
77 ''' 89 '''
78 nacl_dir = os.path.join(SRC_DIR, 'native_client') 90 nacl_dir = os.path.join(SRC_DIR, 'native_client')
79 return FetchVersionInfo(nacl_dir, 'native_client').revision 91 return FetchVersionInfo(nacl_dir, 'native_client').revision
80 92
81 93
82 def FetchVersionInfo(directory=None, 94 def FetchVersionInfo(directory=None,
83 directory_regex_prior_to_src_url='chrome|blink|svn'): 95 directory_regex_prior_to_src_url='chrome|blink|svn'):
84 """ 96 '''
85 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),
86 from some appropriate revision control system. 98 from some appropriate revision control system.
87 99
88 TODO(binji): This is copied from lastchange.py. Remove this function and use 100 TODO(binji): This is copied from lastchange.py. Remove this function and use
89 lastchange.py directly when the dust settles. (see crbug.com/406783) 101 lastchange.py directly when the dust settles. (see crbug.com/406783)
90 """ 102 '''
91 svn_url_regex = re.compile( 103 svn_url_regex = re.compile(
92 r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)') 104 r'.*/(' + directory_regex_prior_to_src_url + r')(/.*)')
93 105
94 version_info = (lastchange.FetchSVNRevision(directory, svn_url_regex) or 106 version_info = (lastchange.FetchSVNRevision(directory, svn_url_regex) or
95 lastchange.FetchGitSVNRevision(directory, svn_url_regex) or 107 lastchange.FetchGitSVNRevision(directory, svn_url_regex) or
96 FetchGitCommitPosition(directory)) 108 FetchGitCommitPosition(directory))
97 if not version_info: 109 if not version_info:
98 version_info = lastchange.VersionInfo(None, None) 110 version_info = lastchange.VersionInfo(None, None)
99 return version_info 111 return version_info
100 112
101 113
102 def FetchGitCommitPosition(directory=None): 114 def FetchGitCommitPosition(directory=None):
103 """ 115 '''
104 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
105 equivalent to the SVN revision if one eixsts. 117 equivalent to the SVN revision if one eixsts.
106 118
107 This is a copy of the (recently reverted) change in lastchange.py. 119 This is a copy of the (recently reverted) change in lastchange.py.
108 TODO(binji): Move this logic to lastchange.py when the dust settles. 120 TODO(binji): Move this logic to lastchange.py when the dust settles.
109 (see crbug.com/406783) 121 (see crbug.com/406783)
110 """ 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 = ''
111 proc = lastchange.RunGitCommand(directory, 132 proc = lastchange.RunGitCommand(directory,
112 ['show', '-s', '--format=%B', 'HEAD']) 133 ['show', '-s', '--format=%B', 'HEAD'])
113 if proc: 134 if proc:
114 output = proc.communicate()[0] 135 output = proc.communicate()[0]
115 if proc.returncode == 0 and output: 136 if proc.returncode == 0 and output:
116 for line in reversed(output.splitlines()): 137 for line in reversed(output.splitlines()):
117 match = re.search('Cr-Commit-Position: (.*)@{#(\d+)}', line) 138 if line.startswith('Cr-Commit-Position:'):
118 if match: 139 pos = line.rsplit()[-1].strip()
119 return lastchange.VersionInfo(match.group(1), match.group(2)) 140 break
120 return lastchange.VersionInfo(None, None) 141 if not pos:
142 return lastchange.VersionInfo('git', hsh)
143 return lastchange.VersionInfo('git', '%s-%s' % (hsh, pos))
144
145
146 def ParseCommitPosition(commit_position):
147 '''
148 Parse a Chrome commit position into its components.
149
150 Given a commit position like:
151 0178d4831bd36b5fb9ff477f03dc43b11626a6dc-refs/heads/master@{#292238}
152 Returns:
153 ("0178d4831bd36b5fb9ff477f03dc43b11626a6dc", "refs/heads/master", "292238")
154 '''
155 m = re.match(r'([0-9a-fA-F]+)-([^@]+)@{#(\d+)}', commit_position)
156 if m:
157 return m.groups()
158 return None
OLDNEW
« no previous file with comments | « native_client_sdk/src/build_tools/build_sdk.py ('k') | native_client_sdk/src/tools/getos.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698