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

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

Issue 680193003: IDL: Generate union type containers (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month 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
(...skipping 20 matching lines...) Expand all
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 39 import sys
40 40
41 from code_generator_v8 import CodeGeneratorDictionaryImpl, CodeGeneratorV8 41 from code_generator_v8 import CodeGeneratorDictionaryImpl, CodeGeneratorV8, Code GeneratorUnionTypeContainers
42 from idl_reader import IdlReader 42 from idl_reader import IdlReader
43 from utilities import read_idl_files_list_from_file, write_file, idl_filename_to _component 43 from utilities import read_idl_files_list_from_file, write_file, idl_filename_to _component
44 44
45 45
46 def parse_options(): 46 def parse_options():
47 parser = OptionParser() 47 parser = OptionParser()
48 parser.add_option('--cache-directory', 48 parser.add_option('--cache-directory',
49 help='cache directory, defaults to output directory') 49 help='cache directory, defaults to output directory')
50 parser.add_option('--generate-dictionary-impl', 50 parser.add_option('--generate-impl',
51 action="store_true", default=False) 51 action="store_true", default=False)
52 parser.add_option('--output-directory') 52 parser.add_option('--output-directory')
53 parser.add_option('--dictionary-impl-output-directory')
53 parser.add_option('--interfaces-info-file') 54 parser.add_option('--interfaces-info-file')
55 parser.add_option('--individual-info-file')
54 parser.add_option('--write-file-only-if-changed', type='int') 56 parser.add_option('--write-file-only-if-changed', type='int')
55 # FIXME: We should always explicitly specify --target-component and 57 # FIXME: We should always explicitly specify --target-component and
56 # remove the default behavior. 58 # remove the default behavior.
57 parser.add_option('--target-component', 59 parser.add_option('--target-component',
58 help='target component to generate code, defaults to ' 60 help='target component to generate code, defaults to '
59 'component of input idl file') 61 'component of input idl file')
60 # ensure output comes last, so command line easy to parse via regexes 62 # ensure output comes last, so command line easy to parse via regexes
61 parser.disable_interspersed_args() 63 parser.disable_interspersed_args()
62 64
63 options, args = parser.parse_args() 65 options, args = parser.parse_args()
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 options.output_directory, 151 options.output_directory,
150 cache_directory=options.cache_directory, 152 cache_directory=options.cache_directory,
151 interfaces_info_filename=options.interfaces_info_file, 153 interfaces_info_filename=options.interfaces_info_file,
152 only_if_changed=options.write_file_only_if_changed, 154 only_if_changed=options.write_file_only_if_changed,
153 target_component=options.target_component) 155 target_component=options.target_component)
154 idl_compiler.compile_file(input_filename) 156 idl_compiler.compile_file(input_filename)
155 157
156 158
157 def generate_dictionary_impl(options, input_filename): 159 def generate_dictionary_impl(options, input_filename):
158 idl_compiler = IdlCompilerDictionaryImpl( 160 idl_compiler = IdlCompilerDictionaryImpl(
159 options.output_directory, 161 options.dictionary_impl_output_directory,
160 cache_directory=options.cache_directory, 162 cache_directory=options.cache_directory,
161 interfaces_info_filename=options.interfaces_info_file, 163 interfaces_info_filename=options.interfaces_info_file,
162 only_if_changed=options.write_file_only_if_changed) 164 only_if_changed=options.write_file_only_if_changed)
163 165
164 idl_filenames = read_idl_files_list_from_file(input_filename) 166 idl_filenames = read_idl_files_list_from_file(input_filename)
165 for idl_filename in idl_filenames: 167 for idl_filename in idl_filenames:
166 idl_compiler.compile_file(idl_filename) 168 idl_compiler.compile_file(idl_filename)
167 169
168 170
171 def generate_union_type_containers(options):
172 if not (options.interfaces_info_file and options.individual_info_file):
173 raise Exception('Interfaces info is required to generate '
174 'union types containers')
175 with open(options.interfaces_info_file) as interfaces_info_file:
176 interfaces_info = pickle.load(interfaces_info_file)
177 with open(options.individual_info_file) as individual_info_file:
178 individual_info = pickle.load(individual_info_file)
179 generator = CodeGeneratorUnionTypeContainers(
180 interfaces_info,
181 options.cache_directory,
182 options.output_directory,
183 options.target_component)
184 output_code_list = generator.generate_code(individual_info['union_types'])
185 for output_path, output_code in output_code_list:
186 write_file(output_code, output_path, options.write_file_only_if_changed)
187
188
169 def main(): 189 def main():
170 options, input_filename = parse_options() 190 options, input_filename = parse_options()
171 if options.generate_dictionary_impl: 191 if options.generate_impl:
172 # |input_filename| should be a file which contains a list of IDL 192 # |input_filename| should be a file which contains a list of IDL
173 # dictionary paths. 193 # dictionary paths.
174 generate_dictionary_impl(options, input_filename) 194 generate_dictionary_impl(options, input_filename)
195 generate_union_type_containers(options)
175 else: 196 else:
176 # |input_filename| should be a path of an IDL file. 197 # |input_filename| should be a path of an IDL file.
177 generate_bindings(options, input_filename) 198 generate_bindings(options, input_filename)
178 199
179 200
180 if __name__ == '__main__': 201 if __name__ == '__main__':
181 sys.exit(main()) 202 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698