| 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. |
| 8 | 8 |
| 9 Usage: | 9 Usage: |
| 10 python find_sdk.py 10.6 # Ignores SDKs < 10.6 | 10 python find_sdk.py 10.6 # Ignores SDKs < 10.6 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 # Try using the toolchain in mac_files. | 45 # Try using the toolchain in mac_files. |
| 46 mac_toolchain.SetToolchainEnvironment() | 46 mac_toolchain.SetToolchainEnvironment() |
| 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, you might have to run ' | 55 raise Exception('Error %d running xcode-select' % job.returncode) |
| 56 '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| ' | 56 sdk_dir = os.path.join( |
| 57 'if you are using Xcode 4.') % job.returncode) | |
| 58 # The Developer folder moved in Xcode 4.3. | |
| 59 xcode43_sdk_path = os.path.join( | |
| 60 out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') | 57 out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') |
| 61 if os.path.isdir(xcode43_sdk_path): | |
| 62 sdk_dir = xcode43_sdk_path | |
| 63 else: | |
| 64 sdk_dir = os.path.join(out.rstrip(), 'SDKs') | |
| 65 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)] |
| 66 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'] |
| 67 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'] |
| 68 if parse_version(s) >= parse_version(min_sdk_version)] | 61 if parse_version(s) >= parse_version(min_sdk_version)] |
| 69 if not sdks: | 62 if not sdks: |
| 70 raise Exception('No %s+ SDK found' % min_sdk_version) | 63 raise Exception('No %s+ SDK found' % min_sdk_version) |
| 71 best_sdk = sorted(sdks, key=parse_version)[0] | 64 best_sdk = sorted(sdks, key=parse_version)[0] |
| 72 | 65 |
| 73 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: |
| 74 print >> sys.stderr, '' | 67 print >> sys.stderr, '' |
| 75 print >> sys.stderr, ' vvvvvvv' | 68 print >> sys.stderr, ' vvvvvvv' |
| 76 print >> sys.stderr, '' | 69 print >> sys.stderr, '' |
| 77 print >> sys.stderr, \ | 70 print >> sys.stderr, \ |
| 78 '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.' \ |
| 79 % min_sdk_version | 72 % min_sdk_version |
| 80 print >> sys.stderr, \ | 73 print >> sys.stderr, \ |
| 81 '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.' |
| 82 print >> sys.stderr, '' | 75 print >> sys.stderr, '' |
| 83 print >> sys.stderr, ' ^^^^^^^' | 76 print >> sys.stderr, ' ^^^^^^^' |
| 84 print >> sys.stderr, '' | 77 print >> sys.stderr, '' |
| 85 return min_sdk_version | 78 return min_sdk_version |
| 86 | 79 |
| 87 if options.print_sdk_path: | 80 if options.print_sdk_path: |
| 88 print subprocess.check_output(['xcodebuild', '-version', '-sdk', | 81 print subprocess.check_output( |
| 89 'macosx' + best_sdk, 'Path']).strip() | 82 ['xcrun', '-sdk', 'macosx' + best_sdk, '--show-sdk-path']).strip() |
| 90 | 83 |
| 91 return best_sdk | 84 return best_sdk |
| 92 | 85 |
| 93 | 86 |
| 94 if __name__ == '__main__': | 87 if __name__ == '__main__': |
| 95 if sys.platform != 'darwin': | 88 if sys.platform != 'darwin': |
| 96 raise Exception("This script only runs on Mac") | 89 raise Exception("This script only runs on Mac") |
| 97 print main() | 90 print main() |
| 98 sys.exit(0) | 91 sys.exit(0) |
| OLD | NEW |