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

Commit a39fc55

Browse files
Flutter Beta 3.25.0-0.1.pre Cherrypicks update entitlements file (#54652)
Hack around: flutter/flutter#153614 CP of #54576
1 parent 3d2c2b5 commit a39fc55

File tree

2 files changed

+106
-21
lines changed

2 files changed

+106
-21
lines changed

sky/tools/create_ios_framework.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def main():
9191
gen_snapshot = os.path.join(x64_out_dir, 'gen_snapshot_x64')
9292
sky_utils.copy_binary(gen_snapshot, os.path.join(dst, 'gen_snapshot_x64'))
9393

94-
zip_archive(dst)
94+
zip_archive(dst, args)
9595
return 0
9696

9797

@@ -163,27 +163,39 @@ def create_framework( # pylint: disable=too-many-arguments
163163
return 0
164164

165165

166-
def zip_archive(dst):
167-
sky_utils.write_codesign_config(os.path.join(dst, 'entitlements.txt'), ['gen_snapshot_arm64'])
166+
def zip_archive(dst, args):
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)
168171

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-
)
172+
without_entitlements = [
173+
'Flutter.xcframework/ios-arm64/Flutter.framework/Flutter',
174+
'Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter',
175+
'extension_safe/Flutter.xcframework/ios-arm64/Flutter.framework/Flutter',
176+
'extension_safe/Flutter.xcframework/ios-arm64_x86_64-simulator/Flutter.framework/Flutter',
177+
]
178+
if args.dsym:
179+
without_entitlements.extend([
180+
'Flutter.xcframework/ios-arm64/dSYMs/Flutter.framework.dSYM/Contents/Resources/DWARF/Flutter',
181+
'Flutter.xcframework/ios-arm64_x86_64-simulator/dSYMs/Flutter.framework.dSYM/Contents/Resources/DWARF/Flutter',
182+
'extension_safe/Flutter.xcframework/ios-arm64/dSYMs/Flutter.framework.dSYM/Contents/Resources/DWARF/Flutter',
183+
'extension_safe/Flutter.xcframework/ios-arm64_x86_64-simulator/dSYMs/Flutter.framework.dSYM/Contents/Resources/DWARF/Flutter',
184+
])
185+
186+
without_entitlements_file = os.path.join(dst, 'without_entitlements.txt')
187+
sky_utils.write_codesign_config(without_entitlements_file, without_entitlements)
188+
# pylint: enable=line-too-long
189+
190+
zip_contents = [
191+
'gen_snapshot_arm64',
192+
'Flutter.xcframework',
193+
'entitlements.txt',
194+
'without_entitlements.txt',
195+
'extension_safe/Flutter.xcframework',
196+
]
197+
sky_utils.assert_valid_codesign_config(dst, zip_contents, with_entitlements, without_entitlements)
198+
sky_utils.create_zip(dst, 'artifacts.zip', zip_contents)
187199

188200

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

sky/tools/sky_utils.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,79 @@ 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 binaries found within zip_contents exactly must be listed in
31+
either entitlements or without_entitlements."""
32+
if _contains_duplicates(entitlements):
33+
log_error('ERROR: duplicate value(s) found in entitlements.txt')
34+
sys.exit(os.EX_DATAERR)
35+
36+
if _contains_duplicates(without_entitlements):
37+
log_error('ERROR: duplicate value(s) found in without_entitlements.txt')
38+
sys.exit(os.EX_DATAERR)
39+
40+
if _contains_duplicates(entitlements + without_entitlements):
41+
log_error('ERROR: value(s) found in both entitlements and without_entitlements.txt')
42+
sys.exit(os.EX_DATAERR)
43+
44+
binaries = set()
45+
for zip_content_path in zip_contents:
46+
# If file, check if Mach-O binary.
47+
if _is_macho_binary(os.path.join(framework_dir, zip_content_path)):
48+
binaries.add(zip_content_path)
49+
# If directory, check transitive closure of files for Mach-O binaries.
50+
for root, _, files in os.walk(os.path.join(framework_dir, zip_content_path)):
51+
for file in [os.path.join(root, f) for f in files]:
52+
if _is_macho_binary(file):
53+
binaries.add(os.path.relpath(file, framework_dir))
54+
55+
# Verify that all Mach-O binaries are listed in either entitlements or without_entitlements.
56+
listed_binaries = set(entitlements + without_entitlements)
57+
if listed_binaries != binaries:
58+
log_error(
59+
'ERROR: binaries listed in entitlements.txt and without_entitlements.txt do not '
60+
'match the set of binaries in the files to be zipped'
61+
)
62+
log_error('Binaries found in files to be zipped:')
63+
for file in sorted(binaries):
64+
log_error(' ' + file)
65+
66+
not_listed = sorted(binaries - listed_binaries)
67+
if not_listed:
68+
log_error('Binaries NOT LISTED in entitlements.txt/without_entitlements.txt:')
69+
for file in not_listed:
70+
log_error(' ' + file)
71+
72+
not_found = sorted(listed_binaries - binaries)
73+
if not_found:
74+
log_error('Binaries listed in entitlements.txt/without_entitlements.txt but NOT FOUND:')
75+
for file in not_found:
76+
log_error(' ' + file)
77+
sys.exit(os.EX_NOINPUT)
78+
79+
80+
def _contains_duplicates(strings):
81+
"""Returns true if the list of strings contains a duplicate value."""
82+
return len(strings) != len(set(strings))
83+
84+
85+
def _is_macho_binary(filename):
86+
"""Returns True if the specified path is file and a Mach-O binary."""
87+
if not os.path.isfile(filename):
88+
return False
89+
90+
with open(filename, 'rb') as file:
91+
chunk = file.read(4)
92+
return chunk in (
93+
b'\xca\xfe\xba\xbe', # Mach-O Universal Big Endian
94+
b'\xce\xfa\xed\xfe', # Mach-O Little Endian (32-bit)
95+
b'\xcf\xfa\xed\xfe', # Mach-O Little Endian (64-bit)
96+
b'\xfe\xed\xfa\xce', # Mach-O Big Endian (32-bit)
97+
b'\xfe\xed\xfa\xcf', # Mach-O Big Endian (64-bit)
98+
)
99+
100+
28101
def buildroot_relative_path(path):
29102
"""Returns the absolute path to the specified buildroot-relative path."""
30103
buildroot_dir = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..', '..'))

0 commit comments

Comments
 (0)