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

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

Issue 429853002: IDL: Add build target for IDL dictionary impl generation in core (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 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 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 CodeGeneratorV8, MODE_BINDINGS, MODE_DICTIONARY_IM PL
42 from idl_reader import IdlReader 42 from idl_reader import IdlReader
43 from utilities import write_file 43 from utilities import write_file
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 14 matching lines...) Expand all
74 76
75 In concrete classes: 77 In concrete classes:
76 * self.code_generator must be set, implementing generate_code() 78 * self.code_generator must be set, implementing generate_code()
77 (returning a list of output code), and 79 (returning a list of output code), and
78 * compile_file() must be implemented (handling output filenames). 80 * compile_file() must be implemented (handling output filenames).
79 """ 81 """
80 __metaclass__ = abc.ABCMeta 82 __metaclass__ = abc.ABCMeta
81 83
82 def __init__(self, output_directory, cache_directory='', 84 def __init__(self, output_directory, cache_directory='',
83 code_generator=None, interfaces_info=None, 85 code_generator=None, interfaces_info=None,
84 interfaces_info_filename='', only_if_changed=False): 86 interfaces_info_filename='', only_if_changed=False,
87 generate_dictionary_impl=False):
85 """ 88 """
86 Args: 89 Args:
87 interfaces_info: 90 interfaces_info:
88 interfaces_info dict 91 interfaces_info dict
89 (avoids auxiliary file in run-bindings-tests) 92 (avoids auxiliary file in run-bindings-tests)
90 interfaces_info_file: filename of pickled interfaces_info 93 interfaces_info_file: filename of pickled interfaces_info
91 """ 94 """
92 cache_directory = cache_directory or output_directory 95 cache_directory = cache_directory or output_directory
93 self.cache_directory = cache_directory 96 self.cache_directory = cache_directory
94 self.code_generator = code_generator 97 self.code_generator = code_generator
98 if generate_dictionary_impl:
99 self.generating_mode = MODE_DICTIONARY_IMPL
100 else:
101 self.generating_mode = MODE_BINDINGS
95 if interfaces_info_filename: 102 if interfaces_info_filename:
96 with open(interfaces_info_filename) as interfaces_info_file: 103 with open(interfaces_info_filename) as interfaces_info_file:
97 interfaces_info = pickle.load(interfaces_info_file) 104 interfaces_info = pickle.load(interfaces_info_file)
98 self.interfaces_info = interfaces_info 105 self.interfaces_info = interfaces_info
99 self.only_if_changed = only_if_changed 106 self.only_if_changed = only_if_changed
100 self.output_directory = output_directory 107 self.output_directory = output_directory
101 self.reader = IdlReader(interfaces_info, cache_directory) 108 self.reader = IdlReader(interfaces_info, cache_directory)
102 109
103 def compile_and_write(self, idl_filename): 110 def compile_and_write(self, idl_filename):
104 interface_name = idl_filename_to_interface_name(idl_filename) 111 interface_name = idl_filename_to_interface_name(idl_filename)
105 definitions = self.reader.read_idl_definitions(idl_filename) 112 definitions = self.reader.read_idl_definitions(idl_filename)
106 output_code_list = self.code_generator.generate_code( 113 output_code_list = self.code_generator.generate_code(
107 definitions, interface_name) 114 definitions, interface_name, mode=self.generating_mode)
108 for output_path, output_code in output_code_list: 115 for output_path, output_code in output_code_list:
109 write_file(output_code, output_path, self.only_if_changed) 116 write_file(output_code, output_path, self.only_if_changed)
110 117
111 @abc.abstractmethod 118 @abc.abstractmethod
112 def compile_file(self, idl_filename): 119 def compile_file(self, idl_filename):
113 pass 120 pass
114 121
115 122
116 class IdlCompilerV8(IdlCompiler): 123 class IdlCompilerV8(IdlCompiler):
117 def __init__(self, *args, **kwargs): 124 def __init__(self, *args, **kwargs):
118 IdlCompiler.__init__(self, *args, **kwargs) 125 IdlCompiler.__init__(self, *args, **kwargs)
119 self.code_generator = CodeGeneratorV8(self.interfaces_info, 126 self.code_generator = CodeGeneratorV8(self.interfaces_info,
120 self.cache_directory, 127 self.cache_directory,
121 self.output_directory) 128 self.output_directory)
122 129
123 def compile_file(self, idl_filename): 130 def compile_file(self, idl_filename):
124 self.compile_and_write(idl_filename) 131 self.compile_and_write(idl_filename)
125 132
126 133
127 def main(): 134 def main():
128 options, idl_filename = parse_options() 135 options, idl_filename = parse_options()
129 idl_compiler = IdlCompilerV8( 136 idl_compiler = IdlCompilerV8(
130 options.output_directory, 137 options.output_directory,
131 cache_directory=options.cache_directory, 138 cache_directory=options.cache_directory,
132 interfaces_info_filename=options.interfaces_info_file, 139 interfaces_info_filename=options.interfaces_info_file,
133 only_if_changed=options.write_file_only_if_changed) 140 only_if_changed=options.write_file_only_if_changed,
141 generate_dictionary_impl=options.generate_dictionary_impl)
134 idl_compiler.compile_file(idl_filename) 142 idl_compiler.compile_file(idl_filename)
135 143
136 144
137 if __name__ == '__main__': 145 if __name__ == '__main__':
138 sys.exit(main()) 146 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698