Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # | 2 # |
| 3 # Copyright (C) 2013 Google Inc. All rights reserved. | 3 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 # | 4 # |
| 5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
| 6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
| 7 # met: | 7 # met: |
| 8 # | 8 # |
| 9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
| 10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 'GarbageCollected', | 44 'GarbageCollected', |
| 45 ]) | 45 ]) |
| 46 | 46 |
| 47 | 47 |
| 48 # interfaces_info is *exported* (in a pickle), and should only contain data | 48 # interfaces_info is *exported* (in a pickle), and should only contain data |
| 49 # about an interface that contains paths or is needed by *other* interfaces, | 49 # about an interface that contains paths or is needed by *other* interfaces, |
| 50 # i.e., file layout data (to abstract the compiler from file paths) or | 50 # i.e., file layout data (to abstract the compiler from file paths) or |
| 51 # public data (to avoid having to read other interfaces unnecessarily). | 51 # public data (to avoid having to read other interfaces unnecessarily). |
| 52 # It should *not* contain full information about an interface (e.g., all | 52 # It should *not* contain full information about an interface (e.g., all |
| 53 # extended attributes), as this would cause unnecessary rebuilds. | 53 # extended attributes), as this would cause unnecessary rebuilds. |
| 54 interfaces_info = {} | 54 interfaces_info = {} |
|
haraken
2014/02/06 03:57:38
Would you add a comment about what information is
Nils Barth (inactive)
2014/02/06 04:49:06
n/p, done!
| |
| 55 | 55 |
| 56 # Auxiliary variables (not visible to future build steps) | 56 # Auxiliary variables (not visible to future build steps) |
| 57 partial_interface_files = {} | 57 partial_interface_files = {} |
| 58 parent_interfaces = {} | 58 parent_interfaces = {} |
| 59 extended_attributes_by_interface = {} # interface name -> extended attributes | 59 extended_attributes_by_interface = {} # interface name -> extended attributes |
| 60 | 60 |
| 61 | 61 |
| 62 class IdlBadFilenameError(Exception): | 62 class IdlBadFilenameError(Exception): |
| 63 """Raised if an IDL filename disagrees with the interface name in the file." "" | 63 """Raised if an IDL filename disagrees with the interface name in the file." "" |
| 64 pass | 64 pass |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 407 | 407 |
| 408 return attributes_list | 408 return attributes_list |
| 409 | 409 |
| 410 | 410 |
| 411 def record_global_constructors_and_extended_attributes(idl_filename, global_cons tructors): | 411 def record_global_constructors_and_extended_attributes(idl_filename, global_cons tructors): |
| 412 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) | 412 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) |
| 413 full_path = os.path.realpath(idl_filename) | 413 full_path = os.path.realpath(idl_filename) |
| 414 idl_file_contents = get_file_contents(full_path) | 414 idl_file_contents = get_file_contents(full_path) |
| 415 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents) | 415 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents) |
| 416 | 416 |
| 417 # Record extended attributes | |
| 418 extended_attributes_by_interface[interface_name] = extended_attributes | |
| 419 | |
| 417 # Record global constructors | 420 # Record global constructors |
| 418 if not is_callback_interface_from_idl(idl_file_contents) and 'NoInterfaceObj ect' not in extended_attributes: | 421 if (not is_callback_interface_from_idl(idl_file_contents) and |
| 422 'NoInterfaceObject' not in extended_attributes): | |
| 419 global_contexts = extended_attributes.get('GlobalContext', 'Window').spl it('&') | 423 global_contexts = extended_attributes.get('GlobalContext', 'Window').spl it('&') |
| 420 new_constructor_list = generate_constructor_attribute_list(interface_nam e, extended_attributes) | 424 new_constructor_list = generate_constructor_attribute_list(interface_nam e, extended_attributes) |
| 421 for global_object in global_contexts: | 425 for global_object in global_contexts: |
| 422 global_constructors[global_object].extend(new_constructor_list) | 426 global_constructors[global_object].extend(new_constructor_list) |
| 423 | 427 |
| 424 # Record parents and extended attributes for generating event names | 428 # Record parents |
| 425 parent = get_parent_interface(idl_file_contents) | 429 parent = get_parent_interface(idl_file_contents) |
| 426 if parent: | 430 if parent: |
| 427 parent_interfaces[interface_name] = parent | 431 parent_interfaces[interface_name] = parent |
| 428 if parent or interface_name == 'Event': | |
| 429 extended_attributes_by_interface[interface_name] = extended_attributes | |
| 430 | 432 |
| 431 | 433 |
| 432 def record_extended_attributes(idl_filename): | 434 def record_extended_attributes(idl_filename): |
| 433 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) | 435 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) |
| 434 full_path = os.path.realpath(idl_filename) | 436 full_path = os.path.realpath(idl_filename) |
| 435 idl_file_contents = get_file_contents(full_path) | 437 idl_file_contents = get_file_contents(full_path) |
| 436 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents) | 438 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents) |
| 437 extended_attributes_by_interface[interface_name] = extended_attributes | 439 extended_attributes_by_interface[interface_name] = extended_attributes |
| 438 | 440 |
| 439 | 441 |
| 440 def generate_ancestors_and_inherited_extended_attributes(interface_name): | 442 def generate_ancestors_and_inherited_extended_attributes(interface_name): |
| 441 interface_info = interfaces_info[interface_name] | 443 interface_info = interfaces_info[interface_name] |
| 444 interface_extended_attributes = extended_attributes_by_interface[interface_n ame] | |
| 445 inherited_extended_attributes = dict( | |
| 446 (key, value) | |
| 447 for key, value in interface_extended_attributes.iteritems() | |
| 448 if key in INHERITED_EXTENDED_ATTRIBUTES) | |
| 442 | 449 |
| 443 def generate_ancestors(interface_name): | 450 def generate_ancestors(interface_name): |
| 444 while interface_name in parent_interfaces: | 451 while interface_name in parent_interfaces: |
| 445 interface_name = parent_interfaces[interface_name] | 452 interface_name = parent_interfaces[interface_name] |
| 446 yield interface_name | 453 yield interface_name |
| 447 | 454 |
| 448 ancestors = list(generate_ancestors(interface_name)) | 455 ancestors = list(generate_ancestors(interface_name)) |
| 456 if not ancestors: | |
| 457 if inherited_extended_attributes: | |
| 458 interface_info['inherited_extended_attributes'] = inherited_extended _attributes | |
| 459 return | |
| 460 | |
| 449 interface_info['ancestors'] = ancestors | 461 interface_info['ancestors'] = ancestors |
| 450 | |
| 451 # Base interface (most distant ancestor) has no parent, and thus its | |
| 452 # extended attributes may not yet be recorded. | |
| 453 base_interface_name = ancestors[-1] | |
| 454 if base_interface_name not in extended_attributes_by_interface: | |
| 455 if base_interface_name not in interfaces_info: | |
| 456 # Absent for support files | |
| 457 return | |
| 458 base_interface_info = interfaces_info[base_interface_name] | |
| 459 base_interface_filename = base_interface_info['full_path'] | |
| 460 record_extended_attributes(base_interface_filename) | |
| 461 | |
| 462 inherited_extended_attributes = {} | |
| 463 for ancestor in ancestors: | 462 for ancestor in ancestors: |
| 464 ancestor_extended_attributes = extended_attributes_by_interface[ancestor ] | 463 # Extended attributes are missing if an ancestor is an interface that |
| 464 # we're not processing, notably real IDL files if only processing test | |
| 465 # IDL files, or generated support files. | |
| 466 ancestor_extended_attributes = extended_attributes_by_interface.get(ance stor, {}) | |
| 465 inherited_extended_attributes.update(dict( | 467 inherited_extended_attributes.update(dict( |
| 466 (key, value) | 468 (key, value) |
| 467 for key, value in ancestor_extended_attributes.iteritems() | 469 for key, value in ancestor_extended_attributes.iteritems() |
| 468 if key in INHERITED_EXTENDED_ATTRIBUTES)) | 470 if key in INHERITED_EXTENDED_ATTRIBUTES)) |
| 469 if inherited_extended_attributes: | 471 if inherited_extended_attributes: |
| 470 interface_info['inherited_extended_attributes'] = inherited_extended_att ributes | 472 interface_info['inherited_extended_attributes'] = inherited_extended_att ributes |
| 471 | 473 |
| 472 | 474 |
| 473 def parse_idl_files(idl_files, global_constructors_filenames): | 475 def parse_idl_files(idl_files, global_constructors_filenames): |
| 474 """Compute dependencies between IDL files, and return constructors on global objects. | 476 """Compute dependencies between IDL files, and return constructors on global objects. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 486 (global_object, []) | 488 (global_object, []) |
| 487 for global_object in global_constructors_filenames]) | 489 for global_object in global_constructors_filenames]) |
| 488 | 490 |
| 489 # Generate dependencies, and (for main IDL files), record | 491 # Generate dependencies, and (for main IDL files), record |
| 490 # global_constructors and extended_attributes_by_interface. | 492 # global_constructors and extended_attributes_by_interface. |
| 491 for idl_filename in idl_files: | 493 for idl_filename in idl_files: |
| 492 # Test skips partial interfaces | 494 # Test skips partial interfaces |
| 493 if generate_dependencies(idl_filename): | 495 if generate_dependencies(idl_filename): |
| 494 record_global_constructors_and_extended_attributes(idl_filename, glo bal_constructors) | 496 record_global_constructors_and_extended_attributes(idl_filename, glo bal_constructors) |
| 495 | 497 |
| 496 for interface_name in parent_interfaces: | 498 for interface_name in interfaces_info: |
| 497 generate_ancestors_and_inherited_extended_attributes(interface_name) | 499 generate_ancestors_and_inherited_extended_attributes(interface_name) |
| 498 | 500 |
| 499 # Add constructors on global objects to partial interfaces | 501 # Add constructors on global objects to partial interfaces |
| 500 # These are all partial interfaces, but the files are dynamically generated, | 502 # These are all partial interfaces, but the files are dynamically generated, |
| 501 # so they need to be handled separately from static partial interfaces. | 503 # so they need to be handled separately from static partial interfaces. |
| 502 for global_object, constructor_filename in global_constructors_filenames.ite ritems(): | 504 for global_object, constructor_filename in global_constructors_filenames.ite ritems(): |
| 503 if global_object in interfaces_info: | 505 if global_object in interfaces_info: |
| 504 # No include path needed, as already included in the header file | 506 # No include path needed, as already included in the header file |
| 505 add_paths_to_partials_dict(global_object, constructor_filename) | 507 add_paths_to_partials_dict(global_object, constructor_filename) |
| 506 | 508 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 write_dependencies_file(options.interface_dependencies_file, only_if_changed ) | 557 write_dependencies_file(options.interface_dependencies_file, only_if_changed ) |
| 556 write_pickle_file(options.interfaces_info_file, interfaces_info, only_if_cha nged) | 558 write_pickle_file(options.interfaces_info_file, interfaces_info, only_if_cha nged) |
| 557 for interface_name, filename in global_constructors_filenames.iteritems(): | 559 for interface_name, filename in global_constructors_filenames.iteritems(): |
| 558 if interface_name in interfaces_info: | 560 if interface_name in interfaces_info: |
| 559 write_global_constructors_partial_interface(interface_name, filename , global_constructors[interface_name], only_if_changed) | 561 write_global_constructors_partial_interface(interface_name, filename , global_constructors[interface_name], only_if_changed) |
| 560 write_event_names_file(options.event_names_file, only_if_changed) | 562 write_event_names_file(options.event_names_file, only_if_changed) |
| 561 | 563 |
| 562 | 564 |
| 563 if __name__ == '__main__': | 565 if __name__ == '__main__': |
| 564 main() | 566 main() |
| OLD | NEW |