2012-07-28 01:31:03 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
"""Prints the lowest locally available SDK version greater than or equal to a
|
2016-10-14 00:34:45 +03:00
|
|
|
given minimum sdk version to standard output. If --developer_dir is passed, then
|
|
|
|
the script will use the Xcode toolchain located at DEVELOPER_DIR.
|
2012-07-28 01:31:03 +04:00
|
|
|
|
|
|
|
Usage:
|
2016-10-14 00:34:45 +03:00
|
|
|
python find_sdk.py [--developer_dir DEVELOPER_DIR] 10.6 # Ignores SDKs < 10.6
|
2012-07-28 01:31:03 +04:00
|
|
|
"""
|
|
|
|
|
2014-09-04 17:57:07 +04:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2012-08-23 01:45:59 +04:00
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
|
2012-07-28 01:31:03 +04:00
|
|
|
def parse_version(version_str):
|
|
|
|
"""'10.6' => [10, 6]"""
|
|
|
|
return map(int, re.findall(r'(\d+)', version_str))
|
|
|
|
|
|
|
|
|
2012-08-23 01:45:59 +04:00
|
|
|
def main():
|
|
|
|
parser = OptionParser()
|
|
|
|
parser.add_option("--verify",
|
|
|
|
action="store_true", dest="verify", default=False,
|
|
|
|
help="return the sdk argument and warn if it doesn't exist")
|
2012-10-06 04:46:29 +04:00
|
|
|
parser.add_option("--sdk_path",
|
|
|
|
action="store", type="string", dest="sdk_path", default="",
|
|
|
|
help="user-specified SDK path; bypasses verification")
|
2014-01-17 05:05:20 +04:00
|
|
|
parser.add_option("--print_sdk_path",
|
|
|
|
action="store_true", dest="print_sdk_path", default=False,
|
|
|
|
help="Additionaly print the path the SDK (appears first).")
|
2016-10-14 00:34:45 +03:00
|
|
|
parser.add_option("--developer_dir", help='Path to Xcode.')
|
2015-08-04 21:51:45 +03:00
|
|
|
options, args = parser.parse_args()
|
|
|
|
if len(args) != 1:
|
|
|
|
parser.error('Please specify a minimum SDK version')
|
2012-08-23 01:45:59 +04:00
|
|
|
min_sdk_version = args[0]
|
|
|
|
|
2016-10-14 00:34:45 +03:00
|
|
|
if options.developer_dir:
|
|
|
|
os.environ['DEVELOPER_DIR'] = options.developer_dir
|
2016-03-31 01:08:05 +03:00
|
|
|
|
2012-07-28 01:31:03 +04:00
|
|
|
job = subprocess.Popen(['xcode-select', '-print-path'],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT)
|
|
|
|
out, err = job.communicate()
|
|
|
|
if job.returncode != 0:
|
2014-09-04 17:57:07 +04:00
|
|
|
print >> sys.stderr, out
|
|
|
|
print >> sys.stderr, err
|
2016-05-19 01:00:06 +03:00
|
|
|
raise Exception('Error %d running xcode-select' % job.returncode)
|
|
|
|
sdk_dir = os.path.join(
|
2012-07-28 01:31:03 +04:00
|
|
|
out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs')
|
|
|
|
sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)]
|
|
|
|
sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6']
|
|
|
|
sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6']
|
|
|
|
if parse_version(s) >= parse_version(min_sdk_version)]
|
|
|
|
if not sdks:
|
|
|
|
raise Exception('No %s+ SDK found' % min_sdk_version)
|
2012-08-23 01:45:59 +04:00
|
|
|
best_sdk = sorted(sdks, key=parse_version)[0]
|
|
|
|
|
2012-10-06 04:46:29 +04:00
|
|
|
if options.verify and best_sdk != min_sdk_version and not options.sdk_path:
|
2014-09-04 17:57:07 +04:00
|
|
|
print >> sys.stderr, ''
|
|
|
|
print >> sys.stderr, ' vvvvvvv'
|
|
|
|
print >> sys.stderr, ''
|
|
|
|
print >> sys.stderr, \
|
2012-08-23 01:45:59 +04:00
|
|
|
'This build requires the %s SDK, but it was not found on your system.' \
|
|
|
|
% min_sdk_version
|
2014-09-04 17:57:07 +04:00
|
|
|
print >> sys.stderr, \
|
2012-08-23 01:45:59 +04:00
|
|
|
'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.'
|
2014-09-04 17:57:07 +04:00
|
|
|
print >> sys.stderr, ''
|
|
|
|
print >> sys.stderr, ' ^^^^^^^'
|
|
|
|
print >> sys.stderr, ''
|
2016-08-09 05:21:31 +03:00
|
|
|
sys.exit(1)
|
2012-08-23 01:45:59 +04:00
|
|
|
|
2014-01-17 05:05:20 +04:00
|
|
|
if options.print_sdk_path:
|
2016-05-19 01:00:06 +03:00
|
|
|
print subprocess.check_output(
|
|
|
|
['xcrun', '-sdk', 'macosx' + best_sdk, '--show-sdk-path']).strip()
|
2014-01-17 05:05:20 +04:00
|
|
|
|
2012-08-23 01:45:59 +04:00
|
|
|
return best_sdk
|
2012-07-28 01:31:03 +04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if sys.platform != 'darwin':
|
|
|
|
raise Exception("This script only runs on Mac")
|
2012-08-23 01:45:59 +04:00
|
|
|
print main()
|
2015-08-04 21:51:45 +03:00
|
|
|
sys.exit(0)
|