This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Expand file tree
/
Copy pathcreate_macos_framework.py
More file actions
executable file
·142 lines (112 loc) · 4.88 KB
/
create_macos_framework.py
File metadata and controls
executable file
·142 lines (112 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import shutil
import sys
import os
from create_xcframework import create_xcframework # pylint: disable=import-error
import sky_utils # pylint: disable=import-error
def main():
parser = argparse.ArgumentParser(
description='Creates FlutterMacOS.framework and FlutterMacOS.xcframework for macOS'
)
parser.add_argument('--dst', type=str, required=True)
parser.add_argument('--arm64-out-dir', type=str, required=True)
parser.add_argument('--x64-out-dir', type=str, required=True)
parser.add_argument('--strip', action='store_true', default=False)
parser.add_argument('--dsym', action='store_true', default=False)
parser.add_argument('--zip', action='store_true', default=False)
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)
)
arm64_framework = os.path.join(arm64_out_dir, 'FlutterMacOS.framework')
if not os.path.isdir(arm64_framework):
print('Cannot find macOS arm64 Framework at %s' % arm64_framework)
return 1
x64_framework = os.path.join(x64_out_dir, 'FlutterMacOS.framework')
if not os.path.isdir(x64_framework):
print('Cannot find macOS x64 Framework at %s' % x64_framework)
return 1
arm64_dylib = sky_utils.get_mac_framework_dylib_path(arm64_framework)
if not os.path.isfile(arm64_dylib):
print('Cannot find macOS arm64 dylib at %s' % arm64_dylib)
return 1
x64_dylib = sky_utils.get_mac_framework_dylib_path(x64_framework)
if not os.path.isfile(x64_dylib):
print('Cannot find macOS x64 dylib at %s' % x64_dylib)
return 1
fat_framework = os.path.join(dst, 'FlutterMacOS.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]
create_xcframework(location=dst, name='FlutterMacOS', frameworks=xcframeworks)
if args.zip:
zip_framework(dst)
return 0
def zip_framework(dst):
framework_dst = os.path.join(dst, 'FlutterMacOS.framework')
sky_utils.write_codesign_config(os.path.join(framework_dst, 'entitlements.txt'), [])
sky_utils.write_codesign_config(
os.path.join(framework_dst, 'without_entitlements.txt'),
[
# TODO(cbracken): Remove the zip file from the path when outer zip is removed.
'FlutterMacOS.framework.zip/Versions/A/FlutterMacOS'
]
)
sky_utils.create_zip(framework_dst, 'FlutterMacOS.framework.zip', ['.'])
# Double zip to make it consistent with legacy artifacts.
# TODO(fujino): remove this once https://github.com/flutter/flutter/issues/125067 is resolved
sky_utils.create_zip(
framework_dst,
'FlutterMacOS.framework_.zip',
[
'FlutterMacOS.framework.zip',
# TODO(cbracken): Move these files to inner zip before removing the outer zip.
'entitlements.txt',
'without_entitlements.txt',
]
)
# Overwrite the FlutterMacOS.framework.zip with the double-zipped archive.
final_src_path = os.path.join(framework_dst, 'FlutterMacOS.framework_.zip')
final_dst_path = os.path.join(dst, 'FlutterMacOS.framework.zip')
shutil.move(final_src_path, final_dst_path)
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'), [])
sky_utils.write_codesign_config(
os.path.join(dst, 'without_entitlements.txt'), [
'FlutterMacOS.xcframework/macos-arm64_x86_64/'
'FlutterMacOS.framework/Versions/A/FlutterMacOS'
]
)
sky_utils.create_zip(
dst,
'framework.zip',
[
'FlutterMacOS.xcframework',
'entitlements.txt',
'without_entitlements.txt',
],
)
if __name__ == '__main__':
sys.exit(main())