Skip to content

Commit ebc2748

Browse files
authored
Fixes to run apple SDK finders as gclient hooks (#825)
Supports flutter/engine#50957
1 parent 7b537de commit ebc2748

File tree

4 files changed

+102
-59
lines changed

4 files changed

+102
-59
lines changed

build/config/ios/ios_sdk.gni

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ if (ios_sdk_path == "") {
5656
ios_simulator_sdk_path = _ios_sim_sdk_result[0]
5757
}
5858

59-
# Compute default target.
6059
if (use_ios_simulator) {
6160
assert(ios_simulator_sdk_path != "")
6261
ios_sdk_path = ios_simulator_sdk_path

build/config/ios/ios_sdk.py

+71-27
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,89 @@
55
import argparse
66
import errno
77
import os
8+
import shutil
89
import subprocess
910
import sys
1011

11-
sys.path.insert(1, '../../build')
12+
sys.path.insert(1, os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
1213
from pyutil.file_util import symlink
1314

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+
))
1623

1724
def main(argv):
1825
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+
)
2442
args = parser.parse_args()
2543

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)
4588
return 0
4689

90+
4791
if __name__ == '__main__':
4892
if sys.platform != 'darwin':
4993
raise Exception('This script only runs on Mac')

build/config/mac/mac_sdk.gni

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,21 @@ import("//build/toolchain/rbe.gni")
77

88
declare_args() {
99
# Minimum supported version of the Mac SDK.
10-
mac_sdk_min = "10.14"
10+
mac_sdk_min = ""
1111

1212
# The MACOSX_DEPLOYMENT_TARGET variable used when compiling.
1313
# Must be of the form x.x.x for Info.plist files.
14-
mac_deployment_target = "10.14.0"
14+
mac_deployment_target = ""
1515

1616
# Path to a specific version of the Mac SDK, not including a backslash at
1717
# the end. If empty, the path to the lowest version greater than or equal to
1818
# mac_sdk_min is used.
1919
mac_sdk_path = ""
2020
}
2121

22+
assert(mac_sdk_min != "")
23+
assert(mac_deployment_target != "")
24+
2225
if (mac_sdk_path == "") {
2326
find_sdk_args = []
2427
if ((use_goma || use_rbe) && create_xcode_symlinks) {

build/mac/find_sdk.py

+26-29
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
2323
from pyutil.file_util import symlink
2424

25+
PREBUILTS = os.path.realpath(os.path.join(
26+
os.path.dirname(__file__), os.pardir, os.pardir, 'flutter', 'prebuilts',
27+
))
2528

2629
def parse_version(version_str):
2730
"""'10.6' => [10, 6]"""
@@ -30,21 +33,31 @@ def parse_version(version_str):
3033

3134
def main():
3235
parser = OptionParser()
33-
parser.add_option("--verify",
34-
action="store_true", dest="verify", default=False,
35-
help="return the sdk argument and warn if it doesn't exist")
36-
parser.add_option("--sdk_path",
37-
action="store", type="string", dest="sdk_path", default="",
38-
help="user-specified SDK path; bypasses verification")
3936
parser.add_option("--print_sdk_path",
4037
action="store_true", dest="print_sdk_path", default=False,
4138
help="Additionaly print the path the SDK (appears first).")
39+
parser.add_option("--as-gclient-hook",
40+
action="store_true", dest="as_gclient_hook", default=False,
41+
help="Whether the script is running as a gclient hook.")
4242
parser.add_option("--symlink",
43-
action="store", type="string", dest="symlink", default="",
43+
action="store", type="string", dest="symlink",
4444
help="Whether to create a symlink in the buildroot to the SDK.")
4545
(options, args) = parser.parse_args()
4646
min_sdk_version = args[0]
4747

48+
# On CI, Xcode is not yet installed when gclient hooks are being run.
49+
# This is because the version of Xcode that CI installs might depend on the
50+
# contents of the repo, so the repo must be set up first, which includes
51+
# running the gclient hooks. Instead, on CI, this script will be run during
52+
# GN.
53+
running_on_luci = os.environ.get('LUCI_CONTEXT') is not None
54+
if running_on_luci and options.as_gclient_hook:
55+
return 0
56+
57+
symlink_path = options.symlink
58+
if not running_on_luci and symlink_path is None:
59+
symlink_path = PREBUILTS
60+
4861
job = subprocess.Popen(['xcode-select', '-print-path'],
4962
universal_newlines=True,
5063
stdout=subprocess.PIPE,
@@ -82,29 +95,13 @@ def main():
8295
print(sdk_json_output)
8396
raise Exception('No %s+ SDK found' % min_sdk_version)
8497

85-
if options.verify and best_sdk != min_sdk_version and not options.sdk_path:
86-
print(sdk_json_output)
87-
sys.stderr.writelines([
88-
'',
89-
' vvvvvvv',
90-
'',
91-
'This build requires the %s SDK, but it was not found on your system.' \
92-
% min_sdk_version,
93-
'Either install it, or explicitly set mac_sdk in your gn args.',
94-
'',
95-
' ^^^^^^^',
96-
''])
97-
return min_sdk_version
98-
99-
if options.symlink or options.print_sdk_path:
100-
if options.symlink:
101-
symlink_target = os.path.join(options.symlink, 'SDKs', os.path.basename(sdk_output))
102-
symlink(sdk_output, symlink_target)
103-
sdk_output = symlink_target
104-
105-
if options.print_sdk_path:
106-
print(sdk_output)
98+
if symlink_path:
99+
sdks_path = os.path.join(symlink_path, 'SDKs')
100+
symlink_target = os.path.join(sdks_path, os.path.basename(sdk_output))
101+
symlink(sdk_output, symlink_target)
102+
sdk_output = symlink_target
107103

104+
print(sdk_output)
108105
return best_sdk
109106

110107

0 commit comments

Comments
 (0)