OLD | NEW |
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 self.cache_directory = cache_directory | 93 self.cache_directory = cache_directory |
94 self.code_generator = code_generator | 94 self.code_generator = code_generator |
95 if interfaces_info_filename: | 95 if interfaces_info_filename: |
96 with open(interfaces_info_filename) as interfaces_info_file: | 96 with open(interfaces_info_filename) as interfaces_info_file: |
97 interfaces_info = pickle.load(interfaces_info_file) | 97 interfaces_info = pickle.load(interfaces_info_file) |
98 self.interfaces_info = interfaces_info | 98 self.interfaces_info = interfaces_info |
99 self.only_if_changed = only_if_changed | 99 self.only_if_changed = only_if_changed |
100 self.output_directory = output_directory | 100 self.output_directory = output_directory |
101 self.reader = IdlReader(interfaces_info, cache_directory) | 101 self.reader = IdlReader(interfaces_info, cache_directory) |
102 | 102 |
103 def compile_and_write(self, idl_filename, output_filenames): | 103 def compile_and_write(self, idl_filename): |
104 interface_name = idl_filename_to_interface_name(idl_filename) | 104 interface_name = idl_filename_to_interface_name(idl_filename) |
105 definitions = self.reader.read_idl_definitions(idl_filename) | 105 definitions = self.reader.read_idl_definitions(idl_filename) |
106 output_code_list = self.code_generator.generate_code( | 106 output_code_list = self.code_generator.generate_code( |
107 definitions, interface_name) | 107 definitions, interface_name) |
108 for output_code, output_filename in zip(output_code_list, | 108 for output_path, output_code in output_code_list: |
109 output_filenames): | 109 write_file(output_code, output_path, self.only_if_changed) |
110 write_file(output_code, output_filename, self.only_if_changed) | |
111 | 110 |
112 @abc.abstractmethod | 111 @abc.abstractmethod |
113 def compile_file(self, idl_filename): | 112 def compile_file(self, idl_filename): |
114 pass | 113 pass |
115 | 114 |
116 | 115 |
117 class IdlCompilerV8(IdlCompiler): | 116 class IdlCompilerV8(IdlCompiler): |
118 def __init__(self, *args, **kwargs): | 117 def __init__(self, *args, **kwargs): |
119 IdlCompiler.__init__(self, *args, **kwargs) | 118 IdlCompiler.__init__(self, *args, **kwargs) |
120 self.code_generator = CodeGeneratorV8(self.interfaces_info, | 119 self.code_generator = CodeGeneratorV8(self.interfaces_info, |
121 self.cache_directory) | 120 self.cache_directory, |
| 121 self.output_directory) |
122 | 122 |
123 def compile_file(self, idl_filename): | 123 def compile_file(self, idl_filename): |
124 interface_name = idl_filename_to_interface_name(idl_filename) | 124 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 | 125 |
131 | 126 |
132 def main(): | 127 def main(): |
133 options, idl_filename = parse_options() | 128 options, idl_filename = parse_options() |
134 idl_compiler = IdlCompilerV8( | 129 idl_compiler = IdlCompilerV8( |
135 options.output_directory, | 130 options.output_directory, |
136 cache_directory=options.cache_directory, | 131 cache_directory=options.cache_directory, |
137 interfaces_info_filename=options.interfaces_info_file, | 132 interfaces_info_filename=options.interfaces_info_file, |
138 only_if_changed=options.write_file_only_if_changed) | 133 only_if_changed=options.write_file_only_if_changed) |
139 idl_compiler.compile_file(idl_filename) | 134 idl_compiler.compile_file(idl_filename) |
140 | 135 |
141 | 136 |
142 if __name__ == '__main__': | 137 if __name__ == '__main__': |
143 sys.exit(main()) | 138 sys.exit(main()) |
OLD | NEW |