Skip to content

Commit cf4507a

Browse files
authored
macOS: Bundle dSYM packages in FlutterMacOS.xcframework (flutter#54696)
As of Xcode 16, App Store validation requires dSYMs for frameworks in app archives. Bundling dSYMs also significantly simplifies stack trace symbolification, so we should be doing this regardless. This adds both framework and simulator framework dSYMs to the FlutterMacOS.xcframework bundle. Issue: flutter#153879 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 29fb079 commit cf4507a

3 files changed

Lines changed: 67 additions & 34 deletions

File tree

sky/tools/create_ios_framework.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ def create_framework( # pylint: disable=too-many-arguments
164164

165165
def zip_archive(dst, args):
166166
# pylint: disable=line-too-long
167+
168+
# When updating with_entitlements and without_entitlements,
169+
# `binariesWithoutEntitlements` and `signedXcframeworks` should be updated in
170+
# the framework's `verifyCodeSignedTestRunner`.
171+
#
172+
# See: https://github.com/flutter/flutter/blob/62382c7b83a16b3f48dc06c19a47f6b8667005a5/dev/bots/suite_runners/run_verify_binaries_codesigned_tests.dart#L82-L130
167173
with_entitlements = ['gen_snapshot_arm64']
168174
with_entitlements_file = os.path.join(dst, 'entitlements.txt')
169175
sky_utils.write_codesign_config(with_entitlements_file, with_entitlements)

sky/tools/create_macos_framework.py

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,22 @@ def main():
6464

6565
# Create XCFramework from the arm64 and x64 fat framework.
6666
xcframeworks = [fat_framework]
67-
create_xcframework(location=dst, name='FlutterMacOS', frameworks=xcframeworks)
67+
dsyms = [fat_framework + '.dSYM'] if args.dsym else None
68+
create_xcframework(location=dst, name='FlutterMacOS', frameworks=xcframeworks, dsyms=dsyms)
6869

6970
if args.zip:
70-
zip_framework(dst)
71+
zip_framework(dst, args)
7172

7273
return 0
7374

7475

75-
def zip_framework(dst):
76+
def zip_framework(dst, args):
77+
# pylint: disable=line-too-long
78+
# When updating with_entitlements and without_entitlements,
79+
# `binariesWithoutEntitlements` and `signedXcframeworks` should be updated in
80+
# the framework's `verifyCodeSignedTestRunner`.
81+
#
82+
# See: https://github.com/flutter/flutter/blob/62382c7b83a16b3f48dc06c19a47f6b8667005a5/dev/bots/suite_runners/run_verify_binaries_codesigned_tests.dart#L82-L130
7683
framework_dst = os.path.join(dst, 'FlutterMacOS.framework')
7784
sky_utils.write_codesign_config(os.path.join(framework_dst, 'entitlements.txt'), [])
7885
sky_utils.write_codesign_config(
@@ -83,6 +90,7 @@ def zip_framework(dst):
8390
]
8491
)
8592
sky_utils.create_zip(framework_dst, 'FlutterMacOS.framework.zip', ['.'])
93+
# pylint: enable=line-too-long
8694

8795
# Double zip to make it consistent with legacy artifacts.
8896
# TODO(fujino): remove this once https://github.com/flutter/flutter/issues/125067 is resolved
@@ -102,40 +110,63 @@ def zip_framework(dst):
102110
final_dst_path = os.path.join(dst, 'FlutterMacOS.framework.zip')
103111
shutil.move(final_src_path, final_dst_path)
104112

105-
zip_xcframework_archive(dst)
113+
zip_xcframework_archive(dst, args)
114+
115+
# Generate Flutter.dSYM.zip for manual symbolification.
116+
#
117+
# Historically, the framework dSYM was named FlutterMacOS.dSYM, so in order
118+
# to remain backward-compatible with existing instructions in docs/Crashes.md
119+
# and existing tooling such as dart-lang/dart_ci, we rename back to that name
120+
#
121+
# TODO(cbracken): remove these archives and the upload steps once we bundle
122+
# dSYMs in app archives. https://github.com/flutter/flutter/issues/153879
123+
framework_dsym = framework_dst + '.dSYM'
124+
if os.path.exists(framework_dsym):
125+
renamed_dsym = framework_dsym.replace('FlutterMacOS.framework.dSYM', 'FlutterMacOS.dSYM')
126+
os.rename(framework_dsym, renamed_dsym)
106127

107-
dsym_dst = os.path.join(dst, 'FlutterMacOS.dSYM')
108-
if os.path.exists(dsym_dst):
109128
# Create a zip of just the contents of the dSYM, then create a zip of that zip.
110129
# TODO(cbracken): remove this once https://github.com/flutter/flutter/issues/125067 is resolved
111-
sky_utils.create_zip(dsym_dst, 'FlutterMacOS.dSYM.zip', ['.'])
112-
sky_utils.create_zip(dsym_dst, 'FlutterMacOS.dSYM_.zip', ['FlutterMacOS.dSYM.zip'])
130+
sky_utils.create_zip(renamed_dsym, 'FlutterMacOS.dSYM.zip', ['.'])
131+
sky_utils.create_zip(renamed_dsym, 'FlutterMacOS.dSYM_.zip', ['FlutterMacOS.dSYM.zip'])
113132

114133
# Move the double-zipped FlutterMacOS.dSYM.zip to dst.
115-
dsym_final_src_path = os.path.join(dsym_dst, 'FlutterMacOS.dSYM_.zip')
134+
dsym_final_src_path = os.path.join(renamed_dsym, 'FlutterMacOS.dSYM_.zip')
116135
dsym_final_dst_path = os.path.join(dst, 'FlutterMacOS.dSYM.zip')
117136
shutil.move(dsym_final_src_path, dsym_final_dst_path)
118137

119138

120-
def zip_xcframework_archive(dst):
121-
sky_utils.write_codesign_config(os.path.join(dst, 'entitlements.txt'), [])
122-
123-
sky_utils.write_codesign_config(
124-
os.path.join(dst, 'without_entitlements.txt'), [
125-
'FlutterMacOS.xcframework/macos-arm64_x86_64/'
126-
'FlutterMacOS.framework/Versions/A/FlutterMacOS'
127-
]
128-
)
129-
130-
sky_utils.create_zip(
131-
dst,
132-
'framework.zip',
133-
[
134-
'FlutterMacOS.xcframework',
135-
'entitlements.txt',
136-
'without_entitlements.txt',
137-
],
138-
)
139+
def zip_xcframework_archive(dst, args):
140+
# pylint: disable=line-too-long
141+
142+
# When updating with_entitlements and without_entitlements,
143+
# `binariesWithoutEntitlements` and `signedXcframeworks` should be updated in
144+
# the framework's `verifyCodeSignedTestRunner`.
145+
#
146+
# See: https://github.com/flutter/flutter/blob/62382c7b83a16b3f48dc06c19a47f6b8667005a5/dev/bots/suite_runners/run_verify_binaries_codesigned_tests.dart#L82-L130
147+
with_entitlements = []
148+
with_entitlements_file = os.path.join(dst, 'entitlements.txt')
149+
sky_utils.write_codesign_config(with_entitlements_file, with_entitlements)
150+
151+
without_entitlements = [
152+
'FlutterMacOS.xcframework/macos-arm64_x86_64/FlutterMacOS.framework/Versions/A/FlutterMacOS',
153+
]
154+
if args.dsym:
155+
without_entitlements.extend([
156+
'FlutterMacOS.xcframework/macos-arm64_x86_64/dSYMs/FlutterMacOS.framework.dSYM/Contents/Resources/DWARF/FlutterMacOS',
157+
])
158+
159+
without_entitlements_file = os.path.join(dst, 'without_entitlements.txt')
160+
sky_utils.write_codesign_config(without_entitlements_file, without_entitlements)
161+
# pylint: enable=line-too-long
162+
163+
zip_contents = [
164+
'FlutterMacOS.xcframework',
165+
'entitlements.txt',
166+
'without_entitlements.txt',
167+
]
168+
sky_utils.assert_valid_codesign_config(dst, zip_contents, with_entitlements, without_entitlements)
169+
sky_utils.create_zip(dst, 'framework.zip', zip_contents)
139170

140171

141172
if __name__ == '__main__':

sky/tools/sky_utils.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _contains_duplicates(strings):
8484

8585
def _is_macho_binary(filename):
8686
"""Returns True if the specified path is file and a Mach-O binary."""
87-
if not os.path.isfile(filename):
87+
if os.path.islink(filename) or not os.path.isfile(filename):
8888
return False
8989

9090
with open(filename, 'rb') as file:
@@ -128,11 +128,7 @@ def create_fat_macos_framework(args, dst, fat_framework, arm64_framework, x64_fr
128128
get_mac_framework_dylib_path(x64_framework)], framework_dylib)
129129
_set_framework_permissions(fat_framework)
130130

131-
# Compute dsym output path, if enabled.
132-
framework_dsym = None
133-
if args.dsym:
134-
framework_dsym = os.path.join(dst, get_framework_name(fat_framework) + '.dSYM')
135-
131+
framework_dsym = fat_framework + '.dSYM' if args.dsym else None
136132
_process_macos_framework(args, dst, framework_dylib, framework_dsym)
137133

138134

0 commit comments

Comments
 (0)