Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
gn.py
Go to the documentation of this file.
1#!/usr/bin/env python3
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
4# found in the LICENSE file.
5
6import argparse
7import os
8import platform
9import subprocess
10import socket
11import sys
12import time
13import utils
14
15HOST_OS = utils.GuessOS()
17SCRIPT_DIR = os.path.dirname(sys.argv[0])
18DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
19AVAILABLE_ARCHS = utils.ARCH_FAMILY.keys()
20
21# Environment variables for default settings.
22DART_USE_TOOLCHAIN = "DART_USE_TOOLCHAIN" # Use instead of --toolchain-prefix
23DART_USE_SYSROOT = "DART_USE_SYSROOT" # Use instead of --target-sysroot
24DART_USE_CRASHPAD = "DART_USE_CRASHPAD" # Use instead of --use-crashpad
25# use instead of --platform-sdk
26DART_MAKE_PLATFORM_SDK = "DART_MAKE_PLATFORM_SDK"
27
28DART_GN_ARGS = "DART_GN_ARGS"
29
30
32 if args.toolchain_prefix:
33 return args.toolchain_prefix
34 return os.environ.get(DART_USE_TOOLCHAIN)
35
36
37def TargetSysroot(args):
38 if args.target_sysroot:
39 return args.target_sysroot
40 return os.environ.get(DART_USE_SYSROOT)
41
42
44 return DART_MAKE_PLATFORM_SDK in os.environ
45
46
47def GetGNArgs(args):
48 if args.gn_args != None:
49 return args.gn_args
50 args = os.environ.get(DART_GN_ARGS) or ""
51 return args.split()
52
53
54def GetOutDir(mode, arch, target_os, sanitizer):
55 return utils.GetBuildRoot(HOST_OS, mode, arch, target_os, sanitizer)
56
57
58def ToCommandLine(gn_args):
59
60 def merge(key, value):
61 if type(value) is bool:
62 return '%s=%s' % (key, 'true' if value else 'false')
63 elif type(value) is int:
64 return '%s=%d' % (key, value)
65 return '%s="%s"' % (key, value)
66
67 return [merge(x, y) for x, y in gn_args.items()]
68
69
70# The C compiler's target under the host toolchain (DART_HOST_ARCH_***).
72 arch = arch.split("_")[-1]
73
74 # For each target architecture, we prefer in descending order
75 # - using the same architecture for the host (supports all architectures)
76 # - using a host architecture with the same word size (supports arm and riscv, which have simulators)
77 # - using a host architecture with a different word size (supports only AOT and only 32-bit target on 64-bit host)
78 if arch in ['ia32']:
79 candidates = ['x86']
80 elif arch in ['x64', 'x64c', 'simx64', 'simx64c']:
81 candidates = ['x64', 'arm64']
82 elif arch in ['arm', 'simarm']:
83 candidates = ['arm', 'x86', 'riscv32', 'arm64', 'x64', 'riscv64']
84 elif arch in ['arm64', 'arm64c', 'simarm64', 'simarm64c']:
85 candidates = ['arm64', 'x64', 'riscv64']
86 elif arch in ['riscv32', 'simriscv32']:
87 candidates = ['riscv32', 'arm', 'x86', 'riscv64', 'arm64', 'x64']
88 elif arch in ['riscv64', 'simriscv64']:
89 candidates = ['riscv64', 'arm64', 'x64']
90 else:
91 raise Exception("Unknown Dart architecture: %s" % arch)
92
93 available = utils.HostArchitectures()
94 for candidate in candidates:
95 if candidate in available:
96 return candidate
97
98 raise Exception(
99 "Failed to find a C host architecture for %s. Need one of %s but only %s are available."
100 % (arch, candidates, available))
101
102
103# The C compiler's target under the target toolchain (DART_HOST_ARCH_***).
105 # Real target architectures
106 if arch.startswith('ia32'):
107 return 'x86'
108 elif arch.startswith('x64'):
109 return 'x64'
110 elif arch.startswith('arm64'):
111 return 'arm64'
112 elif arch.startswith('arm'):
113 return 'arm'
114 elif arch.startswith('riscv32'):
115 return 'riscv32'
116 elif arch.startswith('riscv64'):
117 return 'riscv64'
118
119 # Simulators
120 if arch.endswith('_x64'):
121 return 'x64'
122 elif arch.endswith('_arm64'):
123 return 'arm64'
124 elif arch.endswith('_riscv64'):
125 return 'riscv64'
126 elif arch in ['simarm', 'simriscv32']:
127 candidates = ['arm', 'riscv32', 'x86']
128 elif arch in ['simx64', 'simx64c', 'simarm64', 'simarm64c', 'simriscv64']:
129 candidates = ['arm64', 'riscv64', 'x64']
130 else:
131 raise Exception("Unknown Dart architecture: %s" % arch)
132
133 available = utils.HostArchitectures()
134 for candidate in candidates:
135 if candidate in available:
136 return candidate
137
138 raise Exception(
139 "Failed to find a C target architecture for %s. Need one of %s but only %s are available."
140 % (arch, candidates, available))
141
142
143# The Dart compiler's target (DART_TARGET_ARCH_***)
145 arch = arch.split("_")[0]
146 if arch.startswith("sim"):
147 arch = arch[3:]
148 if arch.endswith("c"):
149 arch = arch[:-1]
150 return arch
151
152
154 return "64c" in arch
155
156
157def HostOsForGn(host_os):
158 if host_os.startswith('macos'):
159 return 'mac'
160 if host_os.startswith('win'):
161 return 'win'
162 return host_os
163
164
165# Where string_map is formatted as X1=Y1,X2=Y2 etc.
166# If key is X1, returns Y1.
167def ParseStringMap(key, string_map):
168 for m in string_map.split(','):
169 l = m.split('=')
170 if l[0] == key:
171 return l[1]
172 return None
173
174
175def UseSysroot(args, gn_args):
176 # Don't try to use a Linux sysroot if we aren't on Linux.
177 if gn_args['target_os'] != 'linux' and HOST_OS != 'linux':
178 return False
179 # Don't use the sysroot if we're given another sysroot.
180 if TargetSysroot(args):
181 return False
182 # Don't use the sysroot if we're given another toolchain.
183 if not gn_args['is_clang']:
184 return False
185 # Fuchsia's Linux sysroot doesn't support RISCV32
186 if gn_args['target_cpu'] in ['riscv32']:
187 return False
188 # Otherwise use the sysroot.
189 return True
190
191
192def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash,
193 git_version):
194 gn_args = {}
195
196 host_os = HostOsForGn(HOST_OS)
197 if target_os == 'host':
198 gn_args['target_os'] = host_os
199 else:
200 gn_args['target_os'] = target_os
201
202 gn_args['host_cpu'] = HostCpuForArch(arch)
203 gn_args['target_cpu'] = TargetCpuForArch(arch)
204 gn_args['dart_target_arch'] = DartTargetCpuForArch(arch)
205 gn_args['dart_use_compressed_pointers'] = IsCompressedPointerArch(arch)
206
207 # Configure Crashpad library if it is used.
208 gn_args['dart_use_crashpad'] = ((args.use_crashpad or
209 DART_USE_CRASHPAD in os.environ) and
210 gn_args['target_cpu'] in ['x86', 'x64'])
211 if gn_args['dart_use_crashpad']:
212 # Tell Crashpad's BUILD files which checkout layout to use.
213 gn_args['crashpad_dependencies'] = 'dart'
214
215 if DartTargetCpuForArch(arch) != HostCpuForArch(arch):
216 # Training an app-jit snapshot under a simulator is slow. Use script
217 # snapshots instead.
218 gn_args['dart_snapshot_kind'] = 'kernel'
219 else:
220 gn_args['dart_snapshot_kind'] = 'app-jit'
221
222 # We only want the fallback root certs in the standalone VM on
223 # Linux and Windows.
224 if gn_args['target_os'] in ['linux', 'win']:
225 gn_args['dart_use_fallback_root_certificates'] = True
226
227 gn_args['bssl_use_clang_integrated_as'] = True
228
229 if gn_args['target_os'] == 'linux':
230 if gn_args['target_cpu'] == 'arm':
231 # Default to -mfloat-abi=hard and -mfpu=neon for arm on Linux as we're
232 # specifying a gnueabihf compiler in //build/toolchain/linux/BUILD.gn.
233 floatabi = 'hard' if args.arm_float_abi == '' else args.arm_float_abi
234 gn_args['arm_version'] = 7
235 gn_args['arm_float_abi'] = floatabi
236 gn_args['arm_use_neon'] = True
237 if gn_args['target_os'] == 'fuchsia':
238 gn_args['fuchsia_target_api_level'] = 16
239
240 gn_args['is_debug'] = mode == 'debug'
241 gn_args['is_release'] = mode == 'release'
242 gn_args['is_product'] = mode == 'product'
243 gn_args['dart_debug'] = mode == 'debug'
244
245 # This setting is only meaningful for Flutter. Standalone builds of the VM
246 # should leave this set to 'develop', which causes the build to defer to
247 # 'is_debug', 'is_release' and 'is_product'.
248 if mode == 'product':
249 gn_args['dart_runtime_mode'] = 'release'
250 else:
251 gn_args['dart_runtime_mode'] = 'develop'
252
253 gn_args['exclude_kernel_service'] = args.exclude_kernel_service
254
255 gn_args['is_clang'] = args.clang
256
257 enable_code_coverage = args.code_coverage and gn_args['is_clang']
258 gn_args['dart_vm_code_coverage'] = enable_code_coverage
259
260 gn_args['is_asan'] = sanitizer == 'asan'
261 gn_args['is_lsan'] = sanitizer == 'lsan'
262 gn_args['is_msan'] = sanitizer == 'msan'
263 gn_args['is_tsan'] = sanitizer == 'tsan'
264 gn_args['is_ubsan'] = sanitizer == 'ubsan'
265 gn_args['is_qemu'] = args.use_qemu
266
267 if not args.platform_sdk:
268 gn_args['dart_platform_sdk'] = args.platform_sdk
269
270 # We don't support stripping on Windows
271 if host_os != 'win':
272 gn_args['dart_stripped_binary'] = 'exe.stripped/dart'
273 gn_args['dart_precompiled_runtime_stripped_binary'] = (
274 'exe.stripped/dart_precompiled_runtime_product')
275 gn_args['gen_snapshot_stripped_binary'] = (
276 'exe.stripped/gen_snapshot_product')
277 gn_args['analyze_snapshot_binary'] = ('exe.stripped/analyze_snapshot')
278 gn_args['wasm_opt_stripped_binary'] = 'exe.stripped/wasm-opt'
279
280 # Setup the user-defined sysroot.
281 if UseSysroot(args, gn_args):
282 gn_args['dart_sysroot'] = 'debian'
283 else:
284 sysroot = TargetSysroot(args)
285 if sysroot:
286 gn_args['target_sysroot'] = ParseStringMap(arch, sysroot)
287
288 toolchain = ToolchainPrefix(args)
289 if toolchain:
290 for arch in ['ia32', 'x64', 'arm', 'arm64', 'riscv32', 'riscv64']:
291 prefix = ParseStringMap(arch, toolchain)
292 if prefix != None:
293 gn_args[arch + '_toolchain_prefix'] = prefix
294
295 gn_args['use_rbe'] = args.rbe
296
297 if args.rbe_expensive_exec_strategy:
298 gn_args[
299 'rbe_expensive_exec_strategy'] = args.rbe_expensive_exec_strategy
300
301 # Code coverage requires -O0 to be set.
302 if enable_code_coverage:
303 gn_args['dart_debug_optimization_level'] = 0
304 gn_args['debug_optimization_level'] = 0
305 elif args.debug_opt_level:
306 gn_args['dart_debug_optimization_level'] = args.debug_opt_level
307 gn_args['debug_optimization_level'] = args.debug_opt_level
308
309 gn_args['verify_sdk_hash'] = verify_sdk_hash
310 gn_args['dart_version_git_info'] = git_version
311
312 if args.codesigning_identity != '':
313 gn_args['codesigning_identity'] = args.codesigning_identity
314
315 return gn_args
316
317
318def ProcessOsOption(os_name):
319 if os_name == 'host':
320 return HOST_OS
321 return os_name
322
323
325 if args.verify_sdk_hash == None:
326 args.verify_sdk_hash = not args.rbe
327 if args.git_version == None:
328 args.git_version = not args.rbe
329 if args.arch == 'all':
330 if platform.system() == 'Darwin':
331 # Targeting 32 bits not supported on MacOS.
332 # See HostArchitectures in utils.py.
333 args.arch = 'x64,simarm64,x64c,simarm64c,simriscv64'
334 else:
335 args.arch = 'ia32,x64,simarm,simarm64,x64c,simarm64c,simriscv32,simriscv64'
336 if args.mode == 'all':
337 args.mode = 'debug,release,product'
338 if args.os == 'all':
339 args.os = 'host,android,fuchsia'
340 if args.sanitizer == 'all':
341 args.sanitizer = 'none,asan,lsan,msan,tsan,ubsan'
342 args.mode = args.mode.split(',')
343 args.arch = args.arch.split(',')
344 args.os = args.os.split(',')
345 args.sanitizer = args.sanitizer.split(',')
346 for mode in args.mode:
347 if not mode in ['debug', 'release', 'product']:
348 print("Unknown mode %s" % mode)
349 return False
350 for i, arch in enumerate(args.arch):
351 args.arch[i] = arch.lower()
352 oses = [ProcessOsOption(os_name) for os_name in args.os]
353 for os_name in oses:
354 if not os_name in [
355 'android', 'freebsd', 'linux', 'macos', 'win32', 'fuchsia'
356 ]:
357 print("Unknown os %s" % os_name)
358 return False
359 if os_name == 'android':
360 if not HOST_OS in ['linux', 'macos']:
361 print(
362 "Cross-compilation to %s is not supported on host os %s." %
363 (os_name, HOST_OS))
364 return False
365 if not arch in [
366 'ia32',
367 'x64',
368 'arm',
369 'arm_x64',
370 'arm64',
371 'x64c',
372 'arm64c',
373 'riscv64',
374 ]:
375 print(
376 "Cross-compilation to %s is not supported for architecture %s."
377 % (os_name, arch))
378 return False
379 elif os_name == 'fuchsia':
380 if not HOST_OS in ['linux', 'macos']:
381 print(
382 "Cross-compilation to %s is not supported on host os %s." %
383 (os_name, HOST_OS))
384 return False
385 if not arch in ['x64', 'arm64', 'x64c', 'arm64c', 'riscv64']:
386 print(
387 "Cross-compilation to %s is not supported for architecture %s."
388 % (os_name, arch))
389 return False
390 elif os_name != HOST_OS:
391 print("Unsupported target os %s" % os_name)
392 return False
393 if HOST_OS != 'win' and args.use_crashpad:
394 print("Crashpad is only supported on Windows")
395 return False
396 if not args.rbe and \
397 (socket.getfqdn().endswith('.corp.google.com') or
398 socket.getfqdn().endswith('.c.googlers.com')):
399 print('You can speed up your build by following: go/dart-rbe')
400 old_rbe_cfg = 'win-intel.cfg' if HOST_OS == 'win32' else 'linux-intel.cfg'
401 new_rbe_cfg = 'windows.cfg' if HOST_OS == 'win32' else 'unix.cfg'
402 if os.environ.get('RBE_cfg') == os.path.join(os.getcwd(), 'build', 'rbe',
403 old_rbe_cfg):
404 print(f'warning: {old_rbe_cfg} is deprecated, please update your '
405 f'RBE_cfg variable to {new_rbe_cfg} use RBE=1 instead per '
406 'go/dart-rbe')
407 return True
408
409
410def os_has_ide(host_os):
411 return host_os.startswith('win') or host_os.startswith('mac')
412
413
414def ide_switch(host_os):
415 if host_os.startswith('win'):
416 return '--ide=vs'
417 elif host_os.startswith('mac'):
418 return '--ide=xcode'
419 else:
420 return '--ide=json'
421
422
424 """Adds arguments that will change the default GN arguments."""
425
426 parser.add_argument('--rbe', help='Use rbe', action='store_true')
427 parser.add_argument('--no-rbe',
428 help='Disable rbe',
429 dest='rbe',
430 action='store_false')
431 parser.set_defaults(rbe=os.environ.get('RBE') == '1' or \
432 os.environ.get('DART_RBE') == '1' or \
433 os.environ.get('RBE_cfg') != None)
434 parser.add_argument('--rbe-expensive-exec-strategy',
435 default=os.environ.get('RBE_exec_strategy'),
436 help='Strategy for expensive RBE compilations',
437 type=str)
438
439 # Disable git hashes when remote compiling to ensure cache hits of the final
440 # output artifacts when nothing has changed.
441 parser.add_argument('--verify-sdk-hash',
442 help='Enable SDK hash checks',
443 dest='verify_sdk_hash',
444 action='store_true')
445 parser.add_argument('-nvh',
446 '--no-verify-sdk-hash',
447 help='Disable SDK hash checks',
448 dest='verify_sdk_hash',
449 action='store_false')
450 parser.set_defaults(verify_sdk_hash=None)
451
452 parser.add_argument('--git-version',
453 help='Enable git commit in version',
454 dest='git_version',
455 action='store_true')
456 parser.add_argument('-ngv',
457 '--no-git-version',
458 help='Disable git commit in version',
459 dest='git_version',
460 action='store_false')
461 parser.set_defaults(git_version=None)
462
463 parser.add_argument('--clang', help='Use Clang', action='store_true')
464 parser.add_argument('--no-clang',
465 help='Disable Clang',
466 dest='clang',
467 action='store_false')
468 parser.set_defaults(clang=True)
469
470 parser.add_argument(
471 '--platform-sdk',
472 help='Directs the create_sdk target to create a smaller "Platform" SDK',
473 default=MakePlatformSDK(),
474 action='store_true')
475 parser.add_argument('--use-crashpad',
476 default=False,
477 dest='use_crashpad',
478 action='store_true')
479 parser.add_argument('--use-qemu',
480 default=False,
481 dest='use_qemu',
482 action='store_true')
483 parser.add_argument('--exclude-kernel-service',
484 help='Exclude the kernel service.',
485 default=False,
486 dest='exclude_kernel_service',
487 action='store_true')
488 parser.add_argument('--arm-float-abi',
489 type=str,
490 help='The ARM float ABI (soft, softfp, hard)',
491 metavar='[soft,softfp,hard]',
492 default='')
493
494 parser.add_argument('--code-coverage',
495 help='Enable code coverage for the standalone VM',
496 default=False,
497 dest="code_coverage",
498 action='store_true')
499 parser.add_argument('--debug-opt-level',
500 '-d',
501 help='The optimization level to use for debug builds',
502 type=str)
503 parser.add_argument('--gn-args',
504 help='Set extra GN args',
505 dest='gn_args',
506 action='append')
507 parser.add_argument(
508 '--toolchain-prefix',
509 '-t',
510 type=str,
511 help='Comma-separated list of arch=/path/to/toolchain-prefix mappings')
512 parser.add_argument('--ide',
513 help='Generate an IDE file.',
514 default=os_has_ide(HOST_OS),
515 action='store_true')
516 parser.add_argument('--export-compile-commands',
517 help='Export compile_commands.json database file.',
518 default=False,
519 action='store_true')
520 parser.add_argument(
521 '--target-sysroot',
522 '-s',
523 type=str,
524 help='Comma-separated list of arch=/path/to/sysroot mappings')
525 parser.add_argument('--use-mallinfo2',
526 help='Use mallinfo2 to collect malloc stats.',
527 default=False,
528 dest='use_mallinfo2',
529 action='store_true')
530 parser.add_argument('--codesigning-identity',
531 help='Sign executables using the given identity.',
532 default='',
533 type=str)
534
535
537 """Adds arguments that influence which configuration will be built."""
538 parser.add_argument("-a",
539 "--arch",
540 type=str,
541 help='Target architectures (comma-separated).',
542 metavar='[all,' + ','.join(AVAILABLE_ARCHS) + ']',
543 default=utils.GuessArchitecture())
544 parser.add_argument('--mode',
545 '-m',
546 type=str,
547 help='Build variants (comma-separated).',
548 metavar='[all,debug,release,product]',
549 default='debug')
550 parser.add_argument('--os',
551 type=str,
552 help='Target OSs (comma-separated).',
553 metavar='[all,host,android,fuchsia]',
554 default='host')
555 parser.add_argument('--sanitizer',
556 type=str,
557 help='Build variants (comma-separated).',
558 metavar='[all,none,asan,lsan,msan,tsan,ubsan]',
559 default='none')
560
561
562def AddOtherArgs(parser):
563 """Adds miscellaneous arguments to the parser."""
564 parser.add_argument("-v",
565 "--verbose",
566 help='Verbose output.',
567 default=False,
568 action="store_true")
569 parser.add_argument("--test",
570 help='Test this script.',
571 default=False,
572 action="store_true")
573
574
575def parse_args(args):
576 args = args[1:]
577 parser = argparse.ArgumentParser(
578 description='A script to run `gn gen`.',
579 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
580
581 config_group = parser.add_argument_group('Configuration Related Arguments')
582 AddCommonConfigurationArgs(config_group)
583
584 gn_group = parser.add_argument_group('GN Related Arguments')
585 AddCommonGnOptionArgs(gn_group)
586
587 other_group = parser.add_argument_group('Other Arguments')
588 AddOtherArgs(other_group)
589
590 options = parser.parse_args(args)
591 if not ProcessOptions(options):
592 parser.print_help()
593 return None
594 return options
595
596
597def InitializeRBE(out_dir, env):
598 RBE_cfg = 'RBE_CFG' if HOST_OS == 'win32' else 'RBE_cfg'
599 RBE_server_address = ('RBE_SERVER_ADDRESS'
600 if HOST_OS == 'win32' else 'RBE_server_address')
601 # Default RBE_cfg to the appropriate configuration file.
602 if not RBE_cfg in env:
603 env[RBE_cfg] = os.path.join(
604 os.getcwd(), 'build', 'rbe',
605 'windows.cfg' if HOST_OS == 'win32' else 'unix.cfg')
606 # Default RBE_server_address to inside the build directory.
607 if not RBE_server_address in env:
608 with open(env[RBE_cfg], 'r') as f:
609 if not any([l.startswith('server_address') for l in f.readlines()]):
610 schema = 'pipe' if HOST_OS == 'win32' else 'unix'
611 socket = os.path.join(os.getcwd(), out_dir, 'reproxy.sock')
612 if HOST_OS == 'win32':
613 socket = socket.replace('\\', '_').replace(':', '_')
614 env[RBE_server_address] = f'{schema}://{socket}'
615
616
617def ExecutableName(basename):
618 if utils.IsWindows():
619 return f'{basename}.exe'
620 return basename
621
622
623def BuildGnCommand(args, mode, arch, target_os, sanitizer, out_dir):
624 if utils.IsWindows():
625 gn = os.path.join(DART_ROOT, 'buildtools', 'win', 'gn.exe')
626 else:
627 gn = os.path.join(DART_ROOT, 'buildtools', 'gn')
628 if not os.path.isfile(gn):
629 raise Exception("Couldn't find the gn binary at path: " + gn)
630
631 # TODO(infra): Re-enable --check. Many targets fail to use
632 # public_deps to re-expose header files to their dependents.
633 # See dartbug.com/32364
634 command = [gn, 'gen', out_dir]
635 gn_args = ToCommandLine(
636 ToGnArgs(args, mode, arch, target_os, sanitizer, args.verify_sdk_hash,
637 args.git_version))
638 gn_args += GetGNArgs(args)
639 if args.ide:
640 command.append(ide_switch(HOST_OS))
641 if args.export_compile_commands:
642 command.append('--export-compile-commands')
643 command.append('--args=%s' % ' '.join(gn_args))
644
645 return command
646
647
649 initialized_rbe = False
650 commands = []
651 for target_os in args.os:
652 for mode in args.mode:
653 for arch in args.arch:
654 for sanitizer in args.sanitizer:
655 out_dir = GetOutDir(mode, arch, target_os, sanitizer)
656 if args.rbe and not initialized_rbe:
657 InitializeRBE(out_dir, env)
658 initialized_rbe = True
659 commands.append(
660 BuildGnCommand(args, mode, arch, target_os, sanitizer,
661 out_dir))
662 if args.verbose:
663 print("gn gen --check in %s" % out_dir)
664
665 active_commands = []
666
667 def cleanup(command):
668 print("Command failed: " + ' '.join(command))
669 for (_, process) in active_commands:
670 process.terminate()
671
672 for command in commands:
673 try:
674 process = subprocess.Popen(command, cwd=DART_ROOT, env=env)
675 active_commands.append([command, process])
676 except Exception as e:
677 print('Error: %s' % e)
678 cleanup(command)
679 return 1
680 while active_commands:
681 time.sleep(0.1)
682 for active_command in active_commands:
683 (command, process) = active_command
684 if process.poll() is not None:
685 active_commands.remove(active_command)
686 if process.returncode != 0:
687 cleanup(command)
688 return 1
689 return 0
690
691
692def ExpectEquals(actual, expected):
693 if actual != expected:
694 raise Exception(f"Actual: {actual} Expected: {expected}")
695
696
698 host_arch = utils.HostArchitectures()[0]
699 host_arch_or_x64 = host_arch
700 if 'x64' in utils.HostArchitectures():
701 # Rosetta means 'x64' may be built directly.
702 host_arch_or_x64 = 'x64'
703
704 ExpectEquals(HostCpuForArch("arm64"), host_arch)
705 ExpectEquals(HostCpuForArch("arm64c"), host_arch)
706 ExpectEquals(HostCpuForArch("simarm64"), host_arch)
707 ExpectEquals(HostCpuForArch("simarm64_x64"), host_arch_or_x64)
708 ExpectEquals(HostCpuForArch("simarm64_arm64"), host_arch)
709 ExpectEquals(HostCpuForArch("simarm64_riscv64"), host_arch)
710 ExpectEquals(HostCpuForArch("x64"), host_arch_or_x64)
711 ExpectEquals(HostCpuForArch("simx64"), host_arch_or_x64)
712 ExpectEquals(HostCpuForArch("simx64_x64"), host_arch_or_x64)
713 ExpectEquals(HostCpuForArch("simx64_arm64"), host_arch)
714 ExpectEquals(HostCpuForArch("simx64_riscv64"), host_arch)
715
716 ExpectEquals(TargetCpuForArch("arm64"), "arm64")
717 ExpectEquals(TargetCpuForArch("arm64c"), "arm64")
718 ExpectEquals(TargetCpuForArch("simarm64"), host_arch)
719 ExpectEquals(TargetCpuForArch("simarm64_x64"), "x64")
720 ExpectEquals(TargetCpuForArch("simarm64_arm64"), "arm64")
721 ExpectEquals(TargetCpuForArch("simarm64_riscv64"), "riscv64")
722 ExpectEquals(TargetCpuForArch("x64"), "x64")
723 ExpectEquals(TargetCpuForArch("simx64"), host_arch)
724 ExpectEquals(TargetCpuForArch("simx64_x64"), "x64")
725 ExpectEquals(TargetCpuForArch("simx64_arm64"), "arm64")
726 ExpectEquals(TargetCpuForArch("simx64_riscv64"), "riscv64")
727
728 ExpectEquals(DartTargetCpuForArch("arm64"), "arm64")
729 ExpectEquals(DartTargetCpuForArch("arm64c"), "arm64")
730 ExpectEquals(DartTargetCpuForArch("simarm64"), "arm64")
731 ExpectEquals(DartTargetCpuForArch("simarm64_x64"), "arm64")
732 ExpectEquals(DartTargetCpuForArch("simarm64_arm64"), "arm64")
733 ExpectEquals(DartTargetCpuForArch("simarm64_riscv64"), "arm64")
735 ExpectEquals(DartTargetCpuForArch("simx64"), "x64")
736 ExpectEquals(DartTargetCpuForArch("simx64_x64"), "x64")
737 ExpectEquals(DartTargetCpuForArch("simx64_arm64"), "x64")
738 ExpectEquals(DartTargetCpuForArch("simx64_riscv64"), "x64")
739
741 ExpectEquals(IsCompressedPointerArch("simarm64c"), True)
742 ExpectEquals(IsCompressedPointerArch("simarm64c_x64"), True)
744 ExpectEquals(IsCompressedPointerArch("simx64c"), True)
745 ExpectEquals(IsCompressedPointerArch("simx64c_x64"), True)
747 ExpectEquals(IsCompressedPointerArch("simarm64"), False)
748 ExpectEquals(IsCompressedPointerArch("simarm64_x64"), False)
750 ExpectEquals(IsCompressedPointerArch("simx64"), False)
751 ExpectEquals(IsCompressedPointerArch("simx64_x64"), False)
752
753 # Our Android bots:
754 ExpectEquals(HostCpuForArch("arm64c"), host_arch)
755 ExpectEquals(TargetCpuForArch("arm64c"), 'arm64')
756 ExpectEquals(DartTargetCpuForArch("arm64c"), 'arm64')
757 ExpectEquals(HostCpuForArch("arm_x64"), host_arch_or_x64)
758 ExpectEquals(TargetCpuForArch("arm_x64"), 'arm')
759 ExpectEquals(DartTargetCpuForArch("arm_x64"), 'arm')
760
761
762def Main(argv):
763 starttime = time.time()
764
765 args = parse_args(argv)
766 if args is None:
767 return 1
768
769 if args.test:
770 RunTests()
771 print("Tests passed.")
772 return 0
773
775
776 if args.verbose:
777 endtime = time.time()
778 print("GN Time: %.3f seconds" % (endtime - starttime))
779
780 return result
781
782
783if __name__ == '__main__':
784 sys.exit(Main(sys.argv))
static void merge(const uint8_t *SK_RESTRICT row, int rowN, const SkAlpha *SK_RESTRICT srcAA, const int16_t *SK_RESTRICT srcRuns, SkAlpha *SK_RESTRICT dstAA, int16_t *SK_RESTRICT dstRuns, int width)
void print(void *str)
Definition bridge.cpp:126
BuildGnCommand(args, mode, arch, target_os, sanitizer, out_dir)
Definition gn.py:623
HostOsForGn(host_os)
Definition gn.py:157
RunGnOnConfiguredConfigurations(args, env={})
Definition gn.py:648
RunTests()
Definition gn.py:697
ExecutableName(basename)
Definition gn.py:617
ToolchainPrefix(args)
Definition gn.py:31
ParseStringMap(key, string_map)
Definition gn.py:167
Main(argv)
Definition gn.py:762
MakePlatformSDK()
Definition gn.py:43
IsCompressedPointerArch(arch)
Definition gn.py:153
ide_switch(host_os)
Definition gn.py:414
ToCommandLine(gn_args)
Definition gn.py:58
AddCommonGnOptionArgs(parser)
Definition gn.py:423
ProcessOptions(args)
Definition gn.py:324
GetGNArgs(args)
Definition gn.py:47
TargetCpuForArch(arch)
Definition gn.py:104
parse_args(args)
Definition gn.py:575
ExpectEquals(actual, expected)
Definition gn.py:692
ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash, git_version)
Definition gn.py:193
UseSysroot(args, gn_args)
Definition gn.py:175
InitializeRBE(out_dir, env)
Definition gn.py:597
AddOtherArgs(parser)
Definition gn.py:562
GetOutDir(mode, arch, target_os, sanitizer)
Definition gn.py:54
ProcessOsOption(os_name)
Definition gn.py:318
os_has_ide(host_os)
Definition gn.py:410
TargetSysroot(args)
Definition gn.py:37
HostCpuForArch(arch)
Definition gn.py:71
AddCommonConfigurationArgs(parser)
Definition gn.py:536
DartTargetCpuForArch(arch)
Definition gn.py:144
HostArchitectures()
Definition utils.py:263
GuessArchitecture()
Definition utils.py:42
IsWindows()
Definition utils.py:72
GetBuildRoot(host_os, mode=None, arch=None, sanitizer=None)
Definition utils.py:143
GuessOS()
Definition utils.py:21