55# found in the LICENSE file.
66
77import argparse
8+ import platform
89import subprocess
910import shutil
1011import sys
1112import os
1213
1314from create_xcframework import create_xcframework # pylint: disable=import-error
14- import sky_utils # 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' )
1524
1625
1726def main ():
@@ -24,18 +33,19 @@ def main():
2433 parser .add_argument ('--x64-out-dir' , type = str , required = True )
2534 parser .add_argument ('--strip' , action = 'store_true' , default = False )
2635 parser .add_argument ('--dsym' , action = 'store_true' , default = False )
36+ # TODO(godofredoc): Remove after recipes v2 have landed.
2737 parser .add_argument ('--zip' , action = 'store_true' , default = False )
2838
2939 args = parser .parse_args ()
3040
31- dst = args .dst if os .path .isabs (args .dst ) else sky_utils . buildroot_relative_path ( args .dst )
41+ dst = ( args .dst if os .path .isabs (args .dst ) else os . path . join ( buildroot_dir , args .dst ) )
3242 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 )
43+ args .arm64_out_dir
44+ if os . path . isabs ( args . arm64_out_dir ) else os . path . join ( buildroot_dir , args .arm64_out_dir )
3545 )
3646 x64_out_dir = (
3747 args .x64_out_dir
38- if os .path .isabs (args .x64_out_dir ) else sky_utils . buildroot_relative_path ( args .x64_out_dir )
48+ if os .path .isabs (args .x64_out_dir ) else os . path . join ( buildroot_dir , args .x64_out_dir )
3949 )
4050
4151 fat_framework_bundle = os .path .join (dst , 'FlutterMacOS.framework' )
@@ -61,15 +71,21 @@ def main():
6171 print ('Cannot find macOS x64 dylib at %s' % x64_dylib )
6272 return 1
6373
64- sky_utils .copy_tree (arm64_framework , fat_framework_bundle , symlinks = True )
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 )
6580
6681 regenerate_symlinks (fat_framework_bundle )
6782
6883 fat_framework_binary = os .path .join (fat_framework_bundle , 'Versions' , 'A' , 'FlutterMacOS' )
6984
7085 # Create the arm64/x64 fat framework.
71- sky_utils .lipo ([arm64_dylib , x64_dylib ], fat_framework_binary )
72-
86+ subprocess .check_call ([
87+ 'lipo' , arm64_dylib , x64_dylib , '-create' , '-output' , fat_framework_binary
88+ ])
7389 # Make the framework readable and executable: u=rwx,go=rx.
7490 subprocess .check_call (['chmod' , '755' , fat_framework_bundle ])
7591
@@ -91,8 +107,7 @@ def main():
91107 xcframeworks = [fat_framework_bundle ]
92108 create_xcframework (location = dst , name = 'FlutterMacOS' , frameworks = xcframeworks )
93109
94- if args .zip :
95- zip_framework (dst )
110+ zip_framework (dst , args )
96111
97112 return 0
98113
@@ -128,79 +143,109 @@ def regenerate_symlinks(fat_framework_bundle):
128143 )
129144
130145
146+ def embed_codesign_configuration (config_path , content ):
147+ with open (config_path , 'w' ) as file :
148+ file .write (content )
149+
150+
131151def process_framework (dst , args , fat_framework_bundle , fat_framework_binary ):
132152 if args .dsym :
133153 dsym_out = os .path .splitext (fat_framework_bundle )[0 ] + '.dSYM'
134- sky_utils . extract_dsym ( fat_framework_binary , dsym_out )
154+ subprocess . check_call ([ DSYMUTIL , '-o' , dsym_out , fat_framework_binary ] )
135155 if args .zip :
136156 dsym_dst = os .path .join (dst , 'FlutterMacOS.dSYM' )
137- sky_utils . create_zip ( dsym_dst , 'FlutterMacOS.dSYM.zip' , [ '.' ], symlinks = True )
157+ subprocess . check_call ([ 'zip' , '-r' , '-y' , ' FlutterMacOS.dSYM.zip' , '.' ], cwd = dsym_dst )
138158 # Double zip to make it consistent with legacy artifacts.
139159 # TODO(fujino): remove this once https://github.com/flutter/flutter/issues/125067 is resolved
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.
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.
143168 dsym_final_src_path = os .path .join (dsym_dst , 'FlutterMacOS.dSYM_.zip' )
144169 dsym_final_dst_path = os .path .join (dst , 'FlutterMacOS.dSYM.zip' )
145170 shutil .move (dsym_final_src_path , dsym_final_dst_path )
146171
147172 if args .strip :
173+ # copy unstripped
148174 unstripped_out = os .path .join (dst , 'FlutterMacOS.unstripped' )
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- )
175+ shutil .copyfile (fat_framework_binary , unstripped_out )
177176
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 )
177+ subprocess .check_call (['strip' , '-x' , '-S' , fat_framework_binary ])
182178
183- zip_xcframework_archive (dst )
184179
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 )
185224
186- def zip_xcframework_archive (dst ):
187- sky_utils .write_codesign_config (os .path .join (dst , 'entitlements.txt' ), [])
188225
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- ]
226+ 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'
194231 )
232+ embed_codesign_configuration (os .path .join (dst , 'entitlements.txt' ), filepath_with_entitlements )
195233
196- sky_utils .create_zip (
197- dst , 'framework.zip' , [
198- 'FlutterMacOS.xcframework' ,
199- 'entitlements.txt' ,
200- 'without_entitlements.txt' ,
201- ]
234+ embed_codesign_configuration (
235+ os .path .join (dst , 'without_entitlements.txt' ), filepath_without_entitlements
202236 )
203237
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 )
248+
204249
205250if __name__ == '__main__' :
206251 sys .exit (main ())
0 commit comments