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

Side by Side Diff: tools/dev/v8gen.py

Issue 2300333002: [gn] Add generic subcommands and provide list command (Closed)
Patch Set: s/x86/ia32 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 | « infra/mb/mb_config.pyl ('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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2016 the V8 project authors. All rights reserved. 2 # Copyright 2016 the V8 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 """Script to generate V8's gn arguments based on common developer defaults 6 """Script to generate V8's gn arguments based on common developer defaults
7 or builder configurations. 7 or builder configurations.
8 8
9 Goma is used by default if a goma folder is detected. The compiler proxy is 9 Goma is used by default if detected. The compiler proxy is assumed to run.
10 assumed to run.
11 10
12 This script can be added to the PATH and be used on other v8 checkouts than 11 This script can be added to the PATH and be used on other checkouts. It always
13 the including one. It always runs for the checkout that nests the CWD. 12 runs for the checkout nesting the CWD.
14 13
15 Configurations of this script live in infra/mb/mb_config.pyl. 14 Configurations of this script live in infra/mb/mb_config.pyl.
16 15
16 Available actions are: {gen,list}. Omitting the action defaults to "gen".
17
17 ------------------------------------------------------------------------------- 18 -------------------------------------------------------------------------------
18 19
19 Examples: 20 Examples:
20 21
21 # Generate the x64.release config in out.gn/x64.release. 22 # Generate the ia32.release config in out.gn/ia32.release.
22 v8gen.py x64.release 23 v8gen.py ia32.release
23 24
24 # Generate into out.gn/foo and disable goma auto-detect. 25 # Generate into out.gn/foo without goma auto-detect.
25 v8gen.py -b x64.release foo --no-goma 26 v8gen.py gen -b ia32.release foo --no-goma
26 27
27 # Pass additional gn arguments after -- (don't use spaces within gn args). 28 # Pass additional gn arguments after -- (don't use spaces within gn args).
28 v8gen.py x64.optdebug -- v8_enable_slow_dchecks=true 29 v8gen.py ia32.optdebug -- v8_enable_slow_dchecks=true
29 30
30 # Generate gn arguments of 'V8 Linux64 - builder' from 'client.v8'. To switch 31 # Generate gn arguments of 'V8 Linux64 - builder' from 'client.v8'. To switch
31 # off goma usage here, the args.gn file must be edited manually. 32 # off goma usage here, the args.gn file must be edited manually.
32 v8gen.py -m client.v8 -b 'V8 Linux64 - builder' 33 v8gen.py -m client.v8 -b 'V8 Linux64 - builder'
33 34
35 # Show available configurations.
36 v8gen.py list
37
34 ------------------------------------------------------------------------------- 38 -------------------------------------------------------------------------------
35 """ 39 """
36 40
37 import argparse 41 import argparse
38 import os 42 import os
39 import re 43 import re
40 import subprocess 44 import subprocess
41 import sys 45 import sys
42 46
47 CONFIG = os.path.join('infra', 'mb', 'mb_config.pyl')
43 GOMA_DEFAULT = os.path.join(os.path.expanduser("~"), 'goma') 48 GOMA_DEFAULT = os.path.join(os.path.expanduser("~"), 'goma')
44 OUT_DIR = 'out.gn' 49 OUT_DIR = 'out.gn'
45 50
51 TOOLS_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
52 sys.path.append(os.path.join(TOOLS_PATH, 'mb'))
53
54 import mb
55
46 56
47 def _sanitize_nonalpha(text): 57 def _sanitize_nonalpha(text):
48 return re.sub(r'[^a-zA-Z0-9.]', '_', text) 58 return re.sub(r'[^a-zA-Z0-9.]', '_', text)
49 59
50 60
51 class GenerateGnArgs(object): 61 class GenerateGnArgs(object):
52 def __init__(self, args): 62 def __init__(self, args):
53 # Split args into this script's arguments and gn args passed to the 63 # Split args into this script's arguments and gn args passed to the
54 # wrapped gn. 64 # wrapped gn.
55 index = args.index('--') if '--' in args else len(args) 65 index = args.index('--') if '--' in args else len(args)
56 self._options = self._parse_arguments(args[:index]) 66 self._options = self._parse_arguments(args[:index])
57 self._gn_args = args[index + 1:] 67 self._gn_args = args[index + 1:]
58 68
59 def _parse_arguments(self, args): 69 def _parse_arguments(self, args):
60 parser = argparse.ArgumentParser( 70 self.parser = argparse.ArgumentParser(
61 description=__doc__, 71 description=__doc__,
62 formatter_class=argparse.RawTextHelpFormatter, 72 formatter_class=argparse.RawTextHelpFormatter,
63 ) 73 )
64 parser.add_argument( 74
75 def add_common_options(p):
76 p.add_argument(
77 '-m', '--master', default='developer_default',
78 help='config group or master from mb_config.pyl - default: '
79 'developer_default')
80 p.add_argument(
81 '-v', '--verbosity', action='count',
82 help='print wrapped commands (use -vv to print output of wrapped '
83 'commands)')
84
85 subps = self.parser.add_subparsers()
86
87 # Command: gen.
88 gen_cmd = subps.add_parser(
89 'gen', help='generate a new set of build files (default)')
90 gen_cmd.set_defaults(func=self.cmd_gen)
91 add_common_options(gen_cmd)
92 gen_cmd.add_argument(
65 'outdir', nargs='?', 93 'outdir', nargs='?',
66 help='optional gn output directory') 94 help='optional gn output directory')
67 parser.add_argument( 95 gen_cmd.add_argument(
68 '-b', '--builder', 96 '-b', '--builder',
69 help='build configuration or builder name from mb_config.pyl, e.g. ' 97 help='build configuration or builder name from mb_config.pyl, e.g. '
70 'x64.release') 98 'x64.release')
71 parser.add_argument( 99 gen_cmd.add_argument(
72 '-m', '--master', default='developer_default',
73 help='config group or master from mb_config.pyl - default: '
74 'developer_default')
75 parser.add_argument(
76 '-p', '--pedantic', action='store_true', 100 '-p', '--pedantic', action='store_true',
77 help='run gn over command-line gn args to catch errors early') 101 help='run gn over command-line gn args to catch errors early')
78 parser.add_argument(
79 '-v', '--verbosity', action='count',
80 help='print wrapped commands (use -vv to print output of wrapped '
81 'commands)')
82 102
83 goma = parser.add_mutually_exclusive_group() 103 goma = gen_cmd.add_mutually_exclusive_group()
84 goma.add_argument( 104 goma.add_argument(
85 '-g' , '--goma', 105 '-g' , '--goma',
86 action='store_true', default=None, dest='goma', 106 action='store_true', default=None, dest='goma',
87 help='force using goma') 107 help='force using goma')
88 goma.add_argument( 108 goma.add_argument(
89 '--nogoma', '--no-goma', 109 '--nogoma', '--no-goma',
90 action='store_false', default=None, dest='goma', 110 action='store_false', default=None, dest='goma',
91 help='don\'t use goma auto detection - goma might still be used if ' 111 help='don\'t use goma auto detection - goma might still be used if '
92 'specified as a gn arg') 112 'specified as a gn arg')
93 113
94 options = parser.parse_args(args) 114 # Command: list.
115 list_cmd = subps.add_parser(
116 'list', help='list available configurations')
117 list_cmd.set_defaults(func=self.cmd_list)
118 add_common_options(list_cmd)
95 119
96 if not options.outdir and not options.builder: 120 # Default to "gen" unless global help is requested.
97 parser.error('please specify either an output directory or ' 121 if not args or args[0] not in subps.choices.keys() + ['-h', '--help']:
98 'a builder/config name (-b), e.g. x64.release') 122 args = ['gen'] + args
99 123
100 if not options.outdir: 124 return self.parser.parse_args(args)
125
126 def cmd_gen(self):
127 if not self._options.outdir and not self._options.builder:
128 self.parser.error('please specify either an output directory or '
129 'a builder/config name (-b), e.g. x64.release')
130
131 if not self._options.outdir:
101 # Derive output directory from builder name. 132 # Derive output directory from builder name.
102 options.outdir = _sanitize_nonalpha(options.builder) 133 self._options.outdir = _sanitize_nonalpha(self._options.builder)
103 else: 134 else:
104 # Also, if this should work on windows, we might need to use \ where 135 # Also, if this should work on windows, we might need to use \ where
105 # outdir is used as path, while using / if it's used in a gn context. 136 # outdir is used as path, while using / if it's used in a gn context.
106 if options.outdir.startswith('/'): 137 if self._options.outdir.startswith('/'):
107 parser.error( 138 self.parser.error(
108 'only output directories relative to %s are supported' % OUT_DIR) 139 'only output directories relative to %s are supported' % OUT_DIR)
109 140
110 if not options.builder: 141 if not self._options.builder:
111 # Derive builder from output directory. 142 # Derive builder from output directory.
112 options.builder = options.outdir 143 self._options.builder = self._options.outdir
113 144
114 return options 145 # Check for builder/config in mb config.
146 if self._options.builder not in self._mbw.masters[self._options.master]:
147 print '%s does not exist in %s for %s' % (
148 self._options.builder, CONFIG, self._options.master)
149 return 1
150
151 # TODO(machenbach): Check if the requested configurations has switched to
152 # gn at all.
153
154 # The directories are separated with slashes in a gn context (platform
155 # independent).
156 gn_outdir = '/'.join([OUT_DIR, self._options.outdir])
157
158 # Call MB to generate the basic configuration.
159 self._call_cmd([
160 sys.executable,
161 '-u', os.path.join('tools', 'mb', 'mb.py'),
162 'gen',
163 '-f', CONFIG,
164 '-m', self._options.master,
165 '-b', self._options.builder,
166 gn_outdir,
167 ])
168
169 # Handle extra gn arguments.
170 gn_args_path = os.path.join(OUT_DIR, self._options.outdir, 'args.gn')
171
172 # Append command-line args.
173 modified = self._append_gn_args(
174 'command-line', gn_args_path, '\n'.join(self._gn_args))
175
176 # Append goma args.
177 # TODO(machenbach): We currently can't remove existing goma args from the
178 # original config. E.g. to build like a bot that uses goma, but switch
179 # goma off.
180 modified |= self._append_gn_args(
181 'goma', gn_args_path, self._goma_args)
182
183 # Regenerate ninja files to check for errors in the additional gn args.
184 if modified and self._options.pedantic:
185 self._call_cmd(['gn', 'gen', gn_outdir])
186 return 0
187
188 def cmd_list(self):
189 print '\n'.join(sorted(self._mbw.masters[self._options.master]))
190 return 0
115 191
116 def verbose_print_1(self, text): 192 def verbose_print_1(self, text):
117 if self._options.verbosity >= 1: 193 if self._options.verbosity >= 1:
118 print '#' * 80 194 print '#' * 80
119 print text 195 print text
120 196
121 def verbose_print_2(self, text): 197 def verbose_print_2(self, text):
122 if self._options.verbosity >= 2: 198 if self._options.verbosity >= 2:
123 indent = ' ' * 2 199 indent = ' ' * 2
124 for l in text.splitlines(): 200 for l in text.splitlines():
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 return True 268 return True
193 269
194 def main(self): 270 def main(self):
195 # Always operate relative to the base directory for better relative-path 271 # Always operate relative to the base directory for better relative-path
196 # handling. This script can be used in any v8 checkout. 272 # handling. This script can be used in any v8 checkout.
197 workdir = self._find_work_dir(os.getcwd()) 273 workdir = self._find_work_dir(os.getcwd())
198 if workdir != os.getcwd(): 274 if workdir != os.getcwd():
199 self.verbose_print_1('cd ' + workdir) 275 self.verbose_print_1('cd ' + workdir)
200 os.chdir(workdir) 276 os.chdir(workdir)
201 277
202 # The directories are separated with slashes in a gn context (platform 278 # Initialize MB as a library.
203 # independent). 279 self._mbw = mb.MetaBuildWrapper()
204 gn_outdir = '/'.join([OUT_DIR, self._options.outdir])
205 280
206 # Call MB to generate the basic configuration. 281 # TODO(machenbach): Factor out common methods independent of mb arguments.
207 self._call_cmd([ 282 self._mbw.ParseArgs(['lookup', '-f', CONFIG])
208 sys.executable, 283 self._mbw.ReadConfigFile()
209 '-u', os.path.join('tools', 'mb', 'mb.py'),
210 'gen',
211 '-f', os.path.join('infra', 'mb', 'mb_config.pyl'),
212 '-m', self._options.master,
213 '-b', self._options.builder,
214 gn_outdir,
215 ])
216 284
217 # Handle extra gn arguments. 285 if not self._options.master in self._mbw.masters:
218 gn_args_path = os.path.join(OUT_DIR, self._options.outdir, 'args.gn') 286 print '%s not found in %s\n' % (self._options.master, CONFIG)
287 print 'Choose one of:\n%s\n' % (
288 '\n'.join(sorted(self._mbw.masters.keys())))
289 return 1
219 290
220 # Append command-line args. 291 return self._options.func()
221 modified = self._append_gn_args(
222 'command-line', gn_args_path, '\n'.join(self._gn_args))
223 292
224 # Append goma args.
225 # TODO(machenbach): We currently can't remove existing goma args from the
226 # original config. E.g. to build like a bot that uses goma, but switch
227 # goma off.
228 modified |= self._append_gn_args(
229 'goma', gn_args_path, self._goma_args)
230
231 # Regenerate ninja files to check for errors in the additional gn args.
232 if modified and self._options.pedantic:
233 self._call_cmd(['gn', 'gen', gn_outdir])
234 return 0
235 293
236 if __name__ == "__main__": 294 if __name__ == "__main__":
237 gen = GenerateGnArgs(sys.argv[1:]) 295 gen = GenerateGnArgs(sys.argv[1:])
238 try: 296 try:
239 sys.exit(gen.main()) 297 sys.exit(gen.main())
240 except Exception: 298 except Exception:
241 if gen._options.verbosity < 2: 299 if gen._options.verbosity < 2:
242 print ('\nHint: You can raise verbosity (-vv) to see the output of ' 300 print ('\nHint: You can raise verbosity (-vv) to see the output of '
243 'failed commands.\n') 301 'failed commands.\n')
244 raise 302 raise
OLDNEW
« no previous file with comments | « infra/mb/mb_config.pyl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698