OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 The Dart project authors. All rights reserved. | 2 # Copyright 2016 The Dart project authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import argparse | 6 import argparse |
7 import multiprocessing | 7 import multiprocessing |
8 import os | 8 import os |
9 import subprocess | 9 import subprocess |
10 import sys | 10 import sys |
11 import time | 11 import time |
12 import utils | 12 import utils |
13 | 13 |
14 HOST_OS = utils.GuessOS() | 14 HOST_OS = utils.GuessOS() |
15 HOST_ARCH = utils.GuessArchitecture() | 15 HOST_ARCH = utils.GuessArchitecture() |
16 SCRIPT_DIR = os.path.dirname(sys.argv[0]) | 16 SCRIPT_DIR = os.path.dirname(sys.argv[0]) |
17 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) | 17 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) |
18 | 18 |
| 19 # Environment variables for default settings. |
| 20 DART_USE_ASAN = "DART_USE_ASAN" # Use instead of --asan |
| 21 DART_USE_MSAN = "DART_USE_MSAN" # Use instead of --msan |
| 22 DART_USE_TSAN = "DART_USE_TSAN" # Use instead of --tsan |
| 23 DART_USE_WHEEZY = "DART_USE_WHEEZY" # Use instread of --wheezy |
| 24 DART_USE_TOOLCHAIN = "DART_USE_TOOLCHAIN" # Use instread of --toolchain-prefix |
| 25 DART_USE_SYSROOT = "DART_USE_SYSROOT" # Use instead of --target-sysroot |
| 26 |
| 27 def use_asan(): |
| 28 return DART_USE_ASAN in os.environ |
| 29 |
| 30 |
| 31 def use_msan(): |
| 32 return DART_USE_MSAN in os.environ |
| 33 |
| 34 |
| 35 def use_tsan(): |
| 36 return DART_USE_TSAN in os.environ |
| 37 |
| 38 |
| 39 def use_wheezy(): |
| 40 return DART_USE_WHEEZY in os.environ |
| 41 |
| 42 |
| 43 def toolchain_prefix(args): |
| 44 if args.toolchain_prefix: |
| 45 return args.toolchain_prefix |
| 46 return os.environ.get(DART_USE_TOOLCHAIN) |
| 47 |
| 48 |
| 49 def target_sysroot(args): |
| 50 if args.target_sysroot: |
| 51 return args.target_sysroot |
| 52 return os.environ.get(DART_USE_SYSROOT) |
| 53 |
19 | 54 |
20 def get_out_dir(mode, arch, target_os): | 55 def get_out_dir(mode, arch, target_os): |
21 return utils.GetBuildRoot(HOST_OS, mode, arch, target_os) | 56 return utils.GetBuildRoot(HOST_OS, mode, arch, target_os) |
22 | 57 |
23 | 58 |
24 def to_command_line(gn_args): | 59 def to_command_line(gn_args): |
25 def merge(key, value): | 60 def merge(key, value): |
26 if type(value) is bool: | 61 if type(value) is bool: |
27 return '%s=%s' % (key, 'true' if value else 'false') | 62 return '%s=%s' % (key, 'true' if value else 'false') |
28 return '%s="%s"' % (key, value) | 63 return '%s="%s"' % (key, value) |
(...skipping 28 matching lines...) Expand all Loading... |
57 | 92 |
58 | 93 |
59 def host_os_for_gn(host_os): | 94 def host_os_for_gn(host_os): |
60 if host_os.startswith('macos'): | 95 if host_os.startswith('macos'): |
61 return 'mac' | 96 return 'mac' |
62 if host_os.startswith('win'): | 97 if host_os.startswith('win'): |
63 return 'win' | 98 return 'win' |
64 return host_os | 99 return host_os |
65 | 100 |
66 | 101 |
| 102 # Where string_map is formatted as X1=Y1,X2=Y2 etc. |
| 103 # If key is X1, returns Y1. |
| 104 def parse_string_map(key, string_map): |
| 105 for m in string_map.split(','): |
| 106 l = m.split('=') |
| 107 if l[0] == key: |
| 108 return l[1] |
| 109 return None |
| 110 |
| 111 |
67 def to_gn_args(args, mode, arch, target_os): | 112 def to_gn_args(args, mode, arch, target_os): |
68 gn_args = {} | 113 gn_args = {} |
69 | 114 |
70 host_os = host_os_for_gn(HOST_OS) | 115 host_os = host_os_for_gn(HOST_OS) |
71 if target_os == 'host': | 116 if target_os == 'host': |
72 gn_args['target_os'] = host_os | 117 gn_args['target_os'] = host_os |
73 else: | 118 else: |
74 gn_args['target_os'] = target_os | 119 gn_args['target_os'] = target_os |
75 | 120 |
76 gn_args['dart_target_arch'] = arch | 121 gn_args['dart_target_arch'] = arch |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 gn_args['is_clang'] = args.clang and has_clang | 175 gn_args['is_clang'] = args.clang and has_clang |
131 | 176 |
132 gn_args['is_asan'] = args.asan and gn_args['is_clang'] | 177 gn_args['is_asan'] = args.asan and gn_args['is_clang'] |
133 gn_args['is_msan'] = args.msan and gn_args['is_clang'] | 178 gn_args['is_msan'] = args.msan and gn_args['is_clang'] |
134 gn_args['is_tsan'] = args.tsan and gn_args['is_clang'] | 179 gn_args['is_tsan'] = args.tsan and gn_args['is_clang'] |
135 | 180 |
136 # Setup the user-defined sysroot. | 181 # Setup the user-defined sysroot. |
137 if gn_args['target_os'] == 'linux' and args.wheezy: | 182 if gn_args['target_os'] == 'linux' and args.wheezy: |
138 gn_args['dart_use_wheezy_sysroot'] = True | 183 gn_args['dart_use_wheezy_sysroot'] = True |
139 else: | 184 else: |
140 if args.target_sysroot: | 185 sysroot = target_sysroot(args) |
141 gn_args['target_sysroot'] = args.target_sysroot | 186 if sysroot: |
| 187 gn_args['target_sysroot'] = parse_string_map(arch, sysroot) |
142 | 188 |
143 if args.toolchain_prefix: | 189 toolchain = toolchain_prefix(args) |
144 gn_args['toolchain_prefix'] = args.toolchain_prefix | 190 if toolchain: |
| 191 gn_args['toolchain_prefix'] = parse_string_map(arch, toolchain) |
145 | 192 |
146 goma_dir = os.environ.get('GOMA_DIR') | 193 goma_dir = os.environ.get('GOMA_DIR') |
147 goma_home_dir = os.path.join(os.getenv('HOME', ''), 'goma') | 194 goma_home_dir = os.path.join(os.getenv('HOME', ''), 'goma') |
148 if args.goma and goma_dir: | 195 if args.goma and goma_dir: |
149 gn_args['use_goma'] = True | 196 gn_args['use_goma'] = True |
150 gn_args['goma_dir'] = goma_dir | 197 gn_args['goma_dir'] = goma_dir |
151 elif args.goma and os.path.exists(goma_home_dir): | 198 elif args.goma and os.path.exists(goma_home_dir): |
152 gn_args['use_goma'] = True | 199 gn_args['use_goma'] = True |
153 gn_args['goma_dir'] = goma_home_dir | 200 gn_args['goma_dir'] = goma_home_dir |
154 else: | 201 else: |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 259 |
213 def ide_switch(host_os): | 260 def ide_switch(host_os): |
214 if host_os.startswith('win'): | 261 if host_os.startswith('win'): |
215 return '--ide=vs' | 262 return '--ide=vs' |
216 elif host_os.startswith('mac'): | 263 elif host_os.startswith('mac'): |
217 return '--ide=xcode' | 264 return '--ide=xcode' |
218 else: | 265 else: |
219 return '--ide=json' | 266 return '--ide=json' |
220 | 267 |
221 | 268 |
222 # Environment variables for default settings. | |
223 DART_USE_ASAN = "DART_USE_ASAN" | |
224 DART_USE_MSAN = "DART_USE_MSAN" | |
225 DART_USE_TSAN = "DART_USE_TSAN" | |
226 DART_USE_WHEEZY = "DART_USE_WHEEZY" | |
227 | |
228 def use_asan(): | |
229 return DART_USE_ASAN in os.environ | |
230 | |
231 def use_msan(): | |
232 return DART_USE_MSAN in os.environ | |
233 | |
234 def use_tsan(): | |
235 return DART_USE_TSAN in os.environ | |
236 | |
237 def use_wheezy(): | |
238 return DART_USE_WHEEZY in os.environ | |
239 | |
240 | |
241 def parse_args(args): | 269 def parse_args(args): |
242 args = args[1:] | 270 args = args[1:] |
243 parser = argparse.ArgumentParser( | 271 parser = argparse.ArgumentParser( |
244 description='A script to run `gn gen`.', | 272 description='A script to run `gn gen`.', |
245 formatter_class=argparse.ArgumentDefaultsHelpFormatter) | 273 formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
246 common_group = parser.add_argument_group('Common Arguments') | 274 common_group = parser.add_argument_group('Common Arguments') |
247 other_group = parser.add_argument_group('Other Arguments') | 275 other_group = parser.add_argument_group('Other Arguments') |
248 | 276 |
249 common_group.add_argument('--arch', '-a', | 277 common_group.add_argument('--arch', '-a', |
250 type=str, | 278 type=str, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 other_group.add_argument('--msan', | 325 other_group.add_argument('--msan', |
298 help='Build with MSAN', | 326 help='Build with MSAN', |
299 default=use_msan(), | 327 default=use_msan(), |
300 action='store_true') | 328 action='store_true') |
301 other_group.add_argument('--no-msan', | 329 other_group.add_argument('--no-msan', |
302 help='Disable MSAN', | 330 help='Disable MSAN', |
303 dest='msan', | 331 dest='msan', |
304 action='store_false') | 332 action='store_false') |
305 other_group.add_argument('--target-sysroot', '-s', | 333 other_group.add_argument('--target-sysroot', '-s', |
306 type=str, | 334 type=str, |
307 help='Path to the toolchain sysroot') | 335 help='Comma-separated list of arch=/path/to/sysroot mappings') |
308 other_group.add_argument('--toolchain-prefix', '-t', | 336 other_group.add_argument('--toolchain-prefix', '-t', |
309 type=str, | 337 type=str, |
310 help='Path to the toolchain prefix') | 338 help='Comma-separated list of arch=/path/to/toolchain-prefix mappings') |
311 other_group.add_argument('--tsan', | 339 other_group.add_argument('--tsan', |
312 help='Build with TSAN', | 340 help='Build with TSAN', |
313 default=use_tsan(), | 341 default=use_tsan(), |
314 action='store_true') | 342 action='store_true') |
315 other_group.add_argument('--no-tsan', | 343 other_group.add_argument('--no-tsan', |
316 help='Disable TSAN', | 344 help='Disable TSAN', |
317 dest='tsan', | 345 dest='tsan', |
318 action='store_false') | 346 action='store_false') |
319 other_group.add_argument('--wheezy', | 347 other_group.add_argument('--wheezy', |
320 help='Use the Debian wheezy sysroot on Linux', | 348 help='Use the Debian wheezy sysroot on Linux', |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 return 1 | 416 return 1 |
389 | 417 |
390 endtime = time.time() | 418 endtime = time.time() |
391 if args.verbose: | 419 if args.verbose: |
392 print ("GN Time: %.3f seconds" % (endtime - starttime)) | 420 print ("GN Time: %.3f seconds" % (endtime - starttime)) |
393 return 0 | 421 return 0 |
394 | 422 |
395 | 423 |
396 if __name__ == '__main__': | 424 if __name__ == '__main__': |
397 sys.exit(main(sys.argv)) | 425 sys.exit(main(sys.argv)) |
OLD | NEW |