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