Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 8a5b7bc

Browse files
committed
iOS: Add dSYM binaries to without_entitlements.txt
In #54414, we added dSYM files for physical and simulator binaries in both regular and extension-safe framework builds, but did not add the dSYMs to the without_entitlements.txt list. This passed all engine pre/post-submit tests, as well as framework tests, but failed during release codesigning in Cocoon in a test here: https://github.com/flutter/cocoon/blob/d849b14bab90e0f90e2f7667e37c9f9a5696b918/cipd_packages/codesign/lib/src/file_codesign_visitor.dart#L305-L313 This adds the missing files to without_entitlements.txt, which fixes a codesigning error as seen in this build log: https://ci.chromium.org/ui/p/dart-internal/builders/flutter/Mac%20Production%20Engine%20Drone/13590/overview A corresponding change was landed on the flutter-3.24-candidate.1 branch: #54573 The build associated with that patch correctly completed code signing in this build: https://ci.chromium.org/ui/p/dart-internal/builders/flutter/Mac%20engine_release_builder/688/overview And more specifically, this sub-build: https://ci.chromium.org/ui/p/dart-internal/builders/flutter/Mac%20Production%20Engine%20Drone/13650/overview And even more specifically, this build step: https://logs.chromium.org/logs/dart-internal/buildbucket/cr-buildbucket/8739493904842446705/+/u/Global_generators/Codesign__Volumes_Work_s_w_ir_cache_builder_src_out_release_unsigned_artifacts.zip/codesign_Apple_engine_binaries/stdout Additionally, this patch adds `sky_utils.assert_valid_codesign_config()` which fails the script (and thus the build) with an error message if any file in scope for code signing (i.e. Mach-O binaries) is not listed in the code-signing config (entitlements.txt, without_entitlements.txt), or any listed file is not found on disk. Issue: flutter/flutter#116493
1 parent 97e990c commit 8a5b7bc

File tree

2 files changed

+85
-20
lines changed

2 files changed

+85
-20
lines changed

sky/tools/create_ios_framework.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -164,26 +164,35 @@ def create_framework( # pylint: disable=too-many-arguments
164164

165165

166166
def zip_archive(dst):
167-
sky_utils.write_codesign_config(os.path.join(dst, 'entitlements.txt'), ['gen_snapshot_arm64'])
168-
169-
sky_utils.write_codesign_config(
170-
os.path.join(dst, 'without_entitlements.txt'), [
171-
'Flutter.xcframework/ios-arm64/Flutter.framework/Flutter',
172-
'Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter',
173-
'extension_safe/Flutter.xcframework/ios-arm64/Flutter.framework/Flutter',
174-
'extension_safe/Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter'
175-
]
176-
)
177-
178-
sky_utils.create_zip(
179-
dst, 'artifacts.zip', [
180-
'gen_snapshot_arm64',
181-
'Flutter.xcframework',
182-
'entitlements.txt',
183-
'without_entitlements.txt',
184-
'extension_safe/Flutter.xcframework',
185-
]
186-
)
167+
# pylint: disable=line-too-long
168+
with_entitlements = ['gen_snapshot_arm64']
169+
with_entitlements_file = os.path.join(dst, 'entitlements.txt')
170+
sky_utils.write_codesign_config(with_entitlements_file, with_entitlements)
171+
172+
without_entitlements = [
173+
'Flutter.xcframework/ios-arm64/Flutter.framework/Flutter',
174+
'Flutter.xcframework/ios-arm64/dSYMs/Flutter.framework.dSYM/Contents/Resources/DWARF/Flutter',
175+
'Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter',
176+
'Flutter.xcframework/ios-arm64_x86_64-simulator/dSYMs/Flutter.framework.dSYM/Contents/Resources/DWARF/Flutter',
177+
'extension_safe/Flutter.xcframework/ios-arm64/Flutter.framework/Flutter',
178+
'extension_safe/Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter',
179+
'extension_safe/Flutter.xcframework/ios-arm64/dSYMs/Flutter.framework.dSYM/Contents/Resources/DWARF/Flutter',
180+
'extension_safe/Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter',
181+
'extension_safe/Flutter.xcframework/ios-arm64_x86_64-simulator/dSYMs/Flutter.framework.dSYM/Contents/Resources/DWARF/Flutter',
182+
]
183+
without_entitlements_file = os.path.join(dst, 'without_entitlements.txt')
184+
sky_utils.write_codesign_config(without_entitlements_file, without_entitlements)
185+
# pylint: enable=line-too-long
186+
187+
zip_contents = [
188+
'gen_snapshot_arm64',
189+
'Flutter.xcframework',
190+
'entitlements.txt',
191+
'without_entitlements.txt',
192+
'extension_safe/Flutter.xcframework',
193+
]
194+
sky_utils.assert_valid_codesign_config(dst, zip_contents, with_entitlements, without_entitlements)
195+
sky_utils.create_zip(dst, 'artifacts.zip', zip_contents)
187196

188197

189198
def process_framework(args, dst, framework_binary, dsym):

sky/tools/sky_utils.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,62 @@ def assert_file(path, what):
2525
sys.exit(os.EX_NOINPUT)
2626

2727

28+
def assert_valid_codesign_config(framework_dir, zip_contents, entitlements, without_entitlements):
29+
"""Exits with exit code 1 if the codesign configuration contents are incorrect.
30+
All Mach-O found within zip_contents exactly must be listed in either
31+
entitlements or without_entitlements."""
32+
binaries = set()
33+
for zip_content_path in zip_contents:
34+
# If file, check if Mach-O binary.
35+
if _is_macho_binary(os.path.join(framework_dir, zip_content_path)):
36+
binaries.add(zip_content_path)
37+
# If directory, check transitive closure of files for Mach-O binaries.
38+
for root, _, files in os.walk(os.path.join(framework_dir, zip_content_path)):
39+
for file in [os.path.join(root, f) for f in files]:
40+
if _is_macho_binary(file):
41+
binaries.add(os.path.relpath(file, framework_dir))
42+
43+
# Verify that all Mach-O binaries are listed in either entitlements or without_entitlements.
44+
listed_binaries = set(entitlements + without_entitlements)
45+
if listed_binaries != binaries:
46+
log_error(
47+
'ERROR: binaries listed in entitlements.txt and without_entitlements.txt do not '
48+
'match the set of binaries in the files to be zipped'
49+
)
50+
log_error('Binaries found in files to be zipped:')
51+
for f in sorted(binaries):
52+
log_error(" " + f)
53+
54+
not_listed = sorted(binaries - listed_binaries)
55+
if not_listed:
56+
log_error('Binaries NOT LISTED in entitlements.txt/without_entitlements.txt:')
57+
for f in not_listed:
58+
log_error(" " + f)
59+
60+
not_found = sorted(listed_binaries - binaries)
61+
if not_found:
62+
log_error('Binaries listed in entitlements.txt/without_entitlements.txt but NOT FOUND:')
63+
for f in not_found:
64+
log_error(" " + f)
65+
sys.exit(1)
66+
67+
68+
def _is_macho_binary(filename):
69+
"""Returns True if the specified path is file and a Mach-O binary."""
70+
if not os.path.isfile(filename):
71+
return False
72+
73+
with open(filename, 'rb') as f:
74+
chunk = f.read(4)
75+
return (
76+
chunk == b'\xca\xfe\xba\xbe' or # Mach-O Universal Big Endian
77+
chunk == b'\xce\xfa\xed\xfe' or # Mach-O Little Endian (32-bit)
78+
chunk == b'\xcf\xfa\xed\xfe' or # Mach-O Little Endian (64-bit)
79+
chunk == b'\xfe\xed\xfa\xce' or # Mach-O Big Endian (32-bit)
80+
chunk == b'\xfe\xed\xfa\xcf' # Mach-O Big Endian (64-bit)
81+
)
82+
83+
2884
def buildroot_relative_path(path):
2985
"""Returns the absolute path to the specified buildroot-relative path."""
3086
buildroot_dir = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..', '..'))

0 commit comments

Comments
 (0)