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 lowest locally available SDK version greater than or equal to a |
| 12 given minimum sdk version to standard output. |
| 13 |
| 14 Usage: |
| 15 python find_sdk.py 10.6 # Ignores SDKs < 10.6 |
| 16 """ |
| 17 |
| 18 def parse_version(version_str): |
| 19 """'10.6' => [10, 6]""" |
| 20 return map(int, re.findall(r'(\d+)', version_str)) |
| 21 |
| 22 |
| 23 def main(min_sdk_version): |
| 24 job = subprocess.Popen(['xcode-select', '-print-path'], |
| 25 stdout=subprocess.PIPE, |
| 26 stderr=subprocess.STDOUT) |
| 27 out, err = job.communicate() |
| 28 if job.returncode != 0: |
| 29 print >>sys.stderr, out |
| 30 print >>sys.stderr, err |
| 31 raise Exception(('Error %d running xcode-select, you might have to run ' |
| 32 '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| ' |
| 33 'if you are using Xcode 4.') % job.returncode) |
| 34 # The Developer folder moved in Xcode 4.3. |
| 35 xcode43_sdk_path = os.path.join( |
| 36 out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') |
| 37 if os.path.isdir(xcode43_sdk_path): |
| 38 sdk_dir = xcode43_sdk_path |
| 39 else: |
| 40 sdk_dir = os.path.join(out.rstrip(), 'SDKs') |
| 41 sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)] |
| 42 sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6'] |
| 43 sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6'] |
| 44 if parse_version(s) >= parse_version(min_sdk_version)] |
| 45 if not sdks: |
| 46 raise Exception('No %s+ SDK found' % min_sdk_version) |
| 47 print sorted(sdks, key=parse_version)[0] |
| 48 |
| 49 |
| 50 if __name__ == '__main__': |
| 51 if sys.platform != 'darwin': |
| 52 raise Exception("This script only runs on Mac") |
| 53 main(min_sdk_version=sys.argv[1]) |
OLD | NEW |