5
5
# found in the LICENSE file.
6
6
7
7
import argparse
8
- import platform
9
8
import subprocess
10
9
import shutil
11
10
import sys
12
11
import os
13
12
14
13
from create_xcframework import create_xcframework # pylint: disable=import-error
15
-
16
- buildroot_dir = os .path .abspath (os .path .join (os .path .realpath (__file__ ), '..' , '..' , '..' , '..' ))
17
-
18
- ARCH_SUBPATH = 'mac-arm64' if platform .processor () == 'arm' else 'mac-x64'
19
- DSYMUTIL = os .path .join (
20
- os .path .dirname (__file__ ), '..' , '..' , 'buildtools' , ARCH_SUBPATH , 'clang' , 'bin' , 'dsymutil'
21
- )
22
-
23
- out_dir = os .path .join (buildroot_dir , 'out' )
14
+ import sky_utils # pylint: disable=import-error
24
15
25
16
26
17
def main ():
@@ -33,19 +24,18 @@ def main():
33
24
parser .add_argument ('--x64-out-dir' , type = str , required = True )
34
25
parser .add_argument ('--strip' , action = 'store_true' , default = False )
35
26
parser .add_argument ('--dsym' , action = 'store_true' , default = False )
36
- # TODO(godofredoc): Remove after recipes v2 have landed.
37
27
parser .add_argument ('--zip' , action = 'store_true' , default = False )
38
28
39
29
args = parser .parse_args ()
40
30
41
- dst = ( args .dst if os .path .isabs (args .dst ) else os . path . join ( buildroot_dir , args .dst ) )
31
+ dst = args .dst if os .path .isabs (args .dst ) else sky_utils . buildroot_relative_path ( args .dst )
42
32
arm64_out_dir = (
43
- args .arm64_out_dir
44
- if os . path . isabs ( args . arm64_out_dir ) else os . path . join ( buildroot_dir , args .arm64_out_dir )
33
+ args .arm64_out_dir if os . path . isabs ( args . arm64_out_dir ) else
34
+ sky_utils . buildroot_relative_path ( args .arm64_out_dir )
45
35
)
46
36
x64_out_dir = (
47
37
args .x64_out_dir
48
- if os .path .isabs (args .x64_out_dir ) else os . path . join ( buildroot_dir , args .x64_out_dir )
38
+ if os .path .isabs (args .x64_out_dir ) else sky_utils . buildroot_relative_path ( args .x64_out_dir )
49
39
)
50
40
51
41
fat_framework_bundle = os .path .join (dst , 'FlutterMacOS.framework' )
@@ -71,21 +61,15 @@ def main():
71
61
print ('Cannot find macOS x64 dylib at %s' % x64_dylib )
72
62
return 1
73
63
74
- if not os .path .isfile (DSYMUTIL ):
75
- print ('Cannot find dsymutil at %s' % DSYMUTIL )
76
- return 1
77
-
78
- shutil .rmtree (fat_framework_bundle , True )
79
- shutil .copytree (arm64_framework , fat_framework_bundle , symlinks = True )
64
+ sky_utils .copy_tree (arm64_framework , fat_framework_bundle , symlinks = True )
80
65
81
66
regenerate_symlinks (fat_framework_bundle )
82
67
83
68
fat_framework_binary = os .path .join (fat_framework_bundle , 'Versions' , 'A' , 'FlutterMacOS' )
84
69
85
70
# Create the arm64/x64 fat framework.
86
- subprocess .check_call ([
87
- 'lipo' , arm64_dylib , x64_dylib , '-create' , '-output' , fat_framework_binary
88
- ])
71
+ sky_utils .lipo ([arm64_dylib , x64_dylib ], fat_framework_binary )
72
+
89
73
# Make the framework readable and executable: u=rwx,go=rx.
90
74
subprocess .check_call (['chmod' , '755' , fat_framework_bundle ])
91
75
@@ -107,7 +91,8 @@ def main():
107
91
xcframeworks = [fat_framework_bundle ]
108
92
create_xcframework (location = dst , name = 'FlutterMacOS' , frameworks = xcframeworks )
109
93
110
- zip_framework (dst , args )
94
+ if args .zip :
95
+ zip_framework (dst )
111
96
112
97
return 0
113
98
@@ -143,108 +128,78 @@ def regenerate_symlinks(fat_framework_bundle):
143
128
)
144
129
145
130
146
- def embed_codesign_configuration (config_path , content ):
147
- with open (config_path , 'w' ) as file :
148
- file .write (content )
149
-
150
-
151
131
def process_framework (dst , args , fat_framework_bundle , fat_framework_binary ):
152
132
if args .dsym :
153
133
dsym_out = os .path .splitext (fat_framework_bundle )[0 ] + '.dSYM'
154
- subprocess . check_call ([ DSYMUTIL , '-o' , dsym_out , fat_framework_binary ] )
134
+ sky_utils . extract_dsym ( fat_framework_binary , dsym_out )
155
135
if args .zip :
156
136
dsym_dst = os .path .join (dst , 'FlutterMacOS.dSYM' )
157
- subprocess . check_call ([ 'zip' , '-r' , '-y' , ' FlutterMacOS.dSYM.zip' , '.' ], cwd = dsym_dst )
137
+ sky_utils . create_zip ( dsym_dst , 'FlutterMacOS.dSYM.zip' , [ '.' ], symlinks = True )
158
138
# Double zip to make it consistent with legacy artifacts.
159
139
# TODO(fujino): remove this once https://github.com/flutter/flutter/issues/125067 is resolved
160
- subprocess .check_call ([
161
- 'zip' ,
162
- '-y' ,
163
- 'FlutterMacOS.dSYM_.zip' ,
164
- 'FlutterMacOS.dSYM.zip' ,
165
- ],
166
- cwd = dsym_dst )
167
- # Use doubled zipped file.
140
+ sky_utils .create_zip (dsym_dst , 'FlutterMacOS.dSYM_.zip' , ['FlutterMacOS.dSYM.zip' ])
141
+
142
+ # Overwrite the FlutterMacOS.dSYM.zip with the double-zipped archive.
168
143
dsym_final_src_path = os .path .join (dsym_dst , 'FlutterMacOS.dSYM_.zip' )
169
144
dsym_final_dst_path = os .path .join (dst , 'FlutterMacOS.dSYM.zip' )
170
145
shutil .move (dsym_final_src_path , dsym_final_dst_path )
171
146
172
147
if args .strip :
173
- # copy unstripped
174
148
unstripped_out = os .path .join (dst , 'FlutterMacOS.unstripped' )
175
- shutil .copyfile (fat_framework_binary , unstripped_out )
176
-
177
- subprocess .check_call (['strip' , '-x' , '-S' , fat_framework_binary ])
149
+ sky_utils .strip_binary (fat_framework_binary , unstripped_out )
150
+
151
+
152
+ def zip_framework (dst ):
153
+ framework_dst = os .path .join (dst , 'FlutterMacOS.framework' )
154
+ sky_utils .write_codesign_config (os .path .join (framework_dst , 'entitlements.txt' ), [])
155
+ sky_utils .write_codesign_config (
156
+ os .path .join (framework_dst , 'without_entitlements.txt' ),
157
+ [
158
+ # TODO(cbracken): Remove the zip file from the path when outer zip is removed.
159
+ 'FlutterMacOS.framework.zip/Versions/A/FlutterMacOS'
160
+ ]
161
+ )
162
+ sky_utils .create_zip (framework_dst , 'FlutterMacOS.framework.zip' , ['.' ], symlinks = True )
163
+
164
+ # Double zip to make it consistent with legacy artifacts.
165
+ # TODO(fujino): remove this once https://github.com/flutter/flutter/issues/125067 is resolved
166
+ sky_utils .create_zip (
167
+ framework_dst ,
168
+ 'FlutterMacOS.framework_.zip' ,
169
+ [
170
+ 'FlutterMacOS.framework.zip' ,
171
+ # TODO(cbracken): Move these files to inner zip before removing the outer zip.
172
+ 'entitlements.txt' ,
173
+ 'without_entitlements.txt' ,
174
+ ],
175
+ symlinks = True
176
+ )
178
177
178
+ # Overwrite the FlutterMacOS.framework.zip with the double-zipped archive.
179
+ final_src_path = os .path .join (framework_dst , 'FlutterMacOS.framework_.zip' )
180
+ final_dst_path = os .path .join (dst , 'FlutterMacOS.framework.zip' )
181
+ shutil .move (final_src_path , final_dst_path )
179
182
180
- def zip_framework (dst , args ):
181
- # Zip FlutterMacOS.framework.
182
- if args .zip :
183
- filepath_with_entitlements = ''
184
-
185
- framework_dst = os .path .join (dst , 'FlutterMacOS.framework' )
186
- # TODO(xilaizhang): Remove the zip file from the path when outer zip is removed.
187
- filepath_without_entitlements = 'FlutterMacOS.framework.zip/Versions/A/FlutterMacOS'
188
-
189
- embed_codesign_configuration (
190
- os .path .join (framework_dst , 'entitlements.txt' ), filepath_with_entitlements
191
- )
192
-
193
- embed_codesign_configuration (
194
- os .path .join (framework_dst , 'without_entitlements.txt' ), filepath_without_entitlements
195
- )
196
- subprocess .check_call ([
197
- 'zip' ,
198
- '-r' ,
199
- '-y' ,
200
- 'FlutterMacOS.framework.zip' ,
201
- '.' ,
202
- ],
203
- cwd = framework_dst )
204
- # Double zip to make it consistent with legacy artifacts.
205
- # TODO(fujino): remove this once https://github.com/flutter/flutter/issues/125067 is resolved
206
- subprocess .check_call (
207
- [
208
- 'zip' ,
209
- '-y' ,
210
- 'FlutterMacOS.framework_.zip' ,
211
- 'FlutterMacOS.framework.zip' ,
212
- # TODO(xilaizhang): Move these files to inner zip before removing the outer zip.
213
- 'entitlements.txt' ,
214
- 'without_entitlements.txt' ,
215
- ],
216
- cwd = framework_dst
217
- )
218
- # Use doubled zipped file.
219
- final_src_path = os .path .join (framework_dst , 'FlutterMacOS.framework_.zip' )
220
- final_dst_path = os .path .join (dst , 'FlutterMacOS.framework.zip' )
221
- shutil .move (final_src_path , final_dst_path )
222
-
223
- zip_xcframework_archive (dst )
183
+ zip_xcframework_archive (dst )
224
184
225
185
226
186
def zip_xcframework_archive (dst ):
227
- filepath_with_entitlements = ''
228
- filepath_without_entitlements = (
229
- 'FlutterMacOS.xcframework/macos-arm64_x86_64/'
230
- 'FlutterMacOS.framework/Versions/A/FlutterMacOS'
231
- )
232
- embed_codesign_configuration (os .path .join (dst , 'entitlements.txt' ), filepath_with_entitlements )
187
+ sky_utils .write_codesign_config (os .path .join (dst , 'entitlements.txt' ), [])
233
188
234
- embed_codesign_configuration (
235
- os .path .join (dst , 'without_entitlements.txt' ), filepath_without_entitlements
189
+ sky_utils .write_codesign_config (
190
+ os .path .join (dst , 'without_entitlements.txt' ), [
191
+ 'FlutterMacOS.xcframework/macos-arm64_x86_64/'
192
+ 'FlutterMacOS.framework/Versions/A/FlutterMacOS'
193
+ ]
236
194
)
237
195
238
- subprocess .check_call ([
239
- 'zip' ,
240
- '-r' ,
241
- '-y' ,
242
- 'framework.zip' ,
243
- 'FlutterMacOS.xcframework' ,
244
- 'entitlements.txt' ,
245
- 'without_entitlements.txt' ,
246
- ],
247
- cwd = dst )
196
+ sky_utils .create_zip (
197
+ dst , 'framework.zip' , [
198
+ 'FlutterMacOS.xcframework' ,
199
+ 'entitlements.txt' ,
200
+ 'without_entitlements.txt' ,
201
+ ]
202
+ )
248
203
249
204
250
205
if __name__ == '__main__' :
0 commit comments