Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
create_macos_gen_snapshots.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2#
3# Copyright 2013 The Flutter Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7import argparse
8import subprocess
9import sys
10import os
11
12buildroot_dir = os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..', '..'))
13
14
15def main():
16 parser = argparse.ArgumentParser(
17 description='Copies architecture-dependent gen_snapshot binaries to output dir'
18 )
19
20 parser.add_argument('--dst', type=str, required=True)
21 parser.add_argument('--clang-dir', type=str, default='clang_x64')
22 parser.add_argument('--x64-out-dir', type=str)
23 parser.add_argument('--arm64-out-dir', type=str)
24 parser.add_argument('--armv7-out-dir', type=str)
25 parser.add_argument('--zip', action='store_true', default=False)
26
27 args = parser.parse_args()
28
29 dst = (args.dst if os.path.isabs(args.dst) else os.path.join(buildroot_dir, args.dst))
30
31 # if dst folder does not exist create it.
32 if not os.path.exists(dst):
33 os.makedirs(dst)
34
35 if args.x64_out_dir:
36 x64_out_dir = (
37 args.x64_out_dir
38 if os.path.isabs(args.x64_out_dir) else os.path.join(buildroot_dir, args.x64_out_dir)
39 )
40 generate_gen_snapshot(x64_out_dir, os.path.join(dst, 'gen_snapshot_x64'))
41
42 if args.arm64_out_dir:
43 arm64_out_dir = (
44 args.arm64_out_dir
45 if os.path.isabs(args.arm64_out_dir) else os.path.join(buildroot_dir, args.arm64_out_dir)
46 )
48 os.path.join(arm64_out_dir, args.clang_dir), os.path.join(dst, 'gen_snapshot_arm64')
49 )
50
51 if args.armv7_out_dir:
52 armv7_out_dir = (
53 args.armv7_out_dir
54 if os.path.isabs(args.armv7_out_dir) else os.path.join(buildroot_dir, args.armv7_out_dir)
55 )
57 os.path.join(armv7_out_dir, args.clang_dir), os.path.join(dst, 'gen_snapshot_armv7')
58 )
59 if args.zip:
60 zip_archive(dst)
61
62
63def embed_codesign_configuration(config_path, contents):
64 with open(config_path, 'w') as file:
65 file.write('\n'.join(contents) + '\n')
66
67
68def zip_archive(dst):
69 snapshot_filepath = ['gen_snapshot_arm64', 'gen_snapshot_x64']
70
71 embed_codesign_configuration(os.path.join(dst, 'entitlements.txt'), snapshot_filepath)
72
73 subprocess.check_call([
74 'zip',
75 '-r',
76 'gen_snapshot.zip',
77 '.',
78 ], cwd=dst)
79
80
81def generate_gen_snapshot(directory, destination):
82 gen_snapshot_dir = os.path.join(directory, 'gen_snapshot')
83 if not os.path.isfile(gen_snapshot_dir):
84 print('Cannot find gen_snapshot at %s' % gen_snapshot_dir)
85 sys.exit(1)
86
87 subprocess.check_call(['xcrun', 'bitcode_strip', '-r', gen_snapshot_dir, '-o', destination])
88
89
90if __name__ == '__main__':
91 sys.exit(main())
void print(void *str)
Definition bridge.cpp:126
embed_codesign_configuration(config_path, contents)
generate_gen_snapshot(directory, destination)
Definition main.py:1