blob: 24617779c64d9c11ac618579eccfaef4bb95dbc7 [file] [log] [blame]
dprankefe4602312015-04-08 16:20:351#!/usr/bin/env python
2# Copyright 2015 The Chromium 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
Dirk Pranke8cb6aa782017-12-16 02:31:336"""MB - the Meta-Build wrapper around GN.
dprankefe4602312015-04-08 16:20:357
Dirk Pranked181a1a2017-12-14 01:47:118MB is a wrapper script for GN that can be used to generate build files
dprankefe4602312015-04-08 16:20:359for sets of canned configurations and analyze them.
10"""
11
12from __future__ import print_function
13
14import argparse
15import ast
dprankec3441d12015-06-23 23:01:3516import errno
dprankefe4602312015-04-08 16:20:3517import json
18import os
dpranke68d1cb182015-09-17 23:30:0019import pipes
Dirk Pranke8cb6aa782017-12-16 02:31:3320import platform
dpranked8113582015-06-05 20:08:2521import pprint
dpranke3cec199c2015-09-22 23:29:0222import re
dprankefe4602312015-04-08 16:20:3523import shutil
24import sys
25import subprocess
dprankef61de2f2015-05-14 04:09:5626import tempfile
dprankebbe6d4672016-04-19 06:56:5727import traceback
dpranke867bcf4a2016-03-14 22:28:3228import urllib2
29
30from collections import OrderedDict
dprankefe4602312015-04-08 16:20:3531
dprankeeca4a782016-04-14 01:42:3832CHROMIUM_SRC_DIR = os.path.dirname(os.path.dirname(os.path.dirname(
33 os.path.abspath(__file__))))
34sys.path = [os.path.join(CHROMIUM_SRC_DIR, 'build')] + sys.path
35
36import gn_helpers
37
38
dprankefe4602312015-04-08 16:20:3539def main(args):
dprankeee5b51f62015-04-09 00:03:2240 mbw = MetaBuildWrapper()
dpranke255085e2016-03-16 05:23:5941 return mbw.Main(args)
dprankefe4602312015-04-08 16:20:3542
43
44class MetaBuildWrapper(object):
45 def __init__(self):
dprankeeca4a782016-04-14 01:42:3846 self.chromium_src_dir = CHROMIUM_SRC_DIR
47 self.default_config = os.path.join(self.chromium_src_dir, 'tools', 'mb',
48 'mb_config.pyl')
kjellander902bcb62016-10-26 06:20:5049 self.default_isolate_map = os.path.join(self.chromium_src_dir, 'testing',
50 'buildbot', 'gn_isolate_map.pyl')
dpranke8c2cfd32015-09-17 20:12:3351 self.executable = sys.executable
dpranked1fba482015-04-14 20:54:5152 self.platform = sys.platform
dpranke8c2cfd32015-09-17 20:12:3353 self.sep = os.sep
dprankefe4602312015-04-08 16:20:3554 self.args = argparse.Namespace()
55 self.configs = {}
Peter Collingbourne4dfb64a2017-08-12 01:00:5556 self.luci_tryservers = {}
dprankefe4602312015-04-08 16:20:3557 self.masters = {}
58 self.mixins = {}
dprankefe4602312015-04-08 16:20:3559
dpranke255085e2016-03-16 05:23:5960 def Main(self, args):
61 self.ParseArgs(args)
62 try:
63 ret = self.args.func()
64 if ret:
65 self.DumpInputFiles()
66 return ret
67 except KeyboardInterrupt:
dprankecb4a2e242016-09-19 01:13:1468 self.Print('interrupted, exiting')
dpranke255085e2016-03-16 05:23:5969 return 130
dprankebbe6d4672016-04-19 06:56:5770 except Exception:
dpranke255085e2016-03-16 05:23:5971 self.DumpInputFiles()
dprankebbe6d4672016-04-19 06:56:5772 s = traceback.format_exc()
73 for l in s.splitlines():
74 self.Print(l)
dpranke255085e2016-03-16 05:23:5975 return 1
76
dprankefe4602312015-04-08 16:20:3577 def ParseArgs(self, argv):
78 def AddCommonOptions(subp):
79 subp.add_argument('-b', '--builder',
80 help='builder name to look up config from')
81 subp.add_argument('-m', '--master',
82 help='master name to look up config from')
83 subp.add_argument('-c', '--config',
84 help='configuration to analyze')
shenghuazhang804b21542016-10-11 02:06:4985 subp.add_argument('--phase',
86 help='optional phase name (used when builders '
87 'do multiple compiles with different '
88 'arguments in a single build)')
dprankefe4602312015-04-08 16:20:3589 subp.add_argument('-f', '--config-file', metavar='PATH',
90 default=self.default_config,
91 help='path to config file '
kjellander902bcb62016-10-26 06:20:5092 '(default is %(default)s)')
93 subp.add_argument('-i', '--isolate-map-file', metavar='PATH',
kjellander902bcb62016-10-26 06:20:5094 help='path to isolate map file '
Zhiling Huang66958462018-02-03 00:28:2095 '(default is %(default)s)',
96 default=[],
97 action='append',
98 dest='isolate_map_files')
dpranked0c138b2016-04-13 18:28:4799 subp.add_argument('-g', '--goma-dir',
100 help='path to goma directory')
agrieve41d21a72016-04-14 18:02:26101 subp.add_argument('--android-version-code',
Dirk Pranked181a1a2017-12-14 01:47:11102 help='Sets GN arg android_default_version_code')
agrieve41d21a72016-04-14 18:02:26103 subp.add_argument('--android-version-name',
Dirk Pranked181a1a2017-12-14 01:47:11104 help='Sets GN arg android_default_version_name')
dprankefe4602312015-04-08 16:20:35105 subp.add_argument('-n', '--dryrun', action='store_true',
106 help='Do a dry run (i.e., do nothing, just print '
107 'the commands that will run)')
dprankee0547cd2015-09-15 01:27:40108 subp.add_argument('-v', '--verbose', action='store_true',
109 help='verbose logging')
dprankefe4602312015-04-08 16:20:35110
111 parser = argparse.ArgumentParser(prog='mb')
112 subps = parser.add_subparsers()
113
114 subp = subps.add_parser('analyze',
115 help='analyze whether changes to a set of files '
116 'will cause a set of binaries to be rebuilt.')
117 AddCommonOptions(subp)
dpranked8113582015-06-05 20:08:25118 subp.add_argument('path', nargs=1,
dprankefe4602312015-04-08 16:20:35119 help='path build was generated into.')
120 subp.add_argument('input_path', nargs=1,
121 help='path to a file containing the input arguments '
122 'as a JSON object.')
123 subp.add_argument('output_path', nargs=1,
124 help='path to a file containing the output arguments '
125 'as a JSON object.')
126 subp.set_defaults(func=self.CmdAnalyze)
127
dprankef37aebb92016-09-23 01:14:49128 subp = subps.add_parser('export',
129 help='print out the expanded configuration for'
130 'each builder as a JSON object')
131 subp.add_argument('-f', '--config-file', metavar='PATH',
132 default=self.default_config,
kjellander902bcb62016-10-26 06:20:50133 help='path to config file (default is %(default)s)')
dprankef37aebb92016-09-23 01:14:49134 subp.add_argument('-g', '--goma-dir',
135 help='path to goma directory')
136 subp.set_defaults(func=self.CmdExport)
137
dprankefe4602312015-04-08 16:20:35138 subp = subps.add_parser('gen',
139 help='generate a new set of build files')
140 AddCommonOptions(subp)
dpranke74559b52015-06-10 21:20:39141 subp.add_argument('--swarming-targets-file',
142 help='save runtime dependencies for targets listed '
143 'in file.')
dpranked8113582015-06-05 20:08:25144 subp.add_argument('path', nargs=1,
dprankefe4602312015-04-08 16:20:35145 help='path to generate build into')
146 subp.set_defaults(func=self.CmdGen)
147
dpranke751516a2015-10-03 01:11:34148 subp = subps.add_parser('isolate',
149 help='generate the .isolate files for a given'
150 'binary')
151 AddCommonOptions(subp)
152 subp.add_argument('path', nargs=1,
153 help='path build was generated into')
154 subp.add_argument('target', nargs=1,
155 help='ninja target to generate the isolate for')
156 subp.set_defaults(func=self.CmdIsolate)
157
dprankefe4602312015-04-08 16:20:35158 subp = subps.add_parser('lookup',
159 help='look up the command for a given config or '
160 'builder')
161 AddCommonOptions(subp)
162 subp.set_defaults(func=self.CmdLookup)
163
dpranke030d7a6d2016-03-26 17:23:50164 subp = subps.add_parser(
165 'run',
166 help='build and run the isolated version of a '
167 'binary',
168 formatter_class=argparse.RawDescriptionHelpFormatter)
169 subp.description = (
170 'Build, isolate, and run the given binary with the command line\n'
171 'listed in the isolate. You may pass extra arguments after the\n'
172 'target; use "--" if the extra arguments need to include switches.\n'
173 '\n'
174 'Examples:\n'
175 '\n'
176 ' % tools/mb/mb.py run -m chromium.linux -b "Linux Builder" \\\n'
177 ' //out/Default content_browsertests\n'
178 '\n'
179 ' % tools/mb/mb.py run out/Default content_browsertests\n'
180 '\n'
181 ' % tools/mb/mb.py run out/Default content_browsertests -- \\\n'
182 ' --test-launcher-retry-limit=0'
183 '\n'
184 )
dpranke751516a2015-10-03 01:11:34185 AddCommonOptions(subp)
186 subp.add_argument('-j', '--jobs', dest='jobs', type=int,
187 help='Number of jobs to pass to ninja')
188 subp.add_argument('--no-build', dest='build', default=True,
189 action='store_false',
190 help='Do not build, just isolate and run')
191 subp.add_argument('path', nargs=1,
dpranke030d7a6d2016-03-26 17:23:50192 help=('path to generate build into (or use).'
193 ' This can be either a regular path or a '
194 'GN-style source-relative path like '
195 '//out/Default.'))
Dirk Pranke8cb6aa782017-12-16 02:31:33196 subp.add_argument('-s', '--swarmed', action='store_true',
197 help='Run under swarming with the default dimensions')
198 subp.add_argument('-d', '--dimension', default=[], action='append', nargs=2,
199 dest='dimensions', metavar='FOO bar',
200 help='dimension to filter on')
201 subp.add_argument('--no-default-dimensions', action='store_false',
202 dest='default_dimensions', default=True,
203 help='Do not automatically add dimensions to the task')
dpranke751516a2015-10-03 01:11:34204 subp.add_argument('target', nargs=1,
205 help='ninja target to build and run')
dpranke030d7a6d2016-03-26 17:23:50206 subp.add_argument('extra_args', nargs='*',
207 help=('extra args to pass to the isolate to run. Use '
208 '"--" as the first arg if you need to pass '
209 'switches'))
dpranke751516a2015-10-03 01:11:34210 subp.set_defaults(func=self.CmdRun)
211
dprankefe4602312015-04-08 16:20:35212 subp = subps.add_parser('validate',
213 help='validate the config file')
dprankea5a77ca2015-07-16 23:24:17214 subp.add_argument('-f', '--config-file', metavar='PATH',
215 default=self.default_config,
kjellander902bcb62016-10-26 06:20:50216 help='path to config file (default is %(default)s)')
dprankefe4602312015-04-08 16:20:35217 subp.set_defaults(func=self.CmdValidate)
218
Peter Collingbourne4dfb64a2017-08-12 01:00:55219 subp = subps.add_parser('gerrit-buildbucket-config',
220 help='Print buildbucket.config for gerrit '
221 '(see MB user guide)')
222 subp.add_argument('-f', '--config-file', metavar='PATH',
223 default=self.default_config,
224 help='path to config file (default is %(default)s)')
225 subp.set_defaults(func=self.CmdBuildbucket)
226
dprankefe4602312015-04-08 16:20:35227 subp = subps.add_parser('help',
228 help='Get help on a subcommand.')
229 subp.add_argument(nargs='?', action='store', dest='subcommand',
230 help='The command to get help for.')
231 subp.set_defaults(func=self.CmdHelp)
232
233 self.args = parser.parse_args(argv)
234
dprankeb2be10a2016-02-22 17:11:00235 def DumpInputFiles(self):
236
dprankef7b7eb7a2016-03-28 22:42:59237 def DumpContentsOfFilePassedTo(arg_name, path):
dprankeb2be10a2016-02-22 17:11:00238 if path and self.Exists(path):
dprankef7b7eb7a2016-03-28 22:42:59239 self.Print("\n# To recreate the file passed to %s:" % arg_name)
dprankecb4a2e242016-09-19 01:13:14240 self.Print("%% cat > %s <<EOF" % path)
dprankeb2be10a2016-02-22 17:11:00241 contents = self.ReadFile(path)
dprankef7b7eb7a2016-03-28 22:42:59242 self.Print(contents)
243 self.Print("EOF\n%\n")
dprankeb2be10a2016-02-22 17:11:00244
dprankef7b7eb7a2016-03-28 22:42:59245 if getattr(self.args, 'input_path', None):
246 DumpContentsOfFilePassedTo(
247 'argv[0] (input_path)', self.args.input_path[0])
248 if getattr(self.args, 'swarming_targets_file', None):
249 DumpContentsOfFilePassedTo(
250 '--swarming-targets-file', self.args.swarming_targets_file)
dprankeb2be10a2016-02-22 17:11:00251
dprankefe4602312015-04-08 16:20:35252 def CmdAnalyze(self):
dpranke751516a2015-10-03 01:11:34253 vals = self.Lookup()
Dirk Pranked181a1a2017-12-14 01:47:11254 return self.RunGNAnalyze(vals)
dprankefe4602312015-04-08 16:20:35255
dprankef37aebb92016-09-23 01:14:49256 def CmdExport(self):
257 self.ReadConfigFile()
258 obj = {}
259 for master, builders in self.masters.items():
260 obj[master] = {}
261 for builder in builders:
262 config = self.masters[master][builder]
263 if not config:
264 continue
265
shenghuazhang804b21542016-10-11 02:06:49266 if isinstance(config, dict):
267 args = {k: self.FlattenConfig(v)['gn_args']
268 for k, v in config.items()}
dprankef37aebb92016-09-23 01:14:49269 elif config.startswith('//'):
270 args = config
271 else:
272 args = self.FlattenConfig(config)['gn_args']
273 if 'error' in args:
274 continue
275
276 obj[master][builder] = args
277
278 # Dump object and trim trailing whitespace.
279 s = '\n'.join(l.rstrip() for l in
280 json.dumps(obj, sort_keys=True, indent=2).splitlines())
281 self.Print(s)
282 return 0
283
dprankefe4602312015-04-08 16:20:35284 def CmdGen(self):
dpranke751516a2015-10-03 01:11:34285 vals = self.Lookup()
Dirk Pranked181a1a2017-12-14 01:47:11286 return self.RunGNGen(vals)
dprankefe4602312015-04-08 16:20:35287
288 def CmdHelp(self):
289 if self.args.subcommand:
290 self.ParseArgs([self.args.subcommand, '--help'])
291 else:
292 self.ParseArgs(['--help'])
293
dpranke751516a2015-10-03 01:11:34294 def CmdIsolate(self):
295 vals = self.GetConfig()
296 if not vals:
297 return 1
Dirk Pranked181a1a2017-12-14 01:47:11298 return self.RunGNIsolate(vals)
dpranke751516a2015-10-03 01:11:34299
300 def CmdLookup(self):
301 vals = self.Lookup()
Dirk Pranked181a1a2017-12-14 01:47:11302 cmd = self.GNCmd('gen', '_path_')
303 gn_args = self.GNArgs(vals)
304 self.Print('\nWriting """\\\n%s""" to _path_/args.gn.\n' % gn_args)
305 env = None
dpranke751516a2015-10-03 01:11:34306
307 self.PrintCmd(cmd, env)
308 return 0
309
310 def CmdRun(self):
311 vals = self.GetConfig()
312 if not vals:
313 return 1
314
315 build_dir = self.args.path[0]
316 target = self.args.target[0]
317
Dirk Pranked181a1a2017-12-14 01:47:11318 if self.args.build:
319 ret = self.Build(target)
dpranke751516a2015-10-03 01:11:34320 if ret:
321 return ret
Dirk Pranked181a1a2017-12-14 01:47:11322 ret = self.RunGNIsolate(vals)
323 if ret:
324 return ret
dpranke751516a2015-10-03 01:11:34325
Dirk Pranke8cb6aa782017-12-16 02:31:33326 if self.args.swarmed:
327 return self._RunUnderSwarming(build_dir, target)
328 else:
329 return self._RunLocallyIsolated(build_dir, target)
330
Robert Iannucci5a9d75f62018-03-02 05:28:20331 @staticmethod
332 def _AddBaseSoftware(cmd):
333 # HACK(iannucci): These packages SHOULD NOT BE HERE.
334 # Remove method once Swarming Pool Task Templates are implemented.
335 # crbug.com/812428
336
337 # Add in required base software. This should be kept in sync with the
338 # `swarming` recipe module in build.git. All references to `swarming_module`
339 # below are purely due to this.
340 cipd_packages = [
341 ('infra/python/cpython/${platform}',
342 'version:2.7.14.chromium14'),
343 ('infra/tools/luci/logdog/butler/${platform}',
344 'git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c'),
345 ('infra/tools/luci/vpython-native/${platform}',
346 'git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c'),
347 ('infra/tools/luci/vpython/${platform}',
348 'git_revision:e1abc57be62d198b5c2f487bfb2fa2d2eb0e867c'),
349 ]
350 for pkg, vers in cipd_packages:
351 cmd.append('--cipd-package=.swarming_module:%s:%s' % (pkg, vers))
352
353 # Add packages to $PATH
354 cmd.extend([
355 '--env-prefix=PATH', '.swarming_module',
356 '--env-prefix=PATH', '.swarming_module/bin',
357 ])
358
359 # Add cache directives for vpython.
360 vpython_cache_path = '.swarming_module_cache/vpython'
361 cmd.extend([
362 '--named-cache=swarming_module_cache_vpython', vpython_cache_path,
363 '--env-prefix=VPYTHON_VIRTUALENV_ROOT', vpython_cache_path,
364 ])
365
Dirk Pranke8cb6aa782017-12-16 02:31:33366 def _RunUnderSwarming(self, build_dir, target):
367 # TODO(dpranke): Look up the information for the target in
368 # the //testing/buildbot.json file, if possible, so that we
369 # can determine the isolate target, command line, and additional
370 # swarming parameters, if possible.
371 #
372 # TODO(dpranke): Also, add support for sharding and merging results.
373 dimensions = []
374 for k, v in self._DefaultDimensions() + self.args.dimensions:
375 dimensions += ['-d', k, v]
376
377 cmd = [
378 self.executable,
379 self.PathJoin('tools', 'swarming_client', 'isolate.py'),
380 'archive',
381 '-s',
382 self.ToSrcRelPath('%s/%s.isolated' % (build_dir, target)),
383 '-I', 'isolateserver.appspot.com',
384 ]
385 ret, out, _ = self.Run(cmd, force_verbose=False)
386 if ret:
387 return ret
388
389 isolated_hash = out.splitlines()[0].split()[0]
390 cmd = [
391 self.executable,
392 self.PathJoin('tools', 'swarming_client', 'swarming.py'),
393 'run',
394 '-s', isolated_hash,
395 '-I', 'isolateserver.appspot.com',
396 '-S', 'chromium-swarm.appspot.com',
397 ] + dimensions
Robert Iannucci5a9d75f62018-03-02 05:28:20398 self._AddBaseSoftware(cmd)
Dirk Pranke8cb6aa782017-12-16 02:31:33399 if self.args.extra_args:
400 cmd += ['--'] + self.args.extra_args
401 ret, _, _ = self.Run(cmd, force_verbose=True, buffer_output=False)
402 return ret
403
404 def _RunLocallyIsolated(self, build_dir, target):
dpranke030d7a6d2016-03-26 17:23:50405 cmd = [
dpranke751516a2015-10-03 01:11:34406 self.executable,
407 self.PathJoin('tools', 'swarming_client', 'isolate.py'),
408 'run',
409 '-s',
dpranke030d7a6d2016-03-26 17:23:50410 self.ToSrcRelPath('%s/%s.isolated' % (build_dir, target)),
Dirk Pranke8cb6aa782017-12-16 02:31:33411 ]
dpranke030d7a6d2016-03-26 17:23:50412 if self.args.extra_args:
Dirk Pranke8cb6aa782017-12-16 02:31:33413 cmd += ['--'] + self.args.extra_args
414 ret, _, _ = self.Run(cmd, force_verbose=True, buffer_output=False)
dpranke751516a2015-10-03 01:11:34415 return ret
416
Dirk Pranke8cb6aa782017-12-16 02:31:33417 def _DefaultDimensions(self):
418 if not self.args.default_dimensions:
419 return []
420
421 # This code is naive and just picks reasonable defaults per platform.
422 if self.platform == 'darwin':
423 os_dim = ('os', 'Mac-10.12')
424 elif self.platform.startswith('linux'):
425 os_dim = ('os', 'Ubuntu-14.04')
426 elif self.platform == 'win32':
427 os_dim = ('os', 'Windows-10-14393')
428 else:
429 raise MBErr('unrecognized platform string "%s"' % self.platform)
430
431 return [('pool', 'Chrome'),
432 ('cpu', 'x86-64'),
433 os_dim]
434
Peter Collingbourne4dfb64a2017-08-12 01:00:55435 def CmdBuildbucket(self):
436 self.ReadConfigFile()
437
438 self.Print('# This file was generated using '
439 '"tools/mb/mb.py gerrit-buildbucket-config".')
440
441 for luci_tryserver in sorted(self.luci_tryservers):
442 self.Print('[bucket "luci.%s"]' % luci_tryserver)
443 for bot in sorted(self.luci_tryservers[luci_tryserver]):
444 self.Print('\tbuilder = %s' % bot)
445
446 for master in sorted(self.masters):
447 if master.startswith('tryserver.'):
448 self.Print('[bucket "master.%s"]' % master)
449 for bot in sorted(self.masters[master]):
450 self.Print('\tbuilder = %s' % bot)
451
452 return 0
453
dpranke0cafc162016-03-19 00:41:10454 def CmdValidate(self, print_ok=True):
dprankefe4602312015-04-08 16:20:35455 errs = []
456
457 # Read the file to make sure it parses.
458 self.ReadConfigFile()
459
dpranke3be00142016-03-17 22:46:04460 # Build a list of all of the configs referenced by builders.
dprankefe4602312015-04-08 16:20:35461 all_configs = {}
dprankefe4602312015-04-08 16:20:35462 for master in self.masters:
dpranke3be00142016-03-17 22:46:04463 for config in self.masters[master].values():
shenghuazhang804b21542016-10-11 02:06:49464 if isinstance(config, dict):
465 for c in config.values():
dprankeb9380a12016-07-21 21:44:09466 all_configs[c] = master
467 else:
468 all_configs[config] = master
dprankefe4602312015-04-08 16:20:35469
dpranke9dd5e252016-04-14 04:23:09470 # Check that every referenced args file or config actually exists.
dprankefe4602312015-04-08 16:20:35471 for config, loc in all_configs.items():
dpranke9dd5e252016-04-14 04:23:09472 if config.startswith('//'):
473 if not self.Exists(self.ToAbsPath(config)):
474 errs.append('Unknown args file "%s" referenced from "%s".' %
475 (config, loc))
476 elif not config in self.configs:
dprankefe4602312015-04-08 16:20:35477 errs.append('Unknown config "%s" referenced from "%s".' %
478 (config, loc))
479
480 # Check that every actual config is actually referenced.
481 for config in self.configs:
482 if not config in all_configs:
483 errs.append('Unused config "%s".' % config)
484
485 # Figure out the whole list of mixins, and check that every mixin
486 # listed by a config or another mixin actually exists.
487 referenced_mixins = set()
488 for config, mixins in self.configs.items():
489 for mixin in mixins:
490 if not mixin in self.mixins:
491 errs.append('Unknown mixin "%s" referenced by config "%s".' %
492 (mixin, config))
493 referenced_mixins.add(mixin)
494
495 for mixin in self.mixins:
496 for sub_mixin in self.mixins[mixin].get('mixins', []):
497 if not sub_mixin in self.mixins:
498 errs.append('Unknown mixin "%s" referenced by mixin "%s".' %
499 (sub_mixin, mixin))
500 referenced_mixins.add(sub_mixin)
501
502 # Check that every mixin defined is actually referenced somewhere.
503 for mixin in self.mixins:
504 if not mixin in referenced_mixins:
505 errs.append('Unreferenced mixin "%s".' % mixin)
506
dpranke255085e2016-03-16 05:23:59507 # If we're checking the Chromium config, check that the 'chromium' bots
508 # which build public artifacts do not include the chrome_with_codecs mixin.
509 if self.args.config_file == self.default_config:
510 if 'chromium' in self.masters:
511 for builder in self.masters['chromium']:
512 config = self.masters['chromium'][builder]
513 def RecurseMixins(current_mixin):
514 if current_mixin == 'chrome_with_codecs':
515 errs.append('Public artifact builder "%s" can not contain the '
516 '"chrome_with_codecs" mixin.' % builder)
517 return
518 if not 'mixins' in self.mixins[current_mixin]:
519 return
520 for mixin in self.mixins[current_mixin]['mixins']:
521 RecurseMixins(mixin)
dalecurtis56fd27e2016-03-09 23:06:41522
dpranke255085e2016-03-16 05:23:59523 for mixin in self.configs[config]:
524 RecurseMixins(mixin)
525 else:
526 errs.append('Missing "chromium" master. Please update this '
527 'proprietary codecs check with the name of the master '
528 'responsible for public build artifacts.')
dalecurtis56fd27e2016-03-09 23:06:41529
dprankefe4602312015-04-08 16:20:35530 if errs:
dpranke4323c80632015-08-10 22:53:54531 raise MBErr(('mb config file %s has problems:' % self.args.config_file) +
dprankea33267872015-08-12 15:45:17532 '\n ' + '\n '.join(errs))
dprankefe4602312015-04-08 16:20:35533
dpranke0cafc162016-03-19 00:41:10534 if print_ok:
535 self.Print('mb config file %s looks ok.' % self.args.config_file)
dprankefe4602312015-04-08 16:20:35536 return 0
537
538 def GetConfig(self):
dpranke751516a2015-10-03 01:11:34539 build_dir = self.args.path[0]
540
dprankef37aebb92016-09-23 01:14:49541 vals = self.DefaultVals()
dpranke751516a2015-10-03 01:11:34542 if self.args.builder or self.args.master or self.args.config:
543 vals = self.Lookup()
Dirk Pranked181a1a2017-12-14 01:47:11544 # Re-run gn gen in order to ensure the config is consistent with the
545 # build dir.
546 self.RunGNGen(vals)
dpranke751516a2015-10-03 01:11:34547 return vals
548
Dirk Pranked181a1a2017-12-14 01:47:11549 toolchain_path = self.PathJoin(self.ToAbsPath(build_dir),
550 'toolchain.ninja')
551 if not self.Exists(toolchain_path):
552 self.Print('Must either specify a path to an existing GN build dir '
553 'or pass in a -m/-b pair or a -c flag to specify the '
554 'configuration')
555 return {}
dpranke751516a2015-10-03 01:11:34556
Dirk Pranked181a1a2017-12-14 01:47:11557 vals['gn_args'] = self.GNArgsFromDir(build_dir)
dpranke751516a2015-10-03 01:11:34558 return vals
559
dprankef37aebb92016-09-23 01:14:49560 def GNArgsFromDir(self, build_dir):
brucedawsonecc0c1cd2016-06-02 18:24:58561 args_contents = ""
562 gn_args_path = self.PathJoin(self.ToAbsPath(build_dir), 'args.gn')
563 if self.Exists(gn_args_path):
564 args_contents = self.ReadFile(gn_args_path)
dpranke751516a2015-10-03 01:11:34565 gn_args = []
566 for l in args_contents.splitlines():
567 fields = l.split(' ')
568 name = fields[0]
569 val = ' '.join(fields[2:])
570 gn_args.append('%s=%s' % (name, val))
571
dprankef37aebb92016-09-23 01:14:49572 return ' '.join(gn_args)
dpranke751516a2015-10-03 01:11:34573
574 def Lookup(self):
dprankef37aebb92016-09-23 01:14:49575 vals = self.ReadIOSBotConfig()
dprankee0f486f2015-11-19 23:42:00576 if not vals:
577 self.ReadConfigFile()
578 config = self.ConfigFromArgs()
dpranke9dd5e252016-04-14 04:23:09579 if config.startswith('//'):
580 if not self.Exists(self.ToAbsPath(config)):
581 raise MBErr('args file "%s" not found' % config)
dprankef37aebb92016-09-23 01:14:49582 vals = self.DefaultVals()
583 vals['args_file'] = config
dpranke9dd5e252016-04-14 04:23:09584 else:
585 if not config in self.configs:
586 raise MBErr('Config "%s" not found in %s' %
587 (config, self.args.config_file))
588 vals = self.FlattenConfig(config)
dpranke751516a2015-10-03 01:11:34589 return vals
dprankefe4602312015-04-08 16:20:35590
dprankef37aebb92016-09-23 01:14:49591 def ReadIOSBotConfig(self):
dprankee0f486f2015-11-19 23:42:00592 if not self.args.master or not self.args.builder:
593 return {}
594 path = self.PathJoin(self.chromium_src_dir, 'ios', 'build', 'bots',
595 self.args.master, self.args.builder + '.json')
596 if not self.Exists(path):
597 return {}
598
599 contents = json.loads(self.ReadFile(path))
dprankee0f486f2015-11-19 23:42:00600 gn_args = ' '.join(contents.get('gn_args', []))
601
dprankef37aebb92016-09-23 01:14:49602 vals = self.DefaultVals()
603 vals['gn_args'] = gn_args
dprankef37aebb92016-09-23 01:14:49604 return vals
dprankee0f486f2015-11-19 23:42:00605
dprankefe4602312015-04-08 16:20:35606 def ReadConfigFile(self):
607 if not self.Exists(self.args.config_file):
608 raise MBErr('config file not found at %s' % self.args.config_file)
609
610 try:
611 contents = ast.literal_eval(self.ReadFile(self.args.config_file))
612 except SyntaxError as e:
613 raise MBErr('Failed to parse config file "%s": %s' %
614 (self.args.config_file, e))
615
dprankefe4602312015-04-08 16:20:35616 self.configs = contents['configs']
Peter Collingbourne4dfb64a2017-08-12 01:00:55617 self.luci_tryservers = contents.get('luci_tryservers', {})
dprankefe4602312015-04-08 16:20:35618 self.masters = contents['masters']
619 self.mixins = contents['mixins']
dprankefe4602312015-04-08 16:20:35620
dprankecb4a2e242016-09-19 01:13:14621 def ReadIsolateMap(self):
Zhiling Huang66958462018-02-03 00:28:20622 if not self.args.isolate_map_files:
623 self.args.isolate_map_files = [self.default_isolate_map]
624
625 for f in self.args.isolate_map_files:
626 if not self.Exists(f):
627 raise MBErr('isolate map file not found at %s' % f)
628 isolate_maps = {}
629 for isolate_map in self.args.isolate_map_files:
630 try:
631 isolate_map = ast.literal_eval(self.ReadFile(isolate_map))
632 duplicates = set(isolate_map).intersection(isolate_maps)
633 if duplicates:
634 raise MBErr(
635 'Duplicate targets in isolate map files: %s.' %
636 ', '.join(duplicates))
637 isolate_maps.update(isolate_map)
638 except SyntaxError as e:
639 raise MBErr(
640 'Failed to parse isolate map file "%s": %s' % (isolate_map, e))
641 return isolate_maps
dprankecb4a2e242016-09-19 01:13:14642
dprankefe4602312015-04-08 16:20:35643 def ConfigFromArgs(self):
644 if self.args.config:
645 if self.args.master or self.args.builder:
646 raise MBErr('Can not specific both -c/--config and -m/--master or '
647 '-b/--builder')
648
649 return self.args.config
650
651 if not self.args.master or not self.args.builder:
652 raise MBErr('Must specify either -c/--config or '
653 '(-m/--master and -b/--builder)')
654
655 if not self.args.master in self.masters:
656 raise MBErr('Master name "%s" not found in "%s"' %
657 (self.args.master, self.args.config_file))
658
659 if not self.args.builder in self.masters[self.args.master]:
660 raise MBErr('Builder name "%s" not found under masters[%s] in "%s"' %
661 (self.args.builder, self.args.master, self.args.config_file))
662
dprankeb9380a12016-07-21 21:44:09663 config = self.masters[self.args.master][self.args.builder]
shenghuazhang804b21542016-10-11 02:06:49664 if isinstance(config, dict):
dprankeb9380a12016-07-21 21:44:09665 if self.args.phase is None:
666 raise MBErr('Must specify a build --phase for %s on %s' %
667 (self.args.builder, self.args.master))
shenghuazhang804b21542016-10-11 02:06:49668 phase = str(self.args.phase)
669 if phase not in config:
670 raise MBErr('Phase %s doesn\'t exist for %s on %s' %
dprankeb9380a12016-07-21 21:44:09671 (phase, self.args.builder, self.args.master))
shenghuazhang804b21542016-10-11 02:06:49672 return config[phase]
dprankeb9380a12016-07-21 21:44:09673
674 if self.args.phase is not None:
675 raise MBErr('Must not specify a build --phase for %s on %s' %
676 (self.args.builder, self.args.master))
677 return config
dprankefe4602312015-04-08 16:20:35678
679 def FlattenConfig(self, config):
680 mixins = self.configs[config]
dprankef37aebb92016-09-23 01:14:49681 vals = self.DefaultVals()
dprankefe4602312015-04-08 16:20:35682
683 visited = []
684 self.FlattenMixins(mixins, vals, visited)
685 return vals
686
dprankef37aebb92016-09-23 01:14:49687 def DefaultVals(self):
688 return {
689 'args_file': '',
690 'cros_passthrough': False,
691 'gn_args': '',
dprankef37aebb92016-09-23 01:14:49692 }
693
dprankefe4602312015-04-08 16:20:35694 def FlattenMixins(self, mixins, vals, visited):
695 for m in mixins:
696 if m not in self.mixins:
697 raise MBErr('Unknown mixin "%s"' % m)
dprankeee5b51f62015-04-09 00:03:22698
dprankefe4602312015-04-08 16:20:35699 visited.append(m)
700
701 mixin_vals = self.mixins[m]
dpranke73ed0d62016-04-25 19:18:34702
703 if 'cros_passthrough' in mixin_vals:
704 vals['cros_passthrough'] = mixin_vals['cros_passthrough']
Dirk Pranke6b99f072017-04-05 00:58:30705 if 'args_file' in mixin_vals:
706 if vals['args_file']:
707 raise MBErr('args_file specified multiple times in mixins '
708 'for %s on %s' % (self.args.builder, self.args.master))
709 vals['args_file'] = mixin_vals['args_file']
dprankefe4602312015-04-08 16:20:35710 if 'gn_args' in mixin_vals:
711 if vals['gn_args']:
712 vals['gn_args'] += ' ' + mixin_vals['gn_args']
713 else:
714 vals['gn_args'] = mixin_vals['gn_args']
dpranke73ed0d62016-04-25 19:18:34715
dprankefe4602312015-04-08 16:20:35716 if 'mixins' in mixin_vals:
717 self.FlattenMixins(mixin_vals['mixins'], vals, visited)
718 return vals
719
Dirk Prankea3727f92017-07-17 17:30:33720 def RunGNGen(self, vals, compute_grit_inputs_for_analyze=False):
dpranke751516a2015-10-03 01:11:34721 build_dir = self.args.path[0]
Dirk Pranke0fd41bcd2015-06-19 00:05:50722
dprankeeca4a782016-04-14 01:42:38723 cmd = self.GNCmd('gen', build_dir, '--check')
724 gn_args = self.GNArgs(vals)
Dirk Prankea3727f92017-07-17 17:30:33725 if compute_grit_inputs_for_analyze:
726 gn_args += ' compute_grit_inputs_for_analyze=true'
dprankeeca4a782016-04-14 01:42:38727
728 # Since GN hasn't run yet, the build directory may not even exist.
729 self.MaybeMakeDirectory(self.ToAbsPath(build_dir))
730
731 gn_args_path = self.ToAbsPath(build_dir, 'args.gn')
dpranke4ff8b9f2016-04-15 03:07:54732 self.WriteFile(gn_args_path, gn_args, force_verbose=True)
dpranke74559b52015-06-10 21:20:39733
734 swarming_targets = []
dpranke751516a2015-10-03 01:11:34735 if getattr(self.args, 'swarming_targets_file', None):
dpranke74559b52015-06-10 21:20:39736 # We need GN to generate the list of runtime dependencies for
737 # the compile targets listed (one per line) in the file so
dprankecb4a2e242016-09-19 01:13:14738 # we can run them via swarming. We use gn_isolate_map.pyl to convert
dpranke74559b52015-06-10 21:20:39739 # the compile targets to the matching GN labels.
dprankeb2be10a2016-02-22 17:11:00740 path = self.args.swarming_targets_file
741 if not self.Exists(path):
742 self.WriteFailureAndRaise('"%s" does not exist' % path,
743 output_path=None)
744 contents = self.ReadFile(path)
745 swarming_targets = set(contents.splitlines())
dprankeb2be10a2016-02-22 17:11:00746
dprankecb4a2e242016-09-19 01:13:14747 isolate_map = self.ReadIsolateMap()
748 err, labels = self.MapTargetsToLabels(isolate_map, swarming_targets)
dprankeb2be10a2016-02-22 17:11:00749 if err:
dprankecb4a2e242016-09-19 01:13:14750 raise MBErr(err)
dpranke74559b52015-06-10 21:20:39751
dpranke751516a2015-10-03 01:11:34752 gn_runtime_deps_path = self.ToAbsPath(build_dir, 'runtime_deps')
dprankecb4a2e242016-09-19 01:13:14753 self.WriteFile(gn_runtime_deps_path, '\n'.join(labels) + '\n')
dpranke74559b52015-06-10 21:20:39754 cmd.append('--runtime-deps-list-file=%s' % gn_runtime_deps_path)
755
dprankefe4602312015-04-08 16:20:35756 ret, _, _ = self.Run(cmd)
dprankee0547cd2015-09-15 01:27:40757 if ret:
758 # If `gn gen` failed, we should exit early rather than trying to
759 # generate isolates. Run() will have already logged any error output.
760 self.Print('GN gen failed: %d' % ret)
761 return ret
dpranke74559b52015-06-10 21:20:39762
jbudoricke3c4f95e2016-04-28 23:17:38763 android = 'target_os="android"' in vals['gn_args']
Kevin Marshallf35fa5f2018-01-29 19:24:42764 fuchsia = 'target_os="fuchsia"' in vals['gn_args']
Nico Weberd94b71a2018-02-22 22:00:30765 win = self.platform == 'win32' or 'target_os="win"' in vals['gn_args']
dpranke74559b52015-06-10 21:20:39766 for target in swarming_targets:
jbudoricke3c4f95e2016-04-28 23:17:38767 if android:
768 # Android targets may be either android_apk or executable. The former
jbudorick91c8a6012016-01-29 23:20:02769 # will result in runtime_deps associated with the stamp file, while the
770 # latter will result in runtime_deps associated with the executable.
dprankecb4a2e242016-09-19 01:13:14771 label = isolate_map[target]['label']
jbudorick91c8a6012016-01-29 23:20:02772 runtime_deps_targets = [
dprankecb4a2e242016-09-19 01:13:14773 target + '.runtime_deps',
dpranke48ccf8f2016-03-28 23:58:28774 'obj/%s.stamp.runtime_deps' % label.replace(':', '/')]
Kevin Marshallf35fa5f2018-01-29 19:24:42775 elif fuchsia:
776 # Only emit a runtime deps file for the group() target on Fuchsia.
777 label = isolate_map[target]['label']
778 runtime_deps_targets = [
779 'obj/%s.stamp.runtime_deps' % label.replace(':', '/')]
dprankecb4a2e242016-09-19 01:13:14780 elif (isolate_map[target]['type'] == 'script' or
781 isolate_map[target].get('label_type') == 'group'):
dpranke6abd8652015-08-28 03:21:11782 # For script targets, the build target is usually a group,
783 # for which gn generates the runtime_deps next to the stamp file
eyaich82d5ac942016-11-03 12:13:49784 # for the label, which lives under the obj/ directory, but it may
785 # also be an executable.
dprankecb4a2e242016-09-19 01:13:14786 label = isolate_map[target]['label']
dpranke48ccf8f2016-03-28 23:58:28787 runtime_deps_targets = [
788 'obj/%s.stamp.runtime_deps' % label.replace(':', '/')]
Nico Weberd94b71a2018-02-22 22:00:30789 if win:
eyaich82d5ac942016-11-03 12:13:49790 runtime_deps_targets += [ target + '.exe.runtime_deps' ]
791 else:
792 runtime_deps_targets += [ target + '.runtime_deps' ]
Nico Weberd94b71a2018-02-22 22:00:30793 elif win:
dpranke48ccf8f2016-03-28 23:58:28794 runtime_deps_targets = [target + '.exe.runtime_deps']
dpranke34bd39d2015-06-24 02:36:52795 else:
dpranke48ccf8f2016-03-28 23:58:28796 runtime_deps_targets = [target + '.runtime_deps']
jbudorick91c8a6012016-01-29 23:20:02797
dpranke48ccf8f2016-03-28 23:58:28798 for r in runtime_deps_targets:
799 runtime_deps_path = self.ToAbsPath(build_dir, r)
800 if self.Exists(runtime_deps_path):
jbudorick91c8a6012016-01-29 23:20:02801 break
802 else:
dpranke48ccf8f2016-03-28 23:58:28803 raise MBErr('did not generate any of %s' %
804 ', '.join(runtime_deps_targets))
dpranke74559b52015-06-10 21:20:39805
dprankecb4a2e242016-09-19 01:13:14806 command, extra_files = self.GetIsolateCommand(target, vals)
dpranked5b2b9432015-06-23 16:55:30807
dpranke48ccf8f2016-03-28 23:58:28808 runtime_deps = self.ReadFile(runtime_deps_path).splitlines()
dpranked5b2b9432015-06-23 16:55:30809
dpranke751516a2015-10-03 01:11:34810 self.WriteIsolateFiles(build_dir, command, target, runtime_deps,
811 extra_files)
dpranked5b2b9432015-06-23 16:55:30812
dpranke751516a2015-10-03 01:11:34813 return 0
814
815 def RunGNIsolate(self, vals):
dprankecb4a2e242016-09-19 01:13:14816 target = self.args.target[0]
817 isolate_map = self.ReadIsolateMap()
818 err, labels = self.MapTargetsToLabels(isolate_map, [target])
819 if err:
820 raise MBErr(err)
821 label = labels[0]
dpranke751516a2015-10-03 01:11:34822
823 build_dir = self.args.path[0]
dprankecb4a2e242016-09-19 01:13:14824 command, extra_files = self.GetIsolateCommand(target, vals)
dpranke751516a2015-10-03 01:11:34825
dprankeeca4a782016-04-14 01:42:38826 cmd = self.GNCmd('desc', build_dir, label, 'runtime_deps')
dpranke40da0202016-02-13 05:05:20827 ret, out, _ = self.Call(cmd)
dpranke751516a2015-10-03 01:11:34828 if ret:
dpranke030d7a6d2016-03-26 17:23:50829 if out:
830 self.Print(out)
dpranke751516a2015-10-03 01:11:34831 return ret
832
833 runtime_deps = out.splitlines()
834
835 self.WriteIsolateFiles(build_dir, command, target, runtime_deps,
836 extra_files)
837
838 ret, _, _ = self.Run([
839 self.executable,
840 self.PathJoin('tools', 'swarming_client', 'isolate.py'),
841 'check',
842 '-i',
843 self.ToSrcRelPath('%s/%s.isolate' % (build_dir, target)),
844 '-s',
845 self.ToSrcRelPath('%s/%s.isolated' % (build_dir, target))],
846 buffer_output=False)
dpranked5b2b9432015-06-23 16:55:30847
dprankefe4602312015-04-08 16:20:35848 return ret
849
dpranke751516a2015-10-03 01:11:34850 def WriteIsolateFiles(self, build_dir, command, target, runtime_deps,
851 extra_files):
852 isolate_path = self.ToAbsPath(build_dir, target + '.isolate')
853 self.WriteFile(isolate_path,
854 pprint.pformat({
855 'variables': {
856 'command': command,
857 'files': sorted(runtime_deps + extra_files),
858 }
859 }) + '\n')
860
861 self.WriteJSON(
862 {
863 'args': [
864 '--isolated',
865 self.ToSrcRelPath('%s/%s.isolated' % (build_dir, target)),
866 '--isolate',
867 self.ToSrcRelPath('%s/%s.isolate' % (build_dir, target)),
868 ],
869 'dir': self.chromium_src_dir,
870 'version': 1,
871 },
872 isolate_path + 'd.gen.json',
873 )
874
dprankecb4a2e242016-09-19 01:13:14875 def MapTargetsToLabels(self, isolate_map, targets):
876 labels = []
877 err = ''
878
dprankecb4a2e242016-09-19 01:13:14879 for target in targets:
880 if target == 'all':
881 labels.append(target)
882 elif target.startswith('//'):
883 labels.append(target)
884 else:
885 if target in isolate_map:
thakis024d6f32017-05-16 23:21:42886 if isolate_map[target]['type'] == 'unknown':
dprankecb4a2e242016-09-19 01:13:14887 err += ('test target "%s" type is unknown\n' % target)
888 else:
thakis024d6f32017-05-16 23:21:42889 labels.append(isolate_map[target]['label'])
dprankecb4a2e242016-09-19 01:13:14890 else:
891 err += ('target "%s" not found in '
892 '//testing/buildbot/gn_isolate_map.pyl\n' % target)
893
894 return err, labels
895
dprankeeca4a782016-04-14 01:42:38896 def GNCmd(self, subcommand, path, *args):
dpranked1fba482015-04-14 20:54:51897 if self.platform == 'linux2':
dpranke40da0202016-02-13 05:05:20898 subdir, exe = 'linux64', 'gn'
dpranked1fba482015-04-14 20:54:51899 elif self.platform == 'darwin':
dpranke40da0202016-02-13 05:05:20900 subdir, exe = 'mac', 'gn'
dpranked1fba482015-04-14 20:54:51901 else:
dpranke40da0202016-02-13 05:05:20902 subdir, exe = 'win', 'gn.exe'
dprankeeca4a782016-04-14 01:42:38903
dpranke40da0202016-02-13 05:05:20904 gn_path = self.PathJoin(self.chromium_src_dir, 'buildtools', subdir, exe)
dpranke10118bf2016-09-16 23:16:08905 return [gn_path, subcommand, path] + list(args)
dpranke9aba8b212016-09-16 22:52:52906
dprankecb4a2e242016-09-19 01:13:14907
dprankeeca4a782016-04-14 01:42:38908 def GNArgs(self, vals):
dpranke73ed0d62016-04-25 19:18:34909 if vals['cros_passthrough']:
910 if not 'GN_ARGS' in os.environ:
911 raise MBErr('MB is expecting GN_ARGS to be in the environment')
912 gn_args = os.environ['GN_ARGS']
dpranke40260182016-04-27 04:45:16913 if not re.search('target_os.*=.*"chromeos"', gn_args):
dpranke39f3be02016-04-27 04:07:30914 raise MBErr('GN_ARGS is missing target_os = "chromeos": (GN_ARGS=%s)' %
dpranke73ed0d62016-04-25 19:18:34915 gn_args)
916 else:
917 gn_args = vals['gn_args']
918
dpranked0c138b2016-04-13 18:28:47919 if self.args.goma_dir:
920 gn_args += ' goma_dir="%s"' % self.args.goma_dir
dprankeeca4a782016-04-14 01:42:38921
agrieve41d21a72016-04-14 18:02:26922 android_version_code = self.args.android_version_code
923 if android_version_code:
924 gn_args += ' android_default_version_code="%s"' % android_version_code
925
926 android_version_name = self.args.android_version_name
927 if android_version_name:
928 gn_args += ' android_default_version_name="%s"' % android_version_name
929
dprankeeca4a782016-04-14 01:42:38930 # Canonicalize the arg string into a sorted, newline-separated list
931 # of key-value pairs, and de-dup the keys if need be so that only
932 # the last instance of each arg is listed.
933 gn_args = gn_helpers.ToGNString(gn_helpers.FromGNArgs(gn_args))
934
dpranke9dd5e252016-04-14 04:23:09935 args_file = vals.get('args_file', None)
936 if args_file:
937 gn_args = ('import("%s")\n' % vals['args_file']) + gn_args
dprankeeca4a782016-04-14 01:42:38938 return gn_args
dprankefe4602312015-04-08 16:20:35939
dprankecb4a2e242016-09-19 01:13:14940 def GetIsolateCommand(self, target, vals):
kylechar50abf5a2016-11-29 16:03:07941 isolate_map = self.ReadIsolateMap()
942
Scott Graham3be4b4162017-09-12 00:41:41943 is_android = 'target_os="android"' in vals['gn_args']
944 is_fuchsia = 'target_os="fuchsia"' in vals['gn_args']
Nico Weberd94b71a2018-02-22 22:00:30945 is_win = self.platform == 'win32' or 'target_os="win"' in vals['gn_args']
jbudoricke8428732016-02-02 02:17:06946
kylechar39705682017-01-19 14:37:23947 # This should be true if tests with type='windowed_test_launcher' are
948 # expected to run using xvfb. For example, Linux Desktop, X11 CrOS and
msisovaea52732017-03-21 08:08:08949 # Ozone CrOS builds. Note that one Ozone build can be used to run differen
950 # backends. Currently, tests are executed for the headless and X11 backends
951 # and both can run under Xvfb.
952 # TODO(tonikitoo,msisov,fwang): Find a way to run tests for the Wayland
953 # backend.
Scott Graham3be4b4162017-09-12 00:41:41954 use_xvfb = self.platform == 'linux2' and not is_android and not is_fuchsia
dpranked8113582015-06-05 20:08:25955
956 asan = 'is_asan=true' in vals['gn_args']
957 msan = 'is_msan=true' in vals['gn_args']
958 tsan = 'is_tsan=true' in vals['gn_args']
pcc46233c22017-06-20 22:11:41959 cfi_diag = 'use_cfi_diag=true' in vals['gn_args']
dpranked8113582015-06-05 20:08:25960
dprankecb4a2e242016-09-19 01:13:14961 test_type = isolate_map[target]['type']
dprankefe0d35e2016-02-05 02:43:59962
dprankecb4a2e242016-09-19 01:13:14963 executable = isolate_map[target].get('executable', target)
Nico Weberd94b71a2018-02-22 22:00:30964 executable_suffix = '.exe' if is_win else ''
dprankefe0d35e2016-02-05 02:43:59965
dprankea55584f12015-07-22 00:52:47966 cmdline = []
Andrii Shyshkalovc158e0102018-01-10 05:52:00967 extra_files = [
968 '../../.vpython',
969 '../../testing/test_env.py',
970 ]
dpranked8113582015-06-05 20:08:25971
dprankecb4a2e242016-09-19 01:13:14972 if test_type == 'nontest':
973 self.WriteFailureAndRaise('We should not be isolating %s.' % target,
974 output_path=None)
975
Scott Graham3be4b4162017-09-12 00:41:41976 if is_android and test_type != "script":
bpastenee428ea92017-02-17 02:20:32977 cmdline = [
John Budorickfb97a852017-12-20 20:10:19978 '../../testing/test_env.py',
hzl9b15df52017-03-23 23:43:04979 '../../build/android/test_wrapper/logdog_wrapper.py',
980 '--target', target,
hzl9ae14452017-04-04 23:38:02981 '--logdog-bin-cmd', '../../bin/logdog_butler',
hzlfc66094f2017-05-18 00:50:48982 '--store-tombstones']
Scott Graham3be4b4162017-09-12 00:41:41983 elif is_fuchsia and test_type != 'script':
John Budorickfb97a852017-12-20 20:10:19984 cmdline = [
985 '../../testing/test_env.py',
986 os.path.join('bin', 'run_%s' % target),
987 ]
kylechar39705682017-01-19 14:37:23988 elif use_xvfb and test_type == 'windowed_test_launcher':
Andrii Shyshkalovc158e0102018-01-10 05:52:00989 extra_files.append('../../testing/xvfb.py')
dprankea55584f12015-07-22 00:52:47990 cmdline = [
dprankefe0d35e2016-02-05 02:43:59991 '../../testing/xvfb.py',
dprankefe0d35e2016-02-05 02:43:59992 './' + str(executable) + executable_suffix,
993 '--brave-new-test-launcher',
994 '--test-launcher-bot-mode',
995 '--asan=%d' % asan,
996 '--msan=%d' % msan,
997 '--tsan=%d' % tsan,
pcc46233c22017-06-20 22:11:41998 '--cfi-diag=%d' % cfi_diag,
dprankea55584f12015-07-22 00:52:47999 ]
1000 elif test_type in ('windowed_test_launcher', 'console_test_launcher'):
dprankea55584f12015-07-22 00:52:471001 cmdline = [
1002 '../../testing/test_env.py',
dprankefe0d35e2016-02-05 02:43:591003 './' + str(executable) + executable_suffix,
dpranked8113582015-06-05 20:08:251004 '--brave-new-test-launcher',
1005 '--test-launcher-bot-mode',
1006 '--asan=%d' % asan,
1007 '--msan=%d' % msan,
1008 '--tsan=%d' % tsan,
pcc46233c22017-06-20 22:11:411009 '--cfi-diag=%d' % cfi_diag,
dprankea55584f12015-07-22 00:52:471010 ]
dpranke6abd8652015-08-28 03:21:111011 elif test_type == 'script':
dpranke6abd8652015-08-28 03:21:111012 cmdline = [
1013 '../../testing/test_env.py',
dprankecb4a2e242016-09-19 01:13:141014 '../../' + self.ToSrcRelPath(isolate_map[target]['script'])
dprankefe0d35e2016-02-05 02:43:591015 ]
dprankea55584f12015-07-22 00:52:471016 elif test_type in ('raw'):
dprankea55584f12015-07-22 00:52:471017 cmdline = [
1018 './' + str(target) + executable_suffix,
dprankefe0d35e2016-02-05 02:43:591019 ]
dpranked8113582015-06-05 20:08:251020
dprankea55584f12015-07-22 00:52:471021 else:
1022 self.WriteFailureAndRaise('No command line for %s found (test type %s).'
1023 % (target, test_type), output_path=None)
dpranked8113582015-06-05 20:08:251024
dprankecb4a2e242016-09-19 01:13:141025 cmdline += isolate_map[target].get('args', [])
dprankefe0d35e2016-02-05 02:43:591026
dpranked8113582015-06-05 20:08:251027 return cmdline, extra_files
1028
dpranke74559b52015-06-10 21:20:391029 def ToAbsPath(self, build_path, *comps):
dpranke8c2cfd32015-09-17 20:12:331030 return self.PathJoin(self.chromium_src_dir,
1031 self.ToSrcRelPath(build_path),
1032 *comps)
dpranked8113582015-06-05 20:08:251033
dprankeee5b51f62015-04-09 00:03:221034 def ToSrcRelPath(self, path):
1035 """Returns a relative path from the top of the repo."""
dpranke030d7a6d2016-03-26 17:23:501036 if path.startswith('//'):
1037 return path[2:].replace('/', self.sep)
1038 return self.RelPath(path, self.chromium_src_dir)
dprankefe4602312015-04-08 16:20:351039
Dirk Pranke0fd41bcd2015-06-19 00:05:501040 def RunGNAnalyze(self, vals):
dprankecb4a2e242016-09-19 01:13:141041 # Analyze runs before 'gn gen' now, so we need to run gn gen
Dirk Pranke0fd41bcd2015-06-19 00:05:501042 # in order to ensure that we have a build directory.
Dirk Prankea3727f92017-07-17 17:30:331043 ret = self.RunGNGen(vals, compute_grit_inputs_for_analyze=True)
Dirk Pranke0fd41bcd2015-06-19 00:05:501044 if ret:
1045 return ret
1046
dprankecb4a2e242016-09-19 01:13:141047 build_path = self.args.path[0]
1048 input_path = self.args.input_path[0]
1049 gn_input_path = input_path + '.gn'
1050 output_path = self.args.output_path[0]
1051 gn_output_path = output_path + '.gn'
1052
dpranke7837fc362015-11-19 03:54:161053 inp = self.ReadInputJSON(['files', 'test_targets',
1054 'additional_compile_targets'])
dprankecda00332015-04-11 04:18:321055 if self.args.verbose:
1056 self.Print()
1057 self.Print('analyze input:')
1058 self.PrintJSON(inp)
1059 self.Print()
1060
dpranke76734662015-04-16 02:17:501061
dpranke7c5f614d2015-07-22 23:43:391062 # This shouldn't normally happen, but could due to unusual race conditions,
1063 # like a try job that gets scheduled before a patch lands but runs after
1064 # the patch has landed.
1065 if not inp['files']:
1066 self.Print('Warning: No files modified in patch, bailing out early.')
dpranke7837fc362015-11-19 03:54:161067 self.WriteJSON({
1068 'status': 'No dependency',
1069 'compile_targets': [],
1070 'test_targets': [],
1071 }, output_path)
dpranke7c5f614d2015-07-22 23:43:391072 return 0
1073
dprankecb4a2e242016-09-19 01:13:141074 gn_inp = {}
dprankeb7b183f2017-04-24 23:50:161075 gn_inp['files'] = ['//' + f for f in inp['files'] if not f.startswith('//')]
dprankef61de2f2015-05-14 04:09:561076
dprankecb4a2e242016-09-19 01:13:141077 isolate_map = self.ReadIsolateMap()
1078 err, gn_inp['additional_compile_targets'] = self.MapTargetsToLabels(
1079 isolate_map, inp['additional_compile_targets'])
1080 if err:
1081 raise MBErr(err)
1082
1083 err, gn_inp['test_targets'] = self.MapTargetsToLabels(
1084 isolate_map, inp['test_targets'])
1085 if err:
1086 raise MBErr(err)
1087 labels_to_targets = {}
1088 for i, label in enumerate(gn_inp['test_targets']):
1089 labels_to_targets[label] = inp['test_targets'][i]
1090
dprankef61de2f2015-05-14 04:09:561091 try:
dprankecb4a2e242016-09-19 01:13:141092 self.WriteJSON(gn_inp, gn_input_path)
1093 cmd = self.GNCmd('analyze', build_path, gn_input_path, gn_output_path)
1094 ret, _, _ = self.Run(cmd, force_verbose=True)
1095 if ret:
1096 return ret
dpranke067d0142015-05-14 22:52:451097
dprankecb4a2e242016-09-19 01:13:141098 gn_outp_str = self.ReadFile(gn_output_path)
1099 try:
1100 gn_outp = json.loads(gn_outp_str)
1101 except Exception as e:
1102 self.Print("Failed to parse the JSON string GN returned: %s\n%s"
1103 % (repr(gn_outp_str), str(e)))
1104 raise
1105
1106 outp = {}
1107 if 'status' in gn_outp:
1108 outp['status'] = gn_outp['status']
1109 if 'error' in gn_outp:
1110 outp['error'] = gn_outp['error']
1111 if 'invalid_targets' in gn_outp:
1112 outp['invalid_targets'] = gn_outp['invalid_targets']
1113 if 'compile_targets' in gn_outp:
Dirk Pranke45165072017-11-08 04:57:491114 all_input_compile_targets = sorted(
1115 set(inp['test_targets'] + inp['additional_compile_targets']))
1116
1117 # If we're building 'all', we can throw away the rest of the targets
1118 # since they're redundant.
dpranke385a3102016-09-20 22:04:081119 if 'all' in gn_outp['compile_targets']:
1120 outp['compile_targets'] = ['all']
1121 else:
Dirk Pranke45165072017-11-08 04:57:491122 outp['compile_targets'] = gn_outp['compile_targets']
1123
1124 # crbug.com/736215: When GN returns targets back, for targets in
1125 # the default toolchain, GN will have generated a phony ninja
1126 # target matching the label, and so we can safely (and easily)
1127 # transform any GN label into the matching ninja target. For
1128 # targets in other toolchains, though, GN doesn't generate the
1129 # phony targets, and we don't know how to turn the labels into
1130 # compile targets. In this case, we also conservatively give up
1131 # and build everything. Probably the right thing to do here is
1132 # to have GN return the compile targets directly.
1133 if any("(" in target for target in outp['compile_targets']):
1134 self.Print('WARNING: targets with non-default toolchains were '
1135 'found, building everything instead.')
1136 outp['compile_targets'] = all_input_compile_targets
1137 else:
dpranke385a3102016-09-20 22:04:081138 outp['compile_targets'] = [
Dirk Pranke45165072017-11-08 04:57:491139 label.replace('//', '') for label in outp['compile_targets']]
1140
1141 # Windows has a maximum command line length of 8k; even Linux
1142 # maxes out at 128k; if analyze returns a *really long* list of
1143 # targets, we just give up and conservatively build everything instead.
1144 # Probably the right thing here is for ninja to support response
1145 # files as input on the command line
1146 # (see https://github.com/ninja-build/ninja/issues/1355).
1147 if len(' '.join(outp['compile_targets'])) > 7*1024:
1148 self.Print('WARNING: Too many compile targets were affected.')
1149 self.Print('WARNING: Building everything instead to avoid '
1150 'command-line length issues.')
1151 outp['compile_targets'] = all_input_compile_targets
1152
1153
dprankecb4a2e242016-09-19 01:13:141154 if 'test_targets' in gn_outp:
1155 outp['test_targets'] = [
1156 labels_to_targets[label] for label in gn_outp['test_targets']]
1157
1158 if self.args.verbose:
1159 self.Print()
1160 self.Print('analyze output:')
1161 self.PrintJSON(outp)
1162 self.Print()
1163
1164 self.WriteJSON(outp, output_path)
1165
dprankef61de2f2015-05-14 04:09:561166 finally:
dprankecb4a2e242016-09-19 01:13:141167 if self.Exists(gn_input_path):
1168 self.RemoveFile(gn_input_path)
1169 if self.Exists(gn_output_path):
1170 self.RemoveFile(gn_output_path)
dprankefe4602312015-04-08 16:20:351171
1172 return 0
1173
dpranked8113582015-06-05 20:08:251174 def ReadInputJSON(self, required_keys):
dprankefe4602312015-04-08 16:20:351175 path = self.args.input_path[0]
dprankecda00332015-04-11 04:18:321176 output_path = self.args.output_path[0]
dprankefe4602312015-04-08 16:20:351177 if not self.Exists(path):
dprankecda00332015-04-11 04:18:321178 self.WriteFailureAndRaise('"%s" does not exist' % path, output_path)
dprankefe4602312015-04-08 16:20:351179
1180 try:
1181 inp = json.loads(self.ReadFile(path))
1182 except Exception as e:
1183 self.WriteFailureAndRaise('Failed to read JSON input from "%s": %s' %
dprankecda00332015-04-11 04:18:321184 (path, e), output_path)
dpranked8113582015-06-05 20:08:251185
1186 for k in required_keys:
1187 if not k in inp:
1188 self.WriteFailureAndRaise('input file is missing a "%s" key' % k,
1189 output_path)
dprankefe4602312015-04-08 16:20:351190
1191 return inp
1192
dpranked5b2b9432015-06-23 16:55:301193 def WriteFailureAndRaise(self, msg, output_path):
1194 if output_path:
dprankee0547cd2015-09-15 01:27:401195 self.WriteJSON({'error': msg}, output_path, force_verbose=True)
dprankefe4602312015-04-08 16:20:351196 raise MBErr(msg)
1197
dprankee0547cd2015-09-15 01:27:401198 def WriteJSON(self, obj, path, force_verbose=False):
dprankecda00332015-04-11 04:18:321199 try:
dprankee0547cd2015-09-15 01:27:401200 self.WriteFile(path, json.dumps(obj, indent=2, sort_keys=True) + '\n',
1201 force_verbose=force_verbose)
dprankecda00332015-04-11 04:18:321202 except Exception as e:
1203 raise MBErr('Error %s writing to the output path "%s"' %
1204 (e, path))
dprankefe4602312015-04-08 16:20:351205
aneeshmde50f472016-04-01 01:13:101206 def CheckCompile(self, master, builder):
1207 url_template = self.args.url_template + '/{builder}/builds/_all?as_text=1'
1208 url = urllib2.quote(url_template.format(master=master, builder=builder),
1209 safe=':/()?=')
1210 try:
1211 builds = json.loads(self.Fetch(url))
1212 except Exception as e:
1213 return str(e)
1214 successes = sorted(
1215 [int(x) for x in builds.keys() if "text" in builds[x] and
1216 cmp(builds[x]["text"][:2], ["build", "successful"]) == 0],
1217 reverse=True)
1218 if not successes:
1219 return "no successful builds"
1220 build = builds[str(successes[0])]
1221 step_names = set([step["name"] for step in build["steps"]])
1222 compile_indicators = set(["compile", "compile (with patch)", "analyze"])
1223 if compile_indicators & step_names:
1224 return "compiles"
1225 return "does not compile"
1226
dpranke3cec199c2015-09-22 23:29:021227 def PrintCmd(self, cmd, env):
1228 if self.platform == 'win32':
1229 env_prefix = 'set '
1230 env_quoter = QuoteForSet
1231 shell_quoter = QuoteForCmd
1232 else:
1233 env_prefix = ''
1234 env_quoter = pipes.quote
1235 shell_quoter = pipes.quote
1236
1237 def print_env(var):
1238 if env and var in env:
1239 self.Print('%s%s=%s' % (env_prefix, var, env_quoter(env[var])))
1240
dprankeec079262016-06-07 02:21:201241 print_env('LLVM_FORCE_HEAD_REVISION')
dpranke3cec199c2015-09-22 23:29:021242
dpranke8c2cfd32015-09-17 20:12:331243 if cmd[0] == self.executable:
dprankefe4602312015-04-08 16:20:351244 cmd = ['python'] + cmd[1:]
dpranke3cec199c2015-09-22 23:29:021245 self.Print(*[shell_quoter(arg) for arg in cmd])
dprankefe4602312015-04-08 16:20:351246
dprankecda00332015-04-11 04:18:321247 def PrintJSON(self, obj):
1248 self.Print(json.dumps(obj, indent=2, sort_keys=True))
1249
dpranke751516a2015-10-03 01:11:341250 def Build(self, target):
1251 build_dir = self.ToSrcRelPath(self.args.path[0])
1252 ninja_cmd = ['ninja', '-C', build_dir]
1253 if self.args.jobs:
1254 ninja_cmd.extend(['-j', '%d' % self.args.jobs])
1255 ninja_cmd.append(target)
1256 ret, _, _ = self.Run(ninja_cmd, force_verbose=False, buffer_output=False)
1257 return ret
1258
1259 def Run(self, cmd, env=None, force_verbose=True, buffer_output=True):
dprankefe4602312015-04-08 16:20:351260 # This function largely exists so it can be overridden for testing.
dprankee0547cd2015-09-15 01:27:401261 if self.args.dryrun or self.args.verbose or force_verbose:
dpranke3cec199c2015-09-22 23:29:021262 self.PrintCmd(cmd, env)
dprankefe4602312015-04-08 16:20:351263 if self.args.dryrun:
1264 return 0, '', ''
dprankee0547cd2015-09-15 01:27:401265
dpranke751516a2015-10-03 01:11:341266 ret, out, err = self.Call(cmd, env=env, buffer_output=buffer_output)
dprankee0547cd2015-09-15 01:27:401267 if self.args.verbose or force_verbose:
dpranke751516a2015-10-03 01:11:341268 if ret:
1269 self.Print(' -> returned %d' % ret)
dprankefe4602312015-04-08 16:20:351270 if out:
dprankeee5b51f62015-04-09 00:03:221271 self.Print(out, end='')
dprankefe4602312015-04-08 16:20:351272 if err:
dprankeee5b51f62015-04-09 00:03:221273 self.Print(err, end='', file=sys.stderr)
dprankefe4602312015-04-08 16:20:351274 return ret, out, err
1275
dpranke751516a2015-10-03 01:11:341276 def Call(self, cmd, env=None, buffer_output=True):
1277 if buffer_output:
1278 p = subprocess.Popen(cmd, shell=False, cwd=self.chromium_src_dir,
1279 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
1280 env=env)
1281 out, err = p.communicate()
1282 else:
1283 p = subprocess.Popen(cmd, shell=False, cwd=self.chromium_src_dir,
1284 env=env)
1285 p.wait()
1286 out = err = ''
dprankefe4602312015-04-08 16:20:351287 return p.returncode, out, err
1288
1289 def ExpandUser(self, path):
1290 # This function largely exists so it can be overridden for testing.
1291 return os.path.expanduser(path)
1292
1293 def Exists(self, path):
1294 # This function largely exists so it can be overridden for testing.
1295 return os.path.exists(path)
1296
dpranke867bcf4a2016-03-14 22:28:321297 def Fetch(self, url):
dpranke030d7a6d2016-03-26 17:23:501298 # This function largely exists so it can be overridden for testing.
dpranke867bcf4a2016-03-14 22:28:321299 f = urllib2.urlopen(url)
1300 contents = f.read()
1301 f.close()
1302 return contents
1303
dprankec3441d12015-06-23 23:01:351304 def MaybeMakeDirectory(self, path):
1305 try:
1306 os.makedirs(path)
1307 except OSError, e:
1308 if e.errno != errno.EEXIST:
1309 raise
1310
dpranke8c2cfd32015-09-17 20:12:331311 def PathJoin(self, *comps):
1312 # This function largely exists so it can be overriden for testing.
1313 return os.path.join(*comps)
1314
dpranke030d7a6d2016-03-26 17:23:501315 def Print(self, *args, **kwargs):
1316 # This function largely exists so it can be overridden for testing.
1317 print(*args, **kwargs)
aneeshmde50f472016-04-01 01:13:101318 if kwargs.get('stream', sys.stdout) == sys.stdout:
1319 sys.stdout.flush()
dpranke030d7a6d2016-03-26 17:23:501320
dprankefe4602312015-04-08 16:20:351321 def ReadFile(self, path):
1322 # This function largely exists so it can be overriden for testing.
1323 with open(path) as fp:
1324 return fp.read()
1325
dpranke030d7a6d2016-03-26 17:23:501326 def RelPath(self, path, start='.'):
1327 # This function largely exists so it can be overriden for testing.
1328 return os.path.relpath(path, start)
1329
dprankef61de2f2015-05-14 04:09:561330 def RemoveFile(self, path):
1331 # This function largely exists so it can be overriden for testing.
1332 os.remove(path)
1333
dprankec161aa92015-09-14 20:21:131334 def RemoveDirectory(self, abs_path):
dpranke8c2cfd32015-09-17 20:12:331335 if self.platform == 'win32':
dprankec161aa92015-09-14 20:21:131336 # In other places in chromium, we often have to retry this command
1337 # because we're worried about other processes still holding on to
1338 # file handles, but when MB is invoked, it will be early enough in the
1339 # build that their should be no other processes to interfere. We
1340 # can change this if need be.
1341 self.Run(['cmd.exe', '/c', 'rmdir', '/q', '/s', abs_path])
1342 else:
1343 shutil.rmtree(abs_path, ignore_errors=True)
1344
dprankef61de2f2015-05-14 04:09:561345 def TempFile(self, mode='w'):
1346 # This function largely exists so it can be overriden for testing.
1347 return tempfile.NamedTemporaryFile(mode=mode, delete=False)
1348
dprankee0547cd2015-09-15 01:27:401349 def WriteFile(self, path, contents, force_verbose=False):
dprankefe4602312015-04-08 16:20:351350 # This function largely exists so it can be overriden for testing.
dprankee0547cd2015-09-15 01:27:401351 if self.args.dryrun or self.args.verbose or force_verbose:
dpranked5b2b9432015-06-23 16:55:301352 self.Print('\nWriting """\\\n%s""" to %s.\n' % (contents, path))
dprankefe4602312015-04-08 16:20:351353 with open(path, 'w') as fp:
1354 return fp.write(contents)
1355
dprankef61de2f2015-05-14 04:09:561356
dprankefe4602312015-04-08 16:20:351357class MBErr(Exception):
1358 pass
1359
1360
dpranke3cec199c2015-09-22 23:29:021361# See http://goo.gl/l5NPDW and http://goo.gl/4Diozm for the painful
1362# details of this next section, which handles escaping command lines
1363# so that they can be copied and pasted into a cmd window.
1364UNSAFE_FOR_SET = set('^<>&|')
1365UNSAFE_FOR_CMD = UNSAFE_FOR_SET.union(set('()%'))
1366ALL_META_CHARS = UNSAFE_FOR_CMD.union(set('"'))
1367
1368
1369def QuoteForSet(arg):
1370 if any(a in UNSAFE_FOR_SET for a in arg):
1371 arg = ''.join('^' + a if a in UNSAFE_FOR_SET else a for a in arg)
1372 return arg
1373
1374
1375def QuoteForCmd(arg):
1376 # First, escape the arg so that CommandLineToArgvW will parse it properly.
dpranke3cec199c2015-09-22 23:29:021377 if arg == '' or ' ' in arg or '"' in arg:
1378 quote_re = re.compile(r'(\\*)"')
1379 arg = '"%s"' % (quote_re.sub(lambda mo: 2 * mo.group(1) + '\\"', arg))
1380
1381 # Then check to see if the arg contains any metacharacters other than
1382 # double quotes; if it does, quote everything (including the double
1383 # quotes) for safety.
1384 if any(a in UNSAFE_FOR_CMD for a in arg):
1385 arg = ''.join('^' + a if a in ALL_META_CHARS else a for a in arg)
1386 return arg
1387
1388
dprankefe4602312015-04-08 16:20:351389if __name__ == '__main__':
dpranke255085e2016-03-16 05:23:591390 sys.exit(main(sys.argv[1:]))