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. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 | 62 |
63 def GetSDKVersion(): | 63 def GetSDKVersion(): |
64 root = GetSDKPath() | 64 root = GetSDKPath() |
65 readme = os.path.join(root, "README") | 65 readme = os.path.join(root, "README") |
66 if not os.path.exists(readme): | 66 if not os.path.exists(readme): |
67 raise Error("README not found in SDK root: %s" % root) | 67 raise Error("README not found in SDK root: %s" % root) |
68 | 68 |
69 version = None | 69 version = None |
70 revision = None | 70 revision = None |
| 71 commit_position = None |
71 for line in open(readme): | 72 for line in open(readme): |
72 if ':' in line: | 73 if ':' in line: |
73 name, value = line.split(':', 1) | 74 name, value = line.split(':', 1) |
74 if name == "Version": | 75 if name == "Version": |
75 version = value.strip() | 76 version = value.strip() |
76 if name == "Chrome Revision": | 77 if name == "Chrome Revision": |
77 revision = value.strip() | 78 revision = value.strip() |
| 79 if name == "Chrome Commit Position": |
| 80 commit_position = value.strip() |
78 | 81 |
79 if revision == None or version == None: | 82 if revision is None or version is None or commit_position is None: |
80 raise Error("error parsing SDK README: %s" % readme) | 83 raise Error("error parsing SDK README: %s" % readme) |
81 | 84 |
82 try: | 85 try: |
83 version = int(version) | 86 version = int(version) |
84 except ValueError: | 87 except ValueError: |
85 raise Error("error parsing SDK README: %s" % readme) | 88 raise Error("error parsing SDK README: %s" % readme) |
86 | 89 |
87 return (version, revision) | 90 return (version, revision, commit_position) |
88 | 91 |
89 | 92 |
90 def GetSystemArch(platform): | 93 def GetSystemArch(platform): |
91 if platform == 'win': | 94 if platform == 'win': |
92 if UseWin64(): | 95 if UseWin64(): |
93 return 'x86_64' | 96 return 'x86_64' |
94 return 'x86_32' | 97 return 'x86_32' |
95 | 98 |
96 if platform in ['mac', 'linux']: | 99 if platform in ['mac', 'linux']: |
97 try: | 100 try: |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 help='Print architecture of current machine (x86_32, x86_64 or arm).') | 200 help='Print architecture of current machine (x86_32, x86_64 or arm).') |
198 parser.add_option('--chrome', action='store_true', | 201 parser.add_option('--chrome', action='store_true', |
199 help='Print the path chrome (by first looking in $CHROME_PATH and ' | 202 help='Print the path chrome (by first looking in $CHROME_PATH and ' |
200 'then $PATH).') | 203 'then $PATH).') |
201 parser.add_option('--nacl-arch', action='store_true', | 204 parser.add_option('--nacl-arch', action='store_true', |
202 help='Print architecture used by NaCl on the current machine.') | 205 help='Print architecture used by NaCl on the current machine.') |
203 parser.add_option('--sdk-version', action='store_true', | 206 parser.add_option('--sdk-version', action='store_true', |
204 help='Print major version of the NaCl SDK.') | 207 help='Print major version of the NaCl SDK.') |
205 parser.add_option('--sdk-revision', action='store_true', | 208 parser.add_option('--sdk-revision', action='store_true', |
206 help='Print revision number of the NaCl SDK.') | 209 help='Print revision number of the NaCl SDK.') |
| 210 parser.add_option('--sdk-commit-position', action='store_true', |
| 211 help='Print commit position of the NaCl SDK.') |
207 parser.add_option('--check-version', | 212 parser.add_option('--check-version', |
208 help='Check that the SDK version is at least as great as the ' | 213 help='Check that the SDK version is at least as great as the ' |
209 'version passed in.') | 214 'version passed in.') |
210 | 215 |
211 options, _ = parser.parse_args(args) | 216 options, _ = parser.parse_args(args) |
212 | 217 |
213 platform = GetPlatform() | 218 platform = GetPlatform() |
214 | 219 |
215 if len(args) > 1: | 220 if len(args) > 1: |
216 parser.error('Only one option can be specified at a time.') | 221 parser.error('Only one option can be specified at a time.') |
217 | 222 |
218 if not args: | 223 if not args: |
219 print platform | 224 print platform |
220 return 0 | 225 return 0 |
221 | 226 |
222 if options.arch: | 227 if options.arch: |
223 out = GetSystemArch(platform) | 228 out = GetSystemArch(platform) |
224 elif options.nacl_arch: | 229 elif options.nacl_arch: |
225 out = GetNaClArch(platform) | 230 out = GetNaClArch(platform) |
226 elif options.chrome: | 231 elif options.chrome: |
227 out = GetChromePath(platform) | 232 out = GetChromePath(platform) |
228 elif options.sdk_version: | 233 elif options.sdk_version: |
229 out = GetSDKVersion()[0] | 234 out = GetSDKVersion()[0] |
230 elif options.sdk_revision: | 235 elif options.sdk_revision: |
231 out = GetSDKVersion()[1] | 236 out = GetSDKVersion()[1] |
| 237 elif options.sdk_commit_position: |
| 238 out = GetSDKVersion()[2] |
232 elif options.check_version: | 239 elif options.check_version: |
233 required_version = ParseVersion(options.check_version) | 240 required_version = ParseVersion(options.check_version) |
234 version = GetSDKVersion() | 241 version = GetSDKVersion() |
235 # We currently ignore the revision and just check the major version number. | 242 # We currently ignore the revision and just check the major version number. |
236 # Currently, version[1] is just a Git hash, which cannot be compared. | 243 # Currently, version[1] is just a Git hash, which cannot be compared. |
237 # TODO(mgiuca): Compare the minor revision numbers (which should be | 244 # TODO(mgiuca): Compare the minor revision numbers (which should be |
238 # Cr-Commit-Position values), when http://crbug.com/406783 is fixed. | 245 # Cr-Commit-Position values), when http://crbug.com/406783 is fixed. |
239 # Then Cr-Commit-Position should be available: see http://crbug.com/406993. | 246 # Then Cr-Commit-Position should be available: see http://crbug.com/406993. |
240 if version[0] < required_version[0]: | 247 if version[0] < required_version[0]: |
241 raise Error("SDK version too old (current: %s, required: %s)" | 248 raise Error("SDK version too old (current: %s, required: %s)" |
242 % (version[0], required_version[0])) | 249 % (version[0], required_version[0])) |
243 out = None | 250 out = None |
244 | 251 |
245 if out: | 252 if out: |
246 print out | 253 print out |
247 return 0 | 254 return 0 |
248 | 255 |
249 | 256 |
250 if __name__ == '__main__': | 257 if __name__ == '__main__': |
251 try: | 258 try: |
252 sys.exit(main(sys.argv[1:])) | 259 sys.exit(main(sys.argv[1:])) |
253 except Error as e: | 260 except Error as e: |
254 sys.stderr.write(str(e) + '\n') | 261 sys.stderr.write(str(e) + '\n') |
255 sys.exit(1) | 262 sys.exit(1) |
OLD | NEW |