| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (C) 2013 Google Inc. All rights reserved. | 2 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 # | 3 # |
| 4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
| 6 # met: | 6 # met: |
| 7 # | 7 # |
| 8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
| 11 # copyright notice, this list of conditions and the following disclaimer | 11 # copyright notice, this list of conditions and the following disclaimer |
| 12 # in the documentation and/or other materials provided with the | 12 # in the documentation and/or other materials provided with the |
| 13 # distribution. | 13 # distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its | 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived from | 15 # contributors may be used to endorse or promote products derived from |
| 16 # this software without specific prior written permission. | 16 # this software without specific prior written permission. |
| 17 # | 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | 29 |
| 30 # pylint: disable=W0403 |
| 31 |
| 30 """Compile an .idl file to Blink V8 bindings (.h and .cpp files). | 32 """Compile an .idl file to Blink V8 bindings (.h and .cpp files). |
| 31 | 33 |
| 32 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | 34 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
| 33 """ | 35 """ |
| 34 | 36 |
| 35 import abc | 37 import abc |
| 36 from optparse import OptionParser | 38 from optparse import OptionParser |
| 37 import os | 39 import os |
| 38 import cPickle as pickle | 40 import cPickle as pickle |
| 39 import sys | 41 import sys |
| 40 | 42 |
| 41 from code_generator_v8 import CodeGeneratorDictionaryImpl, CodeGeneratorV8, Code
GeneratorUnionType, CodeGeneratorCallbackFunction # pylint: disable=W0403 | 43 from code_generator_v8 import CodeGeneratorDictionaryImpl |
| 44 from code_generator_v8 import CodeGeneratorV8 |
| 45 from code_generator_v8 import CodeGeneratorUnionType |
| 46 from code_generator_v8 import CodeGeneratorCallbackFunction |
| 42 from idl_reader import IdlReader | 47 from idl_reader import IdlReader |
| 43 from utilities import create_component_info_provider, read_idl_files_list_from_f
ile, write_file, idl_filename_to_component | 48 from utilities import create_component_info_provider |
| 49 from utilities import read_idl_files_list_from_file |
| 50 from utilities import write_file |
| 44 | 51 |
| 45 | 52 |
| 46 def parse_options(): | 53 def parse_options(): |
| 47 parser = OptionParser() | 54 parser = OptionParser() |
| 48 parser.add_option('--cache-directory', | 55 parser.add_option('--cache-directory', |
| 49 help='cache directory, defaults to output directory') | 56 help='cache directory, defaults to output directory') |
| 50 parser.add_option('--generate-impl', | 57 parser.add_option('--generate-impl', |
| 51 action="store_true", default=False) | 58 action="store_true", default=False) |
| 52 parser.add_option('--output-directory') | 59 parser.add_option('--output-directory') |
| 53 parser.add_option('--impl-output-directory') | 60 parser.add_option('--impl-output-directory') |
| 54 parser.add_option('--info-dir') | 61 parser.add_option('--info-dir') |
| 55 parser.add_option('--write-file-only-if-changed', type='int') | 62 parser.add_option('--write-file-only-if-changed', type='int') |
| 56 # FIXME: We should always explicitly specify --target-component and | 63 # FIXME: We should always explicitly specify --target-component and |
| 57 # remove the default behavior. | 64 # remove the default behavior. |
| 58 parser.add_option('--target-component', | 65 parser.add_option('--target-component', |
| 66 type='choice', |
| 67 choices=['core', 'modules'], |
| 59 help='target component to generate code, defaults to ' | 68 help='target component to generate code, defaults to ' |
| 60 'component of input idl file') | 69 'component of input idl file') |
| 61 # ensure output comes last, so command line easy to parse via regexes | 70 # ensure output comes last, so command line easy to parse via regexes |
| 62 parser.disable_interspersed_args() | 71 parser.disable_interspersed_args() |
| 63 | 72 |
| 64 options, args = parser.parse_args() | 73 options, args = parser.parse_args() |
| 65 if options.output_directory is None: | 74 if options.output_directory is None: |
| 66 parser.error('Must specify output directory using --output-directory.') | 75 parser.error('Must specify output directory using --output-directory.') |
| 67 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) | 76 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) |
| 68 if len(args) != 1: | 77 if len(args) != 1: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 self.code_generator = code_generator | 113 self.code_generator = code_generator |
| 105 self.info_provider = info_provider | 114 self.info_provider = info_provider |
| 106 self.only_if_changed = only_if_changed | 115 self.only_if_changed = only_if_changed |
| 107 self.output_directory = output_directory | 116 self.output_directory = output_directory |
| 108 self.target_component = target_component | 117 self.target_component = target_component |
| 109 self.reader = IdlReader(info_provider.interfaces_info, cache_directory) | 118 self.reader = IdlReader(info_provider.interfaces_info, cache_directory) |
| 110 | 119 |
| 111 def compile_and_write(self, idl_filename): | 120 def compile_and_write(self, idl_filename): |
| 112 interface_name = idl_filename_to_interface_name(idl_filename) | 121 interface_name = idl_filename_to_interface_name(idl_filename) |
| 113 definitions = self.reader.read_idl_definitions(idl_filename) | 122 definitions = self.reader.read_idl_definitions(idl_filename) |
| 114 target_component = self.target_component or idl_filename_to_component(id
l_filename) | 123 target_definitions = definitions[self.target_component] |
| 115 target_definitions = definitions[target_component] | |
| 116 output_code_list = self.code_generator.generate_code( | 124 output_code_list = self.code_generator.generate_code( |
| 117 target_definitions, interface_name) | 125 target_definitions, interface_name) |
| 118 for output_path, output_code in output_code_list: | 126 for output_path, output_code in output_code_list: |
| 119 write_file(output_code, output_path, self.only_if_changed) | 127 write_file(output_code, output_path, self.only_if_changed) |
| 120 | 128 |
| 121 @abc.abstractmethod | 129 @abc.abstractmethod |
| 122 def compile_file(self, idl_filename): | 130 def compile_file(self, idl_filename): |
| 123 pass | 131 pass |
| 124 | 132 |
| 125 | 133 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 156 idl_compiler.compile_file(input_filename) | 164 idl_compiler.compile_file(input_filename) |
| 157 | 165 |
| 158 | 166 |
| 159 def generate_dictionary_impl(options, input_filename): | 167 def generate_dictionary_impl(options, input_filename): |
| 160 info_provider = create_component_info_provider( | 168 info_provider = create_component_info_provider( |
| 161 options.info_dir, options.target_component) | 169 options.info_dir, options.target_component) |
| 162 idl_compiler = IdlCompilerDictionaryImpl( | 170 idl_compiler = IdlCompilerDictionaryImpl( |
| 163 options.impl_output_directory, | 171 options.impl_output_directory, |
| 164 cache_directory=options.cache_directory, | 172 cache_directory=options.cache_directory, |
| 165 info_provider=info_provider, | 173 info_provider=info_provider, |
| 166 only_if_changed=options.write_file_only_if_changed) | 174 only_if_changed=options.write_file_only_if_changed, |
| 175 target_component=options.target_component) |
| 167 | 176 |
| 168 idl_filenames = read_idl_files_list_from_file(input_filename, | 177 idl_filenames = read_idl_files_list_from_file(input_filename, |
| 169 is_gyp_format=True) | 178 is_gyp_format=True) |
| 170 for idl_filename in idl_filenames: | 179 for idl_filename in idl_filenames: |
| 171 idl_compiler.compile_file(idl_filename) | 180 idl_compiler.compile_file(idl_filename) |
| 172 | 181 |
| 173 | 182 |
| 174 def generate_union_type_containers(options): | 183 def generate_union_type_containers(options): |
| 175 info_provider = create_component_info_provider( | 184 info_provider = create_component_info_provider( |
| 176 options.info_dir, options.target_component) | 185 options.info_dir, options.target_component) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 generate_dictionary_impl(options, input_filename) | 217 generate_dictionary_impl(options, input_filename) |
| 209 generate_union_type_containers(options) | 218 generate_union_type_containers(options) |
| 210 generate_callback_function_impl(options) | 219 generate_callback_function_impl(options) |
| 211 else: | 220 else: |
| 212 # |input_filename| should be a path of an IDL file. | 221 # |input_filename| should be a path of an IDL file. |
| 213 generate_bindings(options, input_filename) | 222 generate_bindings(options, input_filename) |
| 214 | 223 |
| 215 | 224 |
| 216 if __name__ == '__main__': | 225 if __name__ == '__main__': |
| 217 sys.exit(main()) | 226 sys.exit(main()) |
| OLD | NEW |