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

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

Issue 178003010: Make an IdlCompiler class (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 class IdlCompiler(object):
79 def __init__(self, output_directory, interfaces_info, idl_attributes_file, o nly_if_changed=False):
80 self.output_directory = output_directory
81 self.only_if_changed = only_if_changed
82 self.reader = IdlReader(interfaces_info, idl_attributes_file, output_dir ectory)
83 self.code_generator = CodeGeneratorV8(interfaces_info, output_directory)
84
85 def compile(self, idl_filename):
86 basename = os.path.basename(idl_filename)
87 interface_name, _ = os.path.splitext(basename)
88
89 definitions = self.reader.read_idl_definitions(idl_filename)
90 header_text, cpp_text = self.code_generator.generate_code(definitions, i nterface_name)
91
92 header_filename = os.path.join(self.output_directory,
93 'V8%s.h' % interface_name)
94 cpp_filename = os.path.join(self.output_directory,
95 'V8%s.cpp' % interface_name)
96 write_file(header_text, header_filename, self.only_if_changed)
97 write_file(cpp_text, cpp_filename, self.only_if_changed)
98
99
78 def main(): 100 def main():
79 options, idl_filename = parse_options() 101 options, idl_filename = parse_options()
80 basename = os.path.basename(idl_filename)
81 interface_name, _ = os.path.splitext(basename)
82 output_directory = options.output_directory
83 only_if_changed = options.write_file_only_if_changed
84 102
85 interfaces_info_filename = options.interfaces_info_file 103 interfaces_info_filename = options.interfaces_info_file
86 if interfaces_info_filename: 104 if interfaces_info_filename:
87 with open(interfaces_info_filename) as interfaces_info_file: 105 with open(interfaces_info_filename) as interfaces_info_file:
88 interfaces_info = pickle.load(interfaces_info_file) 106 interfaces_info = pickle.load(interfaces_info_file)
89 else: 107 else:
90 interfaces_info = None 108 interfaces_info = None
91 109
92 reader = IdlReader(interfaces_info, options.idl_attributes_file, output_dire ctory) 110 idl_compiler = IdlCompiler(options.output_directory,
93 definitions = reader.read_idl_definitions(idl_filename) 111 interfaces_info,
94 112 options.idl_attributes_file,
95 code_generator = CodeGeneratorV8(interfaces_info, output_directory) 113 options.write_file_only_if_changed)
96 header_text, cpp_text = code_generator.generate_code(definitions, interface_ name) 114 idl_compiler.compile(idl_filename)
97
98 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 write_file(header_text, header_filename, only_if_changed)
101 write_file(cpp_text, cpp_filename, only_if_changed)
102
103 115
104 if __name__ == '__main__': 116 if __name__ == '__main__':
105 sys.exit(main()) 117 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698