Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: tools/gn.py

Issue 2350583002: Starting work on full GN build (Closed)
Patch Set: Fixes for Fuchsia and Flutter. Cleanup. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/clang/scripts/update.sh ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
6 import argparse
7 import subprocess
8 import sys
9 import os
10 import utils
11
12 HOST_OS = utils.GuessOS()
13 HOST_ARCH = utils.GuessArchitecture()
14 HOST_CPUS = utils.GuessCpus()
15 SCRIPT_DIR = os.path.dirname(sys.argv[0])
16 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
17
18 def get_out_dir(args):
19 return utils.GetBuildRoot(HOST_OS, args.mode, args.arch, args.os)
20
21 def to_command_line(gn_args):
22 def merge(key, value):
23 if type(value) is bool:
24 return '%s=%s' % (key, 'true' if value else 'false')
25 return '%s="%s"' % (key, value)
26 return [merge(x, y) for x, y in gn_args.iteritems()]
27
28 def host_cpu_for_arch(arch):
29 if arch in ['ia32', 'arm', 'armv6', 'armv5te', 'mips',
30 'simarm', 'simarmv6', 'simarmv5te', 'simmips', 'simdbc']:
31 return 'x86'
32 if arch in ['x64', 'arm64', 'simarm64', 'simdbc64']:
33 return 'x64'
34
35 def target_cpu_for_arch(arch, os):
36 if arch in ['ia32', 'simarm', 'simarmv6', 'simarmv5te', 'simmips']:
37 return 'x86'
38 if arch in ['simarm64']:
39 return 'x64'
40 if arch == 'mips':
41 return 'mipsel'
42 if arch == 'simdbc':
43 return 'arm' if os == 'android' else 'x86'
44 if arch == 'simdbc64':
45 return 'arm64' if os == 'android' else 'x64'
46 return arch
47
48 def to_gn_args(args):
49 gn_args = {}
50
51 if args.os == 'host':
52 gn_args['target_os'] = HOST_OS
53 else:
54 gn_args['target_os'] = args.os
55
56 gn_args['dart_target_arch'] = args.arch
57 gn_args['target_cpu'] = target_cpu_for_arch(args.arch, args.os)
58 gn_args['host_cpu'] = host_cpu_for_arch(args.arch)
59
60 # TODO(zra): This is for the observatory, which currently builds using the
61 # checked-in sdk. If/when the observatory no longer builds with the
62 # checked-in sdk, this can be removed.
63 gn_args['dart_host_pub_exe'] = os.path.join(
64 DART_ROOT, 'tools', 'sdks', HOST_OS, 'dart-sdk', 'bin', 'pub')
65
66 # For Fuchsia support, the default is to not compile in the root
67 # certificates.
68 gn_args['dart_use_fallback_root_certificates'] = True
69
70 gn_args['dart_zlib_path'] = "//runtime/bin/zlib"
71
72 gn_args['is_debug'] = args.mode == 'debug'
73 gn_args['is_release'] = args.mode == 'release'
74 gn_args['is_product'] = args.mode == 'product'
75 gn_args['dart_debug'] = args.mode == 'debug'
76
77 # This setting is only meaningful for Flutter. Standalone builds of the VM
78 # should leave this set to 'develop', which causes the build to defer to
79 # 'is_debug', 'is_release' and 'is_product'.
80 gn_args['dart_runtime_mode'] = 'develop'
81
82 gn_args['is_clang'] = args.clang and args.os not in ['android']
83
84 if args.target_sysroot:
85 gn_args['target_sysroot'] = args.target_sysroot
86
87 if args.toolchain_prefix:
88 gn_args['toolchain_prefix'] = args.toolchain_prefix
89
90 goma_dir = os.environ.get('GOMA_DIR')
91 goma_home_dir = os.path.join(os.getenv('HOME', ''), 'goma')
92 if args.goma and goma_dir:
93 gn_args['use_goma'] = True
94 gn_args['goma_dir'] = goma_dir
95 elif args.goma and os.path.exists(goma_home_dir):
96 gn_args['use_goma'] = True
97 gn_args['goma_dir'] = goma_home_dir
98 else:
99 gn_args['use_goma'] = False
100 gn_args['goma_dir'] = None
101
102 return gn_args
103
104 def parse_args(args):
105 args = args[1:]
106 parser = argparse.ArgumentParser(description='A script run` gn gen`.')
107
108 parser.add_argument('--mode', '-m',
109 type=str,
110 choices=['debug', 'release', 'product'],
111 default='debug')
112 parser.add_argument('--os',
113 type=str,
114 choices=['host', 'android'],
115 default='host')
116 parser.add_argument('--arch', '-a',
117 type=str,
118 choices=['ia32', 'x64', 'simarm', 'arm', 'simarmv6', 'armv6',
119 'simarmv5te', 'armv5te', 'simmips', 'mips', 'simarm64', 'arm64',
120 'simdbc', 'simdbc64'],
121 default='x64')
122
123 parser.add_argument('--goma', default=True, action='store_true')
124 parser.add_argument('--no-goma', dest='goma', action='store_false')
125
126 parser.add_argument('--clang', default=True, action='store_true')
127 parser.add_argument('--no-clang', dest='clang', action='store_false')
128
129 parser.add_argument('--target-sysroot', '-s', type=str)
130 parser.add_argument('--toolchain-prefix', '-t', type=str)
131
132 return parser.parse_args(args)
133
134 def main(argv):
135 args = parse_args(argv)
136
137 if sys.platform.startswith(('cygwin', 'win')):
138 subdir = 'win'
139 elif sys.platform == 'darwin':
140 subdir = 'mac'
141 elif sys.platform.startswith('linux'):
142 subdir = 'linux64'
143 else:
144 raise Error('Unknown platform: ' + sys.platform)
145
146 command = [
147 '%s/buildtools/%s/gn' % (DART_ROOT, subdir),
148 'gen',
149 '--check'
150 ]
151 gn_args = to_command_line(to_gn_args(args))
152 out_dir = get_out_dir(args)
153 print "gn gen --check in %s" % out_dir
154 command.append(out_dir)
155 command.append('--args=%s' % ' '.join(gn_args))
156 return subprocess.call(command, cwd=DART_ROOT)
157
158 if __name__ == '__main__':
159 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « tools/clang/scripts/update.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698