forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gn
executable file
·171 lines (133 loc) · 5.44 KB
/
gn
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python
# Copyright 2015 The Chromium 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 subprocess
import sys
import os
SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def get_out_dir(args):
if args.target_os is not None:
target_dir = [args.target_os]
else:
target_dir = ['host']
target_dir.append(args.runtime_mode)
if args.simulator:
target_dir.append('sim')
if args.unoptimized:
target_dir.append('unopt')
if args.android_cpu != 'arm':
target_dir.append(args.android_cpu)
return os.path.join('out', '_'.join(target_dir))
def to_command_line(gn_args):
def merge(key, value):
if type(value) is bool:
return '%s=%s' % (key, 'true' if value else 'false')
return '%s="%s"' % (key, value)
return [merge(x, y) for x, y in gn_args.iteritems()]
def to_gn_args(args):
if args.simulator:
if args.target_os == 'android':
raise Exception('--simulator is not supported on Android')
elif args.target_os == 'ios':
if args.runtime_mode != 'debug':
raise Exception('iOS simulator only supports the debug runtime mode')
gn_args = {}
gn_args['is_debug'] = args.unoptimized
gn_args['is_clang'] = args.clang and args.target_os not in ['android']
ios_target_cpu = 'arm64'
aot = args.runtime_mode != 'debug'
if args.target_os == 'android':
gn_args['target_os'] = 'android'
elif args.target_os == 'ios':
gn_args['target_os'] = 'ios'
gn_args['ios_deployment_target'] = '7.0'
gn_args['use_ios_simulator'] = args.simulator
if args.simulator:
gn_args['use_libjpeg_turbo'] = False
else:
# Always use AOT on iOS devices until the interpreter stabilizes
aot = True
else:
gn_args['use_aura'] = False
gn_args['use_system_harfbuzz'] = False
aot = False
if args.runtime_mode == 'debug':
gn_args['dart_runtime_mode'] = 'develop'
else:
gn_args['dart_runtime_mode'] = args.runtime_mode
if args.target_os == 'android':
gn_args['target_cpu'] = args.android_cpu
elif args.target_os == 'ios':
if args.simulator:
gn_args['target_cpu'] = 'x64'
else:
gn_args['target_cpu'] = 'arm64'
gn_args['flutter_aot'] = aot
if aot:
gn_args['dart_target_arch'] = gn_args['target_cpu']
# On iOS Devices, use the Dart bytecode interpreter so we don't incur
# snapshotting and linking costs of the precompiler during development.
# We can still use the JIT on the simulator though.
use_dbc = args.target_os == 'ios' and not args.simulator and args.runtime_mode == 'debug'
gn_args['dart_experimental_interpreter'] = use_dbc
gn_args['flutter_product_mode'] = (gn_args['dart_runtime_mode'] == 'release')
if args.target_sysroot:
gn_args['target_sysroot'] = args.target_sysroot
if args.toolchain_prefix:
gn_args['toolchain_prefix'] = args.toolchain_prefix
goma_dir = os.environ.get('GOMA_DIR')
goma_home_dir = os.path.join(os.getenv('HOME', ''), 'goma')
if args.goma and goma_dir:
gn_args['use_goma'] = True
gn_args['goma_dir'] = goma_dir
elif args.goma and os.path.exists(goma_home_dir):
gn_args['use_goma'] = True
gn_args['goma_dir'] = goma_home_dir
else:
gn_args['use_goma'] = False
gn_args['goma_dir'] = None
gn_args['use_glfw'] = args.use_glfw
return gn_args
def parse_args(args):
args = args[1:]
parser = argparse.ArgumentParser(description='A script run` gn gen`.')
parser.add_argument('--unoptimized', default=False, action='store_true')
parser.add_argument('--runtime-mode', type=str, choices=['debug', 'profile', 'release'], default='debug')
parser.add_argument('--target-os', type=str, choices=['android', 'ios'])
parser.add_argument('--android', dest='target_os', action='store_const', const='android')
parser.add_argument('--android-cpu', type=str, choices=['arm', 'x64', 'x86'], default='arm')
parser.add_argument('--ios', dest='target_os', action='store_const', const='ios')
parser.add_argument('--simulator', action='store_true', default=False)
parser.add_argument('--goma', default=True, action='store_true')
parser.add_argument('--no-goma', dest='goma', action='store_false')
parser.add_argument('--clang', default=True, action='store_true')
parser.add_argument('--no-clang', dest='clang', action='store_false')
parser.add_argument('--target-sysroot', type=str)
parser.add_argument('--toolchain-prefix', type=str)
parser.add_argument('--use-glfw', action='store_true', default=False)
return parser.parse_args(args)
def main(argv):
args = parse_args(argv)
if sys.platform.startswith(('cygwin', 'win')):
subdir = 'win'
elif sys.platform == 'darwin':
subdir = 'mac'
elif sys.platform.startswith('linux'):
subdir = 'linux64'
else:
raise Error('Unknown platform: ' + sys.platform)
command = [
'%s/buildtools/%s/gn' % (SRC_ROOT, subdir),
'gen',
'--check'
]
gn_args = to_command_line(to_gn_args(args))
out_dir = get_out_dir(args)
print "gn gen --check in %s" % out_dir
command.append(out_dir)
command.append('--args=%s' % ' '.join(gn_args))
return subprocess.call(command, cwd=SRC_ROOT)
if __name__ == '__main__':
sys.exit(main(sys.argv))