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

Side by Side Diff: sky/engine/bindings-dart/dart/scripts/dart_compiler.py

Issue 875013003: Import Dart bindings as of Blink r188698. This merely copies the files over and does not attach any… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (C) 2013 Google Inc. All rights reserved. 2 # Copyright (C) 2013 Google Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer 11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the 12 # in the documentation and/or other materials provided with the
13 # distribution. 13 # distribution.
14 # * Neither the name of Google Inc. nor the names of its 14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from 15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission. 16 # this software without specific prior written permission.
17 # 17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 29
30 """Compile an .idl file to Blink V8 bindings (.h and .cpp files). 30 """Compile an .idl file to Blink C++ bindings (.h and .cpp files) for Dart:HTML.
31 31
32 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 32 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
33 """ 33 """
34 34
35 import abc 35 import abc
36 from optparse import OptionParser 36 from optparse import OptionParser
37 import os 37 import os
38 import cPickle as pickle 38 import cPickle as pickle
39 import sys
40 39
41 from code_generator_v8 import CodeGeneratorDictionaryImpl, CodeGeneratorV8
42 from idl_reader import IdlReader 40 from idl_reader import IdlReader
43 from utilities import read_idl_files_list_from_file, write_file 41 from utilities import write_file
42
43
44 # TODO(terry): Temporary whitelist of IDL files to skip code generating. e.g.,
45 # adding 'Animation.idl' to this list will skip that IDL file.
46 SKIP_IDL_FILES = ['']
44 47
45 48
46 def parse_options(): 49 def parse_options():
47 parser = OptionParser() 50 parser = OptionParser()
48 parser.add_option('--cache-directory', 51 parser.add_option('--idl-attributes-file',
49 help='cache directory, defaults to output directory') 52 help="location of bindings/IDLExtendedAttributes.txt")
50 parser.add_option('--generate-dictionary-impl',
51 action="store_true", default=False)
52 parser.add_option('--output-directory') 53 parser.add_option('--output-directory')
53 parser.add_option('--interfaces-info-file') 54 parser.add_option('--interfaces-info-file')
54 parser.add_option('--write-file-only-if-changed', type='int') 55 parser.add_option('--write-file-only-if-changed', type='int')
55 # ensure output comes last, so command line easy to parse via regexes 56 # ensure output comes last, so command line easy to parse via regexes
56 parser.disable_interspersed_args() 57 parser.disable_interspersed_args()
57 58
58 options, args = parser.parse_args() 59 options, args = parser.parse_args()
59 if options.output_directory is None: 60 if options.output_directory is None:
60 parser.error('Must specify output directory using --output-directory.') 61 parser.error('Must specify output directory using --output-directory.')
61 options.write_file_only_if_changed = bool(options.write_file_only_if_changed ) 62 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
(...skipping 12 matching lines...) Expand all
74 class IdlCompiler(object): 75 class IdlCompiler(object):
75 """Abstract Base Class for IDL compilers. 76 """Abstract Base Class for IDL compilers.
76 77
77 In concrete classes: 78 In concrete classes:
78 * self.code_generator must be set, implementing generate_code() 79 * self.code_generator must be set, implementing generate_code()
79 (returning a list of output code), and 80 (returning a list of output code), and
80 * compile_file() must be implemented (handling output filenames). 81 * compile_file() must be implemented (handling output filenames).
81 """ 82 """
82 __metaclass__ = abc.ABCMeta 83 __metaclass__ = abc.ABCMeta
83 84
84 def __init__(self, output_directory, cache_directory='', 85 def __init__(self, output_directory, code_generator=None,
85 code_generator=None, interfaces_info=None, 86 interfaces_info=None, interfaces_info_filename='',
86 interfaces_info_filename='', only_if_changed=False): 87 only_if_changed=False):
87 """ 88 """
88 Args: 89 Args:
89 interfaces_info: 90 interfaces_info:
90 interfaces_info dict 91 interfaces_info dict
91 (avoids auxiliary file in run-bindings-tests) 92 (avoids auxiliary file in run-bindings-tests)
92 interfaces_info_file: filename of pickled interfaces_info 93 interfaces_info_file: filename of pickled interfaces_info
93 """ 94 """
94 cache_directory = cache_directory or output_directory
95 self.cache_directory = cache_directory
96 self.code_generator = code_generator 95 self.code_generator = code_generator
97 if interfaces_info_filename: 96 if interfaces_info_filename:
98 with open(interfaces_info_filename) as interfaces_info_file: 97 with open(interfaces_info_filename) as interfaces_info_file:
99 interfaces_info = pickle.load(interfaces_info_file) 98 interfaces_info = pickle.load(interfaces_info_file)
100 self.interfaces_info = interfaces_info 99 self.interfaces_info = interfaces_info
100
101 self.only_if_changed = only_if_changed 101 self.only_if_changed = only_if_changed
102 self.output_directory = output_directory 102 self.output_directory = output_directory
103 self.reader = IdlReader(interfaces_info, cache_directory) 103 self.reader = IdlReader(interfaces_info, output_directory)
104 104
105 def compile_and_write(self, idl_filename): 105 def compile_and_write(self, idl_filename, output_filenames):
106 interface_name = idl_filename_to_interface_name(idl_filename) 106 interface_name = idl_filename_to_interface_name(idl_filename)
107 idl_pickle_filename = os.path.join(self.output_directory,
108 '%s_globals.pickle' % interface_name)
107 definitions = self.reader.read_idl_definitions(idl_filename) 109 definitions = self.reader.read_idl_definitions(idl_filename)
108 output_code_list = self.code_generator.generate_code( 110 output_code_list = self.code_generator.generate_code(definitions,
109 definitions, interface_name) 111 interface_name,
110 for output_path, output_code in output_code_list: 112 idl_pickle_filename ,
111 write_file(output_code, output_path, self.only_if_changed) 113 self.only_if_change d)
114
115 # TODO(terry): Temporary to disable code generating an IDL.
116 base_idl_filename = os.path.basename(idl_filename)
117 if base_idl_filename in SKIP_IDL_FILES:
118 print "----- Skipping %s -----" % base_idl_filename
119 else:
120 for output_code, output_filename in zip(output_code_list, output_fil enames):
121 write_file(output_code, output_filename, self.only_if_changed)
122
123 def generate_global_and_write(self, global_entries, output_filenames):
124 output_code_list = self.code_generator.generate_globals(global_entries)
125 for output_code, output_filename in zip(output_code_list, output_filenam es):
126 write_file(output_code, output_filename, self.only_if_changed)
127
128 def generate_dart_blink_and_write(self, global_entries, output_filename):
129 output_code = self.code_generator.generate_dart_blink(global_entries)
130 write_file(output_code, output_filename, self.only_if_changed)
112 131
113 @abc.abstractmethod 132 @abc.abstractmethod
114 def compile_file(self, idl_filename): 133 def compile_file(self, idl_filename):
115 pass 134 pass
116
117
118 class IdlCompilerV8(IdlCompiler):
119 def __init__(self, *args, **kwargs):
120 IdlCompiler.__init__(self, *args, **kwargs)
121 self.code_generator = CodeGeneratorV8(self.interfaces_info,
122 self.cache_directory,
123 self.output_directory)
124
125 def compile_file(self, idl_filename):
126 self.compile_and_write(idl_filename)
127
128
129 class IdlCompilerDictionaryImpl(IdlCompiler):
130 def __init__(self, *args, **kwargs):
131 IdlCompiler.__init__(self, *args, **kwargs)
132 self.code_generator = CodeGeneratorDictionaryImpl(
133 self.interfaces_info, self.cache_directory, self.output_directory)
134
135 def compile_file(self, idl_filename):
136 self.compile_and_write(idl_filename)
137
138
139 def generate_bindings(options, input_filename):
140 idl_compiler = IdlCompilerV8(
141 options.output_directory,
142 cache_directory=options.cache_directory,
143 interfaces_info_filename=options.interfaces_info_file,
144 only_if_changed=options.write_file_only_if_changed)
145 idl_compiler.compile_file(input_filename)
146
147
148 def generate_dictionary_impl(options, input_filename):
149 idl_compiler = IdlCompilerDictionaryImpl(
150 options.output_directory,
151 cache_directory=options.cache_directory,
152 interfaces_info_filename=options.interfaces_info_file,
153 only_if_changed=options.write_file_only_if_changed)
154
155 idl_filenames = read_idl_files_list_from_file(input_filename)
156 for idl_filename in idl_filenames:
157 idl_compiler.compile_file(idl_filename)
158
159
160 def main():
161 options, input_filename = parse_options()
162 if options.generate_dictionary_impl:
163 # |input_filename| should be a file which contains a list of IDL
164 # dictionary paths.
165 generate_dictionary_impl(options, input_filename)
166 else:
167 # |input_filename| should be a path of an IDL file.
168 generate_bindings(options, input_filename)
169
170
171 if __name__ == '__main__':
172 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698