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

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

Issue 386963003: [WIP][NotForLand] IDL dictionary support (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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 30 matching lines...) Expand all
41 from code_generator_v8 import CodeGeneratorV8 41 from code_generator_v8 import CodeGeneratorV8
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('--output-directory') 50 parser.add_option('--output-directory')
51 parser.add_option('--impl-output-directory')
51 parser.add_option('--interfaces-info-file') 52 parser.add_option('--interfaces-info-file')
52 parser.add_option('--write-file-only-if-changed', type='int') 53 parser.add_option('--write-file-only-if-changed', type='int')
53 # ensure output comes last, so command line easy to parse via regexes 54 # ensure output comes last, so command line easy to parse via regexes
54 parser.disable_interspersed_args() 55 parser.disable_interspersed_args()
55 56
56 options, args = parser.parse_args() 57 options, args = parser.parse_args()
57 if options.output_directory is None: 58 if options.output_directory is None:
58 parser.error('Must specify output directory using --output-directory.') 59 parser.error('Must specify output directory using --output-directory.')
59 options.write_file_only_if_changed = bool(options.write_file_only_if_changed ) 60 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
60 if len(args) != 1: 61 if len(args) != 1:
(...skipping 11 matching lines...) Expand all
72 class IdlCompiler(object): 73 class IdlCompiler(object):
73 """Abstract Base Class for IDL compilers. 74 """Abstract Base Class for IDL compilers.
74 75
75 In concrete classes: 76 In concrete classes:
76 * self.code_generator must be set, implementing generate_code() 77 * self.code_generator must be set, implementing generate_code()
77 (returning a list of output code), and 78 (returning a list of output code), and
78 * compile_file() must be implemented (handling output filenames). 79 * compile_file() must be implemented (handling output filenames).
79 """ 80 """
80 __metaclass__ = abc.ABCMeta 81 __metaclass__ = abc.ABCMeta
81 82
82 def __init__(self, output_directory, cache_directory='', 83 def __init__(self, output_directory, impl_output_directory=None,
Nils Barth (inactive) 2014/07/18 21:52:34 None => '' (blank string better default)
84 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):
85 """ 87 """
86 Args: 88 Args:
87 interfaces_info: 89 interfaces_info:
88 interfaces_info dict 90 interfaces_info dict
89 (avoids auxiliary file in run-bindings-tests) 91 (avoids auxiliary file in run-bindings-tests)
90 interfaces_info_file: filename of pickled interfaces_info 92 interfaces_info_file: filename of pickled interfaces_info
91 """ 93 """
92 cache_directory = cache_directory or output_directory 94 cache_directory = cache_directory or output_directory
93 self.cache_directory = cache_directory 95 self.cache_directory = cache_directory
94 self.code_generator = code_generator 96 self.code_generator = code_generator
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)
100 self.impl_output_directory = impl_output_directory
98 self.interfaces_info = interfaces_info 101 self.interfaces_info = interfaces_info
99 self.only_if_changed = only_if_changed 102 self.only_if_changed = only_if_changed
100 self.output_directory = output_directory 103 self.output_directory = output_directory
101 self.reader = IdlReader(interfaces_info, cache_directory) 104 self.reader = IdlReader(interfaces_info, cache_directory)
102 105
103 def compile_and_write(self, idl_filename, output_filenames): 106 def compile_and_write(self, idl_filename):
104 interface_name = idl_filename_to_interface_name(idl_filename) 107 interface_name = idl_filename_to_interface_name(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 generation_results = self.code_generator.generate_code(
107 definitions, interface_name) 110 definitions, interface_name)
108 for output_code, output_filename in zip(output_code_list, 111 for result in generation_results:
109 output_filenames): 112 write_file(result.output_code, result.output_path,
110 write_file(output_code, output_filename, self.only_if_changed) 113 self.only_if_changed)
111 114
112 @abc.abstractmethod 115 @abc.abstractmethod
113 def compile_file(self, idl_filename): 116 def compile_file(self, idl_filename):
114 pass 117 pass
115 118
116 119
117 class IdlCompilerV8(IdlCompiler): 120 class IdlCompilerV8(IdlCompiler):
118 def __init__(self, *args, **kwargs): 121 def __init__(self, *args, **kwargs):
119 IdlCompiler.__init__(self, *args, **kwargs) 122 IdlCompiler.__init__(self, *args, **kwargs)
120 self.code_generator = CodeGeneratorV8(self.interfaces_info, 123 self.code_generator = CodeGeneratorV8(self.interfaces_info,
121 self.cache_directory) 124 self.cache_directory,
125 self.output_directory,
126 self.impl_output_directory)
122 127
123 def compile_file(self, idl_filename): 128 def compile_file(self, idl_filename):
124 interface_name = idl_filename_to_interface_name(idl_filename) 129 self.compile_and_write(idl_filename)
125 header_filename = os.path.join(self.output_directory,
126 'V8%s.h' % interface_name)
127 cpp_filename = os.path.join(self.output_directory,
128 'V8%s.cpp' % interface_name)
129 self.compile_and_write(idl_filename, (header_filename, cpp_filename))
130 130
131 131
132 def main(): 132 def main():
133 options, idl_filename = parse_options() 133 options, idl_filename = parse_options()
134 idl_compiler = IdlCompilerV8( 134 idl_compiler = IdlCompilerV8(
135 options.output_directory, 135 options.output_directory,
136 options.impl_output_directory,
136 cache_directory=options.cache_directory, 137 cache_directory=options.cache_directory,
137 interfaces_info_filename=options.interfaces_info_file, 138 interfaces_info_filename=options.interfaces_info_file,
138 only_if_changed=options.write_file_only_if_changed) 139 only_if_changed=options.write_file_only_if_changed)
139 idl_compiler.compile_file(idl_filename) 140 idl_compiler.compile_file(idl_filename)
140 141
141 142
142 if __name__ == '__main__': 143 if __name__ == '__main__':
143 sys.exit(main()) 144 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698