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 """Prints the lowest locally available SDK version greater than or equal to a | 6 """Prints the lowest locally available SDK version greater than or equal to a |
7 given minimum sdk version to standard output. | 7 given minimum sdk version to standard output. If --developer_dir is passed, then |
| 8 the script will use the Xcode toolchain located at DEVELOPER_DIR. |
8 | 9 |
9 Usage: | 10 Usage: |
10 python find_sdk.py 10.6 # Ignores SDKs < 10.6 | 11 python find_sdk.py [--developer_dir DEVELOPER_DIR] 10.6 # Ignores SDKs < 10.6 |
11 """ | 12 """ |
12 | 13 |
13 import os | 14 import os |
14 import re | 15 import re |
15 import subprocess | 16 import subprocess |
16 import sys | 17 import sys |
17 | 18 |
18 sys.path.append(os.path.dirname(os.path.dirname(__file__))) | |
19 import mac_toolchain | |
20 | |
21 from optparse import OptionParser | 19 from optparse import OptionParser |
22 | 20 |
23 | 21 |
24 def parse_version(version_str): | 22 def parse_version(version_str): |
25 """'10.6' => [10, 6]""" | 23 """'10.6' => [10, 6]""" |
26 return map(int, re.findall(r'(\d+)', version_str)) | 24 return map(int, re.findall(r'(\d+)', version_str)) |
27 | 25 |
28 | 26 |
29 def main(): | 27 def main(): |
30 parser = OptionParser() | 28 parser = OptionParser() |
31 parser.add_option("--verify", | 29 parser.add_option("--verify", |
32 action="store_true", dest="verify", default=False, | 30 action="store_true", dest="verify", default=False, |
33 help="return the sdk argument and warn if it doesn't exist") | 31 help="return the sdk argument and warn if it doesn't exist") |
34 parser.add_option("--sdk_path", | 32 parser.add_option("--sdk_path", |
35 action="store", type="string", dest="sdk_path", default="", | 33 action="store", type="string", dest="sdk_path", default="", |
36 help="user-specified SDK path; bypasses verification") | 34 help="user-specified SDK path; bypasses verification") |
37 parser.add_option("--print_sdk_path", | 35 parser.add_option("--print_sdk_path", |
38 action="store_true", dest="print_sdk_path", default=False, | 36 action="store_true", dest="print_sdk_path", default=False, |
39 help="Additionaly print the path the SDK (appears first).") | 37 help="Additionaly print the path the SDK (appears first).") |
| 38 parser.add_option("--developer_dir", help='Path to Xcode.') |
40 options, args = parser.parse_args() | 39 options, args = parser.parse_args() |
41 if len(args) != 1: | 40 if len(args) != 1: |
42 parser.error('Please specify a minimum SDK version') | 41 parser.error('Please specify a minimum SDK version') |
43 min_sdk_version = args[0] | 42 min_sdk_version = args[0] |
44 | 43 |
45 # Try using the toolchain in mac_files. | 44 if options.developer_dir: |
46 mac_toolchain.SetToolchainEnvironment() | 45 os.environ['DEVELOPER_DIR'] = options.developer_dir |
47 | 46 |
48 job = subprocess.Popen(['xcode-select', '-print-path'], | 47 job = subprocess.Popen(['xcode-select', '-print-path'], |
49 stdout=subprocess.PIPE, | 48 stdout=subprocess.PIPE, |
50 stderr=subprocess.STDOUT) | 49 stderr=subprocess.STDOUT) |
51 out, err = job.communicate() | 50 out, err = job.communicate() |
52 if job.returncode != 0: | 51 if job.returncode != 0: |
53 print >> sys.stderr, out | 52 print >> sys.stderr, out |
54 print >> sys.stderr, err | 53 print >> sys.stderr, err |
55 raise Exception('Error %d running xcode-select' % job.returncode) | 54 raise Exception('Error %d running xcode-select' % job.returncode) |
56 sdk_dir = os.path.join( | 55 sdk_dir = os.path.join( |
(...skipping 25 matching lines...) Expand all Loading... |
82 ['xcrun', '-sdk', 'macosx' + best_sdk, '--show-sdk-path']).strip() | 81 ['xcrun', '-sdk', 'macosx' + best_sdk, '--show-sdk-path']).strip() |
83 | 82 |
84 return best_sdk | 83 return best_sdk |
85 | 84 |
86 | 85 |
87 if __name__ == '__main__': | 86 if __name__ == '__main__': |
88 if sys.platform != 'darwin': | 87 if sys.platform != 'darwin': |
89 raise Exception("This script only runs on Mac") | 88 raise Exception("This script only runs on Mac") |
90 print main() | 89 print main() |
91 sys.exit(0) | 90 sys.exit(0) |
OLD | NEW |