|
5 | 5 | import argparse
|
6 | 6 | import errno
|
7 | 7 | import os
|
| 8 | +import shutil |
8 | 9 | import subprocess
|
9 | 10 | import sys
|
10 | 11 |
|
11 |
| -sys.path.insert(1, '../../build') |
| 12 | +sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) |
12 | 13 | from pyutil.file_util import symlink
|
13 | 14 |
|
14 |
| -# This script returns the path to the SDK of the given type. Pass the type of |
15 |
| -# SDK you want, which is typically 'iphone' or 'iphonesimulator'. |
| 15 | +# This script creates symlinks under flutter/prebuilts to the iphone and |
| 16 | +# iphone simulator SDKs. |
| 17 | + |
| 18 | +SDKs = ['iphoneos', 'iphonesimulator'] |
| 19 | + |
| 20 | +PREBUILTS = os.path.realpath(os.path.join( |
| 21 | + os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, 'flutter', 'prebuilts', |
| 22 | +)) |
16 | 23 |
|
17 | 24 | def main(argv):
|
18 | 25 | parser = argparse.ArgumentParser()
|
19 |
| - parser.add_argument('--symlink', |
20 |
| - help='Whether to create a symlink in the buildroot to the SDK.') |
21 |
| - parser.add_argument('--sdk', |
22 |
| - choices=['iphoneos', 'iphonesimulator'], |
23 |
| - help='Which SDK to find.') |
| 26 | + parser.add_argument( |
| 27 | + '--as-gclient-hook', |
| 28 | + default=False, |
| 29 | + action='store_true', |
| 30 | + help='Whether the script is running as a gclient hook.', |
| 31 | + ) |
| 32 | + parser.add_argument( |
| 33 | + '--symlink', |
| 34 | + type=str, |
| 35 | + help='Whether to create a symlink in the buildroot to the SDK.', |
| 36 | + ) |
| 37 | + parser.add_argument( |
| 38 | + '--sdk', |
| 39 | + choices=['iphoneos', 'iphonesimulator'], |
| 40 | + help='Which SDK to find.', |
| 41 | + ) |
24 | 42 | args = parser.parse_args()
|
25 | 43 |
|
26 |
| - command = [ |
27 |
| - 'xcodebuild', |
28 |
| - '-version', |
29 |
| - '-sdk', |
30 |
| - args.sdk, |
31 |
| - 'Path' |
32 |
| - ] |
33 |
| - |
34 |
| - sdk_output = subprocess.check_output(command).decode('utf-8').strip() |
35 |
| - if args.symlink: |
36 |
| - symlink_target = os.path.join(args.symlink, 'SDKs', os.path.basename(sdk_output)) |
37 |
| - symlink(sdk_output, symlink_target) |
38 |
| - frameworks_location = os.path.join(sdk_output, '..', '..', 'Library', 'Frameworks') |
39 |
| - frameworks_symlink = os.path.join(args.symlink, 'Library', 'Frameworks') |
40 |
| - symlink(frameworks_location, frameworks_symlink) |
41 |
| - |
42 |
| - sdk_output = symlink_target |
43 |
| - |
44 |
| - print(sdk_output) |
| 44 | + # On CI, Xcode is not yet installed when gclient hooks are being run. |
| 45 | + # This is because the version of Xcode that CI installs might depend on the |
| 46 | + # contents of the repo, so the repo must be set up first, which includes |
| 47 | + # running the gclient hooks. Instead, on CI, this script will be run during |
| 48 | + # GN. |
| 49 | + running_on_luci = os.environ.get('LUCI_CONTEXT') is not None |
| 50 | + if running_on_luci and args.as_gclient_hook: |
| 51 | + return 0 |
| 52 | + |
| 53 | + symlink_path = args.symlink |
| 54 | + if not running_on_luci and symlink_path is None: |
| 55 | + symlink_path = PREBUILTS |
| 56 | + |
| 57 | + sdks = [args.sdk] if args.sdk is not None else SDKs |
| 58 | + |
| 59 | + sdks_path = None |
| 60 | + libraries_path = None |
| 61 | + if symlink_path: |
| 62 | + sdks_path = os.path.join(symlink_path, 'SDKs') |
| 63 | + libraries_path = os.path.join(symlink_path, 'Library') |
| 64 | + # Remove any old files created by this script under PREBUILTS/SDKs. |
| 65 | + if args.as_gclient_hook: |
| 66 | + if os.path.isdir(sdks_path): |
| 67 | + shutil.rmtree(sdks_path) |
| 68 | + if os.path.isdir(libraries_path): |
| 69 | + shutil.rmtree(libraries_path) |
| 70 | + |
| 71 | + for sdk in sdks: |
| 72 | + command = [ |
| 73 | + 'xcodebuild', |
| 74 | + '-version', |
| 75 | + '-sdk', |
| 76 | + sdk, |
| 77 | + 'Path' |
| 78 | + ] |
| 79 | + sdk_output = subprocess.check_output(command).decode('utf-8').strip() |
| 80 | + if symlink_path: |
| 81 | + symlink_target = os.path.join(sdks_path, os.path.basename(sdk_output)) |
| 82 | + symlink(sdk_output, symlink_target) |
| 83 | + frameworks_location = os.path.join(sdk_output, '..', '..', 'Library', 'Frameworks') |
| 84 | + frameworks_symlink = os.path.join(libraries_path, 'Frameworks') |
| 85 | + symlink(frameworks_location, frameworks_symlink) |
| 86 | + sdk_output = symlink_target |
| 87 | + print(sdk_output) |
45 | 88 | return 0
|
46 | 89 |
|
| 90 | + |
47 | 91 | if __name__ == '__main__':
|
48 | 92 | if sys.platform != 'darwin':
|
49 | 93 | raise Exception('This script only runs on Mac')
|
|
0 commit comments