| OLD | NEW |
| 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. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import optparse | 13 import argparse |
| 14 import os | 14 import os |
| 15 import re | 15 import re |
| 16 import subprocess | 16 import subprocess |
| 17 import sys | 17 import sys |
| 18 | 18 |
| 19 import oshelpers | 19 import oshelpers |
| 20 | 20 |
| 21 | 21 |
| 22 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 22 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 23 CHROME_DEFAULT_PATH = { | 23 CHROME_DEFAULT_PATH = { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 Raises: | 209 Raises: |
| 210 Error: The SDK version is older than required_version. | 210 Error: The SDK version is older than required_version. |
| 211 """ | 211 """ |
| 212 version = GetSDKVersion()[:2] | 212 version = GetSDKVersion()[:2] |
| 213 if version < required_version: | 213 if version < required_version: |
| 214 raise Error("SDK version too old (current: %d.%d, required: %d.%d)" | 214 raise Error("SDK version too old (current: %d.%d, required: %d.%d)" |
| 215 % (version[0], version[1], required_version[0], required_version[1])) | 215 % (version[0], version[1], required_version[0], required_version[1])) |
| 216 | 216 |
| 217 | 217 |
| 218 def main(args): | 218 def main(args): |
| 219 parser = optparse.OptionParser() | 219 parser = argparse.ArgumentParser() |
| 220 parser.add_option('--arch', action='store_true', | 220 parser.add_argument('--arch', action='store_true', |
| 221 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).') |
| 222 parser.add_option('--chrome', action='store_true', | 222 parser.add_argument('--chrome', action='store_true', |
| 223 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 ' |
| 224 'then $PATH).') | 224 'then $PATH).') |
| 225 parser.add_option('--nacl-arch', action='store_true', | 225 parser.add_argument('--nacl-arch', action='store_true', |
| 226 help='Print architecture used by NaCl on the current machine.') | 226 help='Print architecture used by NaCl on the current machine.') |
| 227 parser.add_option('--sdk-version', action='store_true', | 227 parser.add_argument('--sdk-version', action='store_true', |
| 228 help='Print major version of the NaCl SDK.') | 228 help='Print major version of the NaCl SDK.') |
| 229 parser.add_option('--sdk-revision', action='store_true', | 229 parser.add_argument('--sdk-revision', action='store_true', |
| 230 help='Print revision number of the NaCl SDK.') | 230 help='Print revision number of the NaCl SDK.') |
| 231 parser.add_option('--sdk-commit-position', action='store_true', | 231 parser.add_argument('--sdk-commit-position', action='store_true', |
| 232 help='Print commit position of the NaCl SDK.') | 232 help='Print commit position of the NaCl SDK.') |
| 233 parser.add_option('--check-version', | 233 parser.add_argument('--check-version', |
| 234 metavar='MAJOR.POSITION', | 234 metavar='MAJOR.POSITION', |
| 235 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 ' |
| 236 'version passed in. MAJOR is the major version number and POSITION ' | 236 'version passed in. MAJOR is the major version number and POSITION ' |
| 237 'is the Cr-Commit-Position number.') | 237 'is the Cr-Commit-Position number.') |
| 238 | 238 |
| 239 options, _ = parser.parse_args(args) | 239 if len(args) > 1: |
| 240 parser.error('Only one option can be specified at a time.') |
| 241 |
| 242 options = parser.parse_args(args) |
| 240 | 243 |
| 241 platform = GetPlatform() | 244 platform = GetPlatform() |
| 242 | 245 |
| 243 if len(args) > 1: | |
| 244 parser.error('Only one option can be specified at a time.') | |
| 245 | |
| 246 if not args: | |
| 247 print platform | |
| 248 return 0 | |
| 249 | |
| 250 if options.arch: | 246 if options.arch: |
| 251 out = GetSystemArch(platform) | 247 out = GetSystemArch(platform) |
| 252 elif options.nacl_arch: | 248 elif options.nacl_arch: |
| 253 out = GetNaClArch(platform) | 249 out = GetNaClArch(platform) |
| 254 elif options.chrome: | 250 elif options.chrome: |
| 255 out = GetChromePath(platform) | 251 out = GetChromePath(platform) |
| 256 elif options.sdk_version: | 252 elif options.sdk_version: |
| 257 out = GetSDKVersion()[0] | 253 out = GetSDKVersion()[0] |
| 258 elif options.sdk_revision: | 254 elif options.sdk_revision: |
| 259 out = GetSDKVersion()[1] | 255 out = GetSDKVersion()[1] |
| 260 elif options.sdk_commit_position: | 256 elif options.sdk_commit_position: |
| 261 out = GetSDKVersion()[2] | 257 out = GetSDKVersion()[2] |
| 262 elif options.check_version: | 258 elif options.check_version: |
| 263 required_version = ParseVersion(options.check_version) | 259 required_version = ParseVersion(options.check_version) |
| 264 CheckVersion(required_version) | 260 CheckVersion(required_version) |
| 265 out = None | 261 out = None |
| 262 else: |
| 263 out = platform |
| 266 | 264 |
| 267 if out: | 265 if out: |
| 268 print out | 266 print out |
| 269 return 0 | 267 return 0 |
| 270 | 268 |
| 271 | 269 |
| 272 if __name__ == '__main__': | 270 if __name__ == '__main__': |
| 273 try: | 271 try: |
| 274 sys.exit(main(sys.argv[1:])) | 272 sys.exit(main(sys.argv[1:])) |
| 275 except Error as e: | 273 except Error as e: |
| 276 sys.stderr.write(str(e) + '\n') | 274 sys.stderr.write(str(e) + '\n') |
| 277 sys.exit(1) | 275 sys.exit(1) |
| OLD | NEW |