OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 # |
| 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are |
| 6 # met: |
| 7 # |
| 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above |
| 11 # copyright notice, this list of conditions and the following disclaimer |
| 12 # in the documentation and/or other materials provided with the |
| 13 # distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived from |
| 16 # this software without specific prior written permission. |
| 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
| 30 import optparse |
| 31 import os.path |
| 32 import pickle |
| 33 import sys |
| 34 |
| 35 # import blink_idl_parser # FIXME: not checked in yet |
| 36 # import json_import_export # FIXME: not using JSON |
| 37 import code_generator_v8 |
| 38 # import interface_merger # FIXME: not checked in yet |
| 39 # import semantic_analyzer # FIXME: not checked in yet |
| 40 |
| 41 |
| 42 def parse_options(): |
| 43 parser = optparse.OptionParser() |
| 44 parser.add_option('--include', dest='idl_directories', action='append') |
| 45 parser.add_option('--output-directory') |
| 46 parser.add_option('--output-headers-directory') |
| 47 parser.add_option('--defines') |
| 48 parser.add_option('--filename') |
| 49 parser.add_option('--verbose', type='int') # FIXME: replace with flag: acti
on='store_true', default=False |
| 50 parser.add_option('--supplemental-dependency-file') |
| 51 parser.add_option('--additional-idl-files', default='') |
| 52 parser.add_option('--idl-attributes-file') |
| 53 parser.add_option('--write-file-only-if-changed', type='int') |
| 54 parser.add_option('--perl-parser', action='store_true', default=False) |
| 55 parser.disable_interspersed_args() # ensure output comes last, so command l
ine easy to parse via regexes (e.g., sanitize-win-build-log.sed) |
| 56 |
| 57 options, args = parser.parse_args() |
| 58 if options.output_directory is None: |
| 59 parser.error('Must specify output directory using --output-directory.') |
| 60 if options.output_headers_directory is None: |
| 61 options.output_headers_directory = options.output_directory |
| 62 if len(args) != 1: |
| 63 parser.error('Must specify exactly 1 input file as argument, but %d give
n.' % len(args)) |
| 64 options.target_idl_file = args[0] |
| 65 return options |
| 66 |
| 67 |
| 68 def read_pickled_idl(interface_name): |
| 69 # Assume pickled file in current directory; |
| 70 # feel free to customize as desired |
| 71 pickle_filename = interface_name + '.pkl' |
| 72 with open(pickle_filename, 'rb') as pickle_file: |
| 73 return pickle.load(pickle_file) |
| 74 |
| 75 |
| 76 def main(): |
| 77 options = parse_options() |
| 78 target_idl_file = os.path.realpath(options.target_idl_file) |
| 79 target_basename = os.path.basename(options.target_idl_file) |
| 80 target_interface_name, _ = os.path.splitext(target_basename) |
| 81 if options.verbose: |
| 82 print target_idl_file |
| 83 |
| 84 # Compute dependencies |
| 85 supplementary_idl_files = [] |
| 86 # FIXME: turn on |
| 87 #if options.supplemental_dependency_file: |
| 88 # try: |
| 89 # supplementary_idl_files = interface_merger.compute_supplementary_id
l_files(target_basename, options.supplemental_dependency_file, options.additiona
l_idl_files) |
| 90 # except interface_merger.IdlNotFoundError: |
| 91 # # We generate empty .h and .cpp files just to tell build scripts th
at .h and .cpp files are created. |
| 92 # code_generator_v8.generate_empty_header_and_cpp(target_interface_na
me, options.output_headers_directory, options.output_directory) |
| 93 # return |
| 94 |
| 95 # Parse the target IDL file |
| 96 # target_document = json_import_export.parse_file(target_idl_file) # Actual
read JSON |
| 97 target_document = read_pickled_idl(target_interface_name) |
| 98 # FIXME: switch to Python parser |
| 99 # parser = BlinkIDLParser(verbose=options.verbose) |
| 100 # return parser.Parse(target_idl_file, defines) |
| 101 |
| 102 # FIXME: turn on |
| 103 # Post-process: check attributes and merge partial interfaces |
| 104 #if options.idl_attributes_file is not None: |
| 105 # attribute_checker = semantic_analyzer.IDLAttributeChecker(options.idl_a
ttributes_file) |
| 106 # attribute_checker.check_idl_attributes(target_document, target_basename
) |
| 107 #interface_merger.merge_partial_interfaces(target_document, target_interface
_name, target_idl_file, supplementary_idl_files, options) |
| 108 |
| 109 # Generate desired output for the target IDL file |
| 110 dependent_idl_files = [target_basename] + supplementary_idl_files |
| 111 code_generator = code_generator_v8.CodeGenerator(target_document, dependent_
idl_files, options) |
| 112 code_generator.write_interfaces(options.output_directory, options.output_hea
ders_directory) |
| 113 |
| 114 |
| 115 if __name__ == '__main__': |
| 116 sys.exit(main()) |
OLD | NEW |