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

Side by Side Diff: Source/bindings/scripts/code_generator_v8.py

Issue 618373003: [bindings] partial interfaces should not violate componentization (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 import jinja2 71 import jinja2
72 72
73 import idl_types 73 import idl_types
74 from idl_types import IdlType 74 from idl_types import IdlType
75 import v8_callback_interface 75 import v8_callback_interface
76 import v8_dictionary 76 import v8_dictionary
77 from v8_globals import includes, interfaces 77 from v8_globals import includes, interfaces
78 import v8_interface 78 import v8_interface
79 import v8_types 79 import v8_types
80 from v8_utilities import capitalize, cpp_name, conditional_string, v8_class_name 80 from v8_utilities import capitalize, cpp_name, conditional_string, v8_class_name
81 from utilities import KNOWN_COMPONENTS 81 from utilities import KNOWN_COMPONENTS, idl_filename_to_component, is_valid_comp onent_dependency
82 82
83 83
84 def render_template(interface_info, header_template, cpp_template, 84 def render_template(include_paths, header_template, cpp_template,
85 template_context): 85 template_context, component=None):
86 template_context['code_generator'] = module_pyname 86 template_context['code_generator'] = module_pyname
87 87
88 # Add includes for any dependencies 88 # Add includes for any dependencies
89 template_context['header_includes'] = sorted( 89 template_context['header_includes'] = sorted(
90 template_context['header_includes']) 90 template_context['header_includes'])
91 includes.update(interface_info.get('dependencies_include_paths', [])) 91
92 for include_path in include_paths:
93 if component:
94 dependency = idl_filename_to_component(include_path)
95 if not is_valid_component_dependency(component, dependency):
haraken 2014/10/16 04:24:07 Shouldn't we raise an exception in this case?
tasak 2014/10/17 07:38:17 Changed. Now assert, because compute_interfaces_in
96 continue
97 includes.add(include_path)
98
92 template_context['cpp_includes'] = sorted(includes) 99 template_context['cpp_includes'] = sorted(includes)
93 100
94 header_text = header_template.render(template_context) 101 header_text = header_template.render(template_context)
95 cpp_text = cpp_template.render(template_context) 102 cpp_text = cpp_template.render(template_context)
96 return header_text, cpp_text 103 return header_text, cpp_text
97 104
98 105
99 class CodeGeneratorBase(object): 106 class CodeGeneratorBase(object):
100 """Base class for v8 bindings generator and IDL dictionary impl generator""" 107 """Base class for v8 bindings generator and IDL dictionary impl generator"""
101 108
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 if definition_name in definitions.dictionaries: 152 if definition_name in definitions.dictionaries:
146 return self.generate_dictionary_code( 153 return self.generate_dictionary_code(
147 definitions, definition_name, 154 definitions, definition_name,
148 definitions.dictionaries[definition_name]) 155 definitions.dictionaries[definition_name])
149 raise ValueError('%s is not in IDL definitions' % definition_name) 156 raise ValueError('%s is not in IDL definitions' % definition_name)
150 157
151 def generate_interface_code(self, definitions, interface_name, interface): 158 def generate_interface_code(self, definitions, interface_name, interface):
152 # Store other interfaces for introspection 159 # Store other interfaces for introspection
153 interfaces.update(definitions.interfaces) 160 interfaces.update(definitions.interfaces)
154 161
162 interface_info = self.interfaces_info[interface_name]
163 component = idl_filename_to_component(
164 interface_info.get('full_path'))
165 include_paths = interface_info.get('dependencies_include_paths')
166
155 # Select appropriate Jinja template and contents function 167 # Select appropriate Jinja template and contents function
168 definition_name = interface_name
156 if interface.is_callback: 169 if interface.is_callback:
157 header_template_filename = 'callback_interface.h' 170 header_template_filename = 'callback_interface.h'
158 cpp_template_filename = 'callback_interface.cpp' 171 cpp_template_filename = 'callback_interface.cpp'
159 interface_context = v8_callback_interface.callback_interface_context 172 interface_context = v8_callback_interface.callback_interface_context
173 elif interface.is_partial:
174 interface_context = v8_interface.interface_context
175 header_template_filename = 'partial_interface.h'
176 cpp_template_filename = 'partial_interface.cpp'
177 definition_name = ''.join([interface_name, 'Partial'])
haraken 2014/10/16 04:24:07 I'd just overwrite interface_name (instead of intr
tasak 2014/10/17 07:38:17 Done.
178 assert component == 'core'
179 component = 'modules'
180 include_paths = interface_info.get('partial_interface_dependencies_i nclude_paths')
160 else: 181 else:
161 header_template_filename = 'interface.h' 182 header_template_filename = 'interface.h'
162 cpp_template_filename = 'interface.cpp' 183 cpp_template_filename = 'interface.cpp'
163 interface_context = v8_interface.interface_context 184 interface_context = v8_interface.interface_context
164 header_template = self.jinja_env.get_template(header_template_filename) 185 header_template = self.jinja_env.get_template(header_template_filename)
165 cpp_template = self.jinja_env.get_template(cpp_template_filename) 186 cpp_template = self.jinja_env.get_template(cpp_template_filename)
166 187
167 interface_info = self.interfaces_info[interface_name]
168
169 template_context = interface_context(interface) 188 template_context = interface_context(interface)
170 # Add the include for interface itself 189 # Add the include for interface itself
171 template_context['header_includes'].add(interface_info['include_path']) 190 template_context['header_includes'].add(interface_info['include_path'])
172 header_text, cpp_text = render_template( 191 header_text, cpp_text = render_template(
173 interface_info, header_template, cpp_template, template_context) 192 include_paths, header_template, cpp_template, template_context,
174 header_path, cpp_path = self.output_paths(interface_name) 193 component)
194 header_path, cpp_path = self.output_paths(definition_name)
175 return ( 195 return (
176 (header_path, header_text), 196 (header_path, header_text),
177 (cpp_path, cpp_text), 197 (cpp_path, cpp_text),
178 ) 198 )
179 199
180 def generate_dictionary_code(self, definitions, dictionary_name, 200 def generate_dictionary_code(self, definitions, dictionary_name,
181 dictionary): 201 dictionary):
182 header_template = self.jinja_env.get_template('dictionary_v8.h') 202 header_template = self.jinja_env.get_template('dictionary_v8.h')
183 cpp_template = self.jinja_env.get_template('dictionary_v8.cpp') 203 cpp_template = self.jinja_env.get_template('dictionary_v8.cpp')
184 template_context = v8_dictionary.dictionary_context(dictionary) 204 template_context = v8_dictionary.dictionary_context(dictionary)
185 interface_info = self.interfaces_info[dictionary_name] 205 interface_info = self.interfaces_info[dictionary_name]
206 include_paths = interface_info.get('dependencies_include_paths')
186 # Add the include for interface itself 207 # Add the include for interface itself
187 template_context['header_includes'].add(interface_info['include_path']) 208 template_context['header_includes'].add(interface_info['include_path'])
188 header_text, cpp_text = render_template( 209 header_text, cpp_text = render_template(
189 interface_info, header_template, cpp_template, template_context) 210 include_paths, header_template, cpp_template, template_context)
190 header_path, cpp_path = self.output_paths(dictionary_name) 211 header_path, cpp_path = self.output_paths(dictionary_name)
191 return ( 212 return (
192 (header_path, header_text), 213 (header_path, header_text),
193 (cpp_path, cpp_text), 214 (cpp_path, cpp_text),
194 ) 215 )
195 216
196 217
197 class CodeGeneratorDictionaryImpl(CodeGeneratorBase): 218 class CodeGeneratorDictionaryImpl(CodeGeneratorBase):
198 def __init__(self, interfaces_info, cache_dir, output_dir): 219 def __init__(self, interfaces_info, cache_dir, output_dir):
199 CodeGeneratorBase.__init__(self, interfaces_info, cache_dir, output_dir) 220 CodeGeneratorBase.__init__(self, interfaces_info, cache_dir, output_dir)
200 221
201 def output_paths(self, definition_name, interface_info): 222 def output_paths(self, definition_name, interface_info):
202 output_dir = posixpath.join(self.output_dir, 223 output_dir = posixpath.join(self.output_dir,
203 interface_info['relative_dir']) 224 interface_info['relative_dir'])
204 header_path = posixpath.join(output_dir, '%s.h' % definition_name) 225 header_path = posixpath.join(output_dir, '%s.h' % definition_name)
205 cpp_path = posixpath.join(output_dir, '%s.cpp' % definition_name) 226 cpp_path = posixpath.join(output_dir, '%s.cpp' % definition_name)
206 return header_path, cpp_path 227 return header_path, cpp_path
207 228
208 def generate_code_internal(self, definitions, definition_name): 229 def generate_code_internal(self, definitions, definition_name):
209 if not definition_name in definitions.dictionaries: 230 if not definition_name in definitions.dictionaries:
210 raise ValueError('%s is not an IDL dictionary') 231 raise ValueError('%s is not an IDL dictionary')
211 dictionary = definitions.dictionaries[definition_name] 232 dictionary = definitions.dictionaries[definition_name]
212 interface_info = self.interfaces_info[definition_name] 233 interface_info = self.interfaces_info[definition_name]
213 header_template = self.jinja_env.get_template('dictionary_impl.h') 234 header_template = self.jinja_env.get_template('dictionary_impl.h')
214 cpp_template = self.jinja_env.get_template('dictionary_impl.cpp') 235 cpp_template = self.jinja_env.get_template('dictionary_impl.cpp')
215 template_context = v8_dictionary.dictionary_impl_context( 236 template_context = v8_dictionary.dictionary_impl_context(
216 dictionary, self.interfaces_info) 237 dictionary, self.interfaces_info)
238 include_paths = interface_info.get('dependencies_include_paths')
217 header_text, cpp_text = render_template( 239 header_text, cpp_text = render_template(
218 interface_info, header_template, cpp_template, template_context) 240 include_paths, header_template, cpp_template, template_context)
219 header_path, cpp_path = self.output_paths( 241 header_path, cpp_path = self.output_paths(
220 definition_name, interface_info) 242 definition_name, interface_info)
221 return ( 243 return (
222 (header_path, header_text), 244 (header_path, header_text),
223 (cpp_path, cpp_text), 245 (cpp_path, cpp_text),
224 ) 246 )
225 247
226 248
227 def initialize_jinja_env(cache_dir): 249 def initialize_jinja_env(cache_dir):
228 jinja_env = jinja2.Environment( 250 jinja_env = jinja2.Environment(
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 325
304 # Create a dummy file as output for the build system, 326 # Create a dummy file as output for the build system,
305 # since filenames of individual cache files are unpredictable and opaque 327 # since filenames of individual cache files are unpredictable and opaque
306 # (they are hashes of the template path, which varies based on environment) 328 # (they are hashes of the template path, which varies based on environment)
307 with open(dummy_filename, 'w') as dummy_file: 329 with open(dummy_filename, 'w') as dummy_file:
308 pass # |open| creates or touches the file 330 pass # |open| creates or touches the file
309 331
310 332
311 if __name__ == '__main__': 333 if __name__ == '__main__':
312 sys.exit(main(sys.argv)) 334 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698