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

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

Issue 345893002: Implement an infrastructure of Blink-in-JS Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 module_pyname = os.path.splitext(module_filename)[0] + '.py' 65 module_pyname = os.path.splitext(module_filename)[0] + '.py'
66 66
67 # jinja2 is in chromium's third_party directory. 67 # jinja2 is in chromium's third_party directory.
68 # Insert at 1 so at front to override system libraries, and 68 # Insert at 1 so at front to override system libraries, and
69 # after path[0] == invoking script dir 69 # after path[0] == invoking script dir
70 sys.path.insert(1, third_party_dir) 70 sys.path.insert(1, third_party_dir)
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_private_script_interface
Nils Barth (inactive) 2014/06/23 03:14:29 alpha
75 import v8_callback_interface 76 import v8_callback_interface
76 from v8_globals import includes, interfaces 77 from v8_globals import includes, interfaces
77 import v8_interface 78 import v8_interface
78 import v8_types 79 import v8_types
79 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
80 81
81 82
82 class CodeGeneratorV8(object): 83 class CodeGeneratorV8(object):
83 def __init__(self, interfaces_info, cache_dir): 84 def __init__(self, interfaces_info, cache_dir):
84 interfaces_info = interfaces_info or {} 85 interfaces_info = interfaces_info or {}
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 # Set local type info 124 # Set local type info
124 IdlType.set_callback_functions(definitions.callback_functions.keys()) 125 IdlType.set_callback_functions(definitions.callback_functions.keys())
125 IdlType.set_enums((enum.name, enum.values) 126 IdlType.set_enums((enum.name, enum.values)
126 for enum in definitions.enumerations.values()) 127 for enum in definitions.enumerations.values())
127 128
128 # Select appropriate Jinja template and contents function 129 # Select appropriate Jinja template and contents function
129 if interface.is_callback: 130 if interface.is_callback:
130 header_template_filename = 'callback_interface.h' 131 header_template_filename = 'callback_interface.h'
131 cpp_template_filename = 'callback_interface.cpp' 132 cpp_template_filename = 'callback_interface.cpp'
132 generate_contents = v8_callback_interface.generate_callback_interfac e 133 generate_contents = v8_callback_interface.generate_callback_interfac e
134 elif 'PrivateScriptInterface' in interface.extended_attributes:
135 header_template_filename = 'private_script_interface.h'
136 cpp_template_filename = 'private_script_interface.cpp'
137 generate_contents = v8_private_script_interface.generate_private_scr ipt_interface
133 else: 138 else:
134 header_template_filename = 'interface.h' 139 header_template_filename = 'interface.h'
135 cpp_template_filename = 'interface.cpp' 140 cpp_template_filename = 'interface.cpp'
136 generate_contents = v8_interface.generate_interface 141 generate_contents = v8_interface.generate_interface
137 header_template = self.jinja_env.get_template(header_template_filename) 142 header_template = self.jinja_env.get_template(header_template_filename)
138 cpp_template = self.jinja_env.get_template(cpp_template_filename) 143 cpp_template = self.jinja_env.get_template(cpp_template_filename)
139 144
140 # Generate contents (input parameters for Jinja) 145 # Generate contents (input parameters for Jinja)
141 template_contents = generate_contents(interface) 146 template_contents = generate_contents(interface)
142 template_contents['code_generator'] = module_pyname 147 template_contents['code_generator'] = module_pyname
143 148
144 # Add includes for interface itself and any dependencies 149 # Add includes for interface itself and any dependencies
145 interface_info = self.interfaces_info[interface_name] 150 interface_info = self.interfaces_info[interface_name]
146 template_contents['header_includes'].add(interface_info['include_path']) 151 if 'PrivateScriptInterface' not in interface.extended_attributes:
Nils Barth (inactive) 2014/06/23 03:14:29 Longer-term we can have private scripts also passe
haraken 2014/06/23 06:01:46 Actually I'm not sure what kind of dependency we'l
Nils Barth (inactive) 2014/06/23 06:21:25 That's fine; just a heads-up. Might want to add a
haraken 2014/06/23 08:15:38 Done.
152 template_contents['header_includes'].add(interface_info['include_pat h'])
147 template_contents['header_includes'] = sorted(template_contents['header_ includes']) 153 template_contents['header_includes'] = sorted(template_contents['header_ includes'])
148 includes.update(interface_info.get('dependencies_include_paths', [])) 154 includes.update(interface_info.get('dependencies_include_paths', []))
149 template_contents['cpp_includes'] = sorted(includes) 155 template_contents['cpp_includes'] = sorted(includes)
150 156
151 # Render Jinja templates 157 # Render Jinja templates
152 header_text = header_template.render(template_contents) 158 header_text = header_template.render(template_contents)
153 cpp_text = cpp_template.render(template_contents) 159 cpp_text = cpp_template.render(template_contents)
154 return header_text, cpp_text 160 return header_text, cpp_text
155 161
156 162
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 219
214 # Create a dummy file as output for the build system, 220 # Create a dummy file as output for the build system,
215 # since filenames of individual cache files are unpredictable and opaque 221 # since filenames of individual cache files are unpredictable and opaque
216 # (they are hashes of the template path, which varies based on environment) 222 # (they are hashes of the template path, which varies based on environment)
217 with open(dummy_filename, 'w') as dummy_file: 223 with open(dummy_filename, 'w') as dummy_file:
218 pass # |open| creates or touches the file 224 pass # |open| creates or touches the file
219 225
220 226
221 if __name__ == '__main__': 227 if __name__ == '__main__':
222 sys.exit(main(sys.argv)) 228 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698