Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: Source/bindings/scripts/idl_compiler.py

Issue 24156003: Revert IDL compiler build flow to Perl, rename 'deprecated' (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 pickle
47 import posixpath
48 import shlex
49 import sys
50
51 import code_generator_v8
52 import idl_reader
53
54 module_path, _ = os.path.split(__file__)
55 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir))
56
57 def parse_options():
58 parser = optparse.OptionParser()
59 parser.add_option('--additional-idl-files')
60 # FIXME: The --dump-json-and-pickle option is only for debugging and will
61 # be removed once we complete migrating all IDL files from the Perl flow to
62 # the Python flow.
63 parser.add_option('--dump-json-and-pickle', action='store_true', default=Fal se)
64 parser.add_option('--idl-attributes-file')
65 parser.add_option('--include', dest='idl_directories', action='append')
66 parser.add_option('--output-directory')
67 parser.add_option('--interface-dependencies-file')
68 parser.add_option('--verbose', action='store_true', default=False)
69 parser.add_option('--write-file-only-if-changed', type='int')
70 # ensure output comes last, so command line easy to parse via regexes
71 parser.disable_interspersed_args()
72
73 options, args = parser.parse_args()
74 if options.output_directory is None:
75 parser.error('Must specify output directory using --output-directory.')
76 if options.additional_idl_files is None:
77 options.additional_idl_files = []
78 else:
79 # additional_idl_files is passed as a string with varied (shell-style)
80 # quoting, hence needs parsing.
81 options.additional_idl_files = shlex.split(options.additional_idl_files)
82 if len(args) != 1:
83 parser.error('Must specify exactly 1 input file as argument, but %d give n.' % len(args))
84 options.idl_filename = os.path.realpath(args[0])
85 return options
86
87
88 def get_relative_dir_posix(filename):
89 """Returns directory of a local file relative to Source, in POSIX format."""
90 relative_path_local = os.path.relpath(filename, source_path)
91 relative_dir_local = os.path.dirname(relative_path_local)
92 return relative_dir_local.replace(os.path.sep, posixpath.sep)
93
94
95 def write_json_and_pickle(definitions, interface_name, output_directory):
96 json_string = definitions.to_json()
97 json_basename = interface_name + '.json'
98 json_filename = os.path.join(output_directory, json_basename)
99 with open(json_filename, 'w') as json_file:
100 json_file.write(json_string)
101 pickle_basename = interface_name + '.pkl'
102 pickle_filename = os.path.join(output_directory, pickle_basename)
103 with open(pickle_filename, 'wb') as pickle_file:
104 pickle.dump(definitions, pickle_file)
105
106
107 def main():
108 options = parse_options()
109 idl_filename = options.idl_filename
110 basename = os.path.basename(idl_filename)
111 interface_name, _ = os.path.splitext(basename)
112 output_directory = options.output_directory
113 verbose = options.verbose
114 if verbose:
115 print idl_filename
116 relative_dir_posix = get_relative_dir_posix(idl_filename)
117
118 reader = idl_reader.IdlReader(options.interface_dependencies_file, options.a dditional_idl_files, options.idl_attributes_file, output_directory, verbose)
119 definitions = reader.read_idl_definitions(idl_filename)
120 code_generator = code_generator_v8.CodeGeneratorV8(definitions, interface_na me, options.output_directory, relative_dir_posix, options.idl_directories, verbo se)
121 if not definitions:
122 # We generate dummy .h and .cpp files just to tell build scripts
123 # that outputs have been created.
124 code_generator.write_dummy_header_and_cpp()
125 return
126 if options.dump_json_and_pickle:
127 write_json_and_pickle(definitions, interface_name, output_directory)
128 return
129 code_generator.write_header_and_cpp()
130
131
132 if __name__ == '__main__':
133 sys.exit(main())
OLDNEW
« no previous file with comments | « Source/bindings/scripts/generate_bindings.pl ('k') | Source/bindings/scripts/idl_definitions.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698