media/webrtc/trunk/build/mac/find_sdk.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 #!/usr/bin/env python
     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
     4 # found in the LICENSE file.
     6 import os
     7 import re
     8 import subprocess
     9 import sys
    11 """Prints the lowest locally available SDK version greater than or equal to a
    12 given minimum sdk version to standard output.
    14 Usage:
    15   python find_sdk.py 10.6  # Ignores SDKs < 10.6
    16 """
    18 from optparse import OptionParser
    21 def parse_version(version_str):
    22   """'10.6' => [10, 6]"""
    23   return map(int, re.findall(r'(\d+)', version_str))
    26 def main():
    27   parser = OptionParser()
    28   parser.add_option("--verify",
    29                     action="store_true", dest="verify", default=False,
    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")
    34   (options, args) = parser.parse_args()
    35   min_sdk_version = args[0]
    37   if sys.platform == 'darwin':
    38     job = subprocess.Popen(['xcode-select', '-print-path'],
    39                            stdout=subprocess.PIPE,
    40                            stderr=subprocess.STDOUT)
    41     out, err = job.communicate()
    42     if job.returncode != 0:
    43       print >>sys.stderr, out
    44       print >>sys.stderr, err
    45       raise Exception(('Error %d running xcode-select, you might have to run '
    46                        '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| '
    47                        'if you are using Xcode 4.') % job.returncode)
    48     # The Developer folder moved in Xcode 4.3.
    49     xcode43_sdk_path = os.path.join(
    50       out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs')
    51     if os.path.isdir(xcode43_sdk_path):
    52       sdk_dir = xcode43_sdk_path
    53     else:
    54       sdk_dir = os.path.join(out.rstrip(), 'SDKs')
    55     sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)]
    56     sdks = [s[0] for s in sdks if s]  # [['10.5'], ['10.6']] => ['10.5', '10.6']
    57     sdks = [s for s in sdks  # ['10.5', '10.6'] => ['10.6']
    58             if parse_version(s) >= parse_version(min_sdk_version)]
    59     if not sdks:
    60       raise Exception('No %s+ SDK found' % min_sdk_version)
    61     best_sdk = sorted(sdks, key=parse_version)[0]
    62   else:
    63     best_sdk = ""
    65   if options.verify and best_sdk != min_sdk_version and not options.sdk_path:
    66     print >>sys.stderr, ''
    67     print >>sys.stderr, '                                           vvvvvvv'
    68     print >>sys.stderr, ''
    69     print >>sys.stderr, \
    70         'This build requires the %s SDK, but it was not found on your system.' \
    71         % min_sdk_version
    72     print >>sys.stderr, \
    73         'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.'
    74     print >>sys.stderr, ''
    75     print >>sys.stderr, '                                           ^^^^^^^'
    76     print >>sys.stderr, ''
    77     return min_sdk_version
    79   return best_sdk
    82 if __name__ == '__main__':
    83   print main()

mercurial