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

Commit 23b6090

Browse files
Reverts "macOS: refactor create_macos_framework.py (#54546)" (#54549)
Reverts: #54546 Initiated by: zanderso Reason for reverting: Failing roll flutter/flutter#153406 Original PR Author: cbracken Reviewed By: {zanderso} This change reverts the following previous change: This is a refactoring with no semantic changes. This refactors the macOS framework creation code to be more readable, and extracts it to sky_utils.py. While I was pulling this out, also generalised the code to not hardcode FlutterMacOS.framework in case we one day manage to generate the iOS and macOS frameworks with the same name. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 69f61b0 commit 23b6090

File tree

2 files changed

+72
-87
lines changed

2 files changed

+72
-87
lines changed

sky/tools/create_macos_framework.py

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# found in the LICENSE file.
66

77
import argparse
8+
import subprocess
89
import shutil
910
import sys
1011
import os
@@ -37,32 +38,57 @@ def main():
3738
if os.path.isabs(args.x64_out_dir) else sky_utils.buildroot_relative_path(args.x64_out_dir)
3839
)
3940

41+
fat_framework_bundle = os.path.join(dst, 'FlutterMacOS.framework')
4042
arm64_framework = os.path.join(arm64_out_dir, 'FlutterMacOS.framework')
43+
x64_framework = os.path.join(x64_out_dir, 'FlutterMacOS.framework')
44+
45+
arm64_dylib = os.path.join(arm64_framework, 'FlutterMacOS')
46+
x64_dylib = os.path.join(x64_framework, 'FlutterMacOS')
47+
4148
if not os.path.isdir(arm64_framework):
4249
print('Cannot find macOS arm64 Framework at %s' % arm64_framework)
4350
return 1
4451

45-
x64_framework = os.path.join(x64_out_dir, 'FlutterMacOS.framework')
4652
if not os.path.isdir(x64_framework):
4753
print('Cannot find macOS x64 Framework at %s' % x64_framework)
4854
return 1
4955

50-
arm64_dylib = sky_utils.get_framework_dylib_path(arm64_framework)
5156
if not os.path.isfile(arm64_dylib):
5257
print('Cannot find macOS arm64 dylib at %s' % arm64_dylib)
5358
return 1
5459

55-
x64_dylib = sky_utils.get_framework_dylib_path(x64_framework)
5660
if not os.path.isfile(x64_dylib):
5761
print('Cannot find macOS x64 dylib at %s' % x64_dylib)
5862
return 1
5963

60-
fat_framework = os.path.join(dst, 'FlutterMacOS.framework')
61-
sky_utils.create_fat_macos_framework(fat_framework, arm64_framework, x64_framework)
62-
process_framework(dst, args, fat_framework)
64+
sky_utils.copy_tree(arm64_framework, fat_framework_bundle, symlinks=True)
65+
66+
regenerate_symlinks(fat_framework_bundle)
67+
68+
fat_framework_binary = os.path.join(fat_framework_bundle, 'Versions', 'A', 'FlutterMacOS')
69+
70+
# Create the arm64/x64 fat framework.
71+
sky_utils.lipo([arm64_dylib, x64_dylib], fat_framework_binary)
72+
73+
# Make the framework readable and executable: u=rwx,go=rx.
74+
subprocess.check_call(['chmod', '755', fat_framework_bundle])
75+
76+
# Add group and other readability to all files.
77+
versions_path = os.path.join(fat_framework_bundle, 'Versions')
78+
subprocess.check_call(['chmod', '-R', 'og+r', versions_path])
79+
# Find all the files below the target dir with owner execute permission
80+
find_subprocess = subprocess.Popen(['find', versions_path, '-perm', '-100', '-print0'],
81+
stdout=subprocess.PIPE)
82+
# Add execute permission for other and group for all files that had it for owner.
83+
xargs_subprocess = subprocess.Popen(['xargs', '-0', 'chmod', 'og+x'],
84+
stdin=find_subprocess.stdout)
85+
find_subprocess.wait()
86+
xargs_subprocess.wait()
87+
88+
process_framework(dst, args, fat_framework_bundle, fat_framework_binary)
6389

6490
# Create XCFramework from the arm64 and x64 fat framework.
65-
xcframeworks = [fat_framework]
91+
xcframeworks = [fat_framework_bundle]
6692
create_xcframework(location=dst, name='FlutterMacOS', frameworks=xcframeworks)
6793

6894
if args.zip:
@@ -71,26 +97,56 @@ def main():
7197
return 0
7298

7399

74-
def process_framework(dst, args, framework_path):
75-
framework_binary = sky_utils.get_framework_dylib_path(framework_path)
100+
def regenerate_symlinks(fat_framework_bundle):
101+
"""Regenerates the symlinks structure.
102+
103+
Recipes V2 upload artifacts in CAS before integration and CAS follows symlinks.
104+
This logic regenerates the symlinks in the expected structure.
105+
"""
106+
if os.path.islink(os.path.join(fat_framework_bundle, 'FlutterMacOS')):
107+
return
108+
os.remove(os.path.join(fat_framework_bundle, 'FlutterMacOS'))
109+
shutil.rmtree(os.path.join(fat_framework_bundle, 'Headers'), True)
110+
shutil.rmtree(os.path.join(fat_framework_bundle, 'Modules'), True)
111+
shutil.rmtree(os.path.join(fat_framework_bundle, 'Resources'), True)
112+
current_version_path = os.path.join(fat_framework_bundle, 'Versions', 'Current')
113+
shutil.rmtree(current_version_path, True)
114+
os.symlink('A', current_version_path)
115+
os.symlink(
116+
os.path.join('Versions', 'Current', 'FlutterMacOS'),
117+
os.path.join(fat_framework_bundle, 'FlutterMacOS')
118+
)
119+
os.symlink(
120+
os.path.join('Versions', 'Current', 'Headers'), os.path.join(fat_framework_bundle, 'Headers')
121+
)
122+
os.symlink(
123+
os.path.join('Versions', 'Current', 'Modules'), os.path.join(fat_framework_bundle, 'Modules')
124+
)
125+
os.symlink(
126+
os.path.join('Versions', 'Current', 'Resources'),
127+
os.path.join(fat_framework_bundle, 'Resources')
128+
)
129+
76130

131+
def process_framework(dst, args, fat_framework_bundle, fat_framework_binary):
77132
if args.dsym:
78-
dsym_out = os.path.join(dst, 'FlutterMacOS.dSYM')
79-
sky_utils.extract_dsym(framework_binary, dsym_out)
133+
dsym_out = os.path.splitext(fat_framework_bundle)[0] + '.dSYM'
134+
sky_utils.extract_dsym(fat_framework_binary, dsym_out)
80135
if args.zip:
81-
# Create a zip of just the contents of the dSYM, then create a zip of that zip.
136+
dsym_dst = os.path.join(dst, 'FlutterMacOS.dSYM')
137+
sky_utils.create_zip(dsym_dst, 'FlutterMacOS.dSYM.zip', ['.'], symlinks=True)
138+
# Double zip to make it consistent with legacy artifacts.
82139
# TODO(fujino): remove this once https://github.com/flutter/flutter/issues/125067 is resolved
83-
sky_utils.create_zip(dsym_out, 'FlutterMacOS.dSYM.zip', ['.'], symlinks=True)
84-
sky_utils.create_zip(dsym_out, 'FlutterMacOS.dSYM_.zip', ['FlutterMacOS.dSYM.zip'])
140+
sky_utils.create_zip(dsym_dst, 'FlutterMacOS.dSYM_.zip', ['FlutterMacOS.dSYM.zip'])
85141

86142
# Overwrite the FlutterMacOS.dSYM.zip with the double-zipped archive.
87-
dsym_final_src_path = os.path.join(dsym_out, 'FlutterMacOS.dSYM_.zip')
143+
dsym_final_src_path = os.path.join(dsym_dst, 'FlutterMacOS.dSYM_.zip')
88144
dsym_final_dst_path = os.path.join(dst, 'FlutterMacOS.dSYM.zip')
89145
shutil.move(dsym_final_src_path, dsym_final_dst_path)
90146

91147
if args.strip:
92148
unstripped_out = os.path.join(dst, 'FlutterMacOS.unstripped')
93-
sky_utils.strip_binary(framework_binary, unstripped_out)
149+
sky_utils.strip_binary(fat_framework_binary, unstripped_out)
94150

95151

96152
def zip_framework(dst):

sky/tools/sky_utils.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -45,67 +45,6 @@ def copy_tree(source_path, destination_path, symlinks=False):
4545
shutil.copytree(source_path, destination_path, symlinks=symlinks)
4646

4747

48-
def create_fat_macos_framework(fat_framework, arm64_framework, x64_framework):
49-
"""Creates a fat framework from two arm64 and x64 frameworks."""
50-
# Clone the arm64 framework bundle as a starting point.
51-
copy_tree(arm64_framework, fat_framework, symlinks=True)
52-
_regenerate_symlinks(fat_framework)
53-
lipo([get_framework_dylib_path(arm64_framework),
54-
get_framework_dylib_path(x64_framework)], get_framework_dylib_path(fat_framework))
55-
_set_framework_permissions(fat_framework)
56-
57-
58-
def _regenerate_symlinks(framework_path):
59-
"""Regenerates the framework symlink structure.
60-
61-
When building on the bots, the framework is produced in one shard, uploaded
62-
to LUCI's content-addressable storage cache (CAS), then pulled down in
63-
another shard. When that happens, symlinks are dereferenced, resulting a
64-
corrupted framework. This regenerates the expected symlink farm.
65-
"""
66-
# If the dylib is symlinked, assume symlinks are all fine and bail out.
67-
# The shutil.rmtree calls below only work on directories, and fail on symlinks.
68-
framework_name = get_framework_name(framework_path)
69-
framework_binary = get_framework_dylib_path(framework_path)
70-
if os.path.islink(os.path.join(framework_path, framework_name)):
71-
return
72-
73-
# Delete any existing files/directories.
74-
os.remove(framework_binary)
75-
shutil.rmtree(os.path.join(framework_path, 'Headers'), True)
76-
shutil.rmtree(os.path.join(framework_path, 'Modules'), True)
77-
shutil.rmtree(os.path.join(framework_path, 'Resources'), True)
78-
current_version_path = os.path.join(framework_path, 'Versions', 'Current')
79-
shutil.rmtree(current_version_path, True)
80-
81-
# Recreate the expected framework symlinks.
82-
os.symlink('A', current_version_path)
83-
os.symlink(os.path.join(current_version_path, framework_name), framework_binary)
84-
os.symlink(os.path.join(current_version_path, 'Headers'), os.path.join(framework_path, 'Headers'))
85-
os.symlink(os.path.join(current_version_path, 'Modules'), os.path.join(framework_path, 'Modules'))
86-
os.symlink(
87-
os.path.join(current_version_path, 'Resources'), os.path.join(framework_path, 'Resources')
88-
)
89-
90-
91-
def _set_framework_permissions(framework_dir):
92-
"""Sets framework contents to be world readable, and world executable if user-executable."""
93-
# Make the framework readable and executable: u=rwx,go=rx.
94-
subprocess.check_call(['chmod', '755', framework_dir])
95-
96-
# Add group and other readability to all files.
97-
subprocess.check_call(['chmod', '-R', 'og+r', framework_dir])
98-
99-
# Find all the files below the target dir with owner execute permission and
100-
# set og+x where it had the execute permission set for the owner.
101-
find_subprocess = subprocess.Popen(['find', framework_dir, '-perm', '-100', '-print0'],
102-
stdout=subprocess.PIPE)
103-
xargs_subprocess = subprocess.Popen(['xargs', '-0', 'chmod', 'og+x'],
104-
stdin=find_subprocess.stdout)
105-
find_subprocess.wait()
106-
xargs_subprocess.wait()
107-
108-
10948
def create_zip(cwd, zip_filename, paths, symlinks=False):
11049
"""Creates a zip archive in cwd, containing a set of cwd-relative files."""
11150
options = ['-r']
@@ -121,16 +60,6 @@ def _dsymutil_path():
12160
return buildroot_relative_path(dsymutil_path)
12261

12362

124-
def get_framework_name(framework_dir):
125-
"""Returns Foo given /path/to/Foo.framework."""
126-
return os.path.splitext(os.path.basename(framework_dir))[0]
127-
128-
129-
def get_framework_dylib_path(framework_dir):
130-
"""Returns /path/to/Foo.framework/Versions/A/Foo given /path/to/Foo.framework."""
131-
return os.path.join(framework_dir, 'Versions', 'A', get_framework_name(framework_dir))
132-
133-
13463
def extract_dsym(binary_path, dsym_out_path):
13564
"""Extracts a dSYM bundle from the specified Mach-O binary."""
13665
arch_dir = 'mac-arm64' if platform.processor() == 'arm' else 'mac-x64'

0 commit comments

Comments
 (0)