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 23 matching lines...) Expand all Loading... | |
| 34 [1] Perl: deprecated_generate_bindings.pl, which calls: | 34 [1] Perl: deprecated_generate_bindings.pl, which calls: |
| 35 deprecated_idl_parser.pm => deprecated_code_generator_v8.pm | 35 deprecated_idl_parser.pm => deprecated_code_generator_v8.pm |
| 36 [2] Python: idl_compiler.py, which calls: | 36 [2] Python: idl_compiler.py, which calls: |
| 37 IDL lexer => IDL parser => Python object builder => | 37 IDL lexer => IDL parser => Python object builder => |
| 38 interface dependency resolver => IDL semantic validator => | 38 interface dependency resolver => IDL semantic validator => |
| 39 C++ code generator | 39 C++ code generator |
| 40 | 40 |
| 41 We will move IDL files from the Perl build flow [1] to the Python build flow [2] | 41 We will move IDL files from the Perl build flow [1] to the Python build flow [2] |
| 42 incrementally. See http://crbug.com/239771 | 42 incrementally. See http://crbug.com/239771 |
| 43 """ | 43 """ |
| 44 import pickle | |
|
haraken
2013/07/16 14:17:51
Nit: alphabetical order please.
Nils Barth (inactive)
2013/07/17 12:05:09
Oops, fixed.
| |
| 44 import optparse | 45 import optparse |
| 45 import os | 46 import os |
| 46 import shlex | 47 import shlex |
| 47 import sys | 48 import sys |
| 48 | 49 |
| 50 import code_generator_v8 | |
| 49 import idl_reader | 51 import idl_reader |
| 50 import code_generator_v8 | |
| 51 | 52 |
| 52 | 53 |
| 53 def parse_options(): | 54 def parse_options(): |
| 54 parser = optparse.OptionParser() | 55 parser = optparse.OptionParser() |
| 55 parser.add_option('--additional-idl-files') | 56 parser.add_option('--additional-idl-files') |
| 57 parser.add_option('--dump-json-and-pickle', action='store_true', default=Fal se) | |
| 56 parser.add_option('--idl-attributes-file') | 58 parser.add_option('--idl-attributes-file') |
| 57 parser.add_option('--include', dest='idl_directories', action='append') | 59 parser.add_option('--include', dest='idl_directories', action='append') |
| 58 parser.add_option('--output-directory') | 60 parser.add_option('--output-directory') |
| 59 parser.add_option('--interface-dependencies-file') | 61 parser.add_option('--interface-dependencies-file') |
| 60 parser.add_option('--verbose', action='store_true', default=False) | 62 parser.add_option('--verbose', action='store_true', default=False) |
| 61 parser.add_option('--write-file-only-if-changed', type='int') | 63 parser.add_option('--write-file-only-if-changed', type='int') |
| 62 # ensure output comes last, so command line easy to parse via regexes | 64 # ensure output comes last, so command line easy to parse via regexes |
| 63 parser.disable_interspersed_args() | 65 parser.disable_interspersed_args() |
| 64 | 66 |
| 65 options, args = parser.parse_args() | 67 options, args = parser.parse_args() |
| 66 if options.output_directory is None: | 68 if options.output_directory is None: |
| 67 parser.error('Must specify output directory using --output-directory.') | 69 parser.error('Must specify output directory using --output-directory.') |
| 68 if options.additional_idl_files is not None: | 70 if options.additional_idl_files is not None: |
| 69 # additional_idl_files is passed as a string with varied (shell-style) | 71 # additional_idl_files is passed as a string with varied (shell-style) |
| 70 # quoting, hence needs parsing. | 72 # quoting, hence needs parsing. |
| 71 options.additional_idl_files = shlex.split(options.additional_idl_files) | 73 options.additional_idl_files = shlex.split(options.additional_idl_files) |
| 72 if len(args) != 1: | 74 if len(args) != 1: |
| 73 parser.error('Must specify exactly 1 input file as argument, but %d give n.' % len(args)) | 75 parser.error('Must specify exactly 1 input file as argument, but %d give n.' % len(args)) |
| 74 options.idl_filename = os.path.realpath(args[0]) | 76 options.idl_filename = os.path.realpath(args[0]) |
| 75 return options | 77 return options |
| 76 | 78 |
| 77 | 79 |
| 80 def write_json_and_pickle(definitions, interface_name, output_directory): | |
|
haraken
2013/07/16 14:17:51
I'm OK with leaving this option until you finish m
Nils Barth (inactive)
2013/07/17 12:05:09
(As above.) Done.
| |
| 81 json_string = definitions.to_json() | |
| 82 json_basename = interface_name + '.json' | |
| 83 json_filename = os.path.join(output_directory, json_basename) | |
| 84 with open(json_filename, 'w') as json_file: | |
| 85 json_file.write(json_string) | |
| 86 # Pickle export (for Koji) | |
|
haraken
2013/07/16 14:17:51
Nit: Remove this comment.
Nils Barth (inactive)
2013/07/17 12:05:09
Done.
| |
| 87 pickle_basename = interface_name + '.pkl' | |
| 88 pickle_filename = os.path.join(output_directory, pickle_basename) | |
| 89 with open(pickle_filename, 'wb') as pickle_file: | |
| 90 pickle.dump(definitions, pickle_file) | |
| 91 | |
| 92 | |
| 78 def main(): | 93 def main(): |
| 79 options = parse_options() | 94 options = parse_options() |
| 80 idl_filename = options.idl_filename | 95 idl_filename = options.idl_filename |
| 81 basename = os.path.basename(idl_filename) | 96 basename = os.path.basename(idl_filename) |
| 82 interface_name, _ = os.path.splitext(basename) | 97 interface_name, _ = os.path.splitext(basename) |
| 83 verbose = options.verbose | 98 verbose = options.verbose |
| 84 if verbose: | 99 if verbose: |
| 85 print idl_filename | 100 print idl_filename |
| 86 | 101 |
| 87 idl_definitions = idl_reader.read_idl_definitions(idl_filename, options.inte rface_dependencies_file, options.additional_idl_files) | 102 definitions = idl_reader.read_idl_definitions(idl_filename, options.interfac e_dependencies_file, options.additional_idl_files, options.idl_attributes_file, verbose=options.verbose) |
| 88 # FIXME: add parameters when add validator | 103 if not definitions: |
| 89 # idl_definitions = idl_reader.read_idl_interface(idl_filename, options.inte rface_dependencies_file, options.additional_idl_files, options.idl_attributes_fi le, verbose=verbose) | |
| 90 if not idl_definitions: | |
| 91 # We generate dummy .h and .cpp files just to tell build scripts | 104 # We generate dummy .h and .cpp files just to tell build scripts |
| 92 # that outputs have been created. | 105 # that outputs have been created. |
| 93 code_generator_v8.generate_dummy_header_and_cpp(interface_name, options. output_directory) | 106 code_generator_v8.generate_dummy_header_and_cpp(interface_name, options. output_directory) |
| 94 return | 107 return |
| 108 if options.dump_json_and_pickle: | |
| 109 write_json_and_pickle(definitions, interface_name, options.output_direct ory) | |
| 110 return | |
| 95 # FIXME: turn on code generator | 111 # FIXME: turn on code generator |
| 96 # Currently idl_definitions must be None (so dummy .h and .cpp files are | 112 # Currently definitions must be None (so dummy .h and .cpp files are |
| 97 # generated), as actual code generator not present yet. | 113 # generated), or --dump-json-and-pickle selected, as actual code generator |
| 98 # code_generator_v8.write_interface(idl_definitions, interface_name, options .output_directory) | 114 # not present yet. |
| 115 # code_generator_v8.write_interface(definitions, interface_name, options.out put_directory) | |
| 99 raise RuntimeError('Stub: code generator not implemented yet') | 116 raise RuntimeError('Stub: code generator not implemented yet') |
| 100 | 117 |
| 101 | 118 |
| 102 if __name__ == '__main__': | 119 if __name__ == '__main__': |
| 103 sys.exit(main()) | 120 sys.exit(main()) |
| OLD | NEW |