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 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 FIXME: Not currently used in build. | 32 FIXME: Not currently used in build. |
33 This is a rewrite of the Perl IDL compiler in Python, but is not complete. | 33 This is a rewrite of the Perl IDL compiler in Python, but is not complete. |
34 Once it is complete, we will switch all IDL files over to Python at once. | 34 Once it is complete, we will switch all IDL files over to Python at once. |
35 Until then, please work on the Perl IDL compiler. | 35 Until then, please work on the Perl IDL compiler. |
36 For details, see bug http://crbug.com/239771 | 36 For details, see bug http://crbug.com/239771 |
37 """ | 37 """ |
38 | 38 |
39 import optparse | 39 import optparse |
40 import os | 40 import os |
41 import cPickle as pickle | |
42 import sys | 41 import sys |
43 | 42 |
44 import code_generator_v8 | 43 import code_generator_v8 |
45 import idl_reader | 44 import idl_reader |
46 | 45 |
47 def parse_options(): | 46 def parse_options(): |
48 parser = optparse.OptionParser() | 47 parser = optparse.OptionParser() |
49 parser.add_option('--idl-attributes-file') | 48 parser.add_option('--idl-attributes-file') |
50 parser.add_option('--output-directory') | 49 parser.add_option('--output-directory') |
51 parser.add_option('--interfaces-info-file') | |
52 parser.add_option('--write-file-only-if-changed', type='int') | 50 parser.add_option('--write-file-only-if-changed', type='int') |
53 # ensure output comes last, so command line easy to parse via regexes | 51 # ensure output comes last, so command line easy to parse via regexes |
54 parser.disable_interspersed_args() | 52 parser.disable_interspersed_args() |
55 | 53 |
56 options, args = parser.parse_args() | 54 options, args = parser.parse_args() |
57 if options.output_directory is None: | 55 if options.output_directory is None: |
58 parser.error('Must specify output directory using --output-directory.') | 56 parser.error('Must specify output directory using --output-directory.') |
59 if len(args) != 1: | 57 if len(args) != 1: |
60 parser.error('Must specify exactly 1 input file as argument, but %d give n.' % len(args)) | 58 parser.error('Must specify exactly 1 input file as argument, but %d give n.' % len(args)) |
61 idl_filename = os.path.realpath(args[0]) | 59 idl_filename = os.path.realpath(args[0]) |
62 return options, idl_filename | 60 return options, idl_filename |
63 | 61 |
64 | 62 |
63 def compile_idl(idl_filename, output_directory, idl_attributes_file, | |
64 curr_interfaces_info={}, reader=None, | |
65 write_header_and_cpp=code_generator_v8.write_header_and_cpp): | |
Nils Barth (inactive)
2014/02/25 07:29:59
I ultimately decided that a code generator object
terry
2014/02/27 23:40:26
This works for me right now. Maybe an abstract ca
| |
66 basename = os.path.basename(idl_filename) | |
67 interface_name, _ = os.path.splitext(basename) | |
68 output_directory = output_directory | |
69 | |
70 interfaces_info = curr_interfaces_info | |
71 | |
72 if reader == None: | |
73 reader = idl_reader.IdlReader(interfaces_info, idl_attributes_file, outp ut_directory) | |
74 definitions = reader.read_idl_definitions(idl_filename) | |
75 write_header_and_cpp(definitions, interface_name, interfaces_info, output_di rectory) | |
76 | |
77 return reader | |
78 | |
79 | |
65 def main(): | 80 def main(): |
66 options, idl_filename = parse_options() | 81 options, idl_filename = parse_options() |
67 basename = os.path.basename(idl_filename) | 82 compile_idl(idl_filename, options.output_directory, options.idl_attributes_f ile) |
68 interface_name, _ = os.path.splitext(basename) | |
69 output_directory = options.output_directory | |
70 | |
71 interfaces_info_filename = options.interfaces_info_file | |
72 if interfaces_info_filename: | |
73 with open(interfaces_info_filename) as interfaces_info_file: | |
74 interfaces_info = pickle.load(interfaces_info_file) | |
75 else: | |
76 interfaces_info = None | |
77 | |
78 reader = idl_reader.IdlReader(interfaces_info, options.idl_attributes_file, output_directory) | |
79 definitions = reader.read_idl_definitions(idl_filename) | |
80 code_generator_v8.write_header_and_cpp(definitions, interface_name, interfac es_info, output_directory) | |
81 | |
82 | 83 |
83 if __name__ == '__main__': | 84 if __name__ == '__main__': |
84 sys.exit(main()) | 85 sys.exit(main()) |
OLD | NEW |