| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 ) | 54 ) |
| 55 module_path = os.path.dirname(os.path.realpath(__file__)) | 55 module_path = os.path.dirname(os.path.realpath(__file__)) |
| 56 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)) |
| 57 | 57 |
| 58 | 58 |
| 59 def parse_options(): | 59 def parse_options(): |
| 60 parser = OptionParser() | 60 parser = OptionParser() |
| 61 parser.add_option('--event-idl-files-list', help='file listing event IDL fil
es') | 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('--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') |
| 64 parser.add_option('--suffix', help='specify a suffix to the namespace, i.e.,
"Modules". Default is None.') |
| 64 | 65 |
| 65 options, args = parser.parse_args() | 66 options, args = parser.parse_args() |
| 66 if options.event_idl_files_list is None: | 67 if options.event_idl_files_list is None: |
| 67 parser.error('Must specify a file listing event IDL files using --event-
idl-files-list.') | 68 parser.error('Must specify a file listing event IDL files using --event-
idl-files-list.') |
| 68 if options.event_interfaces_file is None: | 69 if options.event_interfaces_file is None: |
| 69 parser.error('Must specify an output file using --event-interfaces-file.
') | 70 parser.error('Must specify an output file using --event-interfaces-file.
') |
| 70 if options.write_file_only_if_changed is None: | 71 if options.write_file_only_if_changed is None: |
| 71 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') | 72 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') |
| 72 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) | 73 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) |
| 73 if args: | 74 if args: |
| 74 parser.error('No arguments allowed, but %d given.' % len(args)) | 75 parser.error('No arguments allowed, but %d given.' % len(args)) |
| 75 return options | 76 return options |
| 76 | 77 |
| 77 | 78 |
| 78 def write_event_interfaces_file(event_idl_files, destination_filename, only_if_c
hanged): | 79 def write_event_interfaces_file(event_idl_files, destination_filename, only_if_c
hanged, suffix): |
| 79 def extended_attribute_string(name, value): | 80 def extended_attribute_string(name, value): |
| 80 if name == 'RuntimeEnabled': | 81 if name == 'RuntimeEnabled': |
| 81 value += 'Enabled' | 82 value += 'Enabled' |
| 82 return name + '=' + value | 83 return name + '=' + value |
| 83 | 84 |
| 84 def interface_line(full_path): | 85 def interface_line(full_path): |
| 85 relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, sou
rce_dir)) | 86 relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, sou
rce_dir)) |
| 86 relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep) | 87 relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep) |
| 87 | 88 |
| 88 idl_file_contents = get_file_contents(full_path) | 89 idl_file_contents = get_file_contents(full_path) |
| 89 extended_attributes = get_interface_extended_attributes_from_idl(idl_fil
e_contents) | 90 extended_attributes = get_interface_extended_attributes_from_idl(idl_fil
e_contents) |
| 90 extended_attributes_list = [ | 91 extended_attributes_list = [ |
| 91 extended_attribute_string(name, extended_attributes[name]) | 92 extended_attribute_string(name, extended_attributes[name]) |
| 92 for name in EXPORTED_EXTENDED_ATTRIBUTES | 93 for name in EXPORTED_EXTENDED_ATTRIBUTES |
| 93 if name in extended_attributes] | 94 if name in extended_attributes] |
| 94 | 95 |
| 95 return '%s %s\n' % (relative_path_posix, | 96 return '%s %s\n' % (relative_path_posix, |
| 96 ', '.join(extended_attributes_list)) | 97 ', '.join(extended_attributes_list)) |
| 97 | 98 |
| 98 lines = ['namespace="Event"\n', | 99 lines = ['namespace="Event"\n'] |
| 99 '\n'] | 100 if suffix: |
| 101 lines.append('suffix="' + suffix + '"\n') |
| 102 lines.append('\n') |
| 100 interface_lines = [interface_line(event_idl_file) | 103 interface_lines = [interface_line(event_idl_file) |
| 101 for event_idl_file in event_idl_files] | 104 for event_idl_file in event_idl_files] |
| 102 interface_lines.sort() | 105 interface_lines.sort() |
| 103 lines.extend(interface_lines) | 106 lines.extend(interface_lines) |
| 104 write_file(''.join(lines), destination_filename, only_if_changed) | 107 write_file(''.join(lines), destination_filename, only_if_changed) |
| 105 | 108 |
| 106 | 109 |
| 107 ################################################################################ | 110 ################################################################################ |
| 108 | 111 |
| 109 def main(): | 112 def main(): |
| 110 options = parse_options() | 113 options = parse_options() |
| 111 with open(options.event_idl_files_list) as event_idl_files_list: | 114 with open(options.event_idl_files_list) as event_idl_files_list: |
| 112 event_idl_files = [line.rstrip('\n') for line in event_idl_files_list] | 115 event_idl_files = [line.rstrip('\n') for line in event_idl_files_list] |
| 113 write_event_interfaces_file(event_idl_files, | 116 write_event_interfaces_file(event_idl_files, |
| 114 options.event_interfaces_file, | 117 options.event_interfaces_file, |
| 115 options.write_file_only_if_changed) | 118 options.write_file_only_if_changed, |
| 119 options.suffix) |
| 116 | 120 |
| 117 | 121 |
| 118 if __name__ == '__main__': | 122 if __name__ == '__main__': |
| 119 sys.exit(main()) | 123 sys.exit(main()) |
| OLD | NEW |