From 079c5ecca6693b2f0b09d0d265b4c721e7e44a3b Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Wed, 21 Aug 2024 16:19:59 -0700 Subject: [PATCH] macOS: Make framework creation consistent with iOS (#54685) Separates dSYM creation from archiving, consistent with iOS tooling. This introduces no semantic changes, but simply adjusts `create_fat_macos_framework` and `process_framework` for consistency with the equivalent iOS tooling in `create_ios_framework.py`. Related issue: https://github.com/flutter/flutter/issues/153879 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- sky/tools/create_ios_framework.py | 1 - sky/tools/create_macos_framework.py | 40 +++++++++++------------------ sky/tools/sky_utils.py | 21 +++++++++++++-- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/sky/tools/create_ios_framework.py b/sky/tools/create_ios_framework.py index fab8604388b14..91f398731a9ed 100644 --- a/sky/tools/create_ios_framework.py +++ b/sky/tools/create_ios_framework.py @@ -34,7 +34,6 @@ def main(): args = parser.parse_args() dst = (args.dst if os.path.isabs(args.dst) else sky_utils.buildroot_relative_path(args.dst)) - arm64_out_dir = ( args.arm64_out_dir if os.path.isabs(args.arm64_out_dir) else sky_utils.buildroot_relative_path(args.arm64_out_dir) diff --git a/sky/tools/create_macos_framework.py b/sky/tools/create_macos_framework.py index 42db6c4d3175b..359fb8d86fcf8 100755 --- a/sky/tools/create_macos_framework.py +++ b/sky/tools/create_macos_framework.py @@ -28,10 +28,12 @@ def main(): args = parser.parse_args() dst = args.dst if os.path.isabs(args.dst) else sky_utils.buildroot_relative_path(args.dst) + arm64_out_dir = ( args.arm64_out_dir if os.path.isabs(args.arm64_out_dir) else sky_utils.buildroot_relative_path(args.arm64_out_dir) ) + x64_out_dir = ( args.x64_out_dir if os.path.isabs(args.x64_out_dir) else sky_utils.buildroot_relative_path(args.x64_out_dir) @@ -58,8 +60,7 @@ def main(): return 1 fat_framework = os.path.join(dst, 'FlutterMacOS.framework') - sky_utils.create_fat_macos_framework(fat_framework, arm64_framework, x64_framework) - process_framework(dst, args, fat_framework) + sky_utils.create_fat_macos_framework(args, dst, fat_framework, arm64_framework, x64_framework) # Create XCFramework from the arm64 and x64 fat framework. xcframeworks = [fat_framework] @@ -71,29 +72,6 @@ def main(): return 0 -def process_framework(dst, args, framework_path): - framework_binary = sky_utils.get_mac_framework_dylib_path(framework_path) - - if args.dsym: - dsym_out = os.path.join(dst, 'FlutterMacOS.dSYM') - sky_utils.extract_dsym(framework_binary, dsym_out) - if args.zip: - dsym_dst = os.path.join(dst, 'FlutterMacOS.dSYM') - sky_utils.create_zip(dsym_dst, 'FlutterMacOS.dSYM.zip', ['.']) - # Create a zip of just the contents of the dSYM, then create a zip of that zip. - # TODO(fujino): remove this once https://github.com/flutter/flutter/issues/125067 is resolved - sky_utils.create_zip(dsym_dst, 'FlutterMacOS.dSYM_.zip', ['FlutterMacOS.dSYM.zip']) - - # Overwrite the FlutterMacOS.dSYM.zip with the double-zipped archive. - dsym_final_src_path = os.path.join(dsym_dst, 'FlutterMacOS.dSYM_.zip') - dsym_final_dst_path = os.path.join(dst, 'FlutterMacOS.dSYM.zip') - shutil.move(dsym_final_src_path, dsym_final_dst_path) - - if args.strip: - unstripped_out = os.path.join(dst, 'FlutterMacOS.unstripped') - sky_utils.strip_binary(framework_binary, unstripped_out) - - def zip_framework(dst): framework_dst = os.path.join(dst, 'FlutterMacOS.framework') sky_utils.write_codesign_config(os.path.join(framework_dst, 'entitlements.txt'), []) @@ -126,6 +104,18 @@ def zip_framework(dst): zip_xcframework_archive(dst) + dsym_dst = os.path.join(dst, 'FlutterMacOS.dSYM') + if os.path.exists(dsym_dst): + # Create a zip of just the contents of the dSYM, then create a zip of that zip. + # TODO(cbracken): remove this once https://github.com/flutter/flutter/issues/125067 is resolved + sky_utils.create_zip(dsym_dst, 'FlutterMacOS.dSYM.zip', ['.']) + sky_utils.create_zip(dsym_dst, 'FlutterMacOS.dSYM_.zip', ['FlutterMacOS.dSYM.zip']) + + # Move the double-zipped FlutterMacOS.dSYM.zip to dst. + dsym_final_src_path = os.path.join(dsym_dst, 'FlutterMacOS.dSYM_.zip') + dsym_final_dst_path = os.path.join(dst, 'FlutterMacOS.dSYM.zip') + shutil.move(dsym_final_src_path, dsym_final_dst_path) + def zip_xcframework_archive(dst): sky_utils.write_codesign_config(os.path.join(dst, 'entitlements.txt'), []) diff --git a/sky/tools/sky_utils.py b/sky/tools/sky_utils.py index 1a19885911b2f..1fcb14732595a 100644 --- a/sky/tools/sky_utils.py +++ b/sky/tools/sky_utils.py @@ -118,15 +118,23 @@ def copy_tree(source_path, destination_path, symlinks=False): shutil.copytree(source_path, destination_path, symlinks=symlinks) -def create_fat_macos_framework(fat_framework, arm64_framework, x64_framework): +def create_fat_macos_framework(args, dst, fat_framework, arm64_framework, x64_framework): """Creates a fat framework from two arm64 and x64 frameworks.""" # Clone the arm64 framework bundle as a starting point. copy_tree(arm64_framework, fat_framework, symlinks=True) _regenerate_symlinks(fat_framework) + framework_dylib = get_mac_framework_dylib_path(fat_framework) lipo([get_mac_framework_dylib_path(arm64_framework), - get_mac_framework_dylib_path(x64_framework)], get_mac_framework_dylib_path(fat_framework)) + get_mac_framework_dylib_path(x64_framework)], framework_dylib) _set_framework_permissions(fat_framework) + # Compute dsym output path, if enabled. + framework_dsym = None + if args.dsym: + framework_dsym = os.path.join(dst, get_framework_name(fat_framework) + '.dSYM') + + _process_macos_framework(args, dst, framework_dylib, framework_dsym) + def _regenerate_symlinks(framework_dir): """Regenerates the framework symlink structure. @@ -182,6 +190,15 @@ def _set_framework_permissions(framework_dir): xargs_subprocess.wait() +def _process_macos_framework(args, dst, framework_dylib, dsym): + if dsym: + extract_dsym(framework_dylib, dsym) + + if args.strip: + unstripped_out = os.path.join(dst, 'FlutterMacOS.unstripped') + strip_binary(framework_dylib, unstripped_out) + + def create_zip(cwd, zip_filename, paths): """Creates a zip archive in cwd, containing a set of cwd-relative files.