Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michael@0 | 3 | # Use of this source code is governed by a BSD-style license that can be |
michael@0 | 4 | # found in the LICENSE file. |
michael@0 | 5 | |
michael@0 | 6 | import os |
michael@0 | 7 | import re |
michael@0 | 8 | import subprocess |
michael@0 | 9 | import sys |
michael@0 | 10 | |
michael@0 | 11 | """Prints the lowest locally available SDK version greater than or equal to a |
michael@0 | 12 | given minimum sdk version to standard output. |
michael@0 | 13 | |
michael@0 | 14 | Usage: |
michael@0 | 15 | python find_sdk.py 10.6 # Ignores SDKs < 10.6 |
michael@0 | 16 | """ |
michael@0 | 17 | |
michael@0 | 18 | from optparse import OptionParser |
michael@0 | 19 | |
michael@0 | 20 | |
michael@0 | 21 | def parse_version(version_str): |
michael@0 | 22 | """'10.6' => [10, 6]""" |
michael@0 | 23 | return map(int, re.findall(r'(\d+)', version_str)) |
michael@0 | 24 | |
michael@0 | 25 | |
michael@0 | 26 | def main(): |
michael@0 | 27 | parser = OptionParser() |
michael@0 | 28 | parser.add_option("--verify", |
michael@0 | 29 | action="store_true", dest="verify", default=False, |
michael@0 | 30 | help="return the sdk argument and warn if it doesn't exist") |
michael@0 | 31 | parser.add_option("--sdk_path", |
michael@0 | 32 | action="store", type="string", dest="sdk_path", default="", |
michael@0 | 33 | help="user-specified SDK path; bypasses verification") |
michael@0 | 34 | (options, args) = parser.parse_args() |
michael@0 | 35 | min_sdk_version = args[0] |
michael@0 | 36 | |
michael@0 | 37 | if sys.platform == 'darwin': |
michael@0 | 38 | job = subprocess.Popen(['xcode-select', '-print-path'], |
michael@0 | 39 | stdout=subprocess.PIPE, |
michael@0 | 40 | stderr=subprocess.STDOUT) |
michael@0 | 41 | out, err = job.communicate() |
michael@0 | 42 | if job.returncode != 0: |
michael@0 | 43 | print >>sys.stderr, out |
michael@0 | 44 | print >>sys.stderr, err |
michael@0 | 45 | raise Exception(('Error %d running xcode-select, you might have to run ' |
michael@0 | 46 | '|sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer| ' |
michael@0 | 47 | 'if you are using Xcode 4.') % job.returncode) |
michael@0 | 48 | # The Developer folder moved in Xcode 4.3. |
michael@0 | 49 | xcode43_sdk_path = os.path.join( |
michael@0 | 50 | out.rstrip(), 'Platforms/MacOSX.platform/Developer/SDKs') |
michael@0 | 51 | if os.path.isdir(xcode43_sdk_path): |
michael@0 | 52 | sdk_dir = xcode43_sdk_path |
michael@0 | 53 | else: |
michael@0 | 54 | sdk_dir = os.path.join(out.rstrip(), 'SDKs') |
michael@0 | 55 | sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)] |
michael@0 | 56 | sdks = [s[0] for s in sdks if s] # [['10.5'], ['10.6']] => ['10.5', '10.6'] |
michael@0 | 57 | sdks = [s for s in sdks # ['10.5', '10.6'] => ['10.6'] |
michael@0 | 58 | if parse_version(s) >= parse_version(min_sdk_version)] |
michael@0 | 59 | if not sdks: |
michael@0 | 60 | raise Exception('No %s+ SDK found' % min_sdk_version) |
michael@0 | 61 | best_sdk = sorted(sdks, key=parse_version)[0] |
michael@0 | 62 | else: |
michael@0 | 63 | best_sdk = "" |
michael@0 | 64 | |
michael@0 | 65 | if options.verify and best_sdk != min_sdk_version and not options.sdk_path: |
michael@0 | 66 | print >>sys.stderr, '' |
michael@0 | 67 | print >>sys.stderr, ' vvvvvvv' |
michael@0 | 68 | print >>sys.stderr, '' |
michael@0 | 69 | print >>sys.stderr, \ |
michael@0 | 70 | 'This build requires the %s SDK, but it was not found on your system.' \ |
michael@0 | 71 | % min_sdk_version |
michael@0 | 72 | print >>sys.stderr, \ |
michael@0 | 73 | 'Either install it, or explicitly set mac_sdk in your GYP_DEFINES.' |
michael@0 | 74 | print >>sys.stderr, '' |
michael@0 | 75 | print >>sys.stderr, ' ^^^^^^^' |
michael@0 | 76 | print >>sys.stderr, '' |
michael@0 | 77 | return min_sdk_version |
michael@0 | 78 | |
michael@0 | 79 | return best_sdk |
michael@0 | 80 | |
michael@0 | 81 | |
michael@0 | 82 | if __name__ == '__main__': |
michael@0 | 83 | print main() |