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 We are porting the IDL compiler from Perl to Python. The plan is as follows. |
| 33 We will temporarily have two build flows (see ../derived_sources.gyp): |
| 34 [1] Perl: deprecated_generate_bindings.pl, which calls: |
| 35 deprecated_idl_parser.pm => deprecated_code_generator_v8.pm |
| 36 [2] Python: idl_compiler.py, which calls: |
| 37 IDL lexer => IDL parser => Python object builder => |
| 38 interface dependency resolver => IDL semantic validator => |
| 39 C++ code generator |
| 40 |
| 41 We will move IDL files from the Perl build flow [1] to the Python build flow [2] |
| 42 incrementally. See http://crbug.com/239771 |
| 43 """ |
| 44 import optparse |
| 45 import os |
| 46 import shlex |
| 47 import sys |
| 48 |
| 49 import idl_reader |
| 50 import code_generator_v8 |
| 51 |
| 52 |
| 53 def parse_options(): |
| 54 parser = optparse.OptionParser() |
| 55 parser.add_option('--additional-idl-files') |
| 56 parser.add_option('--idl-attributes-file') |
| 57 parser.add_option('--include', dest='idl_directories', action='append') |
| 58 parser.add_option('--output-directory') |
| 59 parser.add_option('--interface-dependencies-file') |
| 60 parser.add_option('--verbose', action='store_true', default=False) |
| 61 parser.add_option('--write-file-only-if-changed', type='int') |
| 62 # ensure output comes last, so command line easy to parse via regexes |
| 63 parser.disable_interspersed_args() |
| 64 |
| 65 options, args = parser.parse_args() |
| 66 if options.output_directory is None: |
| 67 parser.error('Must specify output directory using --output-directory.') |
| 68 if options.additional_idl_files is not None: |
| 69 # additional_idl_files is passed as a string with varied (shell-style) |
| 70 # quoting, hence needs parsing. |
| 71 options.additional_idl_files = shlex.split(options.additional_idl_files) |
| 72 if len(args) != 1: |
| 73 parser.error('Must specify exactly 1 input file as argument, but %d give
n.' % len(args)) |
| 74 options.idl_filename = os.path.realpath(args[0]) |
| 75 return options |
| 76 |
| 77 |
| 78 def main(): |
| 79 options = parse_options() |
| 80 idl_filename = options.idl_filename |
| 81 basename = os.path.basename(idl_filename) |
| 82 interface_name, _ = os.path.splitext(basename) |
| 83 verbose = options.verbose |
| 84 if verbose: |
| 85 print idl_filename |
| 86 |
| 87 idl_definitions = idl_reader.read_idl_interface(idl_filename, options.interf
ace_dependencies_file, options.additional_idl_files) |
| 88 # FIXME: add parameters when add validator |
| 89 # idl_definitions = idl_reader.read_idl_interface(idl_filename, options.inte
rface_dependencies_file, options.additional_idl_files, options.idl_attributes_fi
le, verbose=verbose) |
| 90 if not idl_definitions: |
| 91 # We generate dummy .h and .cpp files just to tell build scripts |
| 92 # that outputs have been created. |
| 93 code_generator_v8.generate_dummy_header_and_cpp(interface_name, options.
output_directory) |
| 94 return |
| 95 # FIXME: turn on code generator |
| 96 # Currently idl_definitions must be None (so dummy .h and .cpp files are |
| 97 # generated), as actual code generator not present yet. |
| 98 # code_generator_v8.write_interface(idl_definitions, interface_name, options
.output_directory) |
| 99 raise RuntimeError('Stub: code generator not implemented yet') |
| 100 |
| 101 |
| 102 if __name__ == '__main__': |
| 103 sys.exit(main()) |
OLD | NEW |