Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1384)

Side by Side Diff: bindings/scripts/compute_interfaces_info_individual.py

Issue 2786203002: Roll 50: Copied IDLs, PYTHON scripts from WebKit removed deleted files in WebCore (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29 matching lines...) Expand all
40 40
41 Design doc: http://www.chromium.org/developers/design-documents/idl-build 41 Design doc: http://www.chromium.org/developers/design-documents/idl-build
42 """ 42 """
43 43
44 from collections import defaultdict 44 from collections import defaultdict
45 import optparse 45 import optparse
46 import os 46 import os
47 import posixpath 47 import posixpath
48 import sys 48 import sys
49 49
50 from idl_compiler import idl_filename_to_interface_name
50 from idl_definitions import Visitor 51 from idl_definitions import Visitor
51 from idl_reader import IdlReader 52 from idl_reader import IdlReader
52 from utilities import get_file_contents, read_file_to_list, idl_filename_to_inte rface_name, idl_filename_to_component, write_pickle_file, get_interface_extended _attributes_from_idl, is_callback_interface_from_idl 53 from utilities import get_file_contents, read_file_to_list, idl_filename_to_inte rface_name, idl_filename_to_component, write_pickle_file, get_interface_extended _attributes_from_idl, is_callback_interface_from_idl, merge_dict_recursively
53 54
54 module_path = os.path.dirname(__file__) 55 module_path = os.path.dirname(__file__)
55 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) 56 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir))
57 gen_path = os.path.join('gen', 'blink')
56 58
57 59
58 class IdlBadFilenameError(Exception): 60 class IdlBadFilenameError(Exception):
59 """Raised if an IDL filename disagrees with the interface name in the file." "" 61 """Raised if an IDL filename disagrees with the interface name in the file." ""
60 pass 62 pass
61 63
62 64
63 def parse_options(): 65 def parse_options():
64 usage = 'Usage: %prog [options] [generated1.idl]...' 66 usage = 'Usage: %prog [options] [generated1.idl]...'
65 parser = optparse.OptionParser(usage=usage) 67 parser = optparse.OptionParser(usage=usage)
(...skipping 11 matching lines...) Expand all
77 if options.write_file_only_if_changed is None: 79 if options.write_file_only_if_changed is None:
78 parser.error('Must specify whether file is only written if changed using --write-file-only-if-changed.') 80 parser.error('Must specify whether file is only written if changed using --write-file-only-if-changed.')
79 options.write_file_only_if_changed = bool(options.write_file_only_if_changed ) 81 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
80 return options, args 82 return options, args
81 83
82 84
83 ################################################################################ 85 ################################################################################
84 # Computations 86 # Computations
85 ################################################################################ 87 ################################################################################
86 88
87 def relative_dir_posix(idl_filename): 89 def relative_dir_posix(idl_filename, base_path):
88 """Returns relative path to the directory of idl_file in POSIX format.""" 90 """Returns relative path to the directory of idl_file in POSIX format."""
89 relative_path_local = os.path.relpath(idl_filename, source_path) 91 relative_path_local = os.path.relpath(idl_filename, base_path)
90 relative_dir_local = os.path.dirname(relative_path_local) 92 relative_dir_local = os.path.dirname(relative_path_local)
91 return relative_dir_local.replace(os.path.sep, posixpath.sep) 93 return relative_dir_local.replace(os.path.sep, posixpath.sep)
92 94
93 95
94 def include_path(idl_filename, implemented_as=None): 96 def include_path(idl_filename, implemented_as=None):
95 """Returns relative path to header file in POSIX format; used in includes. 97 """Returns relative path to header file in POSIX format; used in includes.
96 98
97 POSIX format is used for consistency of output, so reference tests are 99 POSIX format is used for consistency of output, so reference tests are
98 platform-independent. 100 platform-independent.
99 """ 101 """
100 relative_dir = relative_dir_posix(idl_filename) 102 if idl_filename.startswith(gen_path):
103 relative_dir = relative_dir_posix(idl_filename, gen_path)
104 else:
105 relative_dir = relative_dir_posix(idl_filename, source_path)
101 106
102 # IDL file basename is used even if only a partial interface file 107 # IDL file basename is used even if only a partial interface file
103 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename)) 108 cpp_class_name = implemented_as or idl_filename_to_interface_name(idl_filena me)
104 cpp_class_name = implemented_as or idl_file_basename
105 109
106 return posixpath.join(relative_dir, cpp_class_name + '.h') 110 return posixpath.join(relative_dir, cpp_class_name + '.h')
107 111
108 112
109 def get_implements_from_definitions(definitions, definition_name): 113 def get_implements_from_definitions(definitions, definition_name):
110 left_interfaces = [] 114 left_interfaces = []
111 right_interfaces = [] 115 right_interfaces = []
112 for implement in definitions.implements: 116 for implement in definitions.implements:
113 if definition_name == implement.left_interface: 117 if definition_name == implement.left_interface:
114 right_interfaces.append(implement.right_interface) 118 right_interfaces.append(implement.right_interface)
115 elif definition_name == implement.right_interface: 119 elif definition_name == implement.right_interface:
116 left_interfaces.append(implement.left_interface) 120 left_interfaces.append(implement.left_interface)
117 else: 121 else:
118 raise IdlBadFilenameError( 122 raise IdlBadFilenameError(
119 'implements statement found in unrelated IDL file.\n' 123 'implements statement found in unrelated IDL file.\n'
120 'Statement is:\n' 124 'Statement is:\n'
121 ' %s implements %s;\n' 125 ' %s implements %s;\n'
122 'but filename is unrelated "%s.idl"' % 126 'but filename is unrelated "%s.idl"' %
123 (implement.left_interface, implement.right_interface, definition _name)) 127 (implement.left_interface, implement.right_interface, definition _name))
124 return left_interfaces, right_interfaces 128 return left_interfaces, right_interfaces
125 129
126 130
127 def get_put_forward_interfaces_from_definition(definition): 131 def get_put_forward_interfaces_from_definition(definition):
128 return sorted(set(attribute.idl_type.base_type 132 return sorted(set(attribute.idl_type.base_type
129 for attribute in definition.attributes 133 for attribute in definition.attributes
130 if 'PutForwards' in attribute.extended_attributes)) 134 if 'PutForwards' in attribute.extended_attributes))
131 135
132 136
137 def get_unforgeable_attributes_from_definition(definition):
138 if 'Unforgeable' in definition.extended_attributes:
139 return sorted(definition.attributes)
140 return sorted(attribute for attribute in definition.attributes
141 if 'Unforgeable' in attribute.extended_attributes)
142
143
133 def collect_union_types_from_definitions(definitions): 144 def collect_union_types_from_definitions(definitions):
134 """Traverse definitions and collect all union types.""" 145 """Traverse definitions and collect all union types."""
135 class UnionTypeCollector(Visitor): 146 class UnionTypeCollector(Visitor):
136 def collect(self, definitions): 147 def collect(self, definitions):
137 self._union_types = set() 148 self._union_types = set()
138 definitions.accept(self) 149 definitions.accept(self)
139 return self._union_types 150 return self._union_types
140 151
141 def visit_typed_object(self, typed_object): 152 def visit_typed_object(self, typed_object):
142 for attribute_name in typed_object.idl_type_attributes: 153 for attribute_name in typed_object.idl_type_attributes:
(...skipping 22 matching lines...) Expand all
165 176
166 def add_paths_to_partials_dict(self, partial_interface_name, full_path, 177 def add_paths_to_partials_dict(self, partial_interface_name, full_path,
167 include_paths): 178 include_paths):
168 paths_dict = self.partial_interface_files[partial_interface_name] 179 paths_dict = self.partial_interface_files[partial_interface_name]
169 paths_dict['full_paths'].append(full_path) 180 paths_dict['full_paths'].append(full_path)
170 paths_dict['include_paths'].extend(include_paths) 181 paths_dict['include_paths'].extend(include_paths)
171 182
172 def collect_info(self, idl_filename): 183 def collect_info(self, idl_filename):
173 """Reads an idl file and collects information which is required by the 184 """Reads an idl file and collects information which is required by the
174 binding code generation.""" 185 binding code generation."""
186 def collect_unforgeable_attributes(definition, idl_filename):
187 """Collects [Unforgeable] attributes so that we can define them on
188 sub-interfaces later. The resulting structure is as follows.
189 interfaces_info[interface_name] = {
190 'unforgeable_attributes': {
191 'core': [IdlAttribute, ...],
192 'modules': [IdlAttribute, ...],
193 },
194 ...
195 }
196 """
197 interface_info = {}
198 unforgeable_attributes = get_unforgeable_attributes_from_definition( definition)
199 if not unforgeable_attributes:
200 return interface_info
201
202 if definition.is_partial:
203 interface_basename = idl_filename_to_interface_name(idl_filename )
204 # TODO(yukishiino): [PartialInterfaceImplementedAs] is treated
205 # in interface_dependency_resolver.transfer_extended_attributes.
206 # Come up with a better way to keep them consistent.
207 for attr in unforgeable_attributes:
208 attr.extended_attributes['PartialInterfaceImplementedAs'] = definition.extended_attributes.get('ImplementedAs', interface_basename)
209 component = idl_filename_to_component(idl_filename)
210 interface_info['unforgeable_attributes'] = {}
211 interface_info['unforgeable_attributes'][component] = unforgeable_at tributes
212 return interface_info
213
175 definitions = self.reader.read_idl_file(idl_filename) 214 definitions = self.reader.read_idl_file(idl_filename)
176 215
177 this_union_types = collect_union_types_from_definitions(definitions) 216 this_union_types = collect_union_types_from_definitions(definitions)
178 self.union_types.update(this_union_types) 217 self.union_types.update(this_union_types)
179 self.typedefs.update(definitions.typedefs) 218 self.typedefs.update(definitions.typedefs)
180 # Check enum duplication. 219 # Check enum duplication.
181 for enum_name in definitions.enumerations.keys(): 220 for enum_name in definitions.enumerations.keys():
182 for defined_enum in self.enumerations: 221 for defined_enum in self.enumerations:
183 if defined_enum.name == enum_name: 222 if defined_enum.name == enum_name:
184 raise Exception('Enumeration %s has multiple definitions' % enum_name) 223 raise Exception('Enumeration %s has multiple definitions' % enum_name)
(...skipping 16 matching lines...) Expand all
201 elif definitions.dictionaries: 240 elif definitions.dictionaries:
202 definition = next(definitions.dictionaries.itervalues()) 241 definition = next(definitions.dictionaries.itervalues())
203 interface_info = { 242 interface_info = {
204 'is_callback_interface': False, 243 'is_callback_interface': False,
205 'is_dictionary': True, 244 'is_dictionary': True,
206 'referenced_interfaces': None, 245 'referenced_interfaces': None,
207 } 246 }
208 else: 247 else:
209 return 248 return
210 249
250 if definition.name not in self.interfaces_info:
251 self.interfaces_info[definition.name] = {}
252
253 # Remember [Unforgeable] attributes.
254 if definitions.interfaces:
255 merge_dict_recursively(self.interfaces_info[definition.name],
256 collect_unforgeable_attributes(definition, id l_filename))
257
258 component = idl_filename_to_component(idl_filename)
211 extended_attributes = definition.extended_attributes 259 extended_attributes = definition.extended_attributes
212 implemented_as = extended_attributes.get('ImplementedAs') 260 implemented_as = extended_attributes.get('ImplementedAs')
213 full_path = os.path.realpath(idl_filename) 261 full_path = os.path.realpath(idl_filename)
214 this_include_path = None if 'NoImplHeader' in extended_attributes else i nclude_path(idl_filename, implemented_as) 262 this_include_path = None if 'NoImplHeader' in extended_attributes else i nclude_path(idl_filename, implemented_as)
215 if definition.is_partial: 263 if definition.is_partial:
216 # We don't create interface_info for partial interfaces, but 264 # We don't create interface_info for partial interfaces, but
217 # adds paths to another dict. 265 # adds paths to another dict.
218 partial_include_paths = [] 266 partial_include_paths = []
219 if this_include_path: 267 if this_include_path:
220 partial_include_paths.append(this_include_path) 268 partial_include_paths.append(this_include_path)
221 if this_union_types: 269 if this_union_types:
222 component = idl_filename_to_component(idl_filename)
223 partial_include_paths.append( 270 partial_include_paths.append(
224 'bindings/%s/v8/UnionTypes%s.h' % (component, component.capi talize())) 271 'bindings/%s/v8/UnionTypes%s.h' % (component, component.capi talize()))
225 self.add_paths_to_partials_dict(definition.name, full_path, partial_ include_paths) 272 self.add_paths_to_partials_dict(definition.name, full_path, partial_ include_paths)
273 # Collects C++ header paths which should be included from generated
274 # .cpp files. The resulting structure is as follows.
275 # interfaces_info[interface_name] = {
276 # 'cpp_includes': {
277 # 'core': set(['core/foo/Foo.h', ...]),
278 # 'modules': set(['modules/bar/Bar.h', ...]),
279 # },
280 # ...
281 # }
282 if this_include_path:
283 merge_dict_recursively(
284 self.interfaces_info[definition.name],
285 {'cpp_includes': {component: set([this_include_path])}})
226 return 286 return
227 287
228 # 'implements' statements can be included in either the file for the 288 # 'implements' statements can be included in either the file for the
229 # implement*ing* interface (lhs of 'implements') or implement*ed* interf ace 289 # implement*ing* interface (lhs of 'implements') or implement*ed* interf ace
230 # (rhs of 'implements'). Store both for now, then merge to implement*ing * 290 # (rhs of 'implements'). Store both for now, then merge to implement*ing *
231 # interface later. 291 # interface later.
232 left_interfaces, right_interfaces = get_implements_from_definitions( 292 left_interfaces, right_interfaces = get_implements_from_definitions(
233 definitions, definition.name) 293 definitions, definition.name)
234 294
235 interface_info.update({ 295 interface_info.update({
236 'extended_attributes': extended_attributes, 296 'extended_attributes': extended_attributes,
237 'full_path': full_path, 297 'full_path': full_path,
238 'has_union_types': bool(this_union_types), 298 'has_union_types': bool(this_union_types),
239 'implemented_as': implemented_as, 299 'implemented_as': implemented_as,
240 'implemented_by_interfaces': left_interfaces, 300 'implemented_by_interfaces': left_interfaces,
241 'implements_interfaces': right_interfaces, 301 'implements_interfaces': right_interfaces,
242 'include_path': this_include_path, 302 'include_path': this_include_path,
243 # FIXME: temporary private field, while removing old treatement of 303 # FIXME: temporary private field, while removing old treatement of
244 # 'implements': http://crbug.com/360435 304 # 'implements': http://crbug.com/360435
245 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterfa ce' in extended_attributes, 305 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterfa ce' in extended_attributes,
246 'parent': definition.parent, 306 'parent': definition.parent,
247 'relative_dir': relative_dir_posix(idl_filename), 307 'relative_dir': relative_dir_posix(idl_filename, source_path),
248 }) 308 })
249 self.interfaces_info[definition.name] = interface_info 309 merge_dict_recursively(self.interfaces_info[definition.name], interface_ info)
250 310
251 def get_info_as_dict(self): 311 def get_info_as_dict(self):
252 """Returns info packaged as a dict.""" 312 """Returns info packaged as a dict."""
253 return { 313 return {
254 'interfaces_info': self.interfaces_info, 314 'interfaces_info': self.interfaces_info,
255 # Can't pickle defaultdict, convert to dict 315 # Can't pickle defaultdict, convert to dict
256 # FIXME: this should be included in get_component_info. 316 # FIXME: this should be included in get_component_info.
257 'partial_interface_files': dict(self.partial_interface_files), 317 'partial_interface_files': dict(self.partial_interface_files),
258 } 318 }
259 319
(...skipping 29 matching lines...) Expand all
289 349
290 write_pickle_file(options.interfaces_info_file, 350 write_pickle_file(options.interfaces_info_file,
291 info_collector.get_info_as_dict(), 351 info_collector.get_info_as_dict(),
292 options.write_file_only_if_changed) 352 options.write_file_only_if_changed)
293 write_pickle_file(options.component_info_file, 353 write_pickle_file(options.component_info_file,
294 info_collector.get_component_info_as_dict(), 354 info_collector.get_component_info_as_dict(),
295 options.write_file_only_if_changed) 355 options.write_file_only_if_changed)
296 356
297 if __name__ == '__main__': 357 if __name__ == '__main__':
298 sys.exit(main()) 358 sys.exit(main())
OLDNEW
« no previous file with comments | « bindings/scripts/collect_idls_into_json.py ('k') | bindings/scripts/compute_interfaces_info_overall.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698