| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 2 # Copyright (C) 2013 Google Inc. All rights reserved. | |
| 3 # | |
| 4 # Redistribution and use in source and binary forms, with or without | |
| 5 # modification, are permitted provided that the following conditions are | |
| 6 # met: | |
| 7 # | |
| 8 # * Redistributions of source code must retain the above copyright | |
| 9 # notice, this list of conditions and the following disclaimer. | |
| 10 # * Redistributions in binary form must reproduce the above | |
| 11 # copyright notice, this list of conditions and the following disclaimer | |
| 12 # in the documentation and/or other materials provided with the | |
| 13 # distribution. | |
| 14 # * Neither the name of Google Inc. nor the names of its | |
| 15 # contributors may be used to endorse or promote products derived from | |
| 16 # this software without specific prior written permission. | |
| 17 # | |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 | |
| 30 """Compile an .idl file to Blink V8 bindings (.h and .cpp files). | |
| 31 | |
| 32 FIXME: Not currently used in build. | |
| 33 This is a rewrite of the Perl IDL compiler in Python, but is not complete. | |
| 34 Once it is complete, we will switch all IDL files over to Python at once. | |
| 35 Until then, please work on the Perl IDL compiler. | |
| 36 For details, see bug http://crbug.com/239771 | |
| 37 """ | |
| 38 | |
| 39 from optparse import OptionParser | |
| 40 import os | |
| 41 import cPickle as pickle | |
| 42 import sys | |
| 43 | |
| 44 from code_generator_v8 import CodeGeneratorV8 | |
| 45 from idl_reader import IdlReader | |
| 46 # from utilities import write_file # FIXME: import once in same directory | |
| 47 | |
| 48 def parse_options(): | |
| 49 parser = OptionParser() | |
| 50 parser.add_option('--idl-attributes-file') | |
| 51 parser.add_option('--output-directory') | |
| 52 parser.add_option('--interfaces-info-file') | |
| 53 parser.add_option('--write-file-only-if-changed', type='int') | |
| 54 # ensure output comes last, so command line easy to parse via regexes | |
| 55 parser.disable_interspersed_args() | |
| 56 | |
| 57 options, args = parser.parse_args() | |
| 58 if options.output_directory is None: | |
| 59 parser.error('Must specify output directory using --output-directory.') | |
| 60 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) | |
| 61 if len(args) != 1: | |
| 62 parser.error('Must specify exactly 1 input file as argument, but %d give
n.' % len(args)) | |
| 63 idl_filename = os.path.realpath(args[0]) | |
| 64 return options, idl_filename | |
| 65 | |
| 66 | |
| 67 # FIXME: import from utilities once moved into same directory (lines vs. text) | |
| 68 def write_file(new_text, destination_filename, only_if_changed): | |
| 69 if only_if_changed and os.path.isfile(destination_filename): | |
| 70 with open(destination_filename) as destination_file: | |
| 71 if destination_file.read() == new_text: | |
| 72 return | |
| 73 with open(destination_filename, 'w') as destination_file: | |
| 74 destination_file.write(new_text) | |
| 75 | |
| 76 | |
| 77 def main(): | |
| 78 options, idl_filename = parse_options() | |
| 79 basename = os.path.basename(idl_filename) | |
| 80 interface_name, _ = os.path.splitext(basename) | |
| 81 output_directory = options.output_directory | |
| 82 only_if_changed = options.write_file_only_if_changed | |
| 83 | |
| 84 interfaces_info_filename = options.interfaces_info_file | |
| 85 if interfaces_info_filename: | |
| 86 with open(interfaces_info_filename) as interfaces_info_file: | |
| 87 interfaces_info = pickle.load(interfaces_info_file) | |
| 88 else: | |
| 89 interfaces_info = None | |
| 90 | |
| 91 reader = IdlReader(interfaces_info, options.idl_attributes_file, output_dire
ctory) | |
| 92 definitions = reader.read_idl_definitions(idl_filename) | |
| 93 | |
| 94 code_generator = CodeGeneratorV8(interfaces_info, output_directory) | |
| 95 header_text, cpp_text = code_generator.generate_code(definitions, interface_
name) | |
| 96 | |
| 97 header_filename = os.path.join(output_directory, 'V8%s.h' % interface_name) | |
| 98 cpp_filename = os.path.join(output_directory, 'V8%s.cpp' % interface_name) | |
| 99 write_file(header_text, header_filename, only_if_changed) | |
| 100 write_file(cpp_text, cpp_filename, only_if_changed) | |
| 101 | |
| 102 | |
| 103 if __name__ == '__main__': | |
| 104 sys.exit(main()) | |
| OLD | NEW |