Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34f8df3

Browse files
authored
iOS,macOS: Merge iOS, macOS config (#167945)
Merges iOS and macOS configuration and SDK finder scripts: * //build/mac/find_sdk.py and //build/ios/config/ios_sdk.py merge to //build/mac/apple_sdk.py. * //build/config/ios/ios_sdk.gni and //build/config/mac/mac_sdk.gni merge to //build/config/apple/apple_sdk.gni. gn args for macOS are available on all builds with `host_os == "mac"`. gn args for iOS are available on builds where `is_ios` is true (in place of the existing conditional import logic). Merging the two allows us to check all Apple SDK-related variable for anything missing and run `apple_sdk.py` a maximum of once across all Apple platforms. * Adds `Platforms` directory to `//flutter/prebuilts`, which contains Apple platform symlinks for `iPhoneOS`, `iPhoneSimulator`, `MacOSX`. Adds `ios_device_platform_path`, `ios_simulator_platform_path`, `mac_platform_path` gn args to hold these paths. Adds logic to `//flutter/tools/gn` to locate these paths and prepopulate these args from them to avoid running the script as part of the build. These are used to link to Swift core libs for each platform where necessary, as well as (for tests) test frameworks and `.swiftmodule`s like XCTest.framework. * Eliminates `Library/Frameworks` symlink from `//flutter/prebuilts`. This path is a subdirectory of each of the platform directories above. It was used to populate `platform_frameworks_path` in `//flutter/shell/platform/darwin/ios/BUILD.gn` using sort of sketchy relative-path logic. Further, the existing logic for greating the link was buggy for runs of `ios_sdk.py` where the `--sdk` option was not specified (i.e. all runs where `--as-gclient-hook` were specified). Without this option, we cycle through both `iphoneos` and `iphonesimulator` SDKs, and since this symlink was written on each iteration through the `SDKs` list, it was always linked to the `Library/Frameworks` directory for the last item in the list: `iPhoneSimulator.platform`. The platform arg for the current build is now resolved to `ios_platform_path` from which we resolve `$ios_platform_path/Developer/Library/Frameworks`. A follow-up patch will refactor the iOS build file to extract an iOS test config that eliminates some of the unnecessary duplication of cc_flags, swiftflags, and ld_flags across targets. Issue: #167592 ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 69da944 commit 34f8df3

File tree

14 files changed

+418
-406
lines changed

14 files changed

+418
-406
lines changed

DEPS

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -984,31 +984,19 @@ hooks = [
984984
'terminal.x64,terminal.qemu-arm64',
985985
]
986986
},
987-
# The following two scripts check if they are running in the LUCI
988-
# environment, and do nothing if so. This is because Xcode is not yet
989-
# installed in CI when these hooks are run.
987+
# The following script checks if it is running in the LUCI environment,
988+
# and does nothing if so. This is because Xcode is not yet installed in CI
989+
# when this hook is run.
990990
{
991-
'name': 'Find the iOS device SDKs',
991+
'name': 'Find the iOS and macOS SDKs',
992992
'pattern': '.',
993993
'condition': 'host_os == "mac"',
994994
'action': [
995995
'python3',
996-
'engine/src/build/config/ios/ios_sdk.py',
997-
# This cleans up entries under flutter/prebuilts for this script and the
998-
# following script.
996+
'engine/src/build/mac/apple_sdk.py',
999997
'--as-gclient-hook'
1000998
]
1001999
},
1002-
{
1003-
'name': 'Find the macOS SDK',
1004-
'pattern': '.',
1005-
'condition': 'host_os == "mac"',
1006-
'action': [
1007-
'python3',
1008-
'engine/src/build/mac/find_sdk.py',
1009-
'--as-gclient-hook',
1010-
]
1011-
},
10121000
{
10131001
'name': 'Generate Fuchsia GN build rules',
10141002
'pattern': '.',

engine/src/build/config/BUILDCONFIG.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ if (custom_toolchain != "") {
570570
host_toolchain = "//build/toolchain/mac:clang_$host_cpu"
571571
set_default_toolchain("//build/toolchain/mac:clang_$current_cpu")
572572
} else if (is_ios) {
573-
import("//build/config/ios/ios_sdk.gni") # For use_ios_simulator
573+
import("//build/config/apple/apple_sdk.gni") # For use_ios_simulator
574574
host_toolchain = "//build/toolchain/mac:clang_$host_cpu"
575575
if (use_ios_simulator) {
576576
if (target_cpu == "arm64") {

engine/src/build/config/apple/apple_sdk.gni

Lines changed: 160 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,168 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5+
import("//build/toolchain/rbe.gni")
6+
7+
assert(host_os == "mac")
8+
9+
# Common args across all Apple platforms.
510
declare_args() {
6-
# Path to the Xcode toolchain (XcodeDefault.xctoolchain).
7-
apple_host_toolchain_path = ""
11+
# The MACOSX_DEPLOYMENT_TARGET variable used when compiling.
12+
# Must be of the form x.x.x for Info.plist files.
13+
mac_deployment_target = ""
14+
15+
# Path to the host Xcode toolchain (XcodeDefault.xctoolchain).
16+
mac_host_toolchain_path = ""
17+
18+
# Path to the macOS platform.
19+
mac_platform_path = ""
20+
21+
# Path to a specific version of the macOS SDK, not including a backslash at
22+
# the end.
23+
mac_sdk_path = ""
24+
}
25+
26+
# Must be set above or by gn.
27+
assert(mac_deployment_target != "")
28+
29+
if (is_ios) {
30+
# iOS-specific args.
31+
declare_args() {
32+
# Path to the iOS platform to use.
33+
#
34+
# When empty, this will use the default platform based on the value of
35+
# use_ios_simulator.
36+
ios_platform_path = ""
37+
38+
# Path to the iOS SDK to use.
39+
#
40+
# When empty this will use the default SDK based on the value of
41+
# use_ios_simulator.
42+
ios_sdk_path = ""
43+
44+
# Set to true when targeting a simulator build on iOS. False means that the
45+
# target is for running on the device. The default value is to use the
46+
# Simulator except when targeting GYP's Xcode builds (for compat with the
47+
# existing GYP build).
48+
use_ios_simulator = true
49+
50+
# Alias for use_ios_simulator used by Skia.
51+
ios_use_simulator = true
52+
53+
# Version of iOS that we're targeting.
54+
ios_deployment_target = "13.0"
55+
56+
# The path to the iOS device platform.
57+
ios_device_platform_path = ""
58+
59+
# The path to the iOS simulator platform.
60+
ios_simulator_platform_path = ""
61+
62+
# The path to the iOS device SDK.
63+
ios_device_sdk_path = ""
64+
65+
# The path to the iOS simulator SDK.
66+
ios_simulator_sdk_path = ""
67+
68+
# The path to iOS SDK Swift libraries.
69+
ios_swift_lib_paths = []
70+
71+
# Version of iOS that we're targeting for tests.
72+
ios_testing_deployment_target = "13.0"
73+
}
74+
75+
# Must be set above or by gn.
76+
assert(defined(use_ios_simulator))
77+
assert(defined(ios_use_simulator))
78+
assert(ios_deployment_target != "")
79+
assert(ios_testing_deployment_target != "")
80+
}
81+
82+
# Run apple_sdk.gni to determine SDK paths if necessary.
83+
_need_apple_sdk_run = false
84+
if (mac_host_toolchain_path == "" || #
85+
mac_sdk_path == "" || #
86+
mac_platform_path == "") {
87+
_need_apple_sdk_run = true
88+
}
89+
if (is_ios) {
90+
if (use_ios_simulator &&
91+
(ios_simulator_platform_path == "" || ios_simulator_sdk_path == "")) {
92+
_need_apple_sdk_run = true
93+
}
94+
if (!use_ios_simulator &&
95+
(ios_device_platform_path == "" || ios_device_sdk_path == "")) {
96+
_need_apple_sdk_run = true
97+
}
98+
}
99+
if (_need_apple_sdk_run) {
100+
_args = [ "--print-paths" ]
101+
if (use_rbe && create_xcode_symlinks) {
102+
# RBE has a restriction that paths cannot come from outside the build root.
103+
_args += [
104+
"--symlink",
105+
rebase_path("//flutter/prebuilts"),
106+
]
107+
}
108+
_sdk_result =
109+
exec_script(rebase_path("//build/mac/apple_sdk.py"), _args, "scope")
8110
}
9111

10-
if (apple_host_toolchain_path == "") {
11-
# Outputs the SDK path on the first line, and the host toolchain path on the
12-
# second.
13-
_find_sdk_lines =
14-
exec_script("//build/mac/find_sdk.py", ["--print_sdk_path", "1.0"], "list lines")
112+
# Set SDK paths.
113+
if (mac_host_toolchain_path == "") {
114+
mac_host_toolchain_path = _sdk_result.toolchain_path
115+
}
116+
assert(mac_host_toolchain_path != "")
117+
118+
if (mac_sdk_path == "") {
119+
mac_sdk_path = _sdk_result.macosx_sdk_path
120+
}
121+
assert(mac_sdk_path != "")
122+
123+
if (mac_platform_path == "") {
124+
mac_platform_path = _sdk_result.macosx_platform_path
125+
}
126+
assert(mac_platform_path != "")
127+
128+
if (is_ios) {
129+
if (ios_platform_path == "" || ios_sdk_path == "") {
130+
if (use_ios_simulator) {
131+
if (ios_simulator_platform_path == "") {
132+
ios_simulator_platform_path = _sdk_result.iphonesimulator_platform_path
133+
}
134+
if (ios_simulator_sdk_path == "") {
135+
ios_simulator_sdk_path = _sdk_result.iphonesimulator_sdk_path
136+
}
137+
} else {
138+
if (ios_device_platform_path == "") {
139+
ios_device_platform_path = _sdk_result.iphoneos_platform_path
140+
}
141+
if (ios_device_sdk_path == "") {
142+
ios_device_sdk_path = _sdk_result.iphoneos_sdk_path
143+
}
144+
}
145+
146+
if (use_ios_simulator) {
147+
assert(ios_simulator_platform_path != "")
148+
assert(ios_simulator_sdk_path != "")
149+
ios_platform_path = ios_simulator_platform_path
150+
ios_sdk_path = ios_simulator_sdk_path
151+
} else {
152+
assert(ios_device_platform_path != "")
153+
assert(ios_device_sdk_path != "")
154+
ios_platform_path = ios_device_platform_path
155+
ios_sdk_path = ios_device_sdk_path
156+
}
157+
}
15158

16-
apple_host_toolchain_path = _find_sdk_lines[1]
159+
if (ios_swift_lib_paths == []) {
160+
ios_swift_lib_paths += [ rebase_path("$ios_sdk_path/usr/lib/swift") ]
161+
if (use_ios_simulator) {
162+
ios_swift_lib_paths += [ rebase_path(
163+
"$mac_host_toolchain_path/usr/lib/swift/iphonesimulator") ]
164+
} else {
165+
ios_swift_lib_paths +=
166+
[ rebase_path("$mac_host_toolchain_path/usr/lib/swift/iphoneos") ]
167+
}
168+
}
17169
}

engine/src/build/config/ios/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ config("compiler") {
4949
_swift_version = "5"
5050

5151
# TODO(cbracken): https://github.com/flutter/flutter/issues/167592
52-
# Look up xcode_version in ios_sdk.gni/mac_sdk.gni.
52+
# Look up xcode_version in apple_sdk.gni
5353
#
5454
# This is here so that all files get recompiled after an Xcode update.
5555
# (defines are passed via the command line, and build system rebuild things

engine/src/build/config/ios/ios_sdk.gni

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)