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

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

Issue 618373003: [bindings] partial interfaces should not violate componentization (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Added --target-component instead of --genearte-partial Created 6 years, 2 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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-dictionary-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('--interfaces-info-file') 53 parser.add_option('--interfaces-info-file')
54 parser.add_option('--write-file-only-if-changed', type='int') 54 parser.add_option('--write-file-only-if-changed', type='int')
55 parser.add_option('--target-component',
56 help='target component to generate code, defaults to '
57 'component of input idl file')
tasak 2014/10/14 05:28:20 Now specifying target component instead of --gener
55 # ensure output comes last, so command line easy to parse via regexes 58 # ensure output comes last, so command line easy to parse via regexes
56 parser.disable_interspersed_args() 59 parser.disable_interspersed_args()
57 60
58 options, args = parser.parse_args() 61 options, args = parser.parse_args()
59 if options.output_directory is None: 62 if options.output_directory is None:
60 parser.error('Must specify output directory using --output-directory.') 63 parser.error('Must specify output directory using --output-directory.')
61 options.write_file_only_if_changed = bool(options.write_file_only_if_changed ) 64 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
62 if len(args) != 1: 65 if len(args) != 1:
63 parser.error('Must specify exactly 1 input file as argument, but %d give n.' % len(args)) 66 parser.error('Must specify exactly 1 input file as argument, but %d give n.' % len(args))
64 idl_filename = os.path.realpath(args[0]) 67 idl_filename = os.path.realpath(args[0])
(...skipping 11 matching lines...) Expand all
76 79
77 In concrete classes: 80 In concrete classes:
78 * self.code_generator must be set, implementing generate_code() 81 * self.code_generator must be set, implementing generate_code()
79 (returning a list of output code), and 82 (returning a list of output code), and
80 * compile_file() must be implemented (handling output filenames). 83 * compile_file() must be implemented (handling output filenames).
81 """ 84 """
82 __metaclass__ = abc.ABCMeta 85 __metaclass__ = abc.ABCMeta
83 86
84 def __init__(self, output_directory, cache_directory='', 87 def __init__(self, output_directory, cache_directory='',
85 code_generator=None, interfaces_info=None, 88 code_generator=None, interfaces_info=None,
86 interfaces_info_filename='', only_if_changed=False): 89 interfaces_info_filename='', only_if_changed=False,
90 target_component=None):
87 """ 91 """
88 Args: 92 Args:
89 interfaces_info: 93 interfaces_info:
90 interfaces_info dict 94 interfaces_info dict
91 (avoids auxiliary file in run-bindings-tests) 95 (avoids auxiliary file in run-bindings-tests)
92 interfaces_info_file: filename of pickled interfaces_info 96 interfaces_info_file: filename of pickled interfaces_info
93 """ 97 """
94 cache_directory = cache_directory or output_directory 98 cache_directory = cache_directory or output_directory
95 self.cache_directory = cache_directory 99 self.cache_directory = cache_directory
96 self.code_generator = code_generator 100 self.code_generator = code_generator
97 if interfaces_info_filename: 101 if interfaces_info_filename:
98 with open(interfaces_info_filename) as interfaces_info_file: 102 with open(interfaces_info_filename) as interfaces_info_file:
99 interfaces_info = pickle.load(interfaces_info_file) 103 interfaces_info = pickle.load(interfaces_info_file)
100 self.interfaces_info = interfaces_info 104 self.interfaces_info = interfaces_info
101 self.only_if_changed = only_if_changed 105 self.only_if_changed = only_if_changed
102 self.output_directory = output_directory 106 self.output_directory = output_directory
107 self.target_component = target_component
103 self.reader = IdlReader(interfaces_info, cache_directory) 108 self.reader = IdlReader(interfaces_info, cache_directory)
104 109
105 def compile_and_write(self, idl_filename): 110 def compile_and_write(self, idl_filename):
106 interface_name = idl_filename_to_interface_name(idl_filename) 111 interface_name = idl_filename_to_interface_name(idl_filename)
107 component = idl_filename_to_component(idl_filename)
108 definitions = self.reader.read_idl_definitions(idl_filename) 112 definitions = self.reader.read_idl_definitions(idl_filename)
113 target_component = self.target_component or idl_filename_to_component(id l_filename)
114 target_definitions = definitions[target_component]
109 output_code_list = self.code_generator.generate_code( 115 output_code_list = self.code_generator.generate_code(
110 definitions[component], interface_name) 116 target_definitions, interface_name)
111 for output_path, output_code in output_code_list: 117 for output_path, output_code in output_code_list:
112 write_file(output_code, output_path, self.only_if_changed) 118 write_file(output_code, output_path, self.only_if_changed)
113 119
114 @abc.abstractmethod 120 @abc.abstractmethod
115 def compile_file(self, idl_filename): 121 def compile_file(self, idl_filename):
116 pass 122 pass
117 123
118 124
119 class IdlCompilerV8(IdlCompiler): 125 class IdlCompilerV8(IdlCompiler):
120 def __init__(self, *args, **kwargs): 126 def __init__(self, *args, **kwargs):
(...skipping 14 matching lines...) Expand all
135 141
136 def compile_file(self, idl_filename): 142 def compile_file(self, idl_filename):
137 self.compile_and_write(idl_filename) 143 self.compile_and_write(idl_filename)
138 144
139 145
140 def generate_bindings(options, input_filename): 146 def generate_bindings(options, input_filename):
141 idl_compiler = IdlCompilerV8( 147 idl_compiler = IdlCompilerV8(
142 options.output_directory, 148 options.output_directory,
143 cache_directory=options.cache_directory, 149 cache_directory=options.cache_directory,
144 interfaces_info_filename=options.interfaces_info_file, 150 interfaces_info_filename=options.interfaces_info_file,
145 only_if_changed=options.write_file_only_if_changed) 151 only_if_changed=options.write_file_only_if_changed,
152 target_component=options.target_component)
146 idl_compiler.compile_file(input_filename) 153 idl_compiler.compile_file(input_filename)
147 154
148 155
149 def generate_dictionary_impl(options, input_filename): 156 def generate_dictionary_impl(options, input_filename):
150 idl_compiler = IdlCompilerDictionaryImpl( 157 idl_compiler = IdlCompilerDictionaryImpl(
151 options.output_directory, 158 options.output_directory,
152 cache_directory=options.cache_directory, 159 cache_directory=options.cache_directory,
153 interfaces_info_filename=options.interfaces_info_file, 160 interfaces_info_filename=options.interfaces_info_file,
154 only_if_changed=options.write_file_only_if_changed) 161 only_if_changed=options.write_file_only_if_changed)
155 162
156 idl_filenames = read_idl_files_list_from_file(input_filename) 163 idl_filenames = read_idl_files_list_from_file(input_filename)
157 for idl_filename in idl_filenames: 164 for idl_filename in idl_filenames:
158 idl_compiler.compile_file(idl_filename) 165 idl_compiler.compile_file(idl_filename)
159 166
160 167
161 def main(): 168 def main():
162 options, input_filename = parse_options() 169 options, input_filename = parse_options()
163 if options.generate_dictionary_impl: 170 if options.generate_dictionary_impl:
164 # |input_filename| should be a file which contains a list of IDL 171 # |input_filename| should be a file which contains a list of IDL
165 # dictionary paths. 172 # dictionary paths.
166 generate_dictionary_impl(options, input_filename) 173 generate_dictionary_impl(options, input_filename)
167 else: 174 else:
168 # |input_filename| should be a path of an IDL file. 175 # |input_filename| should be a path of an IDL file.
169 generate_bindings(options, input_filename) 176 generate_bindings(options, input_filename)
170 177
171 178
172 if __name__ == '__main__': 179 if __name__ == '__main__':
173 sys.exit(main()) 180 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698