| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 class IdlBadFilenameError(Exception): | 57 class IdlBadFilenameError(Exception): |
| 58 """Raised if an IDL filename disagrees with the interface name in the file."
"" | 58 """Raised if an IDL filename disagrees with the interface name in the file."
"" |
| 59 pass | 59 pass |
| 60 | 60 |
| 61 | 61 |
| 62 def parse_options(): | 62 def parse_options(): |
| 63 usage = 'Usage: %prog [options] [generated1.idl]...' | 63 usage = 'Usage: %prog [options] [generated1.idl]...' |
| 64 parser = optparse.OptionParser(usage=usage) | 64 parser = optparse.OptionParser(usage=usage) |
| 65 parser.add_option('--cache-directory', help='cache directory') | 65 parser.add_option('--cache-directory', help='cache directory') |
| 66 parser.add_option('--idl-files-list', help='file listing IDL files') | 66 parser.add_option('--idl-files-list', help='file listing IDL files') |
| 67 parser.add_option('--interfaces-info-file', help='output pickle file') | 67 parser.add_option('--interfaces-info-file', help='interface info pickle file
') |
| 68 parser.add_option('--component-wide-info-file', help='component wide info pi
ckle file') |
| 68 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') | 69 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') |
| 69 | 70 |
| 70 options, args = parser.parse_args() | 71 options, args = parser.parse_args() |
| 71 if options.interfaces_info_file is None: | 72 if options.interfaces_info_file is None: |
| 72 parser.error('Must specify an output file using --interfaces-info-file.'
) | 73 parser.error('Must specify an output file using --interfaces-info-file.'
) |
| 73 if options.idl_files_list is None: | 74 if options.idl_files_list is None: |
| 74 parser.error('Must specify a file listing IDL files using --idl-files-li
st.') | 75 parser.error('Must specify a file listing IDL files using --idl-files-li
st.') |
| 75 if options.write_file_only_if_changed is None: | 76 if options.write_file_only_if_changed is None: |
| 76 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') | 77 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') |
| 77 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) | 78 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 elif definitions.dictionaries: | 191 elif definitions.dictionaries: |
| 191 definition = next(definitions.dictionaries.itervalues()) | 192 definition = next(definitions.dictionaries.itervalues()) |
| 192 interface_info = { | 193 interface_info = { |
| 193 'is_callback_interface': False, | 194 'is_callback_interface': False, |
| 194 'is_dictionary': True, | 195 'is_dictionary': True, |
| 195 'referenced_interfaces': None, | 196 'referenced_interfaces': None, |
| 196 } | 197 } |
| 197 else: | 198 else: |
| 198 raise Exception('IDL file must contain one interface or dictionary') | 199 raise Exception('IDL file must contain one interface or dictionary') |
| 199 | 200 |
| 200 self.union_types.update( | 201 this_union_types = collect_union_types_from_definitions(definitions) |
| 201 collect_union_types_from_definitions(definitions)) | 202 self.union_types.update(this_union_types) |
| 202 | 203 |
| 203 extended_attributes = definition.extended_attributes | 204 extended_attributes = definition.extended_attributes |
| 204 implemented_as = extended_attributes.get('ImplementedAs') | 205 implemented_as = extended_attributes.get('ImplementedAs') |
| 205 full_path = os.path.realpath(idl_filename) | 206 full_path = os.path.realpath(idl_filename) |
| 206 this_include_path = None if 'NoImplHeader' in extended_attributes else i
nclude_path(idl_filename, implemented_as) | 207 this_include_path = None if 'NoImplHeader' in extended_attributes else i
nclude_path(idl_filename, implemented_as) |
| 207 if definition.is_partial: | 208 if definition.is_partial: |
| 208 # We don't create interface_info for partial interfaces, but | 209 # We don't create interface_info for partial interfaces, but |
| 209 # adds paths to another dict. | 210 # adds paths to another dict. |
| 210 self.add_paths_to_partials_dict(definition.name, full_path, this_inc
lude_path) | 211 self.add_paths_to_partials_dict(definition.name, full_path, this_inc
lude_path) |
| 211 return | 212 return |
| 212 | 213 |
| 213 # 'implements' statements can be included in either the file for the | 214 # 'implements' statements can be included in either the file for the |
| 214 # implement*ing* interface (lhs of 'implements') or implement*ed* interf
ace | 215 # implement*ing* interface (lhs of 'implements') or implement*ed* interf
ace |
| 215 # (rhs of 'implements'). Store both for now, then merge to implement*ing
* | 216 # (rhs of 'implements'). Store both for now, then merge to implement*ing
* |
| 216 # interface later. | 217 # interface later. |
| 217 left_interfaces, right_interfaces = get_implements_from_definitions( | 218 left_interfaces, right_interfaces = get_implements_from_definitions( |
| 218 definitions, definition.name) | 219 definitions, definition.name) |
| 219 | 220 |
| 220 interface_info.update({ | 221 interface_info.update({ |
| 221 'extended_attributes': extended_attributes, | 222 'extended_attributes': extended_attributes, |
| 222 'full_path': full_path, | 223 'full_path': full_path, |
| 224 'has_union_types': bool(this_union_types), |
| 223 'implemented_as': implemented_as, | 225 'implemented_as': implemented_as, |
| 224 'implemented_by_interfaces': left_interfaces, | 226 'implemented_by_interfaces': left_interfaces, |
| 225 'implements_interfaces': right_interfaces, | 227 'implements_interfaces': right_interfaces, |
| 226 'include_path': this_include_path, | 228 'include_path': this_include_path, |
| 227 # FIXME: temporary private field, while removing old treatement of | 229 # FIXME: temporary private field, while removing old treatement of |
| 228 # 'implements': http://crbug.com/360435 | 230 # 'implements': http://crbug.com/360435 |
| 229 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterfa
ce' in extended_attributes, | 231 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterfa
ce' in extended_attributes, |
| 230 'parent': definition.parent, | 232 'parent': definition.parent, |
| 231 'relative_dir': relative_dir_posix(idl_filename), | 233 'relative_dir': relative_dir_posix(idl_filename), |
| 232 }) | 234 }) |
| 233 self.interfaces_info[definition.name] = interface_info | 235 self.interfaces_info[definition.name] = interface_info |
| 234 | 236 |
| 235 def get_info_as_dict(self): | 237 def get_info_as_dict(self): |
| 236 """Returns info packaged as a dict.""" | 238 """Returns info packaged as a dict.""" |
| 237 return { | 239 return { |
| 238 'interfaces_info': self.interfaces_info, | 240 'interfaces_info': self.interfaces_info, |
| 239 # Can't pickle defaultdict, convert to dict | 241 # Can't pickle defaultdict, convert to dict |
| 242 # FIXME: this should be included in get_component_wide_info. |
| 240 'partial_interface_files': dict(self.partial_interface_files), | 243 'partial_interface_files': dict(self.partial_interface_files), |
| 244 } |
| 245 |
| 246 def get_component_wide_info_as_dict(self): |
| 247 """Returns component wide information as a dict.""" |
| 248 return { |
| 241 'union_types': self.union_types, | 249 'union_types': self.union_types, |
| 242 } | 250 } |
| 243 | 251 |
| 244 | 252 |
| 245 ################################################################################ | 253 ################################################################################ |
| 246 | 254 |
| 247 def main(): | 255 def main(): |
| 248 options, args = parse_options() | 256 options, args = parse_options() |
| 249 | 257 |
| 250 # Static IDL files are passed in a file (generated at GYP time), due to OS | 258 # Static IDL files are passed in a file (generated at GYP time), due to OS |
| 251 # command line length limits | 259 # command line length limits |
| 252 idl_files = read_file_to_list(options.idl_files_list) | 260 idl_files = read_file_to_list(options.idl_files_list) |
| 253 # Generated IDL files are passed at the command line, since these are in the | 261 # Generated IDL files are passed at the command line, since these are in the |
| 254 # build directory, which is determined at build time, not GYP time, so these | 262 # build directory, which is determined at build time, not GYP time, so these |
| 255 # cannot be included in the file listing static files | 263 # cannot be included in the file listing static files |
| 256 idl_files.extend(args) | 264 idl_files.extend(args) |
| 257 | 265 |
| 258 # Compute information for individual files | 266 # Compute information for individual files |
| 259 # Information is stored in global variables interfaces_info and | 267 # Information is stored in global variables interfaces_info and |
| 260 # partial_interface_files. | 268 # partial_interface_files. |
| 261 info_collector = InterfaceInfoCollector(options.cache_directory) | 269 info_collector = InterfaceInfoCollector(options.cache_directory) |
| 262 for idl_filename in idl_files: | 270 for idl_filename in idl_files: |
| 263 info_collector.collect_info(idl_filename) | 271 info_collector.collect_info(idl_filename) |
| 264 | 272 |
| 265 write_pickle_file(options.interfaces_info_file, | 273 write_pickle_file(options.interfaces_info_file, |
| 266 info_collector.get_info_as_dict(), | 274 info_collector.get_info_as_dict(), |
| 267 options.write_file_only_if_changed) | 275 options.write_file_only_if_changed) |
| 268 | 276 write_pickle_file(options.component_wide_info_file, |
| 277 info_collector.get_component_wide_info_as_dict(), |
| 278 options.write_file_only_if_changed) |
| 269 | 279 |
| 270 if __name__ == '__main__': | 280 if __name__ == '__main__': |
| 271 sys.exit(main()) | 281 sys.exit(main()) |
| OLD | NEW |