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

Side by Side Diff: native_client_sdk/src/tools/getos.py

Issue 506863005: [NaCl SDK] getos.py now checks against the Cr-Commit-Position. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sbc-nacl-sdk-fix-getos-tests
Patch Set: Use tuples for comparison. 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/tools/common.mk ('k') | native_client_sdk/src/tools/tests/getos_test.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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Determine OS and various other system properties. 6 """Determine OS and various other system properties.
7 7
8 Determine the name of the platform used and other system properties such as 8 Determine the name of the platform used and other system properties such as
9 the location of Chrome. This is used, for example, to determine the correct 9 the location of Chrome. This is used, for example, to determine the correct
10 Toolchain to invoke. 10 Toolchain to invoke.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 if name == "Chrome Revision": 77 if name == "Chrome Revision":
78 revision = value.strip() 78 revision = value.strip()
79 if name == "Chrome Commit Position": 79 if name == "Chrome Commit Position":
80 commit_position = value.strip() 80 commit_position = value.strip()
81 81
82 if revision is None or version is None or commit_position is None: 82 if revision is None or version is None or commit_position is None:
83 raise Error("error parsing SDK README: %s" % readme) 83 raise Error("error parsing SDK README: %s" % readme)
84 84
85 try: 85 try:
86 version = int(version) 86 version = int(version)
87 revision = int(revision)
87 except ValueError: 88 except ValueError:
88 raise Error("error parsing SDK README: %s" % readme) 89 raise Error("error parsing SDK README: %s" % readme)
89 90
90 return (version, revision, commit_position) 91 return (version, revision, commit_position)
91 92
92 93
93 def GetSystemArch(platform): 94 def GetSystemArch(platform):
94 if platform == 'win': 95 if platform == 'win':
95 if UseWin64(): 96 if UseWin64():
96 return 'x86_64' 97 return 'x86_64'
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 177
177 arch = match.group(2) 178 arch = match.group(2)
178 if 'arm' in arch: 179 if 'arm' in arch:
179 return 'arm' 180 return 'arm'
180 if '64' in arch: 181 if '64' in arch:
181 return 'x86_64' 182 return 'x86_64'
182 return 'x86_32' 183 return 'x86_32'
183 184
184 185
185 def ParseVersion(version): 186 def ParseVersion(version):
187 """Parses a version number of the form '<major>.<position>'.
188
189 <position> is the Cr-Commit-Position number.
190 """
186 if '.' in version: 191 if '.' in version:
187 version = version.split('.') 192 version = version.split('.')
188 else: 193 else:
189 version = (version, '0') 194 version = (version, '0')
190 195
191 try: 196 try:
192 return tuple(int(x) for x in version) 197 return tuple(int(x) for x in version)
193 except ValueError: 198 except ValueError:
194 raise Error('error parsing SDK version: %s' % version) 199 raise Error('error parsing SDK version: %s' % version)
195 200
196 201
202 def CheckVersion(required_version):
203 """Determines whether the current SDK version meets the required version.
204
205 Args:
206 required_version: (major, position) pair, where position is the
207 Cr-Commit-Position number.
Sam Clegg 2014/09/22 17:34:46 I think docstrings use 2-space indentation like th
Matt Giuca 2014/09/23 01:07:36 Yeah you're right. (I was looking at the style gui
Sam Clegg 2014/09/23 01:11:24 Yes, the internal and external style guides differ
208
209 Raises:
210 Error: The SDK version is older than required_version.
211 """
212 version = GetSDKVersion()[:2]
213 if version < required_version:
214 raise Error("SDK version too old (current: %d.%d, required: %d.%d)"
215 % (version[0], version[1], required_version[0], required_version[1]))
216
217
197 def main(args): 218 def main(args):
198 parser = optparse.OptionParser() 219 parser = optparse.OptionParser()
199 parser.add_option('--arch', action='store_true', 220 parser.add_option('--arch', action='store_true',
200 help='Print architecture of current machine (x86_32, x86_64 or arm).') 221 help='Print architecture of current machine (x86_32, x86_64 or arm).')
201 parser.add_option('--chrome', action='store_true', 222 parser.add_option('--chrome', action='store_true',
202 help='Print the path chrome (by first looking in $CHROME_PATH and ' 223 help='Print the path chrome (by first looking in $CHROME_PATH and '
203 'then $PATH).') 224 'then $PATH).')
204 parser.add_option('--nacl-arch', action='store_true', 225 parser.add_option('--nacl-arch', action='store_true',
205 help='Print architecture used by NaCl on the current machine.') 226 help='Print architecture used by NaCl on the current machine.')
206 parser.add_option('--sdk-version', action='store_true', 227 parser.add_option('--sdk-version', action='store_true',
207 help='Print major version of the NaCl SDK.') 228 help='Print major version of the NaCl SDK.')
208 parser.add_option('--sdk-revision', action='store_true', 229 parser.add_option('--sdk-revision', action='store_true',
209 help='Print revision number of the NaCl SDK.') 230 help='Print revision number of the NaCl SDK.')
210 parser.add_option('--sdk-commit-position', action='store_true', 231 parser.add_option('--sdk-commit-position', action='store_true',
211 help='Print commit position of the NaCl SDK.') 232 help='Print commit position of the NaCl SDK.')
212 parser.add_option('--check-version', 233 parser.add_option('--check-version',
234 metavar='MAJOR.POSITION',
213 help='Check that the SDK version is at least as great as the ' 235 help='Check that the SDK version is at least as great as the '
214 'version passed in.') 236 'version passed in. MAJOR is the major version number and POSITION '
237 'is the Cr-Commit-Position number.')
215 238
216 options, _ = parser.parse_args(args) 239 options, _ = parser.parse_args(args)
217 240
218 platform = GetPlatform() 241 platform = GetPlatform()
219 242
220 if len(args) > 1: 243 if len(args) > 1:
221 parser.error('Only one option can be specified at a time.') 244 parser.error('Only one option can be specified at a time.')
222 245
223 if not args: 246 if not args:
224 print platform 247 print platform
225 return 0 248 return 0
226 249
227 if options.arch: 250 if options.arch:
228 out = GetSystemArch(platform) 251 out = GetSystemArch(platform)
229 elif options.nacl_arch: 252 elif options.nacl_arch:
230 out = GetNaClArch(platform) 253 out = GetNaClArch(platform)
231 elif options.chrome: 254 elif options.chrome:
232 out = GetChromePath(platform) 255 out = GetChromePath(platform)
233 elif options.sdk_version: 256 elif options.sdk_version:
234 out = GetSDKVersion()[0] 257 out = GetSDKVersion()[0]
235 elif options.sdk_revision: 258 elif options.sdk_revision:
236 out = GetSDKVersion()[1] 259 out = GetSDKVersion()[1]
237 elif options.sdk_commit_position: 260 elif options.sdk_commit_position:
238 out = GetSDKVersion()[2] 261 out = GetSDKVersion()[2]
239 elif options.check_version: 262 elif options.check_version:
240 required_version = ParseVersion(options.check_version) 263 required_version = ParseVersion(options.check_version)
241 version = GetSDKVersion() 264 CheckVersion(required_version)
242 # We currently ignore the revision and just check the major version number.
243 # Currently, version[1] is just a Git hash, which cannot be compared.
244 # TODO(mgiuca): Compare the minor revision numbers (which should be
245 # Cr-Commit-Position values), when http://crbug.com/406783 is fixed.
246 # Then Cr-Commit-Position should be available: see http://crbug.com/406993.
247 if version[0] < required_version[0]:
248 raise Error("SDK version too old (current: %s, required: %s)"
249 % (version[0], required_version[0]))
250 out = None 265 out = None
251 266
252 if out: 267 if out:
253 print out 268 print out
254 return 0 269 return 0
255 270
256 271
257 if __name__ == '__main__': 272 if __name__ == '__main__':
258 try: 273 try:
259 sys.exit(main(sys.argv[1:])) 274 sys.exit(main(sys.argv[1:]))
260 except Error as e: 275 except Error as e:
261 sys.stderr.write(str(e) + '\n') 276 sys.stderr.write(str(e) + '\n')
262 sys.exit(1) 277 sys.exit(1)
OLDNEW
« no previous file with comments | « native_client_sdk/src/tools/common.mk ('k') | native_client_sdk/src/tools/tests/getos_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698