17SCRIPT_DIR = os.path.dirname(sys.argv[0])
18DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR,
'..'))
19AVAILABLE_ARCHS = utils.ARCH_FAMILY.keys()
22DART_USE_TOOLCHAIN =
"DART_USE_TOOLCHAIN"
23DART_USE_SYSROOT =
"DART_USE_SYSROOT"
24DART_USE_CRASHPAD =
"DART_USE_CRASHPAD"
26DART_MAKE_PLATFORM_SDK =
"DART_MAKE_PLATFORM_SDK"
28DART_GN_ARGS =
"DART_GN_ARGS"
32 if args.toolchain_prefix:
33 return args.toolchain_prefix
34 return os.environ.get(DART_USE_TOOLCHAIN)
38 if args.target_sysroot:
39 return args.target_sysroot
40 return os.environ.get(DART_USE_SYSROOT)
44 return DART_MAKE_PLATFORM_SDK
in os.environ
48 if args.gn_args !=
None:
50 args = os.environ.get(DART_GN_ARGS)
or ""
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)
67 return [
merge(x, y)
for x, y
in gn_args.items()]
72 arch = arch.split(
"_")[-1]
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']
91 raise Exception(
"Unknown Dart architecture: %s" % arch)
94 for candidate
in candidates:
95 if candidate
in available:
99 "Failed to find a C host architecture for %s. Need one of %s but only %s are available."
100 % (arch, candidates, available))
106 if arch.startswith(
'ia32'):
108 elif arch.startswith(
'x64'):
110 elif arch.startswith(
'arm64'):
112 elif arch.startswith(
'arm'):
114 elif arch.startswith(
'riscv32'):
116 elif arch.startswith(
'riscv64'):
120 if arch.endswith(
'_x64'):
122 elif arch.endswith(
'_arm64'):
124 elif arch.endswith(
'_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']
131 raise Exception(
"Unknown Dart architecture: %s" % arch)
134 for candidate
in candidates:
135 if candidate
in available:
139 "Failed to find a C target architecture for %s. Need one of %s but only %s are available."
140 % (arch, candidates, available))
145 arch = arch.split(
"_")[0]
146 if arch.startswith(
"sim"):
148 if arch.endswith(
"c"):
158 if host_os.startswith(
'macos'):
160 if host_os.startswith(
'win'):
168 for m
in string_map.split(
','):
177 if gn_args[
'target_os'] !=
'linux' and HOST_OS !=
'linux':
183 if not gn_args[
'is_clang']:
186 if gn_args[
'target_cpu']
in [
'riscv32']:
192def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash,
197 if target_os ==
'host':
198 gn_args[
'target_os'] = host_os
200 gn_args[
'target_os'] = target_os
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']:
213 gn_args[
'crashpad_dependencies'] =
'dart'
218 gn_args[
'dart_snapshot_kind'] =
'kernel'
220 gn_args[
'dart_snapshot_kind'] =
'app-jit'
224 if gn_args[
'target_os']
in [
'linux',
'win']:
225 gn_args[
'dart_use_fallback_root_certificates'] =
True
227 gn_args[
'bssl_use_clang_integrated_as'] =
True
229 if gn_args[
'target_os'] ==
'linux':
230 if gn_args[
'target_cpu'] ==
'arm':
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'] = 19
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'
248 if mode ==
'product':
249 gn_args[
'dart_runtime_mode'] =
'release'
251 gn_args[
'dart_runtime_mode'] =
'develop'
253 gn_args[
'exclude_kernel_service'] = args.exclude_kernel_service
255 gn_args[
'is_clang'] = args.clang
257 enable_code_coverage = args.code_coverage
and gn_args[
'is_clang']
258 gn_args[
'dart_vm_code_coverage'] = enable_code_coverage
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
267 if not args.platform_sdk:
268 gn_args[
'dart_platform_sdk'] = args.platform_sdk
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'
282 gn_args[
'dart_sysroot'] =
'debian'
290 for arch
in [
'ia32',
'x64',
'arm',
'arm64',
'riscv32',
'riscv64']:
293 gn_args[arch +
'_toolchain_prefix'] = prefix
295 gn_args[
'use_rbe'] = args.rbe
297 if args.rbe_expensive_exec_strategy:
299 'rbe_expensive_exec_strategy'] = args.rbe_expensive_exec_strategy
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
309 gn_args[
'verify_sdk_hash'] = verify_sdk_hash
310 gn_args[
'dart_version_git_info'] = git_version
312 if args.codesigning_identity !=
'':
313 gn_args[
'codesigning_identity'] = args.codesigning_identity
319 if os_name ==
'host':
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':
333 args.arch =
'x64,simarm64,x64c,simarm64c,simriscv64'
335 args.arch =
'ia32,x64,simarm,simarm64,x64c,simarm64c,simriscv32,simriscv64'
336 if args.mode ==
'all':
337 args.mode =
'debug,release,product'
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)
350 for i, arch
in enumerate(args.arch):
351 args.arch[i] = arch.lower()
355 'android',
'freebsd',
'linux',
'macos',
'win32',
'fuchsia'
357 print(
"Unknown os %s" % os_name)
359 if os_name ==
'android':
360 if not HOST_OS
in [
'linux',
'macos']:
362 "Cross-compilation to %s is not supported on host os %s." %
376 "Cross-compilation to %s is not supported for architecture %s."
379 elif os_name ==
'fuchsia':
380 if not HOST_OS
in [
'linux',
'macos']:
382 "Cross-compilation to %s is not supported on host os %s." %
385 if not arch
in [
'x64',
'arm64',
'x64c',
'arm64c',
'riscv64']:
387 "Cross-compilation to %s is not supported for architecture %s."
390 elif os_name != HOST_OS:
391 print(
"Unsupported target os %s" % os_name)
393 if HOST_OS !=
'win' and args.use_crashpad:
394 print(
"Crashpad is only supported on Windows")
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',
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 '
411 return host_os.startswith(
'win')
or host_os.startswith(
'mac')
415 if host_os.startswith(
'win'):
417 elif host_os.startswith(
'mac'):
424 """Adds arguments that will change the default GN arguments."""
426 parser.add_argument(
'--rbe', help=
'Use rbe', action=
'store_true')
427 parser.add_argument(
'--no-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',
441 parser.add_argument(
'--verify-sdk-hash',
442 help=
'Enable SDK hash checks',
443 dest=
'verify_sdk_hash',
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)
452 parser.add_argument(
'--git-version',
453 help=
'Enable git commit in version',
456 parser.add_argument(
'-ngv',
458 help=
'Disable git commit in version',
460 action=
'store_false')
461 parser.set_defaults(git_version=
None)
463 parser.add_argument(
'--clang', help=
'Use Clang', action=
'store_true')
464 parser.add_argument(
'--no-clang',
465 help=
'Disable Clang',
467 action=
'store_false')
468 parser.set_defaults(clang=
True)
472 help=
'Directs the create_sdk target to create a smaller "Platform" SDK',
475 parser.add_argument(
'--use-crashpad',
479 parser.add_argument(
'--use-qemu',
483 parser.add_argument(
'--exclude-kernel-service',
484 help=
'Exclude the kernel service.',
486 dest=
'exclude_kernel_service',
488 parser.add_argument(
'--arm-float-abi',
490 help=
'The ARM float ABI (soft, softfp, hard)',
491 metavar=
'[soft,softfp,hard]',
494 parser.add_argument(
'--code-coverage',
495 help=
'Enable code coverage for the standalone VM',
497 dest=
"code_coverage",
499 parser.add_argument(
'--debug-opt-level',
501 help=
'The optimization level to use for debug builds',
503 parser.add_argument(
'--gn-args',
504 help=
'Set extra GN args',
508 '--toolchain-prefix',
511 help=
'Comma-separated list of arch=/path/to/toolchain-prefix mappings')
512 parser.add_argument(
'--ide',
513 help=
'Generate an IDE file.',
516 parser.add_argument(
'--export-compile-commands',
517 help=
'Export compile_commands.json database file.',
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.',
528 dest=
'use_mallinfo2',
530 parser.add_argument(
'--codesigning-identity',
531 help=
'Sign executables using the given identity.',
537 """Adds arguments that influence which configuration will be built."""
538 parser.add_argument(
"-a",
541 help=
'Target architectures (comma-separated).',
542 metavar=
'[all,' +
','.
join(AVAILABLE_ARCHS) +
']',
544 parser.add_argument(
'--mode',
547 help=
'Build variants (comma-separated).',
548 metavar=
'[all,debug,release,product]',
550 parser.add_argument(
'--os',
552 help=
'Target OSs (comma-separated).',
553 metavar=
'[all,host,android,fuchsia]',
555 parser.add_argument(
'--sanitizer',
557 help=
'Build variants (comma-separated).',
558 metavar=
'[all,none,asan,lsan,msan,tsan,ubsan]',
563 """Adds miscellaneous arguments to the parser."""
564 parser.add_argument(
"-v",
566 help=
'Verbose output.',
569 parser.add_argument(
"--test",
570 help=
'Test this script.',
577 parser = argparse.ArgumentParser(
578 description=
'A script to run `gn gen`.',
579 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
581 config_group = parser.add_argument_group(
'Configuration Related Arguments')
584 gn_group = parser.add_argument_group(
'GN Related Arguments')
587 other_group = parser.add_argument_group(
'Other Arguments')
590 options = parser.parse_args(args)
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')
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')
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}'
619 return f
'{basename}.exe'
625 gn = os.path.join(DART_ROOT,
'buildtools',
'win',
'gn.exe')
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)
634 command = [gn,
'gen', out_dir]
636 ToGnArgs(args, mode, arch, target_os, sanitizer, args.verify_sdk_hash,
641 if args.export_compile_commands:
642 command.append(
'--export-compile-commands')
643 command.append(
'--args=%s' %
' '.
join(gn_args))
649 initialized_rbe =
False
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:
658 initialized_rbe =
True
663 print(
"gn gen --check in %s" % out_dir)
667 def cleanup(command):
668 print(
"Command failed: " +
' '.
join(command))
669 for (_, process)
in active_commands:
672 for command
in commands:
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)
680 while active_commands:
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:
693 if actual != expected:
694 raise Exception(f
"Actual: {actual} Expected: {expected}")
699 host_arch_or_x64 = host_arch
702 host_arch_or_x64 =
'x64'
763 starttime = time.time()
771 print(
"Tests passed.")
777 endtime = time.time()
778 print(
"GN Time: %.3f seconds" % (endtime - starttime))
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)
def IsCompressedPointerArch(arch)
def GetOutDir(mode, arch, target_os, sanitizer)
def AddCommonConfigurationArgs(parser)
def UseSysroot(args, gn_args)
def ExpectEquals(actual, expected)
def ParseStringMap(key, string_map)
def ToolchainPrefix(args)
def TargetCpuForArch(arch)
def AddCommonGnOptionArgs(parser)
def DartTargetCpuForArch(arch)
def ToCommandLine(gn_args)
def ExecutableName(basename)
def ToGnArgs(args, mode, arch, target_os, sanitizer, verify_sdk_hash, git_version)
def RunGnOnConfiguredConfigurations(args, env={})
def ProcessOsOption(os_name)
def BuildGnCommand(args, mode, arch, target_os, sanitizer, out_dir)
def InitializeRBE(out_dir, env)
def print(*args, **kwargs)
SIT bool any(const Vec< 1, T > &x)
def GetBuildRoot(host_os, mode=None, arch=None, sanitizer=None)
static SkString join(const CommandLineFlags::StringArray &)