| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 content = f.read() | 67 content = f.read() |
| 68 f.close() | 68 f.close() |
| 69 | 69 |
| 70 idl_ast = idl_parser.parse( | 70 idl_ast = idl_parser.parse( |
| 71 content, | 71 content, |
| 72 defines=import_options.idl_defines) | 72 defines=import_options.idl_defines) |
| 73 return IDLFile(idl_ast, file_name) | 73 return IDLFile(idl_ast, file_name) |
| 74 except SyntaxError, e: | 74 except SyntaxError, e: |
| 75 raise RuntimeError('Failed to load file %s: %s' | 75 raise RuntimeError('Failed to load file %s: %s' |
| 76 % (file_name, e)) | 76 % (file_name, e)) |
| 77 | 77 |
| 78 def _load_idl_file_to_queue(file_name, import_options, result_queue): | |
| 79 """Loads an IDL file into a result_queue to process in the master thread""" | |
| 80 try: | |
| 81 result = _load_idl_file(file_name, import_options) | |
| 82 result_queue.put(result, False) | |
| 83 return 0 | |
| 84 except RuntimeError, e: | |
| 85 result_queue.put(e, False) | |
| 86 return 1 | |
| 87 except: | |
| 88 result_queue.put('Unknown error loading %s' % file_name, False) | |
| 89 return 1 | |
| 90 | 78 |
| 91 class DatabaseBuilder(object): | 79 class DatabaseBuilder(object): |
| 92 def __init__(self, database): | 80 def __init__(self, database): |
| 93 """DatabaseBuilder is used for importing and merging interfaces into | 81 """DatabaseBuilder is used for importing and merging interfaces into |
| 94 the Database""" | 82 the Database""" |
| 95 self._database = database | 83 self._database = database |
| 96 self._imported_interfaces = [] | 84 self._imported_interfaces = [] |
| 97 self._impl_stmts = [] | 85 self._impl_stmts = [] |
| 98 | 86 |
| 99 def _resolve_type_defs(self, idl_file): | 87 def _resolve_type_defs(self, idl_file): |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 # Step 4: Resolve 'implements' statements | 410 # Step 4: Resolve 'implements' statements |
| 423 for impl_stmt, import_options in self._impl_stmts: | 411 for impl_stmt, import_options in self._impl_stmts: |
| 424 self._merge_impl_stmt(impl_stmt, import_options) | 412 self._merge_impl_stmt(impl_stmt, import_options) |
| 425 | 413 |
| 426 self._impl_stmts = [] | 414 self._impl_stmts = [] |
| 427 self._imported_interfaces = [] | 415 self._imported_interfaces = [] |
| 428 | 416 |
| 429 def import_idl_files(self, file_paths, import_options, parallel): | 417 def import_idl_files(self, file_paths, import_options, parallel): |
| 430 if parallel: | 418 if parallel: |
| 431 # Parse the IDL files in parallel. | 419 # Parse the IDL files in parallel. |
| 432 result_queue = multiprocessing.Queue(len(file_paths)) | 420 pool = multiprocessing.Pool() |
| 433 jobs = [ multiprocessing.Process(target=_load_idl_file_to_queue, | |
| 434 args=(file_path, import_options, | |
| 435 result_queue)) | |
| 436 for file_path in file_paths ] | |
| 437 try: | 421 try: |
| 438 for job in jobs: | 422 for file_path in file_paths: |
| 439 job.start() | 423 pool.apply_async(_load_idl_file, |
| 440 for job in jobs: | 424 [ file_path, import_options], |
| 441 # Timeout and throw after 5 sec. | 425 callback = lambda idl_file: |
| 442 result = result_queue.get(True, 5) | 426 self._process_idl_file(idl_file, import_options)) |
| 443 if isinstance(result, IDLFile): | 427 pool.close() |
| 444 self._process_idl_file(result, import_options) | 428 pool.join() |
| 445 else: | |
| 446 raise result | |
| 447 except: | 429 except: |
| 448 # Clean up child processes on error. | 430 pool.terminate() |
| 449 for job in jobs: | |
| 450 job.terminate() | |
| 451 raise | 431 raise |
| 452 else: | 432 else: |
| 453 # Parse the IDL files in serial. | 433 # Parse the IDL files in serial. |
| 454 for file_path in file_paths: | 434 for file_path in file_paths: |
| 455 idl_file = _load_idl_file(file_path, import_options) | 435 idl_file = _load_idl_file(file_path, import_options) |
| 456 self._process_idl_file(idl_file, import_options) | 436 self._process_idl_file(idl_file, import_options) |
| 457 | 437 |
| 458 def _process_idl_file(self, idl_file, | 438 def _process_idl_file(self, idl_file, |
| 459 import_options): | 439 import_options): |
| 460 self._strip_ext_attributes(idl_file) | 440 self._strip_ext_attributes(idl_file) |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 # TODO(antonm): Ideally we'd like to have pristine copy of WebKit IDLs and
fetch | 559 # TODO(antonm): Ideally we'd like to have pristine copy of WebKit IDLs and
fetch |
| 580 # this information directly from it. Unfortunately right now database is
massaged | 560 # this information directly from it. Unfortunately right now database is
massaged |
| 581 # a lot so it's difficult to maintain necessary information on DOMWindow i
tself. | 561 # a lot so it's difficult to maintain necessary information on DOMWindow i
tself. |
| 582 interface = self._database.GetInterface(type) | 562 interface = self._database.GetInterface(type) |
| 583 if 'V8EnabledPerContext' in attr.ext_attrs: | 563 if 'V8EnabledPerContext' in attr.ext_attrs: |
| 584 interface.ext_attrs['synthesizedV8EnabledPerContext'] = \ | 564 interface.ext_attrs['synthesizedV8EnabledPerContext'] = \ |
| 585 attr.ext_attrs['V8EnabledPerContext'] | 565 attr.ext_attrs['V8EnabledPerContext'] |
| 586 if 'V8EnabledAtRuntime' in attr.ext_attrs: | 566 if 'V8EnabledAtRuntime' in attr.ext_attrs: |
| 587 interface.ext_attrs['synthesizedV8EnabledAtRuntime'] = \ | 567 interface.ext_attrs['synthesizedV8EnabledAtRuntime'] = \ |
| 588 attr.ext_attrs['V8EnabledAtRuntime'] or attr.id | 568 attr.ext_attrs['V8EnabledAtRuntime'] or attr.id |
| OLD | NEW |