1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/build/mac/find_sdk.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +#!/usr/bin/env python 1.5 +# Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.6 +# Use of this source code is governed by a BSD-style license that can be 1.7 +# found in the LICENSE file. 1.8 + 1.9 +import os 1.10 +import re 1.11 +import subprocess 1.12 +import sys 1.13 + 1.14 +"""Prints the lowest locally available SDK version greater than or equal to a 1.15 +given minimum sdk version to standard output. 1.16 + 1.17 +Usage: 1.18 + python find_sdk.py 10.6 # Ignores SDKs < 10.6 1.19 +""" 1.20 + 1.21 +from optparse import OptionParser 1.22 + 1.23 + 1.24 +def parse_version(version_str): 1.25 + """'10.6' => [10, 6]""" 1.26 + return map(int, re.findall(r'(\d+)', version_str)) 1.27 + 1.28 + 1.29 +def main(): 1.30 + parser = OptionParser() 1.31 + parser.add_option("--verify", 1.32 + action="store_true", dest="verify", default=False, 1.33 + help="return the sdk argument and warn if it doesn't exist") 1.34 + parser.add_option("--sdk_path", 1.35 + action="store", type="string", dest="sdk_path", default="", 1.36 + help="user-specified SDK path; bypasses verification") 1.37 + (options, args) = parser.parse_args() 1.38 + min_sdk_version = args[0] 1.39 + 1.40 + if sys.platform == 'darwin': 1.41 + job = subprocess.Popen(['xcode-select', '-print-path'], 1.42 + stdout=subprocess.PIPE, 1.43 + stderr=subprocess.STDOUT) 1.44 + out, err = job.communicate() 1.45 + if job.returncode != 0: 1.46 + print >>sys.stderr, out 1.47 + print >>sys.stderr, err 1.48 + raise Exception(('Error %d running xcode-select, you might have to run ' 1.49 + '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| ' 1.50 + 'if you are using Xcode 4.') % job.returncode) 1.51 + # The Developer folder moved in Xcode 4.3. 1.52 + xcode43_sdk_path = os.path.join( 1.53 + out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') 1.54 + if os.path.isdir(xcode43_sdk_path): 1.55 + sdk_dir = xcode43_sdk_path 1.56 + else: 1.57 + sdk_dir = os.path.join(out.rstrip(), 'SDKs') 1.58 + sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)] 1.59 + sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6'] 1.60 + sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6'] 1.61 + if parse_version(s) >= parse_version(min_sdk_version)] 1.62 + if not sdks: 1.63 + raise Exception('No %s+ SDK found' % min_sdk_version) 1.64 + best_sdk = sorted(sdks, key=parse_version)[0] 1.65 + else: 1.66 + best_sdk = "" 1.67 + 1.68 + if options.verify and best_sdk != min_sdk_version and not options.sdk_path: 1.69 + print >>sys.stderr, '' 1.70 + print >>sys.stderr, ' vvvvvvv' 1.71 + print >>sys.stderr, '' 1.72 + print >>sys.stderr, \ 1.73 + 'This build requires the %s SDK, but it was not found on your system.' \ 1.74 + % min_sdk_version 1.75 + print >>sys.stderr, \ 1.76 + 'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.' 1.77 + print >>sys.stderr, '' 1.78 + print >>sys.stderr, ' ^^^^^^^' 1.79 + print >>sys.stderr, '' 1.80 + return min_sdk_version 1.81 + 1.82 + return best_sdk 1.83 + 1.84 + 1.85 +if __name__ == '__main__': 1.86 + print main()