| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 'DependentLifetime', | 91 'DependentLifetime', |
| 92 'WillBeGarbageCollected', | 92 'WillBeGarbageCollected', |
| 93 ]) | 93 ]) |
| 94 | 94 |
| 95 # Main variable (filled in and exported) | 95 # Main variable (filled in and exported) |
| 96 interfaces_info = {} | 96 interfaces_info = {} |
| 97 | 97 |
| 98 # Auxiliary variables (not visible to future build steps) | 98 # Auxiliary variables (not visible to future build steps) |
| 99 partial_interface_files = {} | 99 partial_interface_files = {} |
| 100 parent_interfaces = {} | 100 parent_interfaces = {} |
| 101 extended_attributes_by_interface = {} # interface name -> extended attributes | 101 inherited_extended_attributes_by_interface = {} # interface name -> extended at
tributes |
| 102 | 102 |
| 103 | 103 |
| 104 class IdlInterfaceFileNotFoundError(Exception): | 104 class IdlInterfaceFileNotFoundError(Exception): |
| 105 """Raised if the IDL file implementing an interface cannot be found.""" | 105 """Raised if the IDL file implementing an interface cannot be found.""" |
| 106 pass | 106 pass |
| 107 | 107 |
| 108 | 108 |
| 109 def parse_options(): | 109 def parse_options(): |
| 110 usage = 'Usage: %prog [options] [generated1.idl]...' | 110 usage = 'Usage: %prog [options] [generated1.idl]...' |
| 111 parser = optparse.OptionParser(usage=usage) | 111 parser = optparse.OptionParser(usage=usage) |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 partial_interface_name = get_partial_interface_name_from_idl(idl_file_conten
ts) | 167 partial_interface_name = get_partial_interface_name_from_idl(idl_file_conten
ts) |
| 168 if partial_interface_name: | 168 if partial_interface_name: |
| 169 add_paths_to_partials_dict(partial_interface_name, full_path, this_inclu
de_path) | 169 add_paths_to_partials_dict(partial_interface_name, full_path, this_inclu
de_path) |
| 170 return | 170 return |
| 171 | 171 |
| 172 # If not a partial interface, the basename is the interface name | 172 # If not a partial interface, the basename is the interface name |
| 173 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) | 173 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) |
| 174 | 174 |
| 175 interfaces_info[interface_name] = { | 175 interfaces_info[interface_name] = { |
| 176 'full_path': full_path, | 176 'full_path': full_path, |
| 177 'implemented_as': implemented_as, |
| 177 'implements_interfaces': get_implemented_interfaces_from_idl(idl_file_co
ntents, interface_name), | 178 'implements_interfaces': get_implemented_interfaces_from_idl(idl_file_co
ntents, interface_name), |
| 179 'include_path': this_include_path, |
| 178 'is_callback_interface': is_callback_interface_from_idl(idl_file_content
s), | 180 'is_callback_interface': is_callback_interface_from_idl(idl_file_content
s), |
| 179 # Interfaces that are referenced (used as types) and that we introspect | 181 # Interfaces that are referenced (used as types) and that we introspect |
| 180 # during code generation (beyond interface-level data ([ImplementedAs], | 182 # during code generation (beyond interface-level data ([ImplementedAs], |
| 181 # is_callback_interface, ancestors, and inherited extended attributes): | 183 # is_callback_interface, ancestors, and inherited extended attributes): |
| 182 # deep dependencies. | 184 # deep dependencies. |
| 183 # These cause rebuilds of referrers, due to the dependency, so these | 185 # These cause rebuilds of referrers, due to the dependency, so these |
| 184 # should be minimized; currently only targets of [PutForwards]. | 186 # should be minimized; currently only targets of [PutForwards]. |
| 185 'referenced_interfaces': get_put_forward_interfaces_from_idl(idl_file_co
ntents), | 187 'referenced_interfaces': get_put_forward_interfaces_from_idl(idl_file_co
ntents), |
| 186 } | 188 } |
| 187 if this_include_path: | |
| 188 interfaces_info[interface_name]['include_path'] = this_include_path | |
| 189 if implemented_as: | |
| 190 interfaces_info[interface_name]['implemented_as'] = implemented_as | |
| 191 | 189 |
| 192 # Record auxiliary information | 190 # Record inheritance information |
| 193 extended_attributes_by_interface[interface_name] = extended_attributes | 191 inherited_extended_attributes_by_interface[interface_name] = dict( |
| 192 (key, value) |
| 193 for key, value in extended_attributes.iteritems() |
| 194 if key in INHERITED_EXTENDED_ATTRIBUTES) |
| 194 parent = get_parent_interface(idl_file_contents) | 195 parent = get_parent_interface(idl_file_contents) |
| 195 if parent: | 196 if parent: |
| 196 parent_interfaces[interface_name] = parent | 197 parent_interfaces[interface_name] = parent |
| 197 | 198 |
| 198 | 199 |
| 199 def compute_inheritance_info(interface_name): | 200 def compute_inheritance_info(interface_name): |
| 200 """Computes inheritance information, namely ancestors and inherited extended
attributes.""" | 201 """Compute inheritance information, namely ancestors and inherited extended
attributes.""" |
| 201 interface_info = interfaces_info[interface_name] | |
| 202 interface_extended_attributes = extended_attributes_by_interface[interface_n
ame] | |
| 203 inherited_extended_attributes = dict( | |
| 204 (key, value) | |
| 205 for key, value in interface_extended_attributes.iteritems() | |
| 206 if key in INHERITED_EXTENDED_ATTRIBUTES) | |
| 207 | |
| 208 def generate_ancestors(interface_name): | 202 def generate_ancestors(interface_name): |
| 209 while interface_name in parent_interfaces: | 203 while interface_name in parent_interfaces: |
| 210 interface_name = parent_interfaces[interface_name] | 204 interface_name = parent_interfaces[interface_name] |
| 211 yield interface_name | 205 yield interface_name |
| 212 | 206 |
| 213 ancestors = list(generate_ancestors(interface_name)) | 207 ancestors = list(generate_ancestors(interface_name)) |
| 214 if not ancestors: | 208 inherited_extended_attributes = inherited_extended_attributes_by_interface[i
nterface_name] |
| 215 if inherited_extended_attributes: | 209 for ancestor in ancestors: |
| 216 interface_info['inherited_extended_attributes'] = inherited_extended
_attributes | 210 # Ancestors may not be present, notably if an ancestor is a generated |
| 217 return | 211 # IDL file and we are running this script from run-bindings-tests, |
| 212 # where we don't generate these files. |
| 213 ancestor_extended_attributes = inherited_extended_attributes_by_interfac
e.get(ancestor, {}) |
| 214 inherited_extended_attributes.update(ancestor_extended_attributes) |
| 218 | 215 |
| 219 interface_info['ancestors'] = ancestors | 216 interfaces_info[interface_name].update({ |
| 220 for ancestor in ancestors: | 217 'ancestors': ancestors, |
| 221 # Extended attributes are missing if an ancestor is an interface that | 218 'inherited_extended_attributes': inherited_extended_attributes, |
| 222 # we're not processing, namely real IDL files if only processing test | 219 }) |
| 223 # IDL files. | |
| 224 ancestor_extended_attributes = extended_attributes_by_interface.get(ance
stor, {}) | |
| 225 inherited_extended_attributes.update(dict( | |
| 226 (key, value) | |
| 227 for key, value in ancestor_extended_attributes.iteritems() | |
| 228 if key in INHERITED_EXTENDED_ATTRIBUTES)) | |
| 229 if inherited_extended_attributes: | |
| 230 interface_info['inherited_extended_attributes'] = inherited_extended_att
ributes | |
| 231 | 220 |
| 232 | 221 |
| 233 def compute_interfaces_info(idl_files): | 222 def compute_interfaces_info(idl_files): |
| 234 """Compute information about IDL files. | 223 """Compute information about IDL files. |
| 235 | 224 |
| 236 Information is stored in global interfaces_info. | 225 Information is stored in global interfaces_info. |
| 237 """ | 226 """ |
| 238 # Compute information for individual files | 227 # Compute information for individual files |
| 239 for idl_filename in idl_files: | 228 for idl_filename in idl_files: |
| 240 compute_individual_info(idl_filename) | 229 compute_individual_info(idl_filename) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 252 if interface_name in partial_interface_files else ([], [])) | 241 if interface_name in partial_interface_files else ([], [])) |
| 253 | 242 |
| 254 implemented_interfaces = interface_info['implements_interfaces'] | 243 implemented_interfaces = interface_info['implements_interfaces'] |
| 255 try: | 244 try: |
| 256 implemented_interfaces_full_paths = [ | 245 implemented_interfaces_full_paths = [ |
| 257 interfaces_info[interface]['full_path'] | 246 interfaces_info[interface]['full_path'] |
| 258 for interface in implemented_interfaces] | 247 for interface in implemented_interfaces] |
| 259 implemented_interfaces_include_paths = [ | 248 implemented_interfaces_include_paths = [ |
| 260 interfaces_info[interface]['include_path'] | 249 interfaces_info[interface]['include_path'] |
| 261 for interface in implemented_interfaces | 250 for interface in implemented_interfaces |
| 262 if 'include_path' in interfaces_info[interface]] | 251 if interfaces_info[interface]['include_path']] |
| 263 except KeyError as key_name: | 252 except KeyError as key_name: |
| 264 raise IdlInterfaceFileNotFoundError('Could not find the IDL file whe
re the following implemented interface is defined: %s' % key_name) | 253 raise IdlInterfaceFileNotFoundError('Could not find the IDL file whe
re the following implemented interface is defined: %s' % key_name) |
| 265 | 254 |
| 266 interface_info['dependencies_full_paths'] = ( | 255 interface_info.update({ |
| 267 partial_interfaces_full_paths + | 256 'dependencies_full_paths': (partial_interfaces_full_paths + |
| 268 implemented_interfaces_full_paths) | 257 implemented_interfaces_full_paths), |
| 269 interface_info['dependencies_include_paths'] = ( | 258 'dependencies_include_paths': (partial_interfaces_include_paths + |
| 270 partial_interfaces_include_paths + | 259 implemented_interfaces_include_paths)
, |
| 271 implemented_interfaces_include_paths) | 260 }) |
| 272 | 261 |
| 273 | 262 |
| 274 ################################################################################ | 263 ################################################################################ |
| 275 | 264 |
| 276 def main(): | 265 def main(): |
| 277 options, args = parse_options() | 266 options, args = parse_options() |
| 278 | 267 |
| 279 # Static IDL files are passed in a file (generated at GYP time), due to OS | 268 # Static IDL files are passed in a file (generated at GYP time), due to OS |
| 280 # command line length limits | 269 # command line length limits |
| 281 with open(options.idl_files_list) as idl_files_list: | 270 with open(options.idl_files_list) as idl_files_list: |
| 282 idl_files = [line.rstrip('\n') for line in idl_files_list] | 271 idl_files = [line.rstrip('\n') for line in idl_files_list] |
| 283 # Generated IDL files are passed at the command line, since these are in the | 272 # Generated IDL files are passed at the command line, since these are in the |
| 284 # build directory, which is determined at build time, not GYP time, so these | 273 # build directory, which is determined at build time, not GYP time, so these |
| 285 # cannot be included in the file listing static files | 274 # cannot be included in the file listing static files |
| 286 idl_files.extend(args) | 275 idl_files.extend(args) |
| 287 | 276 |
| 288 compute_interfaces_info(idl_files) | 277 compute_interfaces_info(idl_files) |
| 289 write_pickle_file(options.interfaces_info_file, | 278 write_pickle_file(options.interfaces_info_file, |
| 290 interfaces_info, | 279 interfaces_info, |
| 291 options.write_file_only_if_changed) | 280 options.write_file_only_if_changed) |
| 292 | 281 |
| 293 | 282 |
| 294 if __name__ == '__main__': | 283 if __name__ == '__main__': |
| 295 sys.exit(main()) | 284 sys.exit(main()) |
| OLD | NEW |