Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 """MB - the Meta-Build wrapper around GYP and GN | 6 """MB - the Meta-Build wrapper around GYP and GN |
| 7 | 7 |
| 8 MB is a wrapper script for GYP and GN that can be used to generate build files | 8 MB is a wrapper script for GYP and GN that can be used to generate build files |
| 9 for sets of canned configurations and analyze them. | 9 for sets of canned configurations and analyze them. |
| 10 """ | 10 """ |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 return 1 | 71 return 1 |
| 72 | 72 |
| 73 def ParseArgs(self, argv): | 73 def ParseArgs(self, argv): |
| 74 def AddCommonOptions(subp): | 74 def AddCommonOptions(subp): |
| 75 subp.add_argument('-b', '--builder', | 75 subp.add_argument('-b', '--builder', |
| 76 help='builder name to look up config from') | 76 help='builder name to look up config from') |
| 77 subp.add_argument('-m', '--master', | 77 subp.add_argument('-m', '--master', |
| 78 help='master name to look up config from') | 78 help='master name to look up config from') |
| 79 subp.add_argument('-c', '--config', | 79 subp.add_argument('-c', '--config', |
| 80 help='configuration to analyze') | 80 help='configuration to analyze') |
| 81 subp.add_argument('--phase', type=int, | 81 subp.add_argument('--phase', |
| 82 help=('build phase for a given build ' | 82 help=('build phase dict for a given build (key in ' |
|
Dirk Pranke
2016/10/11 00:14:05
I would replace the help with something like help=
shenghuazhang
2016/10/11 01:09:27
Done.
| |
| 83 '(int in [1, 2, ...))')) | 83 '([ "key1": "config1", "key2": "config2", ...])')) |
| 84 subp.add_argument('-f', '--config-file', metavar='PATH', | 84 subp.add_argument('-f', '--config-file', metavar='PATH', |
| 85 default=self.default_config, | 85 default=self.default_config, |
| 86 help='path to config file ' | 86 help='path to config file ' |
| 87 '(default is //tools/mb/mb_config.pyl)') | 87 '(default is //tools/mb/mb_config.pyl)') |
| 88 subp.add_argument('-g', '--goma-dir', | 88 subp.add_argument('-g', '--goma-dir', |
| 89 help='path to goma directory') | 89 help='path to goma directory') |
| 90 subp.add_argument('--gyp-script', metavar='PATH', | 90 subp.add_argument('--gyp-script', metavar='PATH', |
| 91 default=self.PathJoin('build', 'gyp_chromium'), | 91 default=self.PathJoin('build', 'gyp_chromium'), |
| 92 help='path to gyp script relative to project root ' | 92 help='path to gyp script relative to project root ' |
| 93 '(default is %(default)s)') | 93 '(default is %(default)s)') |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 def CmdExport(self): | 263 def CmdExport(self): |
| 264 self.ReadConfigFile() | 264 self.ReadConfigFile() |
| 265 obj = {} | 265 obj = {} |
| 266 for master, builders in self.masters.items(): | 266 for master, builders in self.masters.items(): |
| 267 obj[master] = {} | 267 obj[master] = {} |
| 268 for builder in builders: | 268 for builder in builders: |
| 269 config = self.masters[master][builder] | 269 config = self.masters[master][builder] |
| 270 if not config: | 270 if not config: |
| 271 continue | 271 continue |
| 272 | 272 |
| 273 if isinstance(config, list): | 273 if isinstance(config, dict): |
| 274 args = [self.FlattenConfig(c)['gn_args'] for c in config] | 274 args = {k: self.FlattenConfig(v)['gn_args'] |
| 275 for k, v in config.items()} | |
| 275 elif config.startswith('//'): | 276 elif config.startswith('//'): |
| 276 args = config | 277 args = config |
| 277 else: | 278 else: |
| 278 args = self.FlattenConfig(config)['gn_args'] | 279 args = self.FlattenConfig(config)['gn_args'] |
| 279 if 'error' in args: | 280 if 'error' in args: |
| 280 continue | 281 continue |
| 281 | 282 |
| 282 obj[master][builder] = args | 283 obj[master][builder] = args |
| 283 | 284 |
| 284 # Dump object and trim trailing whitespace. | 285 # Dump object and trim trailing whitespace. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 def CmdValidate(self, print_ok=True): | 363 def CmdValidate(self, print_ok=True): |
| 363 errs = [] | 364 errs = [] |
| 364 | 365 |
| 365 # Read the file to make sure it parses. | 366 # Read the file to make sure it parses. |
| 366 self.ReadConfigFile() | 367 self.ReadConfigFile() |
| 367 | 368 |
| 368 # Build a list of all of the configs referenced by builders. | 369 # Build a list of all of the configs referenced by builders. |
| 369 all_configs = {} | 370 all_configs = {} |
| 370 for master in self.masters: | 371 for master in self.masters: |
| 371 for config in self.masters[master].values(): | 372 for config in self.masters[master].values(): |
| 372 if isinstance(config, list): | 373 if isinstance(config, dict): |
| 373 for c in config: | 374 for c in config.values(): |
| 374 all_configs[c] = master | 375 all_configs[c] = master |
| 375 else: | 376 else: |
| 376 all_configs[config] = master | 377 all_configs[config] = master |
| 377 | 378 |
| 378 # Check that every referenced args file or config actually exists. | 379 # Check that every referenced args file or config actually exists. |
| 379 for config, loc in all_configs.items(): | 380 for config, loc in all_configs.items(): |
| 380 if config.startswith('//'): | 381 if config.startswith('//'): |
| 381 if not self.Exists(self.ToAbsPath(config)): | 382 if not self.Exists(self.ToAbsPath(config)): |
| 382 errs.append('Unknown args file "%s" referenced from "%s".' % | 383 errs.append('Unknown args file "%s" referenced from "%s".' % |
| 383 (config, loc)) | 384 (config, loc)) |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 config_only = config_builders - master_builders | 515 config_only = config_builders - master_builders |
| 515 tbd = set() | 516 tbd = set() |
| 516 gyp = set() | 517 gyp = set() |
| 517 done = set() | 518 done = set() |
| 518 notes = {builder: '' for builder in config_builders | master_builders} | 519 notes = {builder: '' for builder in config_builders | master_builders} |
| 519 | 520 |
| 520 for builder in both: | 521 for builder in both: |
| 521 config = self.masters[master][builder] | 522 config = self.masters[master][builder] |
| 522 if config == 'tbd': | 523 if config == 'tbd': |
| 523 tbd.add(builder) | 524 tbd.add(builder) |
| 524 elif isinstance(config, list): | 525 elif isinstance(config, dict): |
| 525 vals = self.FlattenConfig(config[0]) | 526 vals = self.FlattenConfig(config.values()[0]) |
| 526 if vals['type'] == 'gyp': | 527 if vals['type'] == 'gyp': |
| 527 gyp.add(builder) | 528 gyp.add(builder) |
| 528 else: | 529 else: |
| 529 done.add(builder) | 530 done.add(builder) |
| 530 elif config.startswith('//'): | 531 elif config.startswith('//'): |
| 531 done.add(builder) | 532 done.add(builder) |
| 532 else: | 533 else: |
| 533 vals = self.FlattenConfig(config) | 534 vals = self.FlattenConfig(config) |
| 534 if vals['type'] == 'gyp': | 535 if vals['type'] == 'gyp': |
| 535 gyp.add(builder) | 536 gyp.add(builder) |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 | 687 |
| 687 if not self.args.master in self.masters: | 688 if not self.args.master in self.masters: |
| 688 raise MBErr('Master name "%s" not found in "%s"' % | 689 raise MBErr('Master name "%s" not found in "%s"' % |
| 689 (self.args.master, self.args.config_file)) | 690 (self.args.master, self.args.config_file)) |
| 690 | 691 |
| 691 if not self.args.builder in self.masters[self.args.master]: | 692 if not self.args.builder in self.masters[self.args.master]: |
| 692 raise MBErr('Builder name "%s" not found under masters[%s] in "%s"' % | 693 raise MBErr('Builder name "%s" not found under masters[%s] in "%s"' % |
| 693 (self.args.builder, self.args.master, self.args.config_file)) | 694 (self.args.builder, self.args.master, self.args.config_file)) |
| 694 | 695 |
| 695 config = self.masters[self.args.master][self.args.builder] | 696 config = self.masters[self.args.master][self.args.builder] |
| 696 if isinstance(config, list): | 697 if isinstance(config, dict): |
| 697 if self.args.phase is None: | 698 if self.args.phase is None: |
| 698 raise MBErr('Must specify a build --phase for %s on %s' % | 699 raise MBErr('Must specify a build --phase for %s on %s' % |
| 699 (self.args.builder, self.args.master)) | 700 (self.args.builder, self.args.master)) |
| 700 phase = int(self.args.phase) | 701 phase = str(self.args.phase) |
| 701 if phase < 1 or phase > len(config): | 702 if phase not in config: |
| 702 raise MBErr('Phase %d out of bounds for %s on %s' % | 703 raise MBErr('Phase %s doesn\'t exist for %s on %s' % |
| 703 (phase, self.args.builder, self.args.master)) | 704 (phase, self.args.builder, self.args.master)) |
| 704 return config[phase-1] | 705 return config[phase] |
| 705 | 706 |
| 706 if self.args.phase is not None: | 707 if self.args.phase is not None: |
| 707 raise MBErr('Must not specify a build --phase for %s on %s' % | 708 raise MBErr('Must not specify a build --phase for %s on %s' % |
| 708 (self.args.builder, self.args.master)) | 709 (self.args.builder, self.args.master)) |
| 709 return config | 710 return config |
| 710 | 711 |
| 711 def FlattenConfig(self, config): | 712 def FlattenConfig(self, config): |
| 712 mixins = self.configs[config] | 713 mixins = self.configs[config] |
| 713 vals = self.DefaultVals() | 714 vals = self.DefaultVals() |
| 714 | 715 |
| (...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1551 # Then check to see if the arg contains any metacharacters other than | 1552 # Then check to see if the arg contains any metacharacters other than |
| 1552 # double quotes; if it does, quote everything (including the double | 1553 # double quotes; if it does, quote everything (including the double |
| 1553 # quotes) for safety. | 1554 # quotes) for safety. |
| 1554 if any(a in UNSAFE_FOR_CMD for a in arg): | 1555 if any(a in UNSAFE_FOR_CMD for a in arg): |
| 1555 arg = ''.join('^' + a if a in ALL_META_CHARS else a for a in arg) | 1556 arg = ''.join('^' + a if a in ALL_META_CHARS else a for a in arg) |
| 1556 return arg | 1557 return arg |
| 1557 | 1558 |
| 1558 | 1559 |
| 1559 if __name__ == '__main__': | 1560 if __name__ == '__main__': |
| 1560 sys.exit(main(sys.argv[1:])) | 1561 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |