| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 config = self.ConfigFromArgs() | 348 config = self.ConfigFromArgs() |
| 349 if not config in self.configs: | 349 if not config in self.configs: |
| 350 raise MBErr('Config "%s" not found in %s' % | 350 raise MBErr('Config "%s" not found in %s' % |
| 351 (config, self.args.config_file)) | 351 (config, self.args.config_file)) |
| 352 | 352 |
| 353 vals = self.FlattenConfig(config) | 353 vals = self.FlattenConfig(config) |
| 354 | 354 |
| 355 # Do some basic sanity checking on the config so that we | 355 # Do some basic sanity checking on the config so that we |
| 356 # don't have to do this in every caller. | 356 # don't have to do this in every caller. |
| 357 assert 'type' in vals, 'No meta-build type specified in the config' | 357 assert 'type' in vals, 'No meta-build type specified in the config' |
| 358 assert vals['type'] in ('gn', 'gyp'), ( | 358 assert vals['type'] in ('gn', 'gyp', 'passthrough'), ( |
| 359 'Unknown meta-build type "%s"' % vals['gn_args']) | 359 'Unknown meta-build type "%s"' % vals['gn_args']) |
| 360 | 360 |
| 361 if vals['type'] == 'passthrough': |
| 362 vals = self.HandlePassthrough() |
| 363 |
| 364 return vals |
| 365 |
| 366 def HandlePassthrough(self): |
| 367 if 'MB_TYPE' not in os.environ: |
| 368 raise MBErr('MB_TYPE not set in the environment') |
| 369 mb_type = os.environ['MB_TYPE'] |
| 370 if mb_type not in ('gyp', 'gn'): |
| 371 raise MBErr('illegal value "%s" for MB_TYPE', mb_type) |
| 372 |
| 373 vals = self.DefaultConfigVals() |
| 374 vals['type'] = mb_type |
| 375 if mb_type == 'gyp': |
| 376 if 'GYP_CROSSCOMPILE' in os.environ: |
| 377 if os.environ['GYP_CROSSCOMPILE'] == '1': |
| 378 vals['gyp_crosscompile'] = True |
| 379 if 'GYP_DEFINES' not in os.environ: |
| 380 raise MBErr('GYP_DEFINES not set in environment on a ' |
| 381 'passthrough bot set to type GYP.') |
| 382 vals['gyp_defines'] = os.environ['GYP_DEFINES'] |
| 383 else: |
| 384 if 'gn_args' not in os.environ: |
| 385 raise MBErr('GN_ARGS not set in environment on a passthrough bot' |
| 386 ' set to type GN') |
| 387 vals['gn_args'] = os.environ.get('GN_ARGS', '') |
| 388 |
| 361 return vals | 389 return vals |
| 362 | 390 |
| 363 def ReadConfigFile(self): | 391 def ReadConfigFile(self): |
| 364 if not self.Exists(self.args.config_file): | 392 if not self.Exists(self.args.config_file): |
| 365 raise MBErr('config file not found at %s' % self.args.config_file) | 393 raise MBErr('config file not found at %s' % self.args.config_file) |
| 366 | 394 |
| 367 try: | 395 try: |
| 368 contents = ast.literal_eval(self.ReadFile(self.args.config_file)) | 396 contents = ast.literal_eval(self.ReadFile(self.args.config_file)) |
| 369 except SyntaxError as e: | 397 except SyntaxError as e: |
| 370 raise MBErr('Failed to parse config file "%s": %s' % | 398 raise MBErr('Failed to parse config file "%s": %s' % |
| (...skipping 23 matching lines...) Expand all Loading... |
| 394 (self.args.master, self.args.config_file)) | 422 (self.args.master, self.args.config_file)) |
| 395 | 423 |
| 396 if not self.args.builder in self.masters[self.args.master]: | 424 if not self.args.builder in self.masters[self.args.master]: |
| 397 raise MBErr('Builder name "%s" not found under masters[%s] in "%s"' % | 425 raise MBErr('Builder name "%s" not found under masters[%s] in "%s"' % |
| 398 (self.args.builder, self.args.master, self.args.config_file)) | 426 (self.args.builder, self.args.master, self.args.config_file)) |
| 399 | 427 |
| 400 return self.masters[self.args.master][self.args.builder] | 428 return self.masters[self.args.master][self.args.builder] |
| 401 | 429 |
| 402 def FlattenConfig(self, config): | 430 def FlattenConfig(self, config): |
| 403 mixins = self.configs[config] | 431 mixins = self.configs[config] |
| 404 vals = { | 432 vals = self.DefaultConfigVals() |
| 433 visited = [] |
| 434 self.FlattenMixins(mixins, vals, visited) |
| 435 return vals |
| 436 |
| 437 def DefaultConfigVals(self): |
| 438 return { |
| 405 'type': None, | 439 'type': None, |
| 406 'gn_args': [], | 440 'gn_args': [], |
| 407 'gyp_defines': '', | 441 'gyp_defines': '', |
| 408 'gyp_crosscompile': False, | 442 'gyp_crosscompile': False, |
| 409 } | 443 } |
| 410 | 444 |
| 411 visited = [] | |
| 412 self.FlattenMixins(mixins, vals, visited) | |
| 413 return vals | |
| 414 | |
| 415 def FlattenMixins(self, mixins, vals, visited): | 445 def FlattenMixins(self, mixins, vals, visited): |
| 416 for m in mixins: | 446 for m in mixins: |
| 417 if m not in self.mixins: | 447 if m not in self.mixins: |
| 418 raise MBErr('Unknown mixin "%s"' % m) | 448 raise MBErr('Unknown mixin "%s"' % m) |
| 419 | 449 |
| 420 # TODO: check for cycles in mixins. | 450 # TODO: check for cycles in mixins. |
| 421 | 451 |
| 422 visited.append(m) | 452 visited.append(m) |
| 423 | 453 |
| 424 mixin_vals = self.mixins[m] | 454 mixin_vals = self.mixins[m] |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 | 1077 |
| 1048 if __name__ == '__main__': | 1078 if __name__ == '__main__': |
| 1049 try: | 1079 try: |
| 1050 sys.exit(main(sys.argv[1:])) | 1080 sys.exit(main(sys.argv[1:])) |
| 1051 except MBErr as e: | 1081 except MBErr as e: |
| 1052 print(e) | 1082 print(e) |
| 1053 sys.exit(1) | 1083 sys.exit(1) |
| 1054 except KeyboardInterrupt: | 1084 except KeyboardInterrupt: |
| 1055 print("interrupted, exiting", stream=sys.stderr) | 1085 print("interrupted, exiting", stream=sys.stderr) |
| 1056 sys.exit(130) | 1086 sys.exit(130) |
| OLD | NEW |