Chromium Code Reviews| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 # FIXME: import from utilities once moved into same directory (lines vs. text) | 68 # FIXME: import from utilities once moved into same directory (lines vs. text) |
| 69 def write_file(new_text, destination_filename, only_if_changed): | 69 def write_file(new_text, destination_filename, only_if_changed): |
| 70 if only_if_changed and os.path.isfile(destination_filename): | 70 if only_if_changed and os.path.isfile(destination_filename): |
| 71 with open(destination_filename) as destination_file: | 71 with open(destination_filename) as destination_file: |
| 72 if destination_file.read() == new_text: | 72 if destination_file.read() == new_text: |
| 73 return | 73 return |
| 74 with open(destination_filename, 'w') as destination_file: | 74 with open(destination_filename, 'w') as destination_file: |
| 75 destination_file.write(new_text) | 75 destination_file.write(new_text) |
| 76 | 76 |
| 77 | 77 |
| 78 def main(): | 78 def compile_idl(idl_filename, output_directory, idl_attributes_file, |
|
Nils Barth (inactive)
2014/03/03 01:32:48
Initialization makes this a bit ugly.
Let's make t
Nils Barth (inactive)
2014/03/03 06:45:49
This is useful enough that I'm posting it in anoth
terry
2014/03/13 19:58:18
Right - you've added the abstract class.
On 2014/0
| |
| 79 options, idl_filename = parse_options() | 79 interfaces_info_file=None, only_if_changed=True, reader=None, |
| 80 code_generator=CodeGeneratorV8): | |
| 80 basename = os.path.basename(idl_filename) | 81 basename = os.path.basename(idl_filename) |
| 81 interface_name, _ = os.path.splitext(basename) | 82 interface_name, _ = os.path.splitext(basename) |
| 82 output_directory = options.output_directory | 83 output_directory = output_directory |
|
Nils Barth (inactive)
2014/03/03 01:32:48
I don't think this line is necessary ;)
terry
2014/03/13 19:58:18
Not necessary since self.output_directory is set o
| |
| 83 only_if_changed = options.write_file_only_if_changed | |
| 84 | 84 |
| 85 interfaces_info_filename = options.interfaces_info_file | 85 interfaces_info_filename = interfaces_info_file |
| 86 if interfaces_info_filename: | 86 if interfaces_info_filename: |
| 87 with open(interfaces_info_filename) as interfaces_info_file: | 87 with open(interfaces_info_filename) as interfaces_info_file: |
| 88 interfaces_info = pickle.load(interfaces_info_file) | 88 interfaces_info = pickle.load(interfaces_info_file) |
| 89 else: | 89 else: |
| 90 interfaces_info = None | 90 interfaces_info = None |
| 91 | 91 |
| 92 reader = IdlReader(interfaces_info, options.idl_attributes_file, output_dire ctory) | 92 if reader == None: |
| 93 reader = IdlReader(interfaces_info, idl_attributes_file, output_director y) | |
| 93 definitions = reader.read_idl_definitions(idl_filename) | 94 definitions = reader.read_idl_definitions(idl_filename) |
| 94 | 95 |
| 95 code_generator = CodeGeneratorV8(interfaces_info, output_directory) | 96 cg = code_generator(interfaces_info, output_directory) |
|
Nils Barth (inactive)
2014/03/03 01:32:48
In Blink we use full words for names, so |code_gen
terry
2014/03/13 19:58:18
ok.
On 2014/03/03 01:32:48, Nils Barth wrote:
| |
| 96 header_text, cpp_text = code_generator.generate_code(definitions, interface_ name) | 97 header_text, cpp_text = cg.generate_code(definitions, interface_name) |
| 97 | 98 |
| 98 header_filename = os.path.join(output_directory, 'V8%s.h' % interface_name) | 99 header_filename = os.path.join(output_directory, 'V8%s.h' % interface_name) |
| 99 cpp_filename = os.path.join(output_directory, 'V8%s.cpp' % interface_name) | 100 cpp_filename = os.path.join(output_directory, 'V8%s.cpp' % interface_name) |
| 100 write_file(header_text, header_filename, only_if_changed) | 101 write_file(header_text, header_filename, only_if_changed) |
| 101 write_file(cpp_text, cpp_filename, only_if_changed) | 102 write_file(cpp_text, cpp_filename, only_if_changed) |
| 102 | 103 |
| 104 return reader | |
| 105 | |
| 106 | |
| 107 def main(): | |
| 108 options, idl_filename = parse_options() | |
| 109 compile_idl(idl_filename, options.output_directory, options.idl_attributes_f ile, | |
| 110 options.interfaces_info_file, options.write_file_only_if_changed ) | |
| 111 | |
| 103 | 112 |
| 104 if __name__ == '__main__': | 113 if __name__ == '__main__': |
| 105 sys.exit(main()) | 114 sys.exit(main()) |
| OLD | NEW |