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

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

Issue 959933002: Move IDLs to 39 roll (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
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 | Annotate | Revision Log
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 CodeGeneratorV8 41 from code_generator_v8 import CodeGeneratorDictionaryImpl, CodeGeneratorV8
42 from idl_reader import IdlReader 42 from idl_reader import IdlReader
43 from utilities import write_file 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',
51 action="store_true", default=False)
50 parser.add_option('--output-directory') 52 parser.add_option('--output-directory')
51 parser.add_option('--interfaces-info-file') 53 parser.add_option('--interfaces-info-file')
52 parser.add_option('--write-file-only-if-changed', type='int') 54 parser.add_option('--write-file-only-if-changed', type='int')
53 # ensure output comes last, so command line easy to parse via regexes 55 # ensure output comes last, so command line easy to parse via regexes
54 parser.disable_interspersed_args() 56 parser.disable_interspersed_args()
55 57
56 options, args = parser.parse_args() 58 options, args = parser.parse_args()
57 if options.output_directory is None: 59 if options.output_directory is None:
58 parser.error('Must specify output directory using --output-directory.') 60 parser.error('Must specify output directory using --output-directory.')
59 options.write_file_only_if_changed = bool(options.write_file_only_if_changed ) 61 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 if interfaces_info_filename: 97 if interfaces_info_filename:
96 with open(interfaces_info_filename) as interfaces_info_file: 98 with open(interfaces_info_filename) as interfaces_info_file:
97 interfaces_info = pickle.load(interfaces_info_file) 99 interfaces_info = pickle.load(interfaces_info_file)
98 self.interfaces_info = interfaces_info 100 self.interfaces_info = interfaces_info
99 self.only_if_changed = only_if_changed 101 self.only_if_changed = only_if_changed
100 self.output_directory = output_directory 102 self.output_directory = output_directory
101 self.reader = IdlReader(interfaces_info, cache_directory) 103 self.reader = IdlReader(interfaces_info, cache_directory)
102 104
103 def compile_and_write(self, idl_filename): 105 def compile_and_write(self, idl_filename):
104 interface_name = idl_filename_to_interface_name(idl_filename) 106 interface_name = idl_filename_to_interface_name(idl_filename)
107 component = idl_filename_to_component(idl_filename)
105 definitions = self.reader.read_idl_definitions(idl_filename) 108 definitions = self.reader.read_idl_definitions(idl_filename)
106 output_code_list = self.code_generator.generate_code( 109 output_code_list = self.code_generator.generate_code(
107 definitions, interface_name) 110 definitions[component], interface_name)
108 for output_path, output_code in output_code_list: 111 for output_path, output_code in output_code_list:
109 write_file(output_code, output_path, self.only_if_changed) 112 write_file(output_code, output_path, self.only_if_changed)
110 113
111 @abc.abstractmethod 114 @abc.abstractmethod
112 def compile_file(self, idl_filename): 115 def compile_file(self, idl_filename):
113 pass 116 pass
114 117
115 118
116 class IdlCompilerV8(IdlCompiler): 119 class IdlCompilerV8(IdlCompiler):
117 def __init__(self, *args, **kwargs): 120 def __init__(self, *args, **kwargs):
118 IdlCompiler.__init__(self, *args, **kwargs) 121 IdlCompiler.__init__(self, *args, **kwargs)
119 self.code_generator = CodeGeneratorV8(self.interfaces_info, 122 self.code_generator = CodeGeneratorV8(self.interfaces_info,
120 self.cache_directory, 123 self.cache_directory,
121 self.output_directory) 124 self.output_directory)
122 125
123 def compile_file(self, idl_filename): 126 def compile_file(self, idl_filename):
124 self.compile_and_write(idl_filename) 127 self.compile_and_write(idl_filename)
125 128
126 129
127 def main(): 130 class IdlCompilerDictionaryImpl(IdlCompiler):
128 options, idl_filename = parse_options() 131 def __init__(self, *args, **kwargs):
132 IdlCompiler.__init__(self, *args, **kwargs)
133 self.code_generator = CodeGeneratorDictionaryImpl(
134 self.interfaces_info, self.cache_directory, self.output_directory)
135
136 def compile_file(self, idl_filename):
137 self.compile_and_write(idl_filename)
138
139
140 def generate_bindings(options, input_filename):
129 idl_compiler = IdlCompilerV8( 141 idl_compiler = IdlCompilerV8(
130 options.output_directory, 142 options.output_directory,
131 cache_directory=options.cache_directory, 143 cache_directory=options.cache_directory,
132 interfaces_info_filename=options.interfaces_info_file, 144 interfaces_info_filename=options.interfaces_info_file,
133 only_if_changed=options.write_file_only_if_changed) 145 only_if_changed=options.write_file_only_if_changed)
134 idl_compiler.compile_file(idl_filename) 146 idl_compiler.compile_file(input_filename)
147
148
149 def generate_dictionary_impl(options, input_filename):
150 idl_compiler = IdlCompilerDictionaryImpl(
151 options.output_directory,
152 cache_directory=options.cache_directory,
153 interfaces_info_filename=options.interfaces_info_file,
154 only_if_changed=options.write_file_only_if_changed)
155
156 idl_filenames = read_idl_files_list_from_file(input_filename)
157 for idl_filename in idl_filenames:
158 idl_compiler.compile_file(idl_filename)
159
160
161 def main():
162 options, input_filename = parse_options()
163 if options.generate_dictionary_impl:
164 # |input_filename| should be a file which contains a list of IDL
165 # dictionary paths.
166 generate_dictionary_impl(options, input_filename)
167 else:
168 # |input_filename| should be a path of an IDL file.
169 generate_bindings(options, input_filename)
135 170
136 171
137 if __name__ == '__main__': 172 if __name__ == '__main__':
138 sys.exit(main()) 173 sys.exit(main())
OLDNEW
« no previous file with comments | « bindings/scripts/compute_interfaces_info_overall.py ('k') | bindings/scripts/idl_definitions.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698