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

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

Issue 1248043003: Initial patch for the web modules layered platform proposal. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 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
(...skipping 21 matching lines...) Expand all
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, Code GeneratorUnionType 41 from code_generator_v8 import CodeGeneratorDictionaryImpl, CodeGeneratorV8, Code GeneratorUnionType
42 from code_generator_web_modules import CodeGeneratorWebModules
42 from idl_reader import IdlReader 43 from idl_reader import IdlReader
43 from utilities import create_component_info_provider, read_idl_files_list_from_f ile, write_file, idl_filename_to_component 44 from utilities import create_component_info_provider, read_idl_files_list_from_f ile, write_file, idl_filename_to_component
44 45
45 46
46 def parse_options(): 47 def parse_options():
47 parser = OptionParser() 48 parser = OptionParser()
48 parser.add_option('--cache-directory', 49 parser.add_option('--cache-directory',
49 help='cache directory, defaults to output directory') 50 help='cache directory, defaults to output directory')
50 parser.add_option('--generate-impl', 51 parser.add_option('--generate-impl',
51 action="store_true", default=False) 52 action="store_true", default=False)
52 parser.add_option('--output-directory') 53 parser.add_option('--output-directory')
53 parser.add_option('--impl-output-directory') 54 parser.add_option('--impl-output-directory')
54 parser.add_option('--info-dir') 55 parser.add_option('--info-dir')
56 parser.add_option('--web-modules',
57 action="store_true", default=False)
55 parser.add_option('--write-file-only-if-changed', type='int') 58 parser.add_option('--write-file-only-if-changed', type='int')
56 # FIXME: We should always explicitly specify --target-component and 59 # FIXME: We should always explicitly specify --target-component and
57 # remove the default behavior. 60 # remove the default behavior.
58 parser.add_option('--target-component', 61 parser.add_option('--target-component',
59 help='target component to generate code, defaults to ' 62 help='target component to generate code, defaults to '
60 'component of input idl file') 63 'component of input idl file')
61 # ensure output comes last, so command line easy to parse via regexes 64 # ensure output comes last, so command line easy to parse via regexes
62 parser.disable_interspersed_args() 65 parser.disable_interspersed_args()
63 66
64 options, args = parser.parse_args() 67 options, args = parser.parse_args()
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 def __init__(self, *args, **kwargs): 130 def __init__(self, *args, **kwargs):
128 IdlCompiler.__init__(self, *args, **kwargs) 131 IdlCompiler.__init__(self, *args, **kwargs)
129 self.code_generator = CodeGeneratorV8(self.info_provider, 132 self.code_generator = CodeGeneratorV8(self.info_provider,
130 self.cache_directory, 133 self.cache_directory,
131 self.output_directory) 134 self.output_directory)
132 135
133 def compile_file(self, idl_filename): 136 def compile_file(self, idl_filename):
134 self.compile_and_write(idl_filename) 137 self.compile_and_write(idl_filename)
135 138
136 139
140 class IdlCompilerWebModules(IdlCompiler):
141 def __init__(self, *args, **kwargs):
142 IdlCompiler.__init__(self, *args, **kwargs)
143 self.code_generator = CodeGeneratorWebModules(self.info_provider,
144 self.cache_directory,
145 self.output_directory)
146
147 def compile_file(self, idl_filename):
148 self.compile_and_write(idl_filename)
149
150
137 class IdlCompilerDictionaryImpl(IdlCompiler): 151 class IdlCompilerDictionaryImpl(IdlCompiler):
138 def __init__(self, *args, **kwargs): 152 def __init__(self, *args, **kwargs):
139 IdlCompiler.__init__(self, *args, **kwargs) 153 IdlCompiler.__init__(self, *args, **kwargs)
140 self.code_generator = CodeGeneratorDictionaryImpl( 154 self.code_generator = CodeGeneratorDictionaryImpl(
141 self.info_provider, self.cache_directory, self.output_directory) 155 self.info_provider, self.cache_directory, self.output_directory)
142 156
143 def compile_file(self, idl_filename): 157 def compile_file(self, idl_filename):
144 self.compile_and_write(idl_filename) 158 self.compile_and_write(idl_filename)
145 159
146 160
147 def generate_bindings(options, input_filename): 161 def generate_bindings(options, input_filename):
148 info_provider = create_component_info_provider( 162 info_provider = create_component_info_provider(
149 options.info_dir, options.target_component) 163 options.info_dir, options.target_component)
150 idl_compiler = IdlCompilerV8(
151 options.output_directory,
152 cache_directory=options.cache_directory,
153 info_provider=info_provider,
154 only_if_changed=options.write_file_only_if_changed,
155 target_component=options.target_component)
156 idl_compiler.compile_file(input_filename)
157 164
165 if options.web_modules:
166 web_modules_compiler = IdlCompilerWebModules(
167 os.path.join(options.output_directory, "webmodules"),
168 cache_directory=options.cache_directory,
169 info_provider=info_provider,
170 only_if_changed=options.write_file_only_if_changed,
171 target_component=options.target_component)
172 web_modules_compiler.compile_file(input_filename)
173 else:
174 idl_compiler = IdlCompilerV8(
175 os.path.join(options.output_directory, "v8"),
176 cache_directory=options.cache_directory,
177 info_provider=info_provider,
178 only_if_changed=options.write_file_only_if_changed,
179 target_component=options.target_component)
180 idl_compiler.compile_file(input_filename)
158 181
159 def generate_dictionary_impl(options, input_filename): 182 def generate_dictionary_impl(options, input_filename):
160 info_provider = create_component_info_provider( 183 info_provider = create_component_info_provider(
161 options.info_dir, options.target_component) 184 options.info_dir, options.target_component)
162 idl_compiler = IdlCompilerDictionaryImpl( 185 idl_compiler = IdlCompilerDictionaryImpl(
163 options.impl_output_directory, 186 options.impl_output_directory,
164 cache_directory=options.cache_directory, 187 cache_directory=options.cache_directory,
165 info_provider=info_provider, 188 info_provider=info_provider,
166 only_if_changed=options.write_file_only_if_changed) 189 only_if_changed=options.write_file_only_if_changed)
167 190
(...skipping 25 matching lines...) Expand all
193 # dictionary paths. 216 # dictionary paths.
194 generate_dictionary_impl(options, input_filename) 217 generate_dictionary_impl(options, input_filename)
195 generate_union_type_containers(options) 218 generate_union_type_containers(options)
196 else: 219 else:
197 # |input_filename| should be a path of an IDL file. 220 # |input_filename| should be a path of an IDL file.
198 generate_bindings(options, input_filename) 221 generate_bindings(options, input_filename)
199 222
200 223
201 if __name__ == '__main__': 224 if __name__ == '__main__':
202 sys.exit(main()) 225 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698