Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(901)

Side by Side Diff: tools/gyp/find_mac_sdk.py

Issue 12672003: Use the lowest MacOS SDK available on a system (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gyp/common.gypi ('k') | tools/gyp/xcode.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
ahe 2013/03/20 10:50:03 Something fishy with the copyrights in this file.
kustermann 2013/03/21 08:43:00 Well, as you can see on line 10 this file was copi
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
7 # for details. All rights reserved. Use of this source code is governed by a
8 # BSD-style license that can be found in the LICENSE file.
9
10 # This file is a copy of Chromium's src/build/mac/find_sdk.py.
11 # Revision 180337.
12
13 import os
14 import re
15 import subprocess
16 import sys
17
18 """Prints the lowest locally available SDK version greater than or equal to a
19 given minimum sdk version to standard output.
20
21 Usage:
22 python find_sdk.py 10.6 # Ignores SDKs < 10.6
23 """
24
25 from optparse import OptionParser
26
27
28 def parse_version(version_str):
29 """'10.6' => [10, 6]"""
30 return map(int, re.findall(r'(\d+)', version_str))
31
32
33 def main():
34 parser = OptionParser()
35 parser.add_option("--verify",
36 action="store_true", dest="verify", default=False,
37 help="return the sdk argument and warn if it doesn't exist")
38 parser.add_option("--sdk_path",
39 action="store", type="string", dest="sdk_path", default="",
40 help="user-specified SDK path; bypasses verification")
41 (options, args) = parser.parse_args()
42 min_sdk_version = args[0]
43
44 job = subprocess.Popen(['xcode-select', '-print-path'],
45 stdout=subprocess.PIPE,
46 stderr=subprocess.STDOUT)
47 out, err = job.communicate()
48 if job.returncode != 0:
49 print >>sys.stderr, out
50 print >>sys.stderr, err
51 raise Exception(('Error %d running xcode-select, you might have to run '
52 '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| '
53 'if you are using Xcode 4.') % job.returncode)
54 # The Developer folder moved in Xcode 4.3.
55 xcode43_sdk_path = os.path.join(
56 out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs')
57 if os.path.isdir(xcode43_sdk_path):
58 sdk_dir = xcode43_sdk_path
59 else:
60 sdk_dir = os.path.join(out.rstrip(), 'SDKs')
61 sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)]
62 sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6']
63 sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6']
64 if parse_version(s) >= parse_version(min_sdk_version)]
65 if not sdks:
66 raise Exception('No %s+ SDK found' % min_sdk_version)
67 best_sdk = sorted(sdks, key=parse_version)[0]
68
69 if options.verify and best_sdk != min_sdk_version and not options.sdk_path:
70 print >>sys.stderr, ''
71 print >>sys.stderr, ' vvvvvvv'
72 print >>sys.stderr, ''
73 print >>sys.stderr, \
74 'This build requires the %s SDK, but it was not found on your system.' \
75 % min_sdk_version
76 print >>sys.stderr, \
77 'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.'
78 print >>sys.stderr, ''
79 print >>sys.stderr, ' ^^^^^^^'
80 print >>sys.stderr, ''
81 return min_sdk_version
82
83 return best_sdk
84
85
86 if __name__ == '__main__':
87 if sys.platform != 'darwin':
88 raise Exception("This script only runs on Mac")
89 print main()
OLDNEW
« no previous file with comments | « tools/gyp/common.gypi ('k') | tools/gyp/xcode.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698