| OLD | NEW |
| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 import sys | 49 import sys |
| 50 | 50 |
| 51 # Path handling for libraries and templates | 51 # Path handling for libraries and templates |
| 52 # Paths have to be normalized because Jinja uses the exact template path to | 52 # Paths have to be normalized because Jinja uses the exact template path to |
| 53 # determine the hash used in the cache filename, and we need a pre-caching step | 53 # determine the hash used in the cache filename, and we need a pre-caching step |
| 54 # to be concurrency-safe. Use absolute path because __file__ is absolute if | 54 # to be concurrency-safe. Use absolute path because __file__ is absolute if |
| 55 # module is imported, and relative if executed directly. | 55 # module is imported, and relative if executed directly. |
| 56 # If paths differ between pre-caching and individual file compilation, the cache | 56 # If paths differ between pre-caching and individual file compilation, the cache |
| 57 # is regenerated, which causes a race condition and breaks concurrent build, | 57 # is regenerated, which causes a race condition and breaks concurrent build, |
| 58 # since some compile processes will try to read the partially written cache. | 58 # since some compile processes will try to read the partially written cache. |
| 59 module_path = os.path.dirname(os.path.realpath(__file__)) | 59 module_path, module_filename = os.path.split(os.path.realpath(__file__)) |
| 60 third_party_dir = os.path.normpath(os.path.join( | 60 third_party_dir = os.path.normpath(os.path.join( |
| 61 module_path, os.pardir, os.pardir, os.pardir, os.pardir)) | 61 module_path, os.pardir, os.pardir, os.pardir, os.pardir)) |
| 62 templates_dir = os.path.normpath(os.path.join( | 62 templates_dir = os.path.normpath(os.path.join( |
| 63 module_path, os.pardir, 'templates')) | 63 module_path, os.pardir, 'templates')) |
| 64 # Make sure extension is .py, not .pyc or .pyo, so doesn't depend on caching |
| 65 module_pyname = os.path.splitext(module_filename)[0] + '.py' |
| 64 | 66 |
| 65 # jinja2 is in chromium's third_party directory. | 67 # jinja2 is in chromium's third_party directory. |
| 66 # Insert at 1 so at front to override system libraries, and | 68 # Insert at 1 so at front to override system libraries, and |
| 67 # after path[0] == invoking script dir | 69 # after path[0] == invoking script dir |
| 68 sys.path.insert(1, third_party_dir) | 70 sys.path.insert(1, third_party_dir) |
| 69 import jinja2 | 71 import jinja2 |
| 70 | 72 |
| 71 import idl_types | 73 import idl_types |
| 72 from idl_types import IdlType | 74 from idl_types import IdlType |
| 73 import v8_callback_interface | 75 import v8_callback_interface |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 generate_contents = v8_callback_interface.generate_callback_interfac
e | 125 generate_contents = v8_callback_interface.generate_callback_interfac
e |
| 124 else: | 126 else: |
| 125 header_template_filename = 'interface.h' | 127 header_template_filename = 'interface.h' |
| 126 cpp_template_filename = 'interface.cpp' | 128 cpp_template_filename = 'interface.cpp' |
| 127 generate_contents = v8_interface.generate_interface | 129 generate_contents = v8_interface.generate_interface |
| 128 header_template = self.jinja_env.get_template(header_template_filename) | 130 header_template = self.jinja_env.get_template(header_template_filename) |
| 129 cpp_template = self.jinja_env.get_template(cpp_template_filename) | 131 cpp_template = self.jinja_env.get_template(cpp_template_filename) |
| 130 | 132 |
| 131 # Generate contents (input parameters for Jinja) | 133 # Generate contents (input parameters for Jinja) |
| 132 template_contents = generate_contents(interface) | 134 template_contents = generate_contents(interface) |
| 135 template_contents['code_generator'] = module_pyname |
| 133 | 136 |
| 134 # Add includes for interface itself and any dependencies | 137 # Add includes for interface itself and any dependencies |
| 135 interface_info = self.interfaces_info[interface_name] | 138 interface_info = self.interfaces_info[interface_name] |
| 136 template_contents['header_includes'].add(interface_info['include_path']) | 139 template_contents['header_includes'].add(interface_info['include_path']) |
| 137 template_contents['header_includes'] = sorted(template_contents['header_
includes']) | 140 template_contents['header_includes'] = sorted(template_contents['header_
includes']) |
| 138 includes.update(interface_info.get('dependencies_include_paths', [])) | 141 includes.update(interface_info.get('dependencies_include_paths', [])) |
| 139 template_contents['cpp_includes'] = sorted(includes) | 142 template_contents['cpp_includes'] = sorted(includes) |
| 140 | 143 |
| 141 # Render Jinja templates | 144 # Render Jinja templates |
| 142 header_text = header_template.render(template_contents) | 145 header_text = header_template.render(template_contents) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 205 |
| 203 # Create a dummy file as output for the build system, | 206 # Create a dummy file as output for the build system, |
| 204 # since filenames of individual cache files are unpredictable and opaque | 207 # since filenames of individual cache files are unpredictable and opaque |
| 205 # (they are hashes of the template path, which varies based on environment) | 208 # (they are hashes of the template path, which varies based on environment) |
| 206 with open(dummy_filename, 'w') as dummy_file: | 209 with open(dummy_filename, 'w') as dummy_file: |
| 207 pass # |open| creates or touches the file | 210 pass # |open| creates or touches the file |
| 208 | 211 |
| 209 | 212 |
| 210 if __name__ == '__main__': | 213 if __name__ == '__main__': |
| 211 sys.exit(main(sys.argv)) | 214 sys.exit(main(sys.argv)) |
| OLD | NEW |