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. | |
43 First we will land the build changes and idl_compiler.py (in one CL). | |
44 Next we will land all Python files except the code generator (in one CL), | |
45 which reads all IDL files. | |
46 Finally we will incrementally land the code generator (in several CLs), | |
47 moving IDL files to the Python build flow as the code generator is completed. | |
haraken
2013/07/10 06:22:48
I'd remove the part from "First we will...". You c
Nils Barth (inactive)
2013/07/10 07:04:11
Done, at the tracker bug:
Issue 239771: Rewrite th
| |
48 """ | |
49 import optparse | |
50 import os | |
51 import shlex | |
52 import sys | |
53 | |
54 import idl_reader | |
55 import code_generator_v8 | |
56 | |
57 | |
58 def parse_options(): | |
59 parser = optparse.OptionParser() | |
60 parser.add_option('--additional-idl-files') | |
61 parser.add_option('--idl-attributes-file') | |
62 parser.add_option('--include', dest='idl_directories', action='append') | |
63 parser.add_option('--output-directory') | |
64 parser.add_option('--interface-dependencies-file') | |
65 parser.add_option('--verbose', action='store_true', default=False) | |
66 parser.add_option('--write-file-only-if-changed', type='int') | |
67 # ensure output comes last, so command line easy to parse via regexes | |
68 parser.disable_interspersed_args() | |
69 | |
70 options, args = parser.parse_args() | |
71 if options.output_directory is None: | |
72 parser.error('Must specify output directory using --output-directory.') | |
73 if options.additional_idl_files is not None: | |
74 # additional_idl_files is passed as a string with varied (shell-style) | |
75 # quoting, hence needs parsing. | |
76 options.additional_idl_files = shlex.split(options.additional_idl_files) | |
77 if len(args) != 1: | |
78 parser.error('Must specify exactly 1 input file as argument, but %d give n.' % len(args)) | |
79 options.idl_filename = os.path.realpath(args[0]) | |
80 return options | |
81 | |
82 | |
83 def main(): | |
84 options = parse_options() | |
85 idl_filename = options.idl_filename | |
86 basename = os.path.basename(idl_filename) | |
87 interface_name, _ = os.path.splitext(basename) | |
88 verbose = options.verbose | |
89 if verbose: | |
90 print idl_filename | |
91 | |
92 idl_document = idl_reader.read_idl_interface(idl_filename, options.interface _dependencies_file, options.additional_idl_files) | |
93 # FIXME: add parameters when add validator | |
94 # idl_document = idl_reader.read_idl_interface(idl_filename, options.interfa ce_dependencies_file, options.additional_idl_files, options.idl_attributes_file, verbose=verbose) | |
95 if not idl_document: | |
96 # We generate dummy .h and .cpp files just to tell build scripts | |
97 # that outputs have been created. | |
98 code_generator_v8.generate_dummy_header_and_cpp(interface_name, options. output_directory) | |
99 return | |
100 # FIXME: turn on code generator | |
101 # Currently idl_document must be None (so dummy .h and .cpp files are | |
102 # generated), as actual code generator not present yet. | |
103 # code_generator_v8.write_interface(idl_document, interface_name, options.ou tput_directory) | |
104 raise RuntimeError('Stub: code generator not implemented yet') | |
105 | |
106 | |
107 if __name__ == '__main__': | |
108 sys.exit(main()) | |
OLD | NEW |