| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 * paths: | 66 * paths: |
| 67 'full_path': path to the IDL file, so can lookup an IDL by interface name | 67 'full_path': path to the IDL file, so can lookup an IDL by interface name |
| 68 'include_path': path for use in C++ #include directives | 68 'include_path': path for use in C++ #include directives |
| 69 'dependencies_full_paths': paths to dependencies (for merging into main) | 69 'dependencies_full_paths': paths to dependencies (for merging into main) |
| 70 'dependencies_include_paths': paths for use in C++ #include directives | 70 'dependencies_include_paths': paths for use in C++ #include directives |
| 71 | 71 |
| 72 Note that all of these are stable information, unlikely to change without | 72 Note that all of these are stable information, unlikely to change without |
| 73 moving or deleting files (hence requiring a full rebuild anyway) or significant | 73 moving or deleting files (hence requiring a full rebuild anyway) or significant |
| 74 code changes (for inherited extended attributes). | 74 code changes (for inherited extended attributes). |
| 75 | 75 |
| 76 FIXME: also generates EventNames.in; factor out. http://crbug.com/341748 | |
| 77 | |
| 78 Design doc: http://www.chromium.org/developers/design-documents/idl-build | 76 Design doc: http://www.chromium.org/developers/design-documents/idl-build |
| 79 """ | 77 """ |
| 80 | 78 |
| 81 import optparse | 79 import optparse |
| 82 import os | 80 import os |
| 83 import posixpath | 81 import posixpath |
| 84 import sys | 82 import sys |
| 85 | 83 |
| 86 from utilities import get_file_contents, write_file, write_pickle_file, get_inte
rface_extended_attributes_from_idl, is_callback_interface_from_idl, get_partial_
interface_name_from_idl, get_implemented_interfaces_from_idl, get_parent_interfa
ce, get_put_forward_interfaces_from_idl | 84 from utilities import get_file_contents, write_pickle_file, get_interface_extend
ed_attributes_from_idl, is_callback_interface_from_idl, get_partial_interface_na
me_from_idl, get_implemented_interfaces_from_idl, get_parent_interface, get_put_
forward_interfaces_from_idl |
| 87 | 85 |
| 88 module_path = os.path.dirname(__file__) | 86 module_path = os.path.dirname(__file__) |
| 89 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) | 87 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) |
| 90 | 88 |
| 91 INHERITED_EXTENDED_ATTRIBUTES = set([ | 89 INHERITED_EXTENDED_ATTRIBUTES = set([ |
| 92 'ActiveDOMObject', | 90 'ActiveDOMObject', |
| 93 'DependentLifetime', | 91 'DependentLifetime', |
| 94 'WillBeGarbageCollected', | 92 'WillBeGarbageCollected', |
| 95 ]) | 93 ]) |
| 96 | 94 |
| 97 # Main variable (filled in and exported) | 95 # Main variable (filled in and exported) |
| 98 interfaces_info = {} | 96 interfaces_info = {} |
| 99 | 97 |
| 100 # Auxiliary variables (not visible to future build steps) | 98 # Auxiliary variables (not visible to future build steps) |
| 101 partial_interface_files = {} | 99 partial_interface_files = {} |
| 102 parent_interfaces = {} | 100 parent_interfaces = {} |
| 103 extended_attributes_by_interface = {} # interface name -> extended attributes | 101 extended_attributes_by_interface = {} # interface name -> extended attributes |
| 104 | 102 |
| 105 | 103 |
| 106 class IdlInterfaceFileNotFoundError(Exception): | 104 class IdlInterfaceFileNotFoundError(Exception): |
| 107 """Raised if the IDL file implementing an interface cannot be found.""" | 105 """Raised if the IDL file implementing an interface cannot be found.""" |
| 108 pass | 106 pass |
| 109 | 107 |
| 110 | 108 |
| 111 def parse_options(): | 109 def parse_options(): |
| 112 usage = 'Usage: %prog [options] [generated1.idl]...' | 110 usage = 'Usage: %prog [options] [generated1.idl]...' |
| 113 parser = optparse.OptionParser(usage=usage) | 111 parser = optparse.OptionParser(usage=usage) |
| 114 parser.add_option('--event-names-file', help='output file') | |
| 115 parser.add_option('--idl-files-list', help='file listing IDL files') | 112 parser.add_option('--idl-files-list', help='file listing IDL files') |
| 116 parser.add_option('--interfaces-info-file', help='output pickle file') | 113 parser.add_option('--interfaces-info-file', help='output pickle file') |
| 117 parser.add_option('--write-file-only-if-changed', type='int', help='if true,
do not write an output file if it would be identical to the existing one, which
avoids unnecessary rebuilds in ninja') | 114 parser.add_option('--write-file-only-if-changed', type='int', help='if true,
do not write an output file if it would be identical to the existing one, which
avoids unnecessary rebuilds in ninja') |
| 115 |
| 118 options, args = parser.parse_args() | 116 options, args = parser.parse_args() |
| 119 if options.event_names_file is None: | |
| 120 parser.error('Must specify an output file using --event-names-file.') | |
| 121 if options.interfaces_info_file is None: | 117 if options.interfaces_info_file is None: |
| 122 parser.error('Must specify an output file using --interfaces-info-file.'
) | 118 parser.error('Must specify an output file using --interfaces-info-file.'
) |
| 123 if options.idl_files_list is None: | 119 if options.idl_files_list is None: |
| 124 parser.error('Must specify a file listing IDL files using --idl-files-li
st.') | 120 parser.error('Must specify a file listing IDL files using --idl-files-li
st.') |
| 125 if options.write_file_only_if_changed is None: | 121 if options.write_file_only_if_changed is None: |
| 126 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') | 122 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') |
| 127 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) | 123 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) |
| 128 return options, args | 124 return options, args |
| 129 | 125 |
| 130 | 126 |
| 131 ################################################################################ | 127 ################################################################################ |
| 132 # Write files | |
| 133 ################################################################################ | |
| 134 | |
| 135 def write_event_names_file(destination_filename, only_if_changed): | |
| 136 # Generate event names for all interfaces that inherit from Event, | |
| 137 # including Event itself. | |
| 138 # FIXME: factor out. http://crbug.com/341748 | |
| 139 event_names = set( | |
| 140 interface_name | |
| 141 for interface_name, interface_info in interfaces_info.iteritems() | |
| 142 if (interface_name == 'Event' or | |
| 143 ('ancestors' in interface_info and | |
| 144 interface_info['ancestors'][-1] == 'Event'))) | |
| 145 | |
| 146 def extended_attribute_string(name): | |
| 147 value = extended_attributes[name] | |
| 148 if name == 'RuntimeEnabled': | |
| 149 value += 'Enabled' | |
| 150 return name + '=' + value | |
| 151 | |
| 152 source_dir, _ = os.path.split(os.getcwd()) | |
| 153 lines = [] | |
| 154 lines.append('namespace="Event"\n') | |
| 155 lines.append('\n') | |
| 156 for filename, extended_attributes in sorted( | |
| 157 (interface_info['full_path'], | |
| 158 extended_attributes_by_interface[interface_name]) | |
| 159 for interface_name, interface_info in interfaces_info.iteritems() | |
| 160 if interface_name in event_names): | |
| 161 refined_filename, _ = os.path.splitext(os.path.relpath(filename, source_
dir)) | |
| 162 refined_filename = refined_filename.replace(os.sep, posixpath.sep) | |
| 163 extended_attributes_list = [ | |
| 164 extended_attribute_string(name) | |
| 165 for name in 'Conditional', 'ImplementedAs', 'RuntimeEnabled' | |
| 166 if name in extended_attributes] | |
| 167 lines.append('%s %s\n' % (refined_filename, ', '.join(extended_attribute
s_list))) | |
| 168 write_file(lines, destination_filename, only_if_changed) | |
| 169 | |
| 170 | |
| 171 ################################################################################ | |
| 172 # Computations | 128 # Computations |
| 173 ################################################################################ | 129 ################################################################################ |
| 174 | 130 |
| 175 def include_path(idl_filename, implemented_as=None): | 131 def include_path(idl_filename, implemented_as=None): |
| 176 """Returns relative path to header file in POSIX format; used in includes. | 132 """Returns relative path to header file in POSIX format; used in includes. |
| 177 | 133 |
| 178 POSIX format is used for consistency of output, so reference tests are | 134 POSIX format is used for consistency of output, so reference tests are |
| 179 platform-independent. | 135 platform-independent. |
| 180 """ | 136 """ |
| 181 relative_path_local = os.path.relpath(idl_filename, source_path) | 137 relative_path_local = os.path.relpath(idl_filename, source_path) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 278 |
| 323 # Static IDL files are passed in a file (generated at GYP time), due to OS | 279 # Static IDL files are passed in a file (generated at GYP time), due to OS |
| 324 # command line length limits | 280 # command line length limits |
| 325 with open(options.idl_files_list) as idl_files_list: | 281 with open(options.idl_files_list) as idl_files_list: |
| 326 idl_files = [line.rstrip('\n') for line in idl_files_list] | 282 idl_files = [line.rstrip('\n') for line in idl_files_list] |
| 327 # Generated IDL files are passed at the command line, since these are in the | 283 # Generated IDL files are passed at the command line, since these are in the |
| 328 # build directory, which is determined at build time, not GYP time, so these | 284 # build directory, which is determined at build time, not GYP time, so these |
| 329 # cannot be included in the file listing static files | 285 # cannot be included in the file listing static files |
| 330 idl_files.extend(args) | 286 idl_files.extend(args) |
| 331 | 287 |
| 332 only_if_changed = options.write_file_only_if_changed | |
| 333 compute_interfaces_info(idl_files) | 288 compute_interfaces_info(idl_files) |
| 334 write_pickle_file(options.interfaces_info_file, interfaces_info, only_if_cha
nged) | 289 write_pickle_file(options.interfaces_info_file, |
| 335 write_event_names_file(options.event_names_file, only_if_changed) | 290 interfaces_info, |
| 291 options.write_file_only_if_changed) |
| 336 | 292 |
| 337 | 293 |
| 338 if __name__ == '__main__': | 294 if __name__ == '__main__': |
| 339 sys.exit(main()) | 295 sys.exit(main()) |
| OLD | NEW |