9
9
10
10
import argparse
11
11
import os
12
- import platform
13
- import shutil
14
- import subprocess
15
12
import sys
16
13
17
14
from create_xcframework import create_xcframework # pylint: disable=import-error
18
-
19
- ARCH_SUBPATH = 'mac-arm64' if platform .processor () == 'arm' else 'mac-x64'
20
- DSYMUTIL = os .path .join (
21
- os .path .dirname (__file__ ), '..' , '..' , 'buildtools' , ARCH_SUBPATH , 'clang' , 'bin' , 'dsymutil'
15
+ from utils import ( # pylint: disable=import-error
16
+ assert_directory , assert_file , buildroot_relative_path , copy_binary , copy_tree , create_zip ,
17
+ extract_dsym , lipo , strip_binary , write_codesign_config
22
18
)
23
19
24
- buildroot_dir = os .path .abspath (os .path .join (os .path .realpath (__file__ ), '..' , '..' , '..' , '..' ))
25
-
26
20
27
21
def main ():
28
22
parser = argparse .ArgumentParser (
@@ -42,25 +36,25 @@ def main():
42
36
43
37
args = parser .parse_args ()
44
38
45
- dst = (args .dst if os .path .isabs (args .dst ) else os . path . join ( buildroot_dir , args .dst ))
39
+ dst = (args .dst if os .path .isabs (args .dst ) else buildroot_relative_path ( args .dst ))
46
40
47
41
arm64_out_dir = (
48
42
args .arm64_out_dir
49
- if os .path .isabs (args .arm64_out_dir ) else os . path . join ( buildroot_dir , args .arm64_out_dir )
43
+ if os .path .isabs (args .arm64_out_dir ) else buildroot_relative_path ( args .arm64_out_dir )
50
44
)
51
45
52
46
x64_out_dir = None
53
47
if args .x64_out_dir :
54
48
x64_out_dir = (
55
49
args .x64_out_dir
56
- if os .path .isabs (args .x64_out_dir ) else os . path . join ( buildroot_dir , args .x64_out_dir )
50
+ if os .path .isabs (args .x64_out_dir ) else buildroot_relative_path ( args .x64_out_dir )
57
51
)
58
52
59
53
simulator_x64_out_dir = None
60
54
if args .simulator_x64_out_dir :
61
55
simulator_x64_out_dir = (
62
56
args .simulator_x64_out_dir if os .path .isabs (args .simulator_x64_out_dir ) else
63
- os . path . join ( buildroot_dir , args .simulator_x64_out_dir )
57
+ buildroot_relative_path ( args .simulator_x64_out_dir )
64
58
)
65
59
66
60
framework = os .path .join (dst , 'Flutter.framework' )
@@ -72,24 +66,15 @@ def main():
72
66
if args .simulator_arm64_out_dir :
73
67
simulator_arm64_out_dir = (
74
68
args .simulator_arm64_out_dir if os .path .isabs (args .simulator_arm64_out_dir ) else
75
- os . path . join ( buildroot_dir , args .simulator_arm64_out_dir )
69
+ buildroot_relative_path ( args .simulator_arm64_out_dir )
76
70
)
77
71
78
72
if args .simulator_arm64_out_dir is not None :
79
73
simulator_arm64_framework = os .path .join (simulator_arm64_out_dir , 'Flutter.framework' )
80
74
81
- if not os .path .isdir (arm64_framework ):
82
- print ('Cannot find iOS arm64 Framework at %s' % arm64_framework )
83
- return 1
84
-
85
- if not os .path .isdir (simulator_x64_framework ):
86
- print ('Cannot find iOS x64 simulator Framework at %s' % simulator_framework )
87
- return 1
88
-
89
- if not os .path .isfile (DSYMUTIL ):
90
- print ('Cannot find dsymutil at %s' % DSYMUTIL )
91
- return 1
92
-
75
+ assert_directory (arm64_framework , 'iOS arm64 framework' )
76
+ assert_directory (simulator_arm64_framework , 'iOS arm64 simulator framework' )
77
+ assert_directory (simulator_x64_framework , 'iOS x64 simulator framework' )
93
78
create_framework (
94
79
args , dst , framework , arm64_framework , simulator_framework , simulator_x64_framework ,
95
80
simulator_arm64_framework
@@ -101,10 +86,18 @@ def main():
101
86
'%s_extension_safe' % simulator_x64_out_dir , '%s_extension_safe' % simulator_arm64_out_dir
102
87
)
103
88
104
- generate_gen_snapshot (dst , x64_out_dir , arm64_out_dir )
89
+ # Copy gen_snapshot binary to destination directory.
90
+ if arm64_out_dir :
91
+ gen_snapshot = os .path .join (arm64_out_dir , 'gen_snapshot_arm64' )
92
+ copy_binary (gen_snapshot , os .path .join (dst , 'gen_snapshot_arm64' ))
93
+ if x64_out_dir :
94
+ gen_snapshot = os .path .join (x64_out_dir , 'gen_snapshot_x64' )
95
+ copy_binary (gen_snapshot , os .path .join (dst , 'gen_snapshot_x64' ))
96
+
105
97
zip_archive (dst )
106
98
return 0
107
99
100
+
108
101
def create_extension_safe_framework ( # pylint: disable=too-many-arguments
109
102
args , dst , arm64_out_dir , simulator_x64_out_dir , simulator_arm64_out_dir
110
103
):
@@ -128,20 +121,17 @@ def create_extension_safe_framework( # pylint: disable=too-many-arguments
128
121
)
129
122
return 0
130
123
124
+
131
125
def create_framework ( # pylint: disable=too-many-arguments
132
126
args , dst , framework , arm64_framework , simulator_framework ,
133
127
simulator_x64_framework , simulator_arm64_framework
134
128
):
135
129
arm64_dylib = os .path .join (arm64_framework , 'Flutter' )
136
130
simulator_x64_dylib = os .path .join (simulator_x64_framework , 'Flutter' )
137
131
simulator_arm64_dylib = os .path .join (simulator_arm64_framework , 'Flutter' )
138
- if not os .path .isfile (arm64_dylib ):
139
- print ('Cannot find iOS arm64 dylib at %s' % arm64_dylib )
140
- return 1
141
-
142
- if not os .path .isfile (simulator_x64_dylib ):
143
- print ('Cannot find iOS simulator dylib at %s' % simulator_x64_dylib )
144
- return 1
132
+ assert_file (arm64_dylib , 'iOS arm64 dylib' )
133
+ assert_file (simulator_arm64_dylib , 'iOS simulator arm64 dylib' )
134
+ assert_file (simulator_x64_dylib , 'iOS simulator x64 dylib' )
145
135
146
136
# Compute dsym output paths, if enabled.
147
137
framework_dsym = None
@@ -151,23 +141,15 @@ def create_framework( # pylint: disable=too-many-arguments
151
141
simulator_dsym = simulator_framework + '.dSYM'
152
142
153
143
# Emit the framework for physical devices.
154
- shutil .rmtree (framework , True )
155
- shutil .copytree (arm64_framework , framework )
144
+ copy_tree (arm64_framework , framework )
156
145
framework_binary = os .path .join (framework , 'Flutter' )
157
146
process_framework (args , dst , framework_binary , framework_dsym )
158
147
159
148
# Emit the framework for simulators.
160
149
if args .simulator_arm64_out_dir is not None :
161
- shutil .rmtree (simulator_framework , True )
162
- shutil .copytree (simulator_arm64_framework , simulator_framework )
163
-
150
+ copy_tree (simulator_arm64_framework , simulator_framework )
164
151
simulator_framework_binary = os .path .join (simulator_framework , 'Flutter' )
165
-
166
- # Create the arm64/x64 simulator fat framework.
167
- subprocess .check_call ([
168
- 'lipo' , simulator_x64_dylib , simulator_arm64_dylib , '-create' , '-output' ,
169
- simulator_framework_binary
170
- ])
152
+ lipo ([simulator_x64_dylib , simulator_arm64_dylib ], simulator_framework_binary )
171
153
process_framework (args , dst , simulator_framework_binary , simulator_dsym )
172
154
else :
173
155
simulator_framework = simulator_x64_framework
@@ -179,74 +161,41 @@ def create_framework( # pylint: disable=too-many-arguments
179
161
dsyms = [simulator_dsym , framework_dsym ] if args .dsym else None
180
162
create_xcframework (location = dst , name = 'Flutter' , frameworks = xcframeworks , dsyms = dsyms )
181
163
182
- # Add the x64 simulator into the fat framework.
183
- subprocess .check_call ([
184
- 'lipo' , arm64_dylib , simulator_x64_dylib , '-create' , '-output' , framework_binary
185
- ])
186
-
164
+ lipo ([arm64_dylib , simulator_x64_dylib ], framework_binary )
187
165
process_framework (args , dst , framework_binary , framework_dsym )
188
166
return 0
189
167
190
168
191
- def embed_codesign_configuration (config_path , contents ):
192
- with open (config_path , 'w' ) as file :
193
- file .write ('\n ' .join (contents ) + '\n ' )
194
-
195
-
196
169
def zip_archive (dst ):
197
- ios_file_with_entitlements = ['gen_snapshot_arm64' ]
198
- ios_file_without_entitlements = [
199
- 'Flutter.xcframework/ios-arm64/Flutter.framework/Flutter' ,
200
- 'Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter' ,
201
- 'extension_safe/Flutter.xcframework/ios-arm64/Flutter.framework/Flutter' ,
202
- 'extension_safe/Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter'
203
- ]
204
- embed_codesign_configuration (os .path .join (dst , 'entitlements.txt' ), ios_file_with_entitlements )
205
-
206
- embed_codesign_configuration (
207
- os .path .join (dst , 'without_entitlements.txt' ), ios_file_without_entitlements
170
+ write_codesign_config (os .path .join (dst , 'entitlements.txt' ), ['gen_snapshot_arm64' ])
171
+
172
+ write_codesign_config (
173
+ os .path .join (dst , 'without_entitlements.txt' ), [
174
+ 'Flutter.xcframework/ios-arm64/Flutter.framework/Flutter' ,
175
+ 'Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter' ,
176
+ 'extension_safe/Flutter.xcframework/ios-arm64/Flutter.framework/Flutter' ,
177
+ 'extension_safe/Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter'
178
+ ]
208
179
)
209
180
210
- subprocess .check_call ([
211
- 'zip' ,
212
- '-r' ,
213
- 'artifacts.zip' ,
214
- 'gen_snapshot_arm64' ,
215
- 'Flutter.xcframework' ,
216
- 'entitlements.txt' ,
217
- 'without_entitlements.txt' ,
218
- 'extension_safe/Flutter.xcframework' ,
219
- ],
220
- cwd = dst )
181
+ create_zip (
182
+ dst , 'artifacts.zip' , [
183
+ 'gen_snapshot_arm64' ,
184
+ 'Flutter.xcframework' ,
185
+ 'entitlements.txt' ,
186
+ 'without_entitlements.txt' ,
187
+ 'extension_safe/Flutter.xcframework' ,
188
+ ]
189
+ )
221
190
222
191
223
192
def process_framework (args , dst , framework_binary , dsym ):
224
193
if dsym :
225
- subprocess . check_call ([ DSYMUTIL , '-o' , dsym , framework_binary ] )
194
+ extract_dsym ( framework_binary , dsym )
226
195
227
196
if args .strip :
228
- # copy unstripped
229
197
unstripped_out = os .path .join (dst , 'Flutter.unstripped' )
230
- shutil .copyfile (framework_binary , unstripped_out )
231
- subprocess .check_call (['strip' , '-x' , '-S' , framework_binary ])
232
-
233
-
234
- def generate_gen_snapshot (dst , x64_out_dir , arm64_out_dir ):
235
- if x64_out_dir :
236
- x64_path = os .path .join (x64_out_dir , 'gen_snapshot_x64' )
237
- _generate_gen_snapshot (x64_path , os .path .join (dst , 'gen_snapshot_x64' ))
238
-
239
- if arm64_out_dir :
240
- arm64_path = os .path .join (arm64_out_dir , 'gen_snapshot_arm64' )
241
- _generate_gen_snapshot (arm64_path , os .path .join (dst , 'gen_snapshot_arm64' ))
242
-
243
-
244
- def _generate_gen_snapshot (gen_snapshot_path , destination ):
245
- if not os .path .isfile (gen_snapshot_path ):
246
- print ('Cannot find gen_snapshot at %s' % gen_snapshot_path )
247
- sys .exit (1 )
248
-
249
- shutil .copy2 (gen_snapshot_path , destination )
198
+ strip_binary (framework_binary , unstripped_copy_path = unstripped_out )
250
199
251
200
252
201
if __name__ == '__main__' :
0 commit comments