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

Side by Side Diff: bindings/dart/scripts/compiler.py

Issue 540533002: Roll IDL to Dartium37 (r181268) (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 6 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
« no previous file with comments | « bindings/dart/scripts/code_generator_dart.py ('k') | bindings/dart/scripts/dart_attributes.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/python
2 # Copyright (C) 2014 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 Dart bindings (.h and .cpp files).
31
32 Design doc: ??????
33 """
34
35 from optparse import OptionParser
36 import os
37 import sys
38
39 dart_script_path = os.path.dirname(os.path.abspath(__file__))
40 script_path = os.path.join(os.path.dirname(os.path.dirname(dart_script_path)),
41 'scripts')
42 sys.path.extend([script_path])
43
44 from dart_compiler import IdlCompiler
45 from code_generator_dart import CodeGeneratorDart
46
47
48 def parse_options():
49 parser = OptionParser()
50 parser.add_option('--output-directory')
51 parser.add_option('--interfaces-info-file')
52 parser.add_option('--write-file-only-if-changed', type='int', default='1')
53 parser.add_option('--generate-global', type='int')
54 parser.add_option("-p", "--global-pickle-directories",
55 action="store",
56 type='string',
57 dest="global_pickle_directories",
58 nargs=2,
59 help="Directories to load _globals.pickle files (max 2)")
60
61 # ensure output comes last, so command line easy to parse via regexes
62 parser.disable_interspersed_args()
63
64 options, args = parser.parse_args()
65 if options.output_directory is None:
66 parser.error('Must specify output directory using --output-directory.')
67 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
68 options.generate_global = bool(options.generate_global)
69 if len(args) != 1:
70 # parser.error('Must specify exactly 1 input file as argument, but %d gi ven.' % len(args))
71 return options, None
72 idl_filename = os.path.realpath(args[0])
73 return options, idl_filename
74
75
76 def idl_filename_to_interface_name(idl_filename):
77 basename = os.path.basename(idl_filename)
78 interface_name, _ = os.path.splitext(basename)
79 return interface_name
80
81
82 class IdlCompilerDart(IdlCompiler):
83 def __init__(self, *args, **kwargs):
84 IdlCompiler.__init__(self, *args, **kwargs)
85
86 interfaces_info = self.interfaces_info
87 self.output_directory = self.output_directory
88
89 self.code_generator = CodeGeneratorDart(interfaces_info, self.output_dir ectory)
90
91 def compile_file(self, idl_filename):
92 interface_name = idl_filename_to_interface_name(idl_filename)
93 header_filename = os.path.join(self.output_directory,
94 'Dart%s.h' % interface_name)
95 cpp_filename = os.path.join(self.output_directory,
96 'Dart%s.cpp' % interface_name)
97 self.compile_and_write(idl_filename, (header_filename, cpp_filename))
98
99 def generate_global(self, global_pickle_directories):
100 global_header_filename = os.path.join(self.output_directory, 'DartWebkit ClassIds.h')
101 global_cpp_filename = os.path.join(self.output_directory, 'DartWebkitCla ssIds.cpp')
102 self.generate_global_and_write(global_pickle_directories,
103 (global_header_filename, global_cpp_filen ame))
104
105
106 def main():
107 options, idl_filename = parse_options()
108
109 if options.generate_global:
110 idl_compiler = IdlCompilerDart(options.output_directory,
111 interfaces_info_filename=options.interfac es_info_file,
112 only_if_changed=options.write_file_only_i f_changed)
113 idl_compiler.generate_global(options.global_pickle_directories)
114 else:
115 idl_compiler = IdlCompilerDart(options.output_directory,
116 interfaces_info_filename=options.interfac es_info_file,
117 only_if_changed=options.write_file_only_i f_changed)
118 idl_compiler.compile_file(idl_filename)
119
120
121 if __name__ == '__main__':
122 sys.exit(main())
OLDNEW
« no previous file with comments | « bindings/dart/scripts/code_generator_dart.py ('k') | bindings/dart/scripts/dart_attributes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698