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

Side by Side Diff: sky/engine/bindings/scripts/code_generator_dart.py

Issue 1135283005: Sky: Add a CustomDart attribute to the IDL compiler, and use that with Canvas (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: . Created 5 years, 7 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 # 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 for interface_name, interface_info in interfaces_info.iteritems() 99 for interface_name, interface_info in interfaces_info.iteritems()
100 if interface_info['is_callback_interface'])) 100 if interface_info['is_callback_interface']))
101 IdlType.set_implemented_as_interfaces(dict( 101 IdlType.set_implemented_as_interfaces(dict(
102 (interface_name, interface_info['implemented_as']) 102 (interface_name, interface_info['implemented_as'])
103 for interface_name, interface_info in interfaces_info.iteritems() 103 for interface_name, interface_info in interfaces_info.iteritems()
104 if interface_info['implemented_as'])) 104 if interface_info['implemented_as']))
105 dart_types.set_component_dirs(dict( 105 dart_types.set_component_dirs(dict(
106 (interface_name, interface_info['component_dir']) 106 (interface_name, interface_info['component_dir'])
107 for interface_name, interface_info in interfaces_info.iteritems())) 107 for interface_name, interface_info in interfaces_info.iteritems()))
108 108
109 def generate_code(self, definitions, interface_name, idl_pickle_filename, 109 def generate_code(self, definitions, interface_name,
110 only_if_changed): 110 idl_filename, idl_pickle_filename, only_if_changed):
111 """Returns .h/.cpp/.dart code as (header_text, cpp_text, dart_text).""" 111 """Returns .h/.cpp/.dart code as (header_text, cpp_text, dart_text)."""
112 try: 112 try:
113 interface = definitions.interfaces[interface_name] 113 interface = definitions.interfaces[interface_name]
114 except KeyError: 114 except KeyError:
115 raise Exception('%s not in IDL definitions' % interface_name) 115 raise Exception('%s not in IDL definitions' % interface_name)
116 116
117 # Store other interfaces for introspection 117 # Store other interfaces for introspection
118 interfaces.update(definitions.interfaces) 118 interfaces.update(definitions.interfaces)
119 119
120 # Set local type info 120 # Set local type info
(...skipping 21 matching lines...) Expand all
142 template_contents['code_generator'] = module_pyname 142 template_contents['code_generator'] = module_pyname
143 143
144 # Add includes for interface itself and any dependencies 144 # Add includes for interface itself and any dependencies
145 interface_info = self.interfaces_info[interface_name] 145 interface_info = self.interfaces_info[interface_name]
146 template_contents['header_includes'].add(interface_info['include_path']) 146 template_contents['header_includes'].add(interface_info['include_path'])
147 template_contents['header_includes'] = sorted(template_contents['header_ includes']) 147 template_contents['header_includes'] = sorted(template_contents['header_ includes'])
148 includes.update(interface_info.get('dependencies_include_paths', [])) 148 includes.update(interface_info.get('dependencies_include_paths', []))
149 149
150 template_contents['cpp_includes'] = sorted(includes) 150 template_contents['cpp_includes'] = sorted(includes)
151 151
152 # If CustomDart is set, read the custom dart file and add it to our
153 # template parameters.
154 if 'CustomDart' in interface.extended_attributes:
155 dart_filename = os.path.join(os.path.dirname(idl_filename),
156 interface.name + ".dart")
157 with open(dart_filename) as dart_file:
158 custom_dartcode = dart_file.read()
159 template_contents['custom_dartcode'] = custom_dartcode
160
152 idl_world = {'interface': None, 'callback': None} 161 idl_world = {'interface': None, 'callback': None}
153 162
154 # Load the pickle file for this IDL. 163 # Load the pickle file for this IDL.
155 if os.path.isfile(idl_pickle_filename): 164 if os.path.isfile(idl_pickle_filename):
156 with open(idl_pickle_filename) as idl_pickle_file: 165 with open(idl_pickle_filename) as idl_pickle_file:
157 idl_global_data = pickle.load(idl_pickle_file) 166 idl_global_data = pickle.load(idl_pickle_file)
158 idl_pickle_file.close() 167 idl_pickle_file.close()
159 idl_world['interface'] = idl_global_data['interface'] 168 idl_world['interface'] = idl_global_data['interface']
160 idl_world['callback'] = idl_global_data['callback'] 169 idl_world['callback'] = idl_global_data['callback']
161 170
162 if 'interface_name' in template_contents: 171 if 'interface_name' in template_contents:
163 interface_global = {'component_dir': interface_info['component_dir'] , 172 interface_global = {'component_dir': interface_info['component_dir'] ,
164 'name': template_contents['interface_name'], 173 'name': template_contents['interface_name'],
165 'parent_interface': template_contents['parent_in terface'], 174 'parent_interface': template_contents['parent_in terface'],
166 'is_active_dom_object': template_contents['is_ac tive_dom_object'], 175 'is_active_dom_object': template_contents['is_ac tive_dom_object'],
167 'has_resolver': template_contents['interface_nam e'], 176 'has_resolver': template_contents['interface_nam e'],
168 'native_entries': sorted(template_contents['nati ve_entries'], key=lambda(x): x['blink_entry']), 177 'native_entries': sorted(template_contents['nati ve_entries'], key=lambda(x): x['blink_entry']),
169 } 178 }
170 idl_world['interface'] = interface_global 179 idl_world['interface'] = interface_global
171 else: 180 else:
172 callback_global = {'name': template_contents['cpp_class']} 181 callback_global = {'name': template_contents['cpp_class']}
173 idl_world['callback'] = callback_global 182 idl_world['callback'] = callback_global
174 183
175 write_pickle_file(idl_pickle_filename, idl_world, only_if_changed) 184 write_pickle_file(idl_pickle_filename, idl_world, only_if_changed)
176 185
177 # Render Jinja templates 186 # Render Jinja templates
178 header_text = header_template.render(template_contents) 187 header_text = header_template.render(template_contents)
179 cpp_text = cpp_template.render(template_contents) 188 cpp_text = cpp_template.render(template_contents)
180 dart_text = dart_template.render(template_contents) 189 dart_text = dart_template.render(template_contents)
190
181 return header_text, cpp_text, dart_text 191 return header_text, cpp_text, dart_text
182 192
183 def load_global_pickles(self, global_entries): 193 def load_global_pickles(self, global_entries):
184 # List of all interfaces and callbacks for global code generation. 194 # List of all interfaces and callbacks for global code generation.
185 world = {'interfaces': [], 'callbacks': []} 195 world = {'interfaces': [], 'callbacks': []}
186 196
187 # Load all pickled data for each interface. 197 # Load all pickled data for each interface.
188 for (directory, file_list) in global_entries: 198 for (directory, file_list) in global_entries:
189 for idl_filename in file_list: 199 for idl_filename in file_list:
190 interface_name = idl_filename_to_interface_name(idl_filename) 200 interface_name = idl_filename_to_interface_name(idl_filename)
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 281
272 # Create a dummy file as output for the build system, 282 # Create a dummy file as output for the build system,
273 # since filenames of individual cache files are unpredictable and opaque 283 # since filenames of individual cache files are unpredictable and opaque
274 # (they are hashes of the template path, which varies based on environment) 284 # (they are hashes of the template path, which varies based on environment)
275 with open(dummy_filename, 'w') as dummy_file: 285 with open(dummy_filename, 'w') as dummy_file:
276 pass # |open| creates or touches the file 286 pass # |open| creates or touches the file
277 287
278 288
279 if __name__ == '__main__': 289 if __name__ == '__main__':
280 sys.exit(main(sys.argv)) 290 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « sky/engine/bindings/IDLExtendedAttributes.txt ('k') | sky/engine/bindings/scripts/dart_compiler.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698