| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import copy | 6 import copy |
| 7 import database | 7 import database |
| 8 import idlparser | 8 import idlparser |
| 9 import logging | 9 import logging |
| 10 import multiprocessing | 10 import multiprocessing |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 self.source = source | 55 self.source = source |
| 56 self.source_attributes = source_attributes | 56 self.source_attributes = source_attributes |
| 57 self.idl_syntax = idl_syntax | 57 self.idl_syntax = idl_syntax |
| 58 self.idl_defines = idl_defines | 58 self.idl_defines = idl_defines |
| 59 self.rename_operation_arguments_on_merge = \ | 59 self.rename_operation_arguments_on_merge = \ |
| 60 rename_operation_arguments_on_merge | 60 rename_operation_arguments_on_merge |
| 61 self.add_new_interfaces = add_new_interfaces | 61 self.add_new_interfaces = add_new_interfaces |
| 62 self.obsolete_old_declarations = obsolete_old_declarations | 62 self.obsolete_old_declarations = obsolete_old_declarations |
| 63 | 63 |
| 64 | 64 |
| 65 def _load_idl_file(file_name, import_options, result_queue): | 65 def _load_idl_file(file_name, import_options): |
| 66 """Loads an IDL file into memory""" | 66 """Loads an IDL file into memory""" |
| 67 idl_parser = idlparser.IDLParser(import_options.idl_syntax) | 67 idl_parser = idlparser.IDLParser(import_options.idl_syntax) |
| 68 | 68 |
| 69 try: | 69 try: |
| 70 f = open(file_name, 'r') | 70 f = open(file_name, 'r') |
| 71 content = f.read() | 71 content = f.read() |
| 72 f.close() | 72 f.close() |
| 73 | 73 |
| 74 idl_ast = idl_parser.parse( | 74 idl_ast = idl_parser.parse( |
| 75 content, | 75 content, |
| 76 defines=import_options.idl_defines) | 76 defines=import_options.idl_defines) |
| 77 result = IDLFile(idl_ast, file_name) | 77 return IDLFile(idl_ast, file_name) |
| 78 except SyntaxError, e: |
| 79 raise RuntimeError('Failed to load file %s: %s' |
| 80 % (file_name, e)) |
| 81 |
| 82 def _load_idl_file_to_queue(file_name, import_options, result_queue): |
| 83 """Loads an IDL file into a result_queue to process in the master thread""" |
| 84 try: |
| 85 result = _load_idl_file(file_name, import_options) |
| 78 result_queue.put(result, False) | 86 result_queue.put(result, False) |
| 79 return 0 | 87 return 0 |
| 80 except SyntaxError, e: | 88 except RuntimeError, e: |
| 81 result_queue.put(RuntimeError('Failed to load file %s: %s' | 89 result_queue.put(e, False) |
| 82 % (file_name, e)), | |
| 83 False) | |
| 84 return 1 | 90 return 1 |
| 85 except: | 91 except: |
| 86 result_queue.put('Unknown error loading %s' % file_name, False) | 92 result_queue.put('Unknown error loading %s' % file_name, False) |
| 87 return 1 | 93 return 1 |
| 88 | 94 |
| 89 class DatabaseBuilder(object): | 95 class DatabaseBuilder(object): |
| 90 def __init__(self, database): | 96 def __init__(self, database): |
| 91 """DatabaseBuilder is used for importing and merging interfaces into | 97 """DatabaseBuilder is used for importing and merging interfaces into |
| 92 the Database""" | 98 the Database""" |
| 93 self._database = database | 99 self._database = database |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 else: | 424 else: |
| 419 raise Exception("Supplemental target '%s' not found", target) | 425 raise Exception("Supplemental target '%s' not found", target) |
| 420 | 426 |
| 421 # Step 4: Resolve 'implements' statements | 427 # Step 4: Resolve 'implements' statements |
| 422 for impl_stmt, import_options in self._impl_stmts: | 428 for impl_stmt, import_options in self._impl_stmts: |
| 423 self._merge_impl_stmt(impl_stmt, import_options) | 429 self._merge_impl_stmt(impl_stmt, import_options) |
| 424 | 430 |
| 425 self._impl_stmts = [] | 431 self._impl_stmts = [] |
| 426 self._imported_interfaces = [] | 432 self._imported_interfaces = [] |
| 427 | 433 |
| 428 def import_idl_files(self, file_paths, import_options): | 434 def import_idl_files(self, file_paths, import_options, parallel): |
| 429 # Parse the IDL files in parallel. | 435 if parallel: |
| 430 result_queue = multiprocessing.Queue(len(file_paths)) | 436 # Parse the IDL files in parallel. |
| 431 jobs = [ multiprocessing.Process(target=_load_idl_file, | 437 result_queue = multiprocessing.Queue(len(file_paths)) |
| 432 args=(file_path, import_options, | 438 jobs = [ multiprocessing.Process(target=_load_idl_file_to_queue, |
| 433 result_queue)) | 439 args=(file_path, import_options, |
| 434 for file_path in file_paths ] | 440 result_queue)) |
| 435 try: | 441 for file_path in file_paths ] |
| 436 for job in jobs: | 442 try: |
| 437 job.start() | 443 for job in jobs: |
| 438 for job in jobs: | 444 job.start() |
| 439 # Timeout and throw after 5 sec. | 445 for job in jobs: |
| 440 result = result_queue.get(True, 5) | 446 # Timeout and throw after 5 sec. |
| 441 if isinstance(result, IDLFile): | 447 result = result_queue.get(True, 5) |
| 442 self._process_idl_file(result, import_options) | 448 if isinstance(result, IDLFile): |
| 443 else: | 449 self._process_idl_file(result, import_options) |
| 444 raise result | 450 else: |
| 445 except: | 451 raise result |
| 446 # Clean up child processes on error. | 452 except: |
| 447 for job in jobs: | 453 # Clean up child processes on error. |
| 448 job.terminate() | 454 for job in jobs: |
| 449 raise | 455 job.terminate() |
| 456 raise |
| 457 else: |
| 458 # Parse the IDL files in serial. |
| 459 for file_path in file_paths: |
| 460 idl_file = _load_idl_file(file_path, import_options) |
| 461 self._process_idl_file(idl_file, import_options) |
| 450 | 462 |
| 451 def _process_idl_file(self, idl_file, | 463 def _process_idl_file(self, idl_file, |
| 452 import_options): | 464 import_options): |
| 453 self._strip_ext_attributes(idl_file) | 465 self._strip_ext_attributes(idl_file) |
| 454 self._resolve_type_defs(idl_file) | 466 self._resolve_type_defs(idl_file) |
| 455 self._rename_types(idl_file, import_options) | 467 self._rename_types(idl_file, import_options) |
| 456 | 468 |
| 457 def enabled(idl_node): | 469 def enabled(idl_node): |
| 458 return self._is_node_enabled(idl_node, import_options.idl_defines) | 470 return self._is_node_enabled(idl_node, import_options.idl_defines) |
| 459 | 471 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 # TODO(antonm): Ideally we'd like to have pristine copy of WebKit IDLs and
fetch | 584 # TODO(antonm): Ideally we'd like to have pristine copy of WebKit IDLs and
fetch |
| 573 # this information directly from it. Unfortunately right now database is
massaged | 585 # this information directly from it. Unfortunately right now database is
massaged |
| 574 # a lot so it's difficult to maintain necessary information on DOMWindow i
tself. | 586 # a lot so it's difficult to maintain necessary information on DOMWindow i
tself. |
| 575 interface = self._database.GetInterface(type) | 587 interface = self._database.GetInterface(type) |
| 576 if 'V8EnabledPerContext' in attr.ext_attrs: | 588 if 'V8EnabledPerContext' in attr.ext_attrs: |
| 577 interface.ext_attrs['synthesizedV8EnabledPerContext'] = \ | 589 interface.ext_attrs['synthesizedV8EnabledPerContext'] = \ |
| 578 attr.ext_attrs['V8EnabledPerContext'] | 590 attr.ext_attrs['V8EnabledPerContext'] |
| 579 if 'V8EnabledAtRuntime' in attr.ext_attrs: | 591 if 'V8EnabledAtRuntime' in attr.ext_attrs: |
| 580 interface.ext_attrs['synthesizedV8EnabledAtRuntime'] = \ | 592 interface.ext_attrs['synthesizedV8EnabledAtRuntime'] = \ |
| 581 attr.ext_attrs['V8EnabledAtRuntime'] or attr.id | 593 attr.ext_attrs['V8EnabledAtRuntime'] or attr.id |
| OLD | NEW |