| 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 23 matching lines...) Expand all Loading... |
| 34 all interfaces that inherit from Event, including Event itself, | 34 all interfaces that inherit from Event, including Event itself, |
| 35 together with certain extended attributes. | 35 together with certain extended attributes. |
| 36 | 36 |
| 37 Paths are in POSIX format, and relative to Source/. | 37 Paths are in POSIX format, and relative to Source/. |
| 38 | 38 |
| 39 This list is used in core/ to generate EventFactory and EventNames. | 39 This list is used in core/ to generate EventFactory and EventNames. |
| 40 The .in format is documented in build/scripts/in_file.py. | 40 The .in format is documented in build/scripts/in_file.py. |
| 41 """ | 41 """ |
| 42 | 42 |
| 43 from optparse import OptionParser | 43 from optparse import OptionParser |
| 44 import cPickle as pickle | |
| 45 import os | 44 import os |
| 46 import posixpath | 45 import posixpath |
| 47 import sys | 46 import sys |
| 48 | 47 |
| 49 from utilities import get_file_contents, write_file, get_interface_extended_attr
ibutes_from_idl | 48 from utilities import get_file_contents, write_file, get_interface_extended_attr
ibutes_from_idl |
| 50 | 49 |
| 51 EXPORTED_EXTENDED_ATTRIBUTES = ( | 50 EXPORTED_EXTENDED_ATTRIBUTES = ( |
| 52 'Conditional', | 51 'Conditional', |
| 53 'ImplementedAs', | 52 'ImplementedAs', |
| 54 'RuntimeEnabled', | 53 'RuntimeEnabled', |
| 55 ) | 54 ) |
| 56 module_path = os.path.dirname(os.path.realpath(__file__)) | 55 module_path = os.path.dirname(os.path.realpath(__file__)) |
| 57 source_dir = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) | 56 source_dir = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) |
| 58 | 57 |
| 59 | 58 |
| 60 def parse_options(): | 59 def parse_options(): |
| 61 parser = OptionParser() | 60 parser = OptionParser() |
| 61 parser.add_option('--event-idl-files-list', help='file listing event IDL fil
es') |
| 62 parser.add_option('--event-interfaces-file', help='output file') | 62 parser.add_option('--event-interfaces-file', help='output file') |
| 63 parser.add_option('--interfaces-info-file', help='output pickle file') | |
| 64 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') | 63 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') |
| 65 | 64 |
| 66 options, args = parser.parse_args() | 65 options, args = parser.parse_args() |
| 66 if options.event_idl_files_list is None: |
| 67 parser.error('Must specify a file listing event IDL files using --event-
idl-files-list.') |
| 67 if options.event_interfaces_file is None: | 68 if options.event_interfaces_file is None: |
| 68 parser.error('Must specify an output file using --event-interfaces-file.
') | 69 parser.error('Must specify an output file using --event-interfaces-file.
') |
| 69 if options.interfaces_info_file is None: | |
| 70 parser.error('Must specify an input file using --interfaces-info-file.') | |
| 71 if options.write_file_only_if_changed is None: | 70 if options.write_file_only_if_changed is None: |
| 72 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') | 71 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') |
| 73 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) | 72 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) |
| 74 if args: | 73 if args: |
| 75 parser.error('No arguments allowed, but %d given.' % len(args)) | 74 parser.error('No arguments allowed, but %d given.' % len(args)) |
| 76 return options | 75 return options |
| 77 | 76 |
| 78 | 77 |
| 79 def write_event_interfaces_file(interfaces_info, destination_filename, only_if_c
hanged): | 78 def write_event_interfaces_file(event_idl_files, destination_filename, only_if_c
hanged): |
| 80 # Event interfaces are interfaces that inherit from Event, and Event itself | |
| 81 event_interfaces = set( | |
| 82 interface_name | |
| 83 for interface_name, interface_info in interfaces_info.iteritems() | |
| 84 if (interface_name == 'Event' or | |
| 85 (interface_info['ancestors'] and | |
| 86 interface_info['ancestors'][-1] == 'Event'))) | |
| 87 | |
| 88 def extended_attribute_string(name, value): | 79 def extended_attribute_string(name, value): |
| 89 if name == 'RuntimeEnabled': | 80 if name == 'RuntimeEnabled': |
| 90 value += 'Enabled' | 81 value += 'Enabled' |
| 91 return name + '=' + value | 82 return name + '=' + value |
| 92 | 83 |
| 93 def interface_line(interface_name): | 84 def interface_line(full_path): |
| 94 full_path = interfaces_info[interface_name]['full_path'] | |
| 95 | |
| 96 relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, sou
rce_dir)) | 85 relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, sou
rce_dir)) |
| 97 relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep) | 86 relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep) |
| 98 | 87 |
| 99 idl_file_contents = get_file_contents(full_path) | 88 idl_file_contents = get_file_contents(full_path) |
| 100 extended_attributes = get_interface_extended_attributes_from_idl(idl_fil
e_contents) | 89 extended_attributes = get_interface_extended_attributes_from_idl(idl_fil
e_contents) |
| 101 extended_attributes_list = [ | 90 extended_attributes_list = [ |
| 102 extended_attribute_string(name, extended_attributes[name]) | 91 extended_attribute_string(name, extended_attributes[name]) |
| 103 for name in EXPORTED_EXTENDED_ATTRIBUTES | 92 for name in EXPORTED_EXTENDED_ATTRIBUTES |
| 104 if name in extended_attributes] | 93 if name in extended_attributes] |
| 105 | 94 |
| 106 return '%s %s\n' % (relative_path_posix, | 95 return '%s %s\n' % (relative_path_posix, |
| 107 ', '.join(extended_attributes_list)) | 96 ', '.join(extended_attributes_list)) |
| 108 | 97 |
| 109 lines = ['namespace="Event"\n', | 98 lines = ['namespace="Event"\n', |
| 110 '\n'] | 99 '\n'] |
| 111 interface_lines = [interface_line(interface_name) | 100 interface_lines = [interface_line(event_idl_file) |
| 112 for interface_name in event_interfaces] | 101 for event_idl_file in event_idl_files] |
| 113 interface_lines.sort() | 102 interface_lines.sort() |
| 114 lines.extend(interface_lines) | 103 lines.extend(interface_lines) |
| 115 write_file(''.join(lines), destination_filename, only_if_changed) | 104 write_file(''.join(lines), destination_filename, only_if_changed) |
| 116 | 105 |
| 117 | 106 |
| 118 ################################################################################ | 107 ################################################################################ |
| 119 | 108 |
| 120 def main(): | 109 def main(): |
| 121 options = parse_options() | 110 options = parse_options() |
| 122 with open(options.interfaces_info_file) as interfaces_info_file: | 111 with open(options.event_idl_files_list) as event_idl_files_list: |
| 123 interfaces_info = pickle.load(interfaces_info_file) | 112 event_idl_files = [line.rstrip('\n') for line in event_idl_files_list] |
| 124 write_event_interfaces_file(interfaces_info, | 113 write_event_interfaces_file(event_idl_files, |
| 125 options.event_interfaces_file, | 114 options.event_interfaces_file, |
| 126 options.write_file_only_if_changed) | 115 options.write_file_only_if_changed) |
| 127 | 116 |
| 128 | 117 |
| 129 if __name__ == '__main__': | 118 if __name__ == '__main__': |
| 130 sys.exit(main()) | 119 sys.exit(main()) |
| OLD | NEW |