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