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 | 6 import os |
7 import re | 7 import re |
8 import subprocess | 8 import subprocess |
9 import sys | 9 import sys |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 def parse_version(version_str): | 21 def parse_version(version_str): |
22 """'10.6' => [10, 6]""" | 22 """'10.6' => [10, 6]""" |
23 return map(int, re.findall(r'(\d+)', version_str)) | 23 return map(int, re.findall(r'(\d+)', version_str)) |
24 | 24 |
25 | 25 |
26 def main(): | 26 def main(): |
27 parser = OptionParser() | 27 parser = OptionParser() |
28 parser.add_option("--verify", | 28 parser.add_option("--verify", |
29 action="store_true", dest="verify", default=False, | 29 action="store_true", dest="verify", default=False, |
30 help="return the sdk argument and warn if it doesn't exist") | 30 help="return the sdk argument and warn if it doesn't exist") |
31 parser.add_option("--sdk_path", | |
32 action="store", type="string", dest="sdk_path", default="", | |
33 help="user-specified SDK path; bypasses verification") | |
TVL
2012/10/05 21:18:35
it skips the warning at the end if best != min. b
| |
31 (options, args) = parser.parse_args() | 34 (options, args) = parser.parse_args() |
32 min_sdk_version = args[0] | 35 min_sdk_version = args[0] |
33 | 36 |
34 job = subprocess.Popen(['xcode-select', '-print-path'], | 37 job = subprocess.Popen(['xcode-select', '-print-path'], |
35 stdout=subprocess.PIPE, | 38 stdout=subprocess.PIPE, |
36 stderr=subprocess.STDOUT) | 39 stderr=subprocess.STDOUT) |
37 out, err = job.communicate() | 40 out, err = job.communicate() |
38 if job.returncode != 0: | 41 if job.returncode != 0: |
39 print >>sys.stderr, out | 42 print >>sys.stderr, out |
40 print >>sys.stderr, err | 43 print >>sys.stderr, err |
41 raise Exception(('Error %d running xcode-select, you might have to run ' | 44 raise Exception(('Error %d running xcode-select, you might have to run ' |
42 '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| ' | 45 '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| ' |
43 'if you are using Xcode 4.') % job.returncode) | 46 'if you are using Xcode 4.') % job.returncode) |
44 # The Developer folder moved in Xcode 4.3. | 47 # The Developer folder moved in Xcode 4.3. |
45 xcode43_sdk_path = os.path.join( | 48 xcode43_sdk_path = os.path.join( |
46 out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') | 49 out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') |
47 if os.path.isdir(xcode43_sdk_path): | 50 if os.path.isdir(xcode43_sdk_path): |
48 sdk_dir = xcode43_sdk_path | 51 sdk_dir = xcode43_sdk_path |
49 else: | 52 else: |
50 sdk_dir = os.path.join(out.rstrip(), 'SDKs') | 53 sdk_dir = os.path.join(out.rstrip(), 'SDKs') |
51 sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)] | 54 sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)] |
52 sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6'] | 55 sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6'] |
53 sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6'] | 56 sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6'] |
54 if parse_version(s) >= parse_version(min_sdk_version)] | 57 if parse_version(s) >= parse_version(min_sdk_version)] |
55 if not sdks: | 58 if not sdks: |
56 raise Exception('No %s+ SDK found' % min_sdk_version) | 59 raise Exception('No %s+ SDK found' % min_sdk_version) |
57 best_sdk = sorted(sdks, key=parse_version)[0] | 60 best_sdk = sorted(sdks, key=parse_version)[0] |
58 | 61 |
59 if options.verify and best_sdk != min_sdk_version: | 62 if options.verify and best_sdk != min_sdk_version and not options.sdk_path: |
60 print >>sys.stderr, '' | 63 print >>sys.stderr, '' |
61 print >>sys.stderr, ' vvvvvvv' | 64 print >>sys.stderr, ' vvvvvvv' |
62 print >>sys.stderr, '' | 65 print >>sys.stderr, '' |
63 print >>sys.stderr, \ | 66 print >>sys.stderr, \ |
64 'This build requires the %s SDK, but it was not found on your system.' \ | 67 'This build requires the %s SDK, but it was not found on your system.' \ |
65 % min_sdk_version | 68 % min_sdk_version |
66 print >>sys.stderr, \ | 69 print >>sys.stderr, \ |
67 'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.' | 70 'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.' |
68 print >>sys.stderr, '' | 71 print >>sys.stderr, '' |
69 print >>sys.stderr, ' ^^^^^^^' | 72 print >>sys.stderr, ' ^^^^^^^' |
70 print >>sys.stderr, '' | 73 print >>sys.stderr, '' |
71 return min_sdk_version | 74 return min_sdk_version |
72 | 75 |
73 return best_sdk | 76 return best_sdk |
74 | 77 |
75 | 78 |
76 if __name__ == '__main__': | 79 if __name__ == '__main__': |
77 if sys.platform != 'darwin': | 80 if sys.platform != 'darwin': |
78 raise Exception("This script only runs on Mac") | 81 raise Exception("This script only runs on Mac") |
79 print main() | 82 print main() |
OLD | NEW |