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 17 matching lines...) Expand all Loading... |
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 import optparse | 31 import optparse |
32 import os | 32 import os |
33 import cPickle as pickle | 33 import cPickle as pickle |
34 import posixpath | 34 import posixpath |
35 import re | 35 import re |
36 import string | 36 import string |
37 | 37 |
| 38 module_path, _ = os.path.split(__file__) |
| 39 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) |
| 40 |
38 | 41 |
39 class IdlBadFilenameError(Exception): | 42 class IdlBadFilenameError(Exception): |
40 """Raised if an IDL filename disagrees with the interface name in the file."
"" | 43 """Raised if an IDL filename disagrees with the interface name in the file."
"" |
41 pass | 44 pass |
42 | 45 |
43 | 46 |
44 class IdlInterfaceFileNotFoundError(Exception): | 47 class IdlInterfaceFileNotFoundError(Exception): |
45 """Raised if the IDL file implementing an interface cannot be found.""" | 48 """Raised if the IDL file implementing an interface cannot be found.""" |
46 pass | 49 pass |
47 | 50 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 for constructor_attribute in sorted(constructor_attributes_list)]
+ | 232 for constructor_attribute in sorted(constructor_attributes_list)]
+ |
230 ['};\n']) | 233 ['};\n']) |
231 write_file(lines, destination_filename, only_if_changed) | 234 write_file(lines, destination_filename, only_if_changed) |
232 | 235 |
233 | 236 |
234 def generate_dependencies(idl_file_name, interfaces_info, partial_interface_file
s): | 237 def generate_dependencies(idl_file_name, interfaces_info, partial_interface_file
s): |
235 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name)) | 238 interface_name, _ = os.path.splitext(os.path.basename(idl_file_name)) |
236 full_path = os.path.realpath(idl_file_name) | 239 full_path = os.path.realpath(idl_file_name) |
237 idl_file_contents = get_file_contents(full_path) | 240 idl_file_contents = get_file_contents(full_path) |
238 | 241 |
| 242 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co
ntents) |
| 243 implemented_as = extended_attributes.get('ImplementedAs') |
| 244 |
| 245 # Relative path to header file, used in includes |
| 246 relative_path_local = os.path.relpath(idl_file_name, source_path) |
| 247 relative_dir_local = os.path.dirname(relative_path_local) |
| 248 posix_dir = relative_dir_local.replace(os.path.sep, posixpath.sep) |
| 249 cpp_class_name = implemented_as or interface_name |
| 250 include_path = os.path.join(posix_dir, cpp_class_name + '.h') |
| 251 |
239 # Handle partial interfaces | 252 # Handle partial interfaces |
240 partial_interface_name = get_partial_interface_name_from_idl(idl_file_conten
ts) | 253 partial_interface_name = get_partial_interface_name_from_idl(idl_file_conten
ts) |
241 if partial_interface_name: | 254 if partial_interface_name: |
242 partial_interface_files.setdefault(partial_interface_name, []).append(fu
ll_path) | 255 partial_interface_files.setdefault(partial_interface_name, []).append(fu
ll_path) |
243 return partial_interface_name | 256 return partial_interface_name |
244 | 257 |
245 # Non-partial interfaces default to having bindings generated, | 258 # Non-partial interfaces default to having bindings generated, |
246 # but are removed later if they are implemented by another interface | 259 # but are removed later if they are implemented by another interface |
247 interfaces_info[interface_name] = { | 260 interfaces_info[interface_name] = { |
248 'full_path': full_path, | 261 'full_path': full_path, |
| 262 'include_path': include_path, |
249 'implements_interfaces': get_implemented_interfaces_from_idl(idl_file_co
ntents, interface_name), | 263 'implements_interfaces': get_implemented_interfaces_from_idl(idl_file_co
ntents, interface_name), |
250 'is_callback_interface': is_callback_interface_from_idl(idl_file_content
s), | 264 'is_callback_interface': is_callback_interface_from_idl(idl_file_content
s), |
251 } | 265 } |
252 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co
ntents) | 266 if implemented_as: |
253 if 'ImplementedAs' in extended_attributes: | 267 interfaces_info[interface_name]['implemented_as'] = implemented_as |
254 interfaces_info[interface_name]['implemented_as'] = extended_attributes[
'ImplementedAs'] | |
255 | 268 |
256 return None | 269 return None |
257 | 270 |
258 | 271 |
259 def remove_interfaces_implemented_somewhere(interfaces_info): | 272 def remove_interfaces_implemented_somewhere(interfaces_info): |
260 # Interfaces that are implemented by another interface do not have | 273 # Interfaces that are implemented by another interface do not have |
261 # their own bindings generated, as this would be redundant with the | 274 # their own bindings generated, as this would be redundant with the |
262 # actual implementation. | 275 # actual implementation. |
263 implemented_somewhere = set().union(*[ | 276 implemented_somewhere = set().union(*[ |
264 interface_info['implements_interfaces'] | 277 interface_info['implements_interfaces'] |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 write_pickle_file(options.interfaces_info_file, interfaces_info, only_if_cha
nged) | 440 write_pickle_file(options.interfaces_info_file, interfaces_info, only_if_cha
nged) |
428 write_bindings_derived_sources_file(options.bindings_derived_sources_file, b
indings_derived_sources, only_if_changed) | 441 write_bindings_derived_sources_file(options.bindings_derived_sources_file, b
indings_derived_sources, only_if_changed) |
429 for interface_name, filename in global_constructors_filenames.iteritems(): | 442 for interface_name, filename in global_constructors_filenames.iteritems(): |
430 if interface_name in interfaces_info: | 443 if interface_name in interfaces_info: |
431 generate_global_constructors_partial_interface(interface_name, filen
ame, global_constructors[interface_name], only_if_changed) | 444 generate_global_constructors_partial_interface(interface_name, filen
ame, global_constructors[interface_name], only_if_changed) |
432 generate_event_names_file(options.event_names_file, event_names, interfaces_
info, interface_extended_attributes, only_if_changed) | 445 generate_event_names_file(options.event_names_file, event_names, interfaces_
info, interface_extended_attributes, only_if_changed) |
433 | 446 |
434 | 447 |
435 if __name__ == '__main__': | 448 if __name__ == '__main__': |
436 main() | 449 main() |
OLD | NEW |