| 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 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 | 6 """Prints the lowest locally available SDK version greater than or equal to a |
| 12 given minimum sdk version to standard output. | 7 given minimum sdk version to standard output. |
| 13 | 8 |
| 14 Usage: | 9 Usage: |
| 15 python find_sdk.py 10.6 # Ignores SDKs < 10.6 | 10 python find_sdk.py 10.6 # Ignores SDKs < 10.6 |
| 16 """ | 11 """ |
| 17 | 12 |
| 13 import os |
| 14 import re |
| 15 import subprocess |
| 16 import sys |
| 17 |
| 18 |
| 18 from optparse import OptionParser | 19 from optparse import OptionParser |
| 19 | 20 |
| 20 | 21 |
| 21 def parse_version(version_str): | 22 def parse_version(version_str): |
| 22 """'10.6' => [10, 6]""" | 23 """'10.6' => [10, 6]""" |
| 23 return map(int, re.findall(r'(\d+)', version_str)) | 24 return map(int, re.findall(r'(\d+)', version_str)) |
| 24 | 25 |
| 25 | 26 |
| 26 def main(): | 27 def main(): |
| 27 parser = OptionParser() | 28 parser = OptionParser() |
| 28 parser.add_option("--verify", | 29 parser.add_option("--verify", |
| 29 action="store_true", dest="verify", default=False, | 30 action="store_true", dest="verify", default=False, |
| 30 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") |
| 31 parser.add_option("--sdk_path", | 32 parser.add_option("--sdk_path", |
| 32 action="store", type="string", dest="sdk_path", default="", | 33 action="store", type="string", dest="sdk_path", default="", |
| 33 help="user-specified SDK path; bypasses verification") | 34 help="user-specified SDK path; bypasses verification") |
| 34 parser.add_option("--print_sdk_path", | 35 parser.add_option("--print_sdk_path", |
| 35 action="store_true", dest="print_sdk_path", default=False, | 36 action="store_true", dest="print_sdk_path", default=False, |
| 36 help="Additionaly print the path the SDK (appears first).") | 37 help="Additionaly print the path the SDK (appears first).") |
| 37 (options, args) = parser.parse_args() | 38 (options, args) = parser.parse_args() |
| 38 min_sdk_version = args[0] | 39 min_sdk_version = args[0] |
| 39 | 40 |
| 40 job = subprocess.Popen(['xcode-select', '-print-path'], | 41 job = subprocess.Popen(['xcode-select', '-print-path'], |
| 41 stdout=subprocess.PIPE, | 42 stdout=subprocess.PIPE, |
| 42 stderr=subprocess.STDOUT) | 43 stderr=subprocess.STDOUT) |
| 43 out, err = job.communicate() | 44 out, err = job.communicate() |
| 44 if job.returncode != 0: | 45 if job.returncode != 0: |
| 45 print >>sys.stderr, out | 46 print >> sys.stderr, out |
| 46 print >>sys.stderr, err | 47 print >> sys.stderr, err |
| 47 raise Exception(('Error %d running xcode-select, you might have to run ' | 48 raise Exception(('Error %d running xcode-select, you might have to run ' |
| 48 '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| ' | 49 '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| ' |
| 49 'if you are using Xcode 4.') % job.returncode) | 50 'if you are using Xcode 4.') % job.returncode) |
| 50 # The Developer folder moved in Xcode 4.3. | 51 # The Developer folder moved in Xcode 4.3. |
| 51 xcode43_sdk_path = os.path.join( | 52 xcode43_sdk_path = os.path.join( |
| 52 out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') | 53 out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') |
| 53 if os.path.isdir(xcode43_sdk_path): | 54 if os.path.isdir(xcode43_sdk_path): |
| 54 sdk_dir = xcode43_sdk_path | 55 sdk_dir = xcode43_sdk_path |
| 55 else: | 56 else: |
| 56 sdk_dir = os.path.join(out.rstrip(), 'SDKs') | 57 sdk_dir = os.path.join(out.rstrip(), 'SDKs') |
| 57 sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)] | 58 sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)] |
| 58 sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6'] | 59 sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6'] |
| 59 sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6'] | 60 sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6'] |
| 60 if parse_version(s) >= parse_version(min_sdk_version)] | 61 if parse_version(s) >= parse_version(min_sdk_version)] |
| 61 if not sdks: | 62 if not sdks: |
| 62 raise Exception('No %s+ SDK found' % min_sdk_version) | 63 raise Exception('No %s+ SDK found' % min_sdk_version) |
| 63 best_sdk = sorted(sdks, key=parse_version)[0] | 64 best_sdk = sorted(sdks, key=parse_version)[0] |
| 64 | 65 |
| 65 if options.verify and best_sdk != min_sdk_version and not options.sdk_path: | 66 if options.verify and best_sdk != min_sdk_version and not options.sdk_path: |
| 66 print >>sys.stderr, '' | 67 print >> sys.stderr, '' |
| 67 print >>sys.stderr, ' vvvvvvv' | 68 print >> sys.stderr, ' vvvvvvv' |
| 68 print >>sys.stderr, '' | 69 print >> sys.stderr, '' |
| 69 print >>sys.stderr, \ | 70 print >> sys.stderr, \ |
| 70 'This build requires the %s SDK, but it was not found on your system.' \ | 71 'This build requires the %s SDK, but it was not found on your system.' \ |
| 71 % min_sdk_version | 72 % min_sdk_version |
| 72 print >>sys.stderr, \ | 73 print >> sys.stderr, \ |
| 73 'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.' | 74 'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.' |
| 74 print >>sys.stderr, '' | 75 print >> sys.stderr, '' |
| 75 print >>sys.stderr, ' ^^^^^^^' | 76 print >> sys.stderr, ' ^^^^^^^' |
| 76 print >>sys.stderr, '' | 77 print >> sys.stderr, '' |
| 77 return min_sdk_version | 78 return min_sdk_version |
| 78 | 79 |
| 79 if options.print_sdk_path: | 80 if options.print_sdk_path: |
| 80 print subprocess.check_output(['xcodebuild', '-version', '-sdk', | 81 print subprocess.check_output(['xcodebuild', '-version', '-sdk', |
| 81 'macosx' + best_sdk, 'Path']).strip() | 82 'macosx' + best_sdk, 'Path']).strip() |
| 82 | 83 |
| 83 return best_sdk | 84 return best_sdk |
| 84 | 85 |
| 85 | 86 |
| 86 if __name__ == '__main__': | 87 if __name__ == '__main__': |
| 87 if sys.platform != 'darwin': | 88 if sys.platform != 'darwin': |
| 88 raise Exception("This script only runs on Mac") | 89 raise Exception("This script only runs on Mac") |
| 89 print main() | 90 print main() |
| OLD | NEW |