Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
create_full_ios_framework.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright 2013 The Flutter Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# Generates and zip the ios flutter framework including the architecture
8# dependent snapshot.
9
10import argparse
11import os
12import platform
13import shutil
14import subprocess
15import sys
16
17from create_xcframework import create_xcframework # pylint: disable=import-error
18
19ARCH_SUBPATH = 'mac-arm64' if platform.processor() == 'arm' else 'mac-x64'
20DSYMUTIL = os.path.join(
21 os.path.dirname(__file__), '..', '..', 'buildtools', ARCH_SUBPATH, 'clang', 'bin', 'dsymutil'
22)
23
24buildroot_dir = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..', '..'))
25
26
27def main():
28 parser = argparse.ArgumentParser(
29 description=(
30 'Creates Flutter.framework, Flutter.xcframework and '
31 'copies architecture-dependent gen_snapshot binaries to output dir'
32 )
33 )
34
35 parser.add_argument('--dst', type=str, required=True)
36 parser.add_argument('--clang-dir', type=str, default='clang_x64')
37 parser.add_argument('--x64-out-dir', type=str)
38 parser.add_argument('--arm64-out-dir', type=str, required=True)
39 parser.add_argument('--simulator-x64-out-dir', type=str, required=True)
40 parser.add_argument('--simulator-arm64-out-dir', type=str, required=False)
41 parser.add_argument('--strip', action='store_true', default=False)
42 parser.add_argument('--dsym', action='store_true', default=False)
43
44 args = parser.parse_args()
45
46 dst = (args.dst if os.path.isabs(args.dst) else os.path.join(buildroot_dir, args.dst))
47
48 arm64_out_dir = (
49 args.arm64_out_dir
50 if os.path.isabs(args.arm64_out_dir) else os.path.join(buildroot_dir, args.arm64_out_dir)
51 )
52
53 x64_out_dir = None
54 if args.x64_out_dir:
55 x64_out_dir = (
56 args.x64_out_dir
57 if os.path.isabs(args.x64_out_dir) else os.path.join(buildroot_dir, args.x64_out_dir)
58 )
59
60 simulator_x64_out_dir = None
61 if args.simulator_x64_out_dir:
62 simulator_x64_out_dir = (
63 args.simulator_x64_out_dir if os.path.isabs(args.simulator_x64_out_dir) else
64 os.path.join(buildroot_dir, args.simulator_x64_out_dir)
65 )
66
67 framework = os.path.join(dst, 'Flutter.framework')
68 simulator_framework = os.path.join(dst, 'sim', 'Flutter.framework')
69 arm64_framework = os.path.join(arm64_out_dir, 'Flutter.framework')
70 simulator_x64_framework = os.path.join(simulator_x64_out_dir, 'Flutter.framework')
71
72 simulator_arm64_out_dir = None
73 if args.simulator_arm64_out_dir:
74 simulator_arm64_out_dir = (
75 args.simulator_arm64_out_dir if os.path.isabs(args.simulator_arm64_out_dir) else
76 os.path.join(buildroot_dir, args.simulator_arm64_out_dir)
77 )
78
79 if args.simulator_arm64_out_dir is not None:
80 simulator_arm64_framework = os.path.join(simulator_arm64_out_dir, 'Flutter.framework')
81
82 if not os.path.isdir(arm64_framework):
83 print('Cannot find iOS arm64 Framework at %s' % arm64_framework)
84 return 1
85
86 if not os.path.isdir(simulator_x64_framework):
87 print('Cannot find iOS x64 simulator Framework at %s' % simulator_framework)
88 return 1
89
90 if not os.path.isfile(DSYMUTIL):
91 print('Cannot find dsymutil at %s' % DSYMUTIL)
92 return 1
93
95 args, dst, framework, arm64_framework, simulator_framework, simulator_x64_framework,
96 simulator_arm64_framework
97 )
98
99 extension_safe_dst = os.path.join(dst, 'extension_safe')
101 args, extension_safe_dst, '%s_extension_safe' % arm64_out_dir,
102 '%s_extension_safe' % simulator_x64_out_dir, '%s_extension_safe' % simulator_arm64_out_dir
103 )
104
105 generate_gen_snapshot(args, dst, x64_out_dir, arm64_out_dir)
106 zip_archive(dst)
107 return 0
108
109def create_extension_safe_framework( # pylint: disable=too-many-arguments
110 args, dst, arm64_out_dir, simulator_x64_out_dir, simulator_arm64_out_dir
111):
112 framework = os.path.join(dst, 'Flutter.framework')
113 simulator_framework = os.path.join(dst, 'sim', 'Flutter.framework')
114 arm64_framework = os.path.join(arm64_out_dir, 'Flutter.framework')
115 simulator_x64_framework = os.path.join(simulator_x64_out_dir, 'Flutter.framework')
116 simulator_arm64_framework = os.path.join(simulator_arm64_out_dir, 'Flutter.framework')
117
118 if not os.path.isdir(arm64_framework):
119 print('Cannot find extension safe iOS arm64 Framework at %s' % arm64_framework)
120 return 1
121
122 if not os.path.isdir(simulator_x64_framework):
123 print('Cannot find extension safe iOS x64 simulator Framework at %s' % simulator_x64_framework)
124 return 1
125
127 args, dst, framework, arm64_framework, simulator_framework, simulator_x64_framework,
128 simulator_arm64_framework
129 )
130 return 0
131
132def create_framework( # pylint: disable=too-many-arguments
133 args, dst, framework, arm64_framework, simulator_framework,
134 simulator_x64_framework, simulator_arm64_framework
135):
136 arm64_dylib = os.path.join(arm64_framework, 'Flutter')
137 simulator_x64_dylib = os.path.join(simulator_x64_framework, 'Flutter')
138 simulator_arm64_dylib = os.path.join(simulator_arm64_framework, 'Flutter')
139 if not os.path.isfile(arm64_dylib):
140 print('Cannot find iOS arm64 dylib at %s' % arm64_dylib)
141 return 1
142
143 if not os.path.isfile(simulator_x64_dylib):
144 print('Cannot find iOS simulator dylib at %s' % simulator_x64_dylib)
145 return 1
146
147 shutil.rmtree(framework, True)
148 shutil.copytree(arm64_framework, framework)
149 framework_binary = os.path.join(framework, 'Flutter')
150 process_framework(args, dst, framework, framework_binary)
151
152 if args.simulator_arm64_out_dir is not None:
153 shutil.rmtree(simulator_framework, True)
154 shutil.copytree(simulator_arm64_framework, simulator_framework)
155
156 simulator_framework_binary = os.path.join(simulator_framework, 'Flutter')
157
158 # Create the arm64/x64 simulator fat framework.
159 subprocess.check_call([
160 'lipo', simulator_x64_dylib, simulator_arm64_dylib, '-create', '-output',
161 simulator_framework_binary
162 ])
163 process_framework(args, dst, simulator_framework, simulator_framework_binary)
164 else:
165 simulator_framework = simulator_x64_framework
166
167 # Create XCFramework from the arm-only fat framework and the arm64/x64
168 # simulator frameworks, or just the x64 simulator framework if only that one
169 # exists.
170 xcframeworks = [simulator_framework, framework]
171 create_xcframework(location=dst, name='Flutter', frameworks=xcframeworks)
172
173 # Add the x64 simulator into the fat framework
174 subprocess.check_call([
175 'lipo', arm64_dylib, simulator_x64_dylib, '-create', '-output', framework_binary
176 ])
177
178 process_framework(args, dst, framework, framework_binary)
179 return 0
180
181
182def embed_codesign_configuration(config_path, contents):
183 with open(config_path, 'w') as file:
184 file.write('\n'.join(contents) + '\n')
185
186
187def zip_archive(dst):
188 ios_file_with_entitlements = ['gen_snapshot_arm64']
189 ios_file_without_entitlements = [
190 'Flutter.xcframework/ios-arm64/Flutter.framework/Flutter',
191 'Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter',
192 'extension_safe/Flutter.xcframework/ios-arm64/Flutter.framework/Flutter',
193 'extension_safe/Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter'
194 ]
195 embed_codesign_configuration(os.path.join(dst, 'entitlements.txt'), ios_file_with_entitlements)
196
198 os.path.join(dst, 'without_entitlements.txt'), ios_file_without_entitlements
199 )
200
201 subprocess.check_call([
202 'zip',
203 '-r',
204 'artifacts.zip',
205 'gen_snapshot_arm64',
206 'Flutter.xcframework',
207 'entitlements.txt',
208 'without_entitlements.txt',
209 'extension_safe/Flutter.xcframework',
210 ],
211 cwd=dst)
212 if os.path.exists(os.path.join(dst, 'Flutter.dSYM')):
213 subprocess.check_call(['zip', '-r', 'Flutter.dSYM.zip', 'Flutter.dSYM'], cwd=dst)
214
215 if os.path.exists(os.path.join(dst, 'extension_safe', 'Flutter.dSYM')):
216 subprocess.check_call(['zip', '-r', 'extension_safe_Flutter.dSYM.zip', 'Flutter.dSYM'], cwd=dst)
217
218
219def process_framework(args, dst, framework, framework_binary):
220 if args.dsym:
221 dsym_out = os.path.splitext(framework)[0] + '.dSYM'
222 subprocess.check_call([DSYMUTIL, '-o', dsym_out, framework_binary])
223
224 if args.strip:
225 # copy unstripped
226 unstripped_out = os.path.join(dst, 'Flutter.unstripped')
227 shutil.copyfile(framework_binary, unstripped_out)
228
229 subprocess.check_call(['strip', '-x', '-S', framework_binary])
230
231
232def generate_gen_snapshot(args, dst, x64_out_dir, arm64_out_dir):
233 if x64_out_dir:
234 _generate_gen_snapshot(x64_out_dir, os.path.join(dst, 'gen_snapshot_x64'))
235
236 if arm64_out_dir:
238 os.path.join(arm64_out_dir, args.clang_dir), os.path.join(dst, 'gen_snapshot_arm64')
239 )
240
241
242def _generate_gen_snapshot(directory, destination):
243 gen_snapshot_dir = os.path.join(directory, 'gen_snapshot')
244 if not os.path.isfile(gen_snapshot_dir):
245 print('Cannot find gen_snapshot at %s' % gen_snapshot_dir)
246 sys.exit(1)
247
248 subprocess.check_call(['xcrun', 'bitcode_strip', '-r', gen_snapshot_dir, '-o', destination])
249
250
251if __name__ == '__main__':
252 sys.exit(main())
void print(void *str)
Definition bridge.cpp:126
_generate_gen_snapshot(directory, destination)
process_framework(args, dst, framework, framework_binary)
create_framework(args, dst, framework, arm64_framework, simulator_framework, simulator_x64_framework, simulator_arm64_framework)
generate_gen_snapshot(args, dst, x64_out_dir, arm64_out_dir)
embed_codesign_configuration(config_path, contents)
create_extension_safe_framework(args, dst, arm64_out_dir, simulator_x64_out_dir, simulator_arm64_out_dir)
Definition main.py:1