OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 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 |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import os |
| 7 import re |
| 8 import subprocess |
| 9 import sys |
| 10 |
| 11 """Prints the best locally available SDK version to standard output.""" |
| 12 |
| 13 def parse_version(version_str): |
| 14 """'10.6' => [10, 6]""" |
| 15 return map(int, re.findall(r'(\d+)', version_str)) |
| 16 |
| 17 |
| 18 def main(): |
| 19 job = subprocess.Popen(['xcode-select', '-print-path'], |
| 20 stdout=subprocess.PIPE, |
| 21 stderr=subprocess.STDOUT) |
| 22 out, err = job.communicate() |
| 23 if job.returncode != 0: |
| 24 print >>sys.stderr, out |
| 25 print >>sys.stderr, err |
| 26 raise Exception(('Error %d running xcode-select, you might have to run ' |
| 27 '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| ' |
| 28 'if you are using Xcode 4.') % job.returncode) |
| 29 # The Developer folder moved in Xcode 4.3. |
| 30 xcode43_sdk_path = os.path.join( |
| 31 out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') |
| 32 if os.path.isdir(xcode43_sdk_path): |
| 33 sdk_dir = xcode43_sdk_path |
| 34 else: |
| 35 sdk_dir = os.path.join(out.rstrip(), 'SDKs') |
| 36 sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)] |
| 37 sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6'] |
| 38 sdks = [s for s in sdks |
| 39 if parse_version(s) >= [10, 6]] # ['10.5', '10.6'] => ['10.6'] |
| 40 if not sdks: |
| 41 raise Exception('No 10.6+ SDK found') |
| 42 print sorted(sdks, key=parse_version)[0] |
| 43 |
| 44 |
| 45 if __name__ == '__main__': |
| 46 if sys.platform == 'darwin': |
| 47 main() |
OLD | NEW |