| Index: Source/bindings/scripts/generate_event_interfaces.py
|
| diff --git a/Source/bindings/scripts/generate_event_interfaces.py b/Source/bindings/scripts/generate_event_interfaces.py
|
| index f9c820957b283b08ccbd94b32a67301d363cbce9..0cd8ec35fb475262e44b4e6198d5e898e0421fc7 100755
|
| --- a/Source/bindings/scripts/generate_event_interfaces.py
|
| +++ b/Source/bindings/scripts/generate_event_interfaces.py
|
| @@ -34,11 +34,13 @@ The event interfaces .in file contains a list of all Event interfaces, i.e.,
|
| all interfaces that inherit from Event, including Event itself,
|
| together with certain extended attributes.
|
|
|
| +Paths are in POSIX format, and relative to Source/.
|
| +
|
| This list is used in core/ to generate EventFactory and EventNames.
|
| The .in format is documented in build/scripts/in_file.py.
|
| """
|
|
|
| -import optparse
|
| +from optparse import OptionParser
|
| import cPickle as pickle
|
| import os
|
| import posixpath
|
| @@ -46,19 +48,24 @@ import sys
|
|
|
| from utilities import get_file_contents, write_file, get_interface_extended_attributes_from_idl
|
|
|
| -interfaces_info = {}
|
| -extended_attributes_by_interface = {} # interface name -> extended attributes
|
| +EXPORTED_EXTENDED_ATTRIBUTES = (
|
| + 'Conditional',
|
| + 'ImplementedAs',
|
| + 'RuntimeEnabled',
|
| +)
|
| +module_path = os.path.dirname(os.path.realpath(__file__))
|
| +source_dir = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir))
|
|
|
|
|
| def parse_options():
|
| - parser = optparse.OptionParser()
|
| - parser.add_option('--event-names-file', help='output file')
|
| + parser = OptionParser()
|
| + parser.add_option('--event-interfaces-file', help='output file')
|
| parser.add_option('--interfaces-info-file', help='output pickle file')
|
| 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')
|
|
|
| options, args = parser.parse_args()
|
| - if options.event_names_file is None:
|
| - parser.error('Must specify an output file using --event-names-file.')
|
| + if options.event_interfaces_file is None:
|
| + parser.error('Must specify an output file using --event-interfaces-file.')
|
| if options.interfaces_info_file is None:
|
| parser.error('Must specify an input file using --interfaces-info-file.')
|
| if options.write_file_only_if_changed is None:
|
| @@ -69,49 +76,42 @@ def parse_options():
|
| return options
|
|
|
|
|
| -def store_event_extended_attributes():
|
| +def write_event_interfaces_file(interfaces_info, destination_filename, only_if_changed):
|
| + # Event interfaces are interfaces that inherit from Event, and Event itself
|
| event_interfaces = set(
|
| interface_name
|
| for interface_name, interface_info in interfaces_info.iteritems()
|
| if (interface_name == 'Event' or
|
| ('ancestors' in interface_info and
|
| interface_info['ancestors'][-1] == 'Event')))
|
| - for interface_name in event_interfaces:
|
| - interface_info = interfaces_info[interface_name]
|
| - idl_file_contents = get_file_contents(interface_info['full_path'])
|
| - extended_attributes_by_interface[interface_name] = get_interface_extended_attributes_from_idl(idl_file_contents)
|
| -
|
|
|
| -def write_event_names_file(destination_filename, only_if_changed):
|
| - event_names = set(
|
| - interface_name
|
| - for interface_name, interface_info in interfaces_info.iteritems()
|
| - if (interface_name == 'Event' or
|
| - ('ancestors' in interface_info and
|
| - interface_info['ancestors'][-1] == 'Event')))
|
| -
|
| - def extended_attribute_string(name):
|
| - value = extended_attributes[name]
|
| + def extended_attribute_string(name, value):
|
| if name == 'RuntimeEnabled':
|
| value += 'Enabled'
|
| return name + '=' + value
|
|
|
| - source_dir, _ = os.path.split(os.getcwd())
|
| - lines = []
|
| - lines.append('namespace="Event"\n')
|
| - lines.append('\n')
|
| - for filename, extended_attributes in sorted(
|
| - (interface_info['full_path'],
|
| - extended_attributes_by_interface[interface_name])
|
| - for interface_name, interface_info in interfaces_info.iteritems()
|
| - if interface_name in event_names):
|
| - refined_filename, _ = os.path.splitext(os.path.relpath(filename, source_dir))
|
| - refined_filename = refined_filename.replace(os.sep, posixpath.sep)
|
| + def interface_line(interface_name):
|
| + full_path = interfaces_info[interface_name]['full_path']
|
| +
|
| + relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, source_dir))
|
| + relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep)
|
| +
|
| + idl_file_contents = get_file_contents(full_path)
|
| + extended_attributes = get_interface_extended_attributes_from_idl(idl_file_contents)
|
| extended_attributes_list = [
|
| - extended_attribute_string(name)
|
| - for name in 'Conditional', 'ImplementedAs', 'RuntimeEnabled'
|
| + extended_attribute_string(name, extended_attributes[name])
|
| + for name in EXPORTED_EXTENDED_ATTRIBUTES
|
| if name in extended_attributes]
|
| - lines.append('%s %s\n' % (refined_filename, ', '.join(extended_attributes_list)))
|
| +
|
| + return '%s %s\n' % (relative_path_posix,
|
| + ', '.join(extended_attributes_list))
|
| +
|
| + lines = ['namespace="Event"\n',
|
| + '\n']
|
| + interface_lines = [interface_line(interface_name)
|
| + for interface_name in event_interfaces]
|
| + interface_lines.sort()
|
| + lines.extend(interface_lines)
|
| write_file(lines, destination_filename, only_if_changed)
|
|
|
|
|
| @@ -120,10 +120,10 @@ def write_event_names_file(destination_filename, only_if_changed):
|
| def main():
|
| options = parse_options()
|
| with open(options.interfaces_info_file) as interfaces_info_file:
|
| - interfaces_info.update(pickle.load(interfaces_info_file))
|
| - store_event_extended_attributes()
|
| - write_event_names_file(options.event_names_file,
|
| - options.write_file_only_if_changed)
|
| + interfaces_info = pickle.load(interfaces_info_file)
|
| + write_event_interfaces_file(interfaces_info,
|
| + options.event_interfaces_file,
|
| + options.write_file_only_if_changed)
|
|
|
|
|
| if __name__ == '__main__':
|
|
|